jenkins.model.Jenkins.checkGoodName()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(222)

本文整理了Java中jenkins.model.Jenkins.checkGoodName()方法的一些代码示例,展示了Jenkins.checkGoodName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.checkGoodName()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:checkGoodName

Jenkins.checkGoodName介绍

[英]Check if the given name is suitable as a name for job, view, etc.
[中]检查给定名称是否适合作为作业、视图等的名称。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Instantiate View subtype from XML stream.
  3. *
  4. * @param name Alternative name to use or {@code null} to keep the one in xml.
  5. */
  6. public static View createViewFromXML(String name, InputStream xml) throws IOException {
  7. try (InputStream in = new BufferedInputStream(xml)) {
  8. View v = (View) Jenkins.XSTREAM.fromXML(in);
  9. if (name != null) v.name = name;
  10. Jenkins.checkGoodName(v.name);
  11. return v;
  12. } catch(StreamException|ConversionException|Error e) {// mostly reflection errors
  13. throw new IOException("Unable to read",e);
  14. }
  15. }

代码示例来源:origin: jenkinsci/jenkins

  1. public static boolean needsEscape(String name) {
  2. try {
  3. Jenkins.checkGoodName(name);
  4. // additional restricted chars
  5. for( int i=0; i<name.length(); i++ ) {
  6. char ch = name.charAt(i);
  7. if(" ()\t\n".indexOf(ch)!=-1)
  8. return true;
  9. }
  10. return false;
  11. } catch (Failure failure) {
  12. return true;
  13. }
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. public FormValidation doCheckName(@QueryParameter String value ) {
  2. String name = Util.fixEmptyAndTrim(value);
  3. if(name==null)
  4. return FormValidation.error(Messages.NodeDescriptor_CheckName_Mandatory());
  5. try {
  6. Jenkins.checkGoodName(name);
  7. } catch (Failure f) {
  8. return FormValidation.error(f.getMessage());
  9. }
  10. return FormValidation.ok();
  11. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Creates a new log recorder.
  3. */
  4. @RequirePOST
  5. public HttpResponse doNewLogRecorder(@QueryParameter String name) {
  6. Jenkins.checkGoodName(name);
  7. logRecorders.put(name,new LogRecorder(name));
  8. // redirect to the config screen
  9. return new HttpRedirect(name+"/configure");
  10. }

代码示例来源:origin: jenkinsci/jenkins

  1. protected int run() throws Exception {
  2. Jenkins h = Jenkins.getActiveInstance();
  3. if (h.getItemByFullName(name)!=null) {
  4. throw new IllegalStateException("Job '"+name+"' already exists");
  5. }
  6. ModifiableTopLevelItemGroup ig = h;
  7. int i = name.lastIndexOf('/');
  8. if (i > 0) {
  9. String group = name.substring(0, i);
  10. Item item = h.getItemByFullName(group);
  11. if (item == null) {
  12. throw new IllegalArgumentException("Unknown ItemGroup " + group);
  13. }
  14. if (item instanceof ModifiableTopLevelItemGroup) {
  15. ig = (ModifiableTopLevelItemGroup) item;
  16. } else {
  17. throw new IllegalStateException("Can't create job from CLI in " + group);
  18. }
  19. name = name.substring(i + 1);
  20. }
  21. Jenkins.checkGoodName(name);
  22. ig.createProjectFromXML(name, stdin);
  23. return 0;
  24. }
  25. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Checks if a top-level view with the given name exists and
  3. * make sure that the name is good as a view name.
  4. */
  5. public FormValidation doCheckViewName(@QueryParameter String value) {
  6. checkPermission(View.CREATE);
  7. String name = fixEmpty(value);
  8. if (name == null)
  9. return FormValidation.ok();
  10. // already exists?
  11. if (getView(name) != null)
  12. return FormValidation.error(Messages.Hudson_ViewAlreadyExists(name));
  13. // good view name?
  14. try {
  15. checkGoodName(name);
  16. } catch (Failure e) {
  17. return FormValidation.error(e.getMessage());
  18. }
  19. return FormValidation.ok();
  20. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Renames this view.
  3. */
  4. public void rename(String newName) throws Failure, FormException {
  5. if(name.equals(newName)) return; // noop
  6. Jenkins.checkGoodName(newName);
  7. if(owner.getView(newName)!=null)
  8. throw new FormException(Messages.Hudson_ViewAlreadyExists(newName),"name");
  9. String oldName = name;
  10. name = newName;
  11. owner.onViewRenamed(this,oldName,newName);
  12. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Makes sure that the given name is good as an agent name.
  3. * @return trimmed name if valid; throws ParseException if not
  4. */
  5. public String checkName(String name) throws Failure {
  6. if(name==null)
  7. throw new Failure("Query parameter 'name' is required");
  8. name = name.trim();
  9. Jenkins.checkGoodName(name);
  10. if(Jenkins.getInstance().getNode(name)!=null)
  11. throw new Failure(Messages.ComputerSet_SlaveAlreadyExists(name));
  12. // looks good
  13. return name;
  14. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Makes sure that the given name is good as a job name.
  3. * For use from {@code newJob}.
  4. */
  5. @Restricted(DoNotUse.class) // called from newJob view
  6. public FormValidation doCheckJobName(@QueryParameter String value) {
  7. // this method can be used to check if a file exists anywhere in the file system,
  8. // so it should be protected.
  9. getOwner().checkPermission(Item.CREATE);
  10. if (Util.fixEmpty(value) == null) {
  11. return FormValidation.ok();
  12. }
  13. try {
  14. Jenkins.checkGoodName(value);
  15. value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same
  16. Jenkins.getInstance().getProjectNamingStrategy().checkName(value);
  17. } catch (Failure e) {
  18. return FormValidation.error(e.getMessage());
  19. }
  20. if (getOwner().getItemGroup().getItem(value) != null) {
  21. return FormValidation.error(Messages.Hudson_JobAlreadyExists(value));
  22. }
  23. // looks good
  24. return FormValidation.ok();
  25. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Called by {@link #doConfirmRename} and {@code rename.jelly} to validate renames.
  3. * @return {@link FormValidation#ok} if this item can be renamed as specified, otherwise
  4. * {@link FormValidation#error} with a message explaining the problem.
  5. */
  6. @Restricted(NoExternalUse.class)
  7. public @Nonnull FormValidation doCheckNewName(@QueryParameter String newName) {
  8. // TODO: Create an Item.RENAME permission to use here, see JENKINS-18649.
  9. if (!hasPermission(Item.CONFIGURE)) {
  10. if (parent instanceof AccessControlled) {
  11. ((AccessControlled)parent).checkPermission(Item.CREATE);
  12. }
  13. checkPermission(Item.DELETE);
  14. }
  15. newName = newName == null ? null : newName.trim();
  16. try {
  17. Jenkins.checkGoodName(newName);
  18. assert newName != null; // Would have thrown Failure
  19. if (newName.equals(name)) {
  20. return FormValidation.warning(Messages.AbstractItem_NewNameUnchanged());
  21. }
  22. Jenkins.get().getProjectNamingStrategy().checkName(newName);
  23. checkIfNameIsUsed(newName);
  24. checkRename(newName);
  25. } catch (Failure e) {
  26. return FormValidation.error(e.getMessage());
  27. }
  28. return FormValidation.ok();
  29. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Accepts submission from the configuration page.
  3. */
  4. @RequirePOST
  5. public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  6. JSONObject src = req.getSubmittedForm();
  7. String newName = src.getString("name"), redirect = ".";
  8. XmlFile oldFile = null;
  9. if(!name.equals(newName)) {
  10. Jenkins.checkGoodName(newName);
  11. oldFile = getConfigFile();
  12. // rename
  13. getParent().logRecorders.remove(name);
  14. this.name = newName;
  15. getParent().logRecorders.put(name,this);
  16. redirect = "../" + Util.rawEncode(newName) + '/';
  17. }
  18. List<Target> newTargets = req.bindJSONToList(Target.class, src.get("targets"));
  19. for (Target t : newTargets)
  20. t.enable();
  21. targets.replaceBy(newTargets);
  22. save();
  23. if (oldFile!=null) oldFile.delete();
  24. rsp.sendRedirect2(redirect);
  25. }

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * Accepts the update to the node configuration.
  3. */
  4. @RequirePOST
  5. public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
  6. checkPermission(CONFIGURE);
  7. String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
  8. Jenkins.checkGoodName(proposedName);
  9. Node node = getNode();
  10. if (node == null) {
  11. throw new ServletException("No such node " + nodeName);
  12. }
  13. if ((!proposedName.equals(nodeName))
  14. && Jenkins.getActiveInstance().getNode(proposedName) != null) {
  15. throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name");
  16. }
  17. String nExecutors = req.getSubmittedForm().getString("numExecutors");
  18. if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) {
  19. throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
  20. }
  21. Node result = node.reconfigure(req, req.getSubmittedForm());
  22. Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result);
  23. // take the user back to the agent top page.
  24. rsp.sendRedirect2("../" + result.getNodeName() + '/');
  25. }

代码示例来源:origin: jenkinsci/jenkins

  1. Jenkins.checkGoodName(name);
  2. if(owner.getView(name)!=null)
  3. throw new Failure(Messages.Hudson_ViewAlreadyExists(name));

代码示例来源:origin: jenkinsci/jenkins

  1. Jenkins.checkGoodName(name);
  2. name = name.trim();
  3. if(parent.getItem(name)!=null)

代码示例来源:origin: i-m-c/jenkins-inheritance-plugin

  1. private FormValidation validGoodName(String variance) {
  2. if (StringUtils.isBlank(variance)) {
  3. return FormValidation.ok();
  4. }
  5. try {
  6. Jenkins.checkGoodName(variance);
  7. return FormValidation.ok();
  8. } catch (Failure e) {
  9. return FormValidation.error(e.getMessage());
  10. }
  11. }
  12. }

代码示例来源:origin: jenkinsci/promoted-builds-plugin

  1. public FormValidation doCheckName(@QueryParameter String name) {
  2. name = Util.fixEmptyAndTrim(name);
  3. if (name == null) {
  4. return FormValidation.error(Messages.JobPropertyImpl_ValidateRequired());
  5. }
  6. try {
  7. Jenkins.checkGoodName(name);
  8. } catch (Failure f) {
  9. return FormValidation.error(f.getMessage());
  10. }
  11. return FormValidation.ok();
  12. }
  13. }

代码示例来源:origin: jenkinsci/openstack-cloud-plugin

  1. @Restricted(DoNotUse.class)
  2. @RequirePOST
  3. public FormValidation doCheckName(@QueryParameter String value) {
  4. try {
  5. Jenkins.checkGoodName(value);
  6. return FormValidation.ok();
  7. } catch (Failure ex) {
  8. return FormValidation.error(ex.getMessage());
  9. }
  10. }
  11. }

代码示例来源:origin: jenkinsci/openstack-cloud-plugin

  1. @Restricted(DoNotUse.class)
  2. @RequirePOST
  3. public FormValidation doCheckName(@QueryParameter String value) {
  4. try {
  5. Jenkins.checkGoodName(value);
  6. return FormValidation.ok();
  7. } catch (Failure ex) {
  8. return FormValidation.error(ex.getMessage());
  9. }
  10. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. /**
  2. * Creates a new log recorder.
  3. */
  4. @RequirePOST
  5. public HttpResponse doNewLogRecorder(@QueryParameter String name) {
  6. Jenkins.checkGoodName(name);
  7. logRecorders.put(name,new LogRecorder(name));
  8. // redirect to the config screen
  9. return new HttpRedirect(name+"/configure");
  10. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. /**
  2. * Renames this view.
  3. */
  4. public void rename(String newName) throws Failure, FormException {
  5. if(name.equals(newName)) return; // noop
  6. Jenkins.checkGoodName(newName);
  7. if(owner.getView(newName)!=null)
  8. throw new FormException(Messages.Hudson_ViewAlreadyExists(newName),"name");
  9. String oldName = name;
  10. name = newName;
  11. owner.onViewRenamed(this,oldName,newName);
  12. }

相关文章

Jenkins类方法