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

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

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

Jenkins.getProjectNamingStrategy介绍

[英]The strategy used to check the project names.
[中]用于检查项目名称的策略。

代码示例

代码示例来源: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. @Override
  2. public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException {
  3. // for compatibility reasons, the actual value is stored in Jenkins
  4. Jenkins j = Jenkins.get();
  5. final JSONObject optJSONObject = json.optJSONObject("useProjectNamingStrategy");
  6. if (optJSONObject != null) {
  7. final JSONObject strategyObject = optJSONObject.getJSONObject("namingStrategy");
  8. final String className = strategyObject.getString("$class");
  9. try {
  10. Class clazz = Class.forName(className, true, j.getPluginManager().uberClassLoader);
  11. final ProjectNamingStrategy strategy = (ProjectNamingStrategy) req.bindJSON(clazz, strategyObject);
  12. j.setProjectNamingStrategy(strategy);
  13. } catch (ClassNotFoundException e) {
  14. throw new FormException(e, "namingStrategy");
  15. }
  16. }
  17. if (j.getProjectNamingStrategy() == null) {
  18. j.setProjectNamingStrategy(DefaultProjectNamingStrategy.DEFAULT_NAMING_STRATEGY);
  19. }
  20. return true;
  21. }
  22. }

代码示例来源: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. public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException {
  2. acl.checkPermission(Item.CREATE);
  3. Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  4. Items.verifyItemDoesNotAlreadyExist(parent, name, null);

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

  1. public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify )
  2. throws IOException {
  3. acl.checkPermission(Item.CREATE);
  4. type.checkApplicableIn(parent);
  5. acl.getACL().checkCreatePermission(parent, type);
  6. Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  7. Items.verifyItemDoesNotAlreadyExist(parent, name, null);
  8. TopLevelItem item = type.newInstance(parent, name);
  9. item.onCreatedFromScratch();
  10. item.save();
  11. add(item);
  12. Jenkins.getInstance().rebuildDependencyGraphAsync();
  13. if (notify)
  14. ItemListener.fireOnCreated(item);
  15. return item;
  16. }

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

  1. final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy();
  2. if(namingStrategy.isForceExistingJobs()){
  3. namingStrategy.checkName(name);

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

  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/promoted-builds-plugin

  1. /** @see ItemGroupMixIn#createProjectFromXML */
  2. public PromotionProcess createProcessFromXml(final String name, InputStream xml) throws IOException {
  3. owner.checkPermission(Item.CONFIGURE); // CREATE is ItemGroup-scoped and owner is not an ItemGroup
  4. Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  5. if (getItem(name) != null) {
  6. throw new IllegalArgumentException(owner.getDisplayName() + " already contains an item '" + name + "'");
  7. }
  8. File configXml = Items.getConfigFile(getRootDirFor(name)).getFile();
  9. File dir = configXml.getParentFile();
  10. if (!dir.mkdirs()) {
  11. throw new IOException("Cannot create directories for "+dir);
  12. }
  13. try {
  14. IOUtils.copy(xml, configXml);
  15. PromotionProcess result = Items.whileUpdatingByXml(new MasterToSlaveCallable<PromotionProcess, IOException>() {
  16. @Override public PromotionProcess call() throws IOException {
  17. setOwner(owner);
  18. return getItem(name);
  19. }
  20. });
  21. if (result == null) {
  22. throw new IOException("failed to load from " + configXml);
  23. }
  24. ItemListener.fireOnCreated(result);
  25. return result;
  26. } catch (IOException e) {
  27. Util.deleteRecursive(dir);
  28. throw e;
  29. }
  30. }

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

  1. @Override
  2. public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException {
  3. // for compatibility reasons, the actual value is stored in Jenkins
  4. Jenkins j = Jenkins.getInstance();
  5. final JSONObject optJSONObject = json.optJSONObject("useProjectNamingStrategy");
  6. if (optJSONObject != null) {
  7. final JSONObject strategyObject = optJSONObject.getJSONObject("namingStrategy");
  8. final String className = strategyObject.getString("$class");
  9. try {
  10. Class clazz = Class.forName(className, true, Jenkins.getInstance().getPluginManager().uberClassLoader);
  11. final ProjectNamingStrategy strategy = (ProjectNamingStrategy) req.bindJSON(clazz, strategyObject);
  12. j.setProjectNamingStrategy(strategy);
  13. } catch (ClassNotFoundException e) {
  14. throw new FormException(e, "namingStrategy");
  15. }
  16. }
  17. if (j.getProjectNamingStrategy() == null) {
  18. j.setProjectNamingStrategy(DefaultProjectNamingStrategy.DEFAULT_NAMING_STRATEGY);
  19. }
  20. return true;
  21. }
  22. }

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

  1. public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException {
  2. acl.checkPermission(Item.CREATE);
  3. Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  4. Items.verifyItemDoesNotAlreadyExist(parent, name, null);

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

  1. public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify )
  2. throws IOException {
  3. acl.checkPermission(Item.CREATE);
  4. type.checkApplicableIn(parent);
  5. acl.getACL().checkCreatePermission(parent, type);
  6. Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  7. Items.verifyItemDoesNotAlreadyExist(parent, name, null);
  8. TopLevelItem item = type.newInstance(parent, name);
  9. item.onCreatedFromScratch();
  10. item.save();
  11. add(item);
  12. Jenkins.getInstance().rebuildDependencyGraphAsync();
  13. if (notify)
  14. ItemListener.fireOnCreated(item);
  15. return item;
  16. }

代码示例来源:origin: org.jenkins-ci.plugins/cloudbees-folder

  1. ProjectNamingStrategy namingStrategy = Jenkins.getActiveInstance().getProjectNamingStrategy();
  2. if (newName != null && !newName.equals(name)) {

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

  1. final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy();
  2. if (validRename(name, newName)) {
  3. newName = newName.trim();

代码示例来源:origin: jenkinsci/cloudbees-folder-plugin

  1. ProjectNamingStrategy namingStrategy = Jenkins.get().getProjectNamingStrategy();
  2. if (namingStrategy.isForceExistingJobs()) {
  3. namingStrategy.checkName(name);

相关文章

Jenkins类方法