本文整理了Java中jenkins.model.Jenkins.checkGoodName()
方法的一些代码示例,展示了Jenkins.checkGoodName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.checkGoodName()
方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:checkGoodName
[英]Check if the given name is suitable as a name for job, view, etc.
[中]检查给定名称是否适合作为作业、视图等的名称。
代码示例来源:origin: jenkinsci/jenkins
/**
* Instantiate View subtype from XML stream.
*
* @param name Alternative name to use or {@code null} to keep the one in xml.
*/
public static View createViewFromXML(String name, InputStream xml) throws IOException {
try (InputStream in = new BufferedInputStream(xml)) {
View v = (View) Jenkins.XSTREAM.fromXML(in);
if (name != null) v.name = name;
Jenkins.checkGoodName(v.name);
return v;
} catch(StreamException|ConversionException|Error e) {// mostly reflection errors
throw new IOException("Unable to read",e);
}
}
代码示例来源:origin: jenkinsci/jenkins
public static boolean needsEscape(String name) {
try {
Jenkins.checkGoodName(name);
// additional restricted chars
for( int i=0; i<name.length(); i++ ) {
char ch = name.charAt(i);
if(" ()\t\n".indexOf(ch)!=-1)
return true;
}
return false;
} catch (Failure failure) {
return true;
}
}
代码示例来源:origin: jenkinsci/jenkins
public FormValidation doCheckName(@QueryParameter String value ) {
String name = Util.fixEmptyAndTrim(value);
if(name==null)
return FormValidation.error(Messages.NodeDescriptor_CheckName_Mandatory());
try {
Jenkins.checkGoodName(name);
} catch (Failure f) {
return FormValidation.error(f.getMessage());
}
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Creates a new log recorder.
*/
@RequirePOST
public HttpResponse doNewLogRecorder(@QueryParameter String name) {
Jenkins.checkGoodName(name);
logRecorders.put(name,new LogRecorder(name));
// redirect to the config screen
return new HttpRedirect(name+"/configure");
}
代码示例来源:origin: jenkinsci/jenkins
protected int run() throws Exception {
Jenkins h = Jenkins.getActiveInstance();
if (h.getItemByFullName(name)!=null) {
throw new IllegalStateException("Job '"+name+"' already exists");
}
ModifiableTopLevelItemGroup ig = h;
int i = name.lastIndexOf('/');
if (i > 0) {
String group = name.substring(0, i);
Item item = h.getItemByFullName(group);
if (item == null) {
throw new IllegalArgumentException("Unknown ItemGroup " + group);
}
if (item instanceof ModifiableTopLevelItemGroup) {
ig = (ModifiableTopLevelItemGroup) item;
} else {
throw new IllegalStateException("Can't create job from CLI in " + group);
}
name = name.substring(i + 1);
}
Jenkins.checkGoodName(name);
ig.createProjectFromXML(name, stdin);
return 0;
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Checks if a top-level view with the given name exists and
* make sure that the name is good as a view name.
*/
public FormValidation doCheckViewName(@QueryParameter String value) {
checkPermission(View.CREATE);
String name = fixEmpty(value);
if (name == null)
return FormValidation.ok();
// already exists?
if (getView(name) != null)
return FormValidation.error(Messages.Hudson_ViewAlreadyExists(name));
// good view name?
try {
checkGoodName(name);
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}
return FormValidation.ok();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* 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);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Makes sure that the given name is good as an agent name.
* @return trimmed name if valid; throws ParseException if not
*/
public String checkName(String name) throws Failure {
if(name==null)
throw new Failure("Query parameter 'name' is required");
name = name.trim();
Jenkins.checkGoodName(name);
if(Jenkins.getInstance().getNode(name)!=null)
throw new Failure(Messages.ComputerSet_SlaveAlreadyExists(name));
// looks good
return name;
}
代码示例来源: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
/**
* 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
/**
* Accepts submission from the configuration page.
*/
@RequirePOST
public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
JSONObject src = req.getSubmittedForm();
String newName = src.getString("name"), redirect = ".";
XmlFile oldFile = null;
if(!name.equals(newName)) {
Jenkins.checkGoodName(newName);
oldFile = getConfigFile();
// rename
getParent().logRecorders.remove(name);
this.name = newName;
getParent().logRecorders.put(name,this);
redirect = "../" + Util.rawEncode(newName) + '/';
}
List<Target> newTargets = req.bindJSONToList(Target.class, src.get("targets"));
for (Target t : newTargets)
t.enable();
targets.replaceBy(newTargets);
save();
if (oldFile!=null) oldFile.delete();
rsp.sendRedirect2(redirect);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* 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() + '/');
}
代码示例来源:origin: jenkinsci/jenkins
Jenkins.checkGoodName(name);
if(owner.getView(name)!=null)
throw new Failure(Messages.Hudson_ViewAlreadyExists(name));
代码示例来源:origin: jenkinsci/jenkins
Jenkins.checkGoodName(name);
name = name.trim();
if(parent.getItem(name)!=null)
代码示例来源:origin: i-m-c/jenkins-inheritance-plugin
private FormValidation validGoodName(String variance) {
if (StringUtils.isBlank(variance)) {
return FormValidation.ok();
}
try {
Jenkins.checkGoodName(variance);
return FormValidation.ok();
} catch (Failure e) {
return FormValidation.error(e.getMessage());
}
}
}
代码示例来源:origin: jenkinsci/promoted-builds-plugin
public FormValidation doCheckName(@QueryParameter String name) {
name = Util.fixEmptyAndTrim(name);
if (name == null) {
return FormValidation.error(Messages.JobPropertyImpl_ValidateRequired());
}
try {
Jenkins.checkGoodName(name);
} catch (Failure f) {
return FormValidation.error(f.getMessage());
}
return FormValidation.ok();
}
}
代码示例来源:origin: jenkinsci/openstack-cloud-plugin
@Restricted(DoNotUse.class)
@RequirePOST
public FormValidation doCheckName(@QueryParameter String value) {
try {
Jenkins.checkGoodName(value);
return FormValidation.ok();
} catch (Failure ex) {
return FormValidation.error(ex.getMessage());
}
}
}
代码示例来源:origin: jenkinsci/openstack-cloud-plugin
@Restricted(DoNotUse.class)
@RequirePOST
public FormValidation doCheckName(@QueryParameter String value) {
try {
Jenkins.checkGoodName(value);
return FormValidation.ok();
} catch (Failure ex) {
return FormValidation.error(ex.getMessage());
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Creates a new log recorder.
*/
@RequirePOST
public HttpResponse doNewLogRecorder(@QueryParameter String name) {
Jenkins.checkGoodName(name);
logRecorders.put(name,new LogRecorder(name));
// redirect to the config screen
return new HttpRedirect(name+"/configure");
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* 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);
}
内容来源于网络,如有侵权,请联系作者删除!