/** Serves <tt>help.html</tt> from the resource of {@link #clazz}. */ public void doHelp(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); if (path.contains("..")) throw new ServletException("Illegal path: " + path); path = path.replace('/', '-'); for (Class c = clazz; c != null; c = c.getSuperclass()) { RequestDispatcher rd = Stapler.getCurrentRequest().getView(c, "help" + path); if (rd != null) { // Jelly-generated help page rd.forward(req, rsp); return; } InputStream in = getHelpStream(c, path); if (in != null) { // TODO: generalize macro expansion and perhaps even support JEXL rsp.setContentType("text/html;charset=UTF-8"); String literal = IOUtils.toString(in, "UTF-8"); rsp.getWriter() .println( Util.replaceMacro( literal, Collections.singletonMap("rootURL", req.getContextPath()))); in.close(); return; } } rsp.sendError(SC_NOT_FOUND); }
/** * Saves the form to the configuration and disk. * * @param req StaplerRequest * @param rsp StaplerResponse * @throws ServletException if something unfortunate happens. * @throws IOException if something unfortunate happens. * @throws InterruptedException if something unfortunate happens. */ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException, InterruptedException { getProject().checkPermission(AbstractProject.BUILD); if (isRebuildAvailable()) { if (!req.getMethod().equals("POST")) { // show the parameter entry form. req.getView(this, "index.jelly").forward(req, rsp); return; } build = req.findAncestorObject(AbstractBuild.class); ParametersDefinitionProperty paramDefProp = build.getProject().getProperty(ParametersDefinitionProperty.class); List<ParameterValue> values = new ArrayList<ParameterValue>(); ParametersAction paramAction = build.getAction(ParametersAction.class); JSONObject formData = req.getSubmittedForm(); if (!formData.isEmpty()) { JSONArray a = JSONArray.fromObject(formData.get("parameter")); for (Object o : a) { JSONObject jo = (JSONObject) o; String name = jo.getString("name"); ParameterValue parameterValue = getParameterValue(paramDefProp, name, paramAction, req, jo); if (parameterValue != null) { values.add(parameterValue); } } } CauseAction cause = new CauseAction(new RebuildCause(build)); Hudson.getInstance() .getQueue() .schedule(build.getProject(), 0, new ParametersAction(values), cause); rsp.sendRedirect("../../"); } }
/** * Call this method while rebuilding non parameterized build. . * * @param currentBuild current build. * @param response current response object. * @throws ServletException if something unfortunate happens. * @throws IOException if something unfortunate happens. * @throws InterruptedException if something unfortunate happens. */ public void nonParameterizedRebuild(AbstractBuild currentBuild, StaplerResponse response) throws ServletException, IOException, InterruptedException { getProject().checkPermission(AbstractProject.BUILD); CauseAction cause = new CauseAction(new RebuildCause(currentBuild)); Hudson.getInstance().getQueue().schedule(currentBuild.getProject(), 0, null, cause); response.sendRedirect("../../"); }
/** * Creates a first admin user account. * * <p>This can be run by anyone, but only to create the very first user account. */ public void doCreateFirstAccount(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (hasSomeUser()) { rsp.sendError(SC_UNAUTHORIZED, "First user was already created"); return; } User u = createAccount(req, rsp, "firstUser.jelly"); if (u != null) { tryToMakeAdmin(u); loginAndTakeBack(req, rsp, u); } }
/** * Handles the rebuild request and redirects to parameterized and non parameterized build when * needed. * * @param request StaplerRequest the request. * @param response StaplerResponse the response handler. * @throws IOException in case of Stapler issues * @throws ServletException if something unfortunate happens. * @throws InterruptedException if something unfortunate happens. */ public void doIndex(StaplerRequest request, StaplerResponse response) throws IOException, ServletException, InterruptedException { AbstractBuild currentBuild = request.findAncestorObject(AbstractBuild.class); if (currentBuild != null) { ParametersAction paramAction = currentBuild.getAction(ParametersAction.class); if (paramAction != null) { response.sendRedirect(PARAMETERIZED_URL); } else { nonParameterizedRebuild(currentBuild, response); } } }