/** * Performs syntax check. */ public FormValidation doCheckScmpoll_spec(@QueryParameter String value, @QueryParameter boolean ignorePostCommitHooks, @AncestorInPath Item item) { if (StringUtils.isBlank(value)) { if (ignorePostCommitHooks) { return FormValidation.ok(Messages.SCMTrigger_no_schedules_no_hooks()); } else { return FormValidation.ok(Messages.SCMTrigger_no_schedules_hooks()); } } else { return Jenkins.getInstance().getDescriptorByType(TimerTrigger.DescriptorImpl.class) .doCheckSpec(value, item); } } }
@Restricted(NoExternalUse.class) public FormValidation doCheckTmpDir(@QueryParameter String value){ if(StringUtils.isBlank(value) || Jenkins.getInstance().hasPermission(Jenkins.RUN_SCRIPTS)){ return FormValidation.ok(); }else{ return FormValidation.error(Messages.General_MissingPermission()); } }
@RequirePOST public HttpResponse doRename(@AncestorInPath User u, @QueryParameter String tokenUuid, @QueryParameter String newName) throws IOException { // only current user + administrator can rename token u.checkPermission(Jenkins.ADMINISTER); if (StringUtils.isBlank(newName)) { return HttpResponses.errorJSON("The name cannot be empty"); } if(StringUtils.isBlank(tokenUuid)){ // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } ApiTokenProperty p = u.getProperty(ApiTokenProperty.class); if (p == null) { return HttpResponses.errorWithoutStack(400, "The user does not have any ApiToken yet, try generating one before."); } boolean renameOk = p.tokenStore.renameToken(tokenUuid, newName); if(!renameOk){ // that could potentially happen if the token is removed from another page // between your page loaded and your action return HttpResponses.errorJSON("No token found, try refreshing the page"); } u.save(); return HttpResponses.ok(); }
public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @QueryParameter String value) { if (!project.hasPermission(Item.CONFIGURE)) { return FormValidation.ok(); } StringTokenizer tokens = new StringTokenizer(Util.fixNull(value),","); boolean hasProjects = false; while(tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(projectName)) { Job item = Jenkins.getInstance().getItem(projectName, project, Job.class); if (item == null) { Job nearest = Items.findNearest(Job.class, projectName, project.getParent()); String alternative = nearest != null ? nearest.getRelativeNameFrom(project) : "?"; return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoSuchProject(projectName, alternative)); } hasProjects = true; } } if (!hasProjects) { return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified()); } return FormValidation.ok(); }
public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp, @QueryParameter String iconStyle) throws IOException, ServletException { getOwner().checkPermission(Item.CREATE); JellyContext ctx; if (StringUtils.isNotBlank(iconStyle)) { ctx = new JellyContext(); ctx.setVariable("resURL", req.getContextPath() + Jenkins.RESOURCE_PATH); ctx = null; for (TopLevelItemDescriptor descriptor : DescriptorVisibilityFilter.apply(getOwner().getItemGroup(), Items.all(Jenkins.getAuthentication(), getOwner().getItemGroup()))) { ItemCategory ic = ItemCategory.getCategory(descriptor); Map<String, Serializable> metadata = new HashMap<String, Serializable>(); metadata.put("iconFilePathPattern", descriptor.getIconFilePathPattern()); String iconClassName = descriptor.getIconClassName(); if (StringUtils.isNotBlank(iconClassName)) { metadata.put("iconClassName", iconClassName); if (ctx != null) { Icon icon = IconSet.icons .getIconByClassSpec(StringUtils.join(new String[]{iconClassName, iconStyle}, " ")); if (icon != null) { metadata.put("iconQualifiedUrl", icon.getQualifiedUrl(ctx));
private boolean containsNoBranches(@QueryParameter String value) { return StringUtils.isEmpty(value) || StringUtils.containsOnly(value, new char[]{',', ' '}); }
public FormValidation doCheckCredentialsId(@QueryParameter String value, @AncestorInPath Item project) throws IOException, ServletException { if (project != null && StringUtils.isBlank(value) && StringUtils.isBlank(credentialsId)) { return FormValidation.error("Please specify the credentials to use"); } else { return FormValidation.ok(); } }
public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){ if(Util.fixEmptyAndTrim(customWorkspace)==null) return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty()); else return FormValidation.ok(); }
/** * Makes sure that the given name is good as an agent name. */ public FormValidation doCheckName(@QueryParameter String value) throws IOException, ServletException { Jenkins.getInstance().checkPermission(Computer.CREATE); if(Util.fixEmpty(value)==null) return FormValidation.ok(); try { checkName(value); return FormValidation.ok(); } catch (Failure e) { return FormValidation.error(e.getMessage()); } }
public FormValidation doCheck(@AncestorInPath AbstractProject project, @QueryParameter String value) { // Require CONFIGURE permission on this project if(!project.hasPermission(Item.CONFIGURE)) return FormValidation.ok(); for (String name : Util.tokenize(fixNull(value), ",")) { name = name.trim(); if (Helper.getActiveInstance().getItem(name,project) == null) { final AbstractProject<?,?> nearest = AbstractProject.findNearest(name); return FormValidation.error(Messages.BuildTrigger_NoSuchProject(name, nearest != null ? nearest.getName() : null)); } } return FormValidation.ok(); }
/** * Fails if a global view with the given name does not exist. */ public FormValidation doViewExistsCheck(@QueryParameter String value) { checkPermission(View.CREATE); String view = Util.fixEmpty(value); if(view==null) return FormValidation.ok(); if(Jenkins.getInstance().getView(view)!=null) return FormValidation.ok(); else return FormValidation.error(Messages.ProxyView_NoSuchViewExists(value)); }
/** * Validates the retry count Regex */ public FormValidation doCheckRetryCount(@QueryParameter String value)throws IOException,ServletException{ // retry count is optional so this is ok if(value == null || value.trim().equals("")) return FormValidation.ok(); if (!value.matches("[0-9]*")) { return FormValidation.error("Invalid retry count"); } return FormValidation.ok(); }
/** * Performs on-the-fly validation of the errorlevel. */ @Restricted(DoNotUse.class) public FormValidation doCheckUnstableReturn(@QueryParameter String value) { value = Util.fixEmptyAndTrim(value); if (value == null) { return FormValidation.ok(); } long unstableReturn; try { unstableReturn = Long.parseLong(value); } catch (NumberFormatException e) { return FormValidation.error(hudson.model.Messages.Hudson_NotANumber()); } if (unstableReturn == 0) { return FormValidation.warning(hudson.tasks.Messages.BatchFile_invalid_exit_code_zero()); } if (unstableReturn < Integer.MIN_VALUE || unstableReturn > Integer.MAX_VALUE) { return FormValidation.error(hudson.tasks.Messages.BatchFile_invalid_exit_code_range(unstableReturn)); } return FormValidation.ok(); }
public FormValidation doCheckNewSource(@QueryParameter String newSource){ Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String normalized = Util.fixEmptyAndTrim(newSource); File f = new File(newSource); if (normalized == null) { return FormValidation.ok(); // empty, do nothing } else if (!f.exists() && !ConfigurationAsCode.isSupportedURI(normalized)) { return FormValidation.error("Configuration cannot be applied. File or URL cannot be parsed or do not exist."); } try { final Map<Source, String> issues = collectIssues(newSource); final JSONArray errors = collectProblems(issues, "error"); if (!errors.isEmpty()) { return FormValidation.error(errors.toString()); } final JSONArray warnings = collectProblems(issues, "warning"); if (!warnings.isEmpty()) { return FormValidation.warning(warnings.toString()); } return FormValidation.okWithMarkup("The configuration can be applied"); } catch (ConfiguratorException e) { return FormValidation.error(e, e.getCause().getMessage()); } catch (IllegalArgumentException e) { return FormValidation.error(e, e.getCause().getMessage()); } }
/** * Performs syntactical check on the remote FS for agents. */ public FormValidation doCheckRemoteFS(@QueryParameter String value) throws IOException, ServletException { if(Util.fixEmptyAndTrim(value)==null) return FormValidation.error(Messages.Slave_Remote_Director_Mandatory()); if(value.startsWith("\\\\") || value.startsWith("/net/")) return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning()); if (Util.isRelativePath(value)) { return FormValidation.warning(Messages.Slave_Remote_Relative_Path_Warning()); } return FormValidation.ok(); }
/** * Checks if a top-level view with the given name exists. * @deprecated 1.512 */ @Deprecated public FormValidation doViewExistsCheck(@QueryParameter String value) { checkPermission(View.CREATE); String view = fixEmpty(value); if(view==null) return FormValidation.ok(); if(getView(view)==null) return FormValidation.ok(); else return FormValidation.error(Messages.Hudson_ViewAlreadyExists(view)); }
/** * Validate the value for a remote (repository) location. */ @RequirePOST public FormValidation doCheckCredentialsId(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String remote, @QueryParameter String value) { // Test the connection only if we may use the credentials (cf. hudson.plugins.git.UserRemoteConfig.DescriptorImpl.doCheckUrl) if (context == null && !Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER) || context != null && !context.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } return checkCredentialsId(req, context, remote, value); }
/** * 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(); }
public FormValidation doCheckCommand(@QueryParameter String value) { if (!Jenkins.getInstance().hasPermission(Jenkins.RUN_SCRIPTS)) { return FormValidation.warning(Messages.CommandLauncher_cannot_be_configured_by_non_administrato()); } if(Util.fixEmptyAndTrim(value)==null) return FormValidation.error(Messages.CommandLauncher_NoLaunchCommand()); else return FormValidation.ok(); } }
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context, @QueryParameter String value) { AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance()); if (!ac.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(value); } return new StandardListBoxModel().includeAs( ACL.SYSTEM, context, DockerServerCredentials.class, Collections.<DomainRequirement>emptyList()); }