@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { int i=0; try { i = Integer.parseInt(json.getString("quietPeriod")); } catch (NumberFormatException e) { // fall through } try { // for compatibility reasons, this value is stored in Jenkins Jenkins.get().setQuietPeriod(i); return true; } catch (IOException e) { throw new FormException(e,"quietPeriod"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { // for compatibility reasons, the actual value is stored in Jenkins Jenkins j = Jenkins.get(); if (json.has("primaryView")) { final String viewName = json.getString("primaryView"); final View newPrimaryView = j.getView(viewName); if (newPrimaryView == null) { throw new FormException(Messages.GlobalDefaultViewConfiguration_ViewDoesNotExist(viewName), "primaryView"); } j.setPrimaryView(newPrimaryView); } else { // Fallback if the view is not specified j.setPrimaryView(j.getViews().iterator().next()); } return true; } }
@Override protected void submit(StaplerRequest req) throws IOException, ServletException, FormException { String proxiedViewName = req.getSubmittedForm().getString("proxiedViewName"); if (Jenkins.getInstance().getView(proxiedViewName) == null) { throw new FormException("Not an existing global view", "proxiedViewName"); } this.proxiedViewName = proxiedViewName; }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { // for backward compatibility reasons, this configuration is stored in Jenkins Jenkins.getInstance().setNoUsageStatistics(json.has("usageStatisticsCollected") ? null : true); return true; } catch (IOException e) { throw new FormException(e,"usageStatisticsCollected"); } }
j.setSlaveAgentPort(new ServerTcpPort(json.getJSONObject("slaveAgentPort")).getPort()); } catch (IOException e) { throw new hudson.model.Descriptor.FormException(e, "slaveAgentPortType");
throw new FormException(Messages.Slave_InvalidConfig_NoName(), null); throw new FormException(Messages.Slave_InvalidConfig_Executors(name), null);
/** * Accepts the update to the node configuration. */ @RequirePOST public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException { checkPermission(CONFIGURE); String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name")); Jenkins.checkGoodName(proposedName); Node node = getNode(); if (node == null) { throw new ServletException("No such node " + nodeName); } if ((!proposedName.equals(nodeName)) && Jenkins.getActiveInstance().getNode(proposedName) != null) { throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name"); } String nExecutors = req.getSubmittedForm().getString("numExecutors"); if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) { throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors"); } Node result = node.reconfigure(req, req.getSubmittedForm()); Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result); // take the user back to the agent top page. rsp.sendRedirect2("../" + result.getNodeName() + '/'); }
@Override public Details newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (req == null) { // Should never happen, see newInstance() Javadoc throw new FormException("Stapler request is missing in the call", "staplerRequest"); } String pwd = Util.fixEmpty(req.getParameter("user.password")); String pwd2= Util.fixEmpty(req.getParameter("user.password2")); if(!Util.fixNull(pwd).equals(Util.fixNull(pwd2))) throw new FormException("Please confirm the password by typing it twice","user.password2"); String data = Protector.unprotect(pwd); if(data!=null) { String prefix = Stapler.getCurrentRequest().getSession().getId() + ':'; if(data.startsWith(prefix)) return Details.fromHashedPassword(data.substring(prefix.length())); } User user = Util.getNearestAncestorOfTypeOrThrow(req, User.class); // the UserSeedProperty is not touched by the configure page UserSeedProperty userSeedProperty = user.getProperty(UserSeedProperty.class); if (userSeedProperty != null) { userSeedProperty.renewSeed(); } return Details.fromPlainPassword(Util.fixNull(pwd)); }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException { // for compatibility reasons, the actual value is stored in Jenkins Jenkins j = Jenkins.get(); final JSONObject optJSONObject = json.optJSONObject("useProjectNamingStrategy"); if (optJSONObject != null) { final JSONObject strategyObject = optJSONObject.getJSONObject("namingStrategy"); final String className = strategyObject.getString("$class"); try { Class clazz = Class.forName(className, true, j.getPluginManager().uberClassLoader); final ProjectNamingStrategy strategy = (ProjectNamingStrategy) req.bindJSON(clazz, strategyObject); j.setProjectNamingStrategy(strategy); } catch (ClassNotFoundException e) { throw new FormException(e, "namingStrategy"); } } if (j.getProjectNamingStrategy() == null) { j.setProjectNamingStrategy(DefaultProjectNamingStrategy.DEFAULT_NAMING_STRATEGY); } return true; } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { Jenkins j = Jenkins.get(); try { // for compatibility reasons, this value is stored in Jenkins String num = json.getString("numExecutors"); if (!num.matches("\\d+")) { throw new FormException(Messages.Hudson_Computer_IncorrectNumberOfExecutors(),"numExecutors"); } j.setNumExecutors(json.getInt("numExecutors")); if (req.hasParameter("master.mode")) j.setMode(Mode.valueOf(req.getParameter("master.mode"))); else j.setMode(Mode.NORMAL); j.setLabelString(json.optString("labelString", "")); return true; } catch (IOException e) { throw new FormException(e,"numExecutors"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { Jenkins j = Jenkins.get(); JSONObject np = json.getJSONObject("globalNodeProperties"); if (!np.isNullObject()) { j.getGlobalNodeProperties().rebuild(req, np, NodeProperty.for_(j)); } return true; } catch (IOException e) { throw new FormException(e,"globalNodeProperties"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { // for compatibility reasons, this value is stored in Jenkins Jenkins.get().setScmCheckoutRetryCount(json.getInt("scmCheckoutRetryCount")); return true; } catch (IOException e) { throw new FormException(e,"quietPeriod"); } catch (JSONException e) { throw new FormException(e.getMessage(), "quietPeriod"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { Jenkins.get().clouds.rebuildHetero(req,json, Cloud.all(), "cloud"); return true; } catch (IOException e) { throw new FormException(e,"clouds"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { authenticators.rebuildHetero(req,json, QueueItemAuthenticatorDescriptor.all(),"authenticators"); return true; } catch (IOException e) { throw new FormException(e,"authenticators"); } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { artifactManagerFactories.rebuildHetero(req, json, ArtifactManagerFactoryDescriptor.all(), "artifactManagerFactories"); return true; } catch (IOException x) { throw new FormException(x, "artifactManagerFactories"); } }
@Override public DefaultCrumbIssuer newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (req == null) { // This state is prohibited according to the Javadoc of the super method. throw new FormException("DefaultCrumbIssuer new instance method is called for null Stapler request. " + "Such call is prohibited.", "req"); } return req.bindJSON(DefaultCrumbIssuer.class, formData); } }
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (req == null) { // This state is prohibited according to the Javadoc of the super method. throw new FormException("Maven Build Step new instance method is called for null Stapler request. " + "Such call is prohibited.", "req"); } return req.bindJSON(Maven.class,formData); } }
/** * Renames this view. */ public void rename(String newName) throws Failure, FormException { if(name.equals(newName)) return; // noop Jenkins.checkGoodName(newName); if(owner.getView(newName)!=null) throw new FormException(Messages.Hudson_ViewAlreadyExists(newName),"name"); String oldName = name; name = newName; owner.onViewRenamed(this,oldName,newName); }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { for( JSONObject o : StructuredForm.toList(json, "plugin")) Jenkins.get().pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o); return true; } catch (IOException | ServletException e) { throw new FormException(e,"plugin"); } } }
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { try { // for backward compatibility reasons, this configuration is stored in Jenkins Jenkins.getInstance().setNoUsageStatistics(json.has("usageStatisticsCollected") ? null : true); return true; } catch (IOException e) { throw new FormException(e,"usageStatisticsCollected"); } }