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

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

本文整理了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

/**
 * Makes sure that the given name is good as a job name.
 * For use from {@code newJob}.
 */
@Restricted(DoNotUse.class) // called from newJob view
public FormValidation doCheckJobName(@QueryParameter String value) {
  // this method can be used to check if a file exists anywhere in the file system,
  // so it should be protected.
  getOwner().checkPermission(Item.CREATE);
  if (Util.fixEmpty(value) == null) {
    return FormValidation.ok();
  }
  try {
    Jenkins.checkGoodName(value);
    value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same
    Jenkins.getInstance().getProjectNamingStrategy().checkName(value);
  } catch (Failure e) {
    return FormValidation.error(e.getMessage());
  }
  if (getOwner().getItemGroup().getItem(value) != null) {
    return FormValidation.error(Messages.Hudson_JobAlreadyExists(value));
  }
  // looks good
  return FormValidation.ok();
}

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

@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;
  }
}

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

/**
 * Called by {@link #doConfirmRename} and {@code rename.jelly} to validate renames.
 * @return {@link FormValidation#ok} if this item can be renamed as specified, otherwise
 * {@link FormValidation#error} with a message explaining the problem.
 */
@Restricted(NoExternalUse.class)
public @Nonnull FormValidation doCheckNewName(@QueryParameter String newName) {
  // TODO: Create an Item.RENAME permission to use here, see JENKINS-18649.
  if (!hasPermission(Item.CONFIGURE)) {
    if (parent instanceof AccessControlled) {
      ((AccessControlled)parent).checkPermission(Item.CREATE);
    }
    checkPermission(Item.DELETE);
  }
  newName = newName == null ? null : newName.trim();
  try {
    Jenkins.checkGoodName(newName);
    assert newName != null; // Would have thrown Failure
    if (newName.equals(name)) {
      return FormValidation.warning(Messages.AbstractItem_NewNameUnchanged());
    }
    Jenkins.get().getProjectNamingStrategy().checkName(newName);
    checkIfNameIsUsed(newName);
    checkRename(newName);
  } catch (Failure e) {
    return FormValidation.error(e.getMessage());
  }
  return FormValidation.ok();
}

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

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

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

public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify )
    throws IOException {
  acl.checkPermission(Item.CREATE);
  type.checkApplicableIn(parent);
  acl.getACL().checkCreatePermission(parent, type);
  Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  Items.verifyItemDoesNotAlreadyExist(parent, name, null);
  TopLevelItem item = type.newInstance(parent, name);
  item.onCreatedFromScratch();
  item.save();
  add(item);
  Jenkins.getInstance().rebuildDependencyGraphAsync();
  if (notify)
    ItemListener.fireOnCreated(item);
  return item;
}

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

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

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

/**
 * Makes sure that the given name is good as a job name.
 * For use from {@code newJob}.
 */
@Restricted(DoNotUse.class) // called from newJob view
public FormValidation doCheckJobName(@QueryParameter String value) {
  // this method can be used to check if a file exists anywhere in the file system,
  // so it should be protected.
  getOwner().checkPermission(Item.CREATE);
  if (Util.fixEmpty(value) == null) {
    return FormValidation.ok();
  }
  try {
    Jenkins.checkGoodName(value);
    value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same
    Jenkins.getInstance().getProjectNamingStrategy().checkName(value);
  } catch (Failure e) {
    return FormValidation.error(e.getMessage());
  }
  if (getOwner().getItemGroup().getItem(value) != null) {
    return FormValidation.error(Messages.Hudson_JobAlreadyExists(value));
  }
  // looks good
  return FormValidation.ok();
}

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

/** @see ItemGroupMixIn#createProjectFromXML */
public PromotionProcess createProcessFromXml(final String name, InputStream xml) throws IOException {
  owner.checkPermission(Item.CONFIGURE); // CREATE is ItemGroup-scoped and owner is not an ItemGroup
  Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  if (getItem(name) != null) {
    throw new IllegalArgumentException(owner.getDisplayName() + " already contains an item '" + name + "'");
  }
  File configXml = Items.getConfigFile(getRootDirFor(name)).getFile();
  File dir = configXml.getParentFile();
  if (!dir.mkdirs()) {
    throw new IOException("Cannot create directories for "+dir);
  }
  try {
    IOUtils.copy(xml, configXml);
    PromotionProcess result = Items.whileUpdatingByXml(new MasterToSlaveCallable<PromotionProcess, IOException>() {
      @Override public PromotionProcess call() throws IOException {
        setOwner(owner);
        return getItem(name);
      }
    });
    if (result == null) {
      throw new IOException("failed to load from " + configXml);
    }
    ItemListener.fireOnCreated(result);
    return result;
  } catch (IOException e) {
    Util.deleteRecursive(dir);
    throw e;
  }
}

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

@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.getInstance();
    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, Jenkins.getInstance().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;
  }
}

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

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

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

public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify )
    throws IOException {
  acl.checkPermission(Item.CREATE);
  type.checkApplicableIn(parent);
  acl.getACL().checkCreatePermission(parent, type);
  Jenkins.getInstance().getProjectNamingStrategy().checkName(name);
  Items.verifyItemDoesNotAlreadyExist(parent, name, null);
  TopLevelItem item = type.newInstance(parent, name);
  item.onCreatedFromScratch();
  item.save();
  add(item);
  Jenkins.getInstance().rebuildDependencyGraphAsync();
  if (notify)
    ItemListener.fireOnCreated(item);
  return item;
}

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

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

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

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

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

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

相关文章

微信公众号

最新文章

更多

Jenkins类方法