/** * 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(); }
@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; } }
/** * 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(); }
public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException { acl.checkPermission(Item.CREATE); Jenkins.getInstance().getProjectNamingStrategy().checkName(name); Items.verifyItemDoesNotAlreadyExist(parent, name, null);
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; }
final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy(); if(namingStrategy.isForceExistingJobs()){ namingStrategy.checkName(name);
/** * 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(); }
/** @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; } }
@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; } }
public synchronized TopLevelItem createProjectFromXML(String name, InputStream xml) throws IOException { acl.checkPermission(Item.CREATE); Jenkins.getInstance().getProjectNamingStrategy().checkName(name); Items.verifyItemDoesNotAlreadyExist(parent, name, null);
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; }
ProjectNamingStrategy namingStrategy = Jenkins.getActiveInstance().getProjectNamingStrategy(); if (newName != null && !newName.equals(name)) {
final ProjectNamingStrategy namingStrategy = Jenkins.getInstance().getProjectNamingStrategy(); if (validRename(name, newName)) { newName = newName.trim();
ProjectNamingStrategy namingStrategy = Jenkins.get().getProjectNamingStrategy(); if (namingStrategy.isForceExistingJobs()) { namingStrategy.checkName(name);