org.kohsuke.stapler.QueryParameter Java Examples
The following examples show how to use
org.kohsuke.stapler.QueryParameter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroovyParser.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Performs on-the-fly validation on the regular expression. * * @param regexp * the regular expression * * @return the validation result */ public FormValidation doCheckRegexp(@QueryParameter(required = true) final String regexp) { try { if (StringUtils.isBlank(regexp)) { return FormValidation.error(Messages.GroovyParser_Error_Regexp_isEmpty()); } Pattern pattern = Pattern.compile(regexp); Ensure.that(pattern).isNotNull(); return FormValidation.ok(); } catch (PatternSyntaxException exception) { return FormValidation.error( Messages.GroovyParser_Error_Regexp_invalid(exception.getLocalizedMessage())); } }
Example #2
Source File: JiraCloudSiteConfig.java From atlassian-jira-software-cloud-plugin with Apache License 2.0 | 6 votes |
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter final String credentialsId) { Jenkins instance = Jenkins.get(); if (!instance.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs( ACL.SYSTEM, instance, StringCredentials.class, URIRequirementBuilder.fromUri(ATLASSIAN_API_URL).build(), CredentialsMatchers.always()); }
Example #3
Source File: ModelValidation.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Performs on-the-fly validation on the source code directory. * * @param project * the project * @param sourceDirectory * the file pattern * * @return the validation result */ public FormValidation doCheckSourceDirectory(@AncestorInPath final AbstractProject<?, ?> project, @QueryParameter final String sourceDirectory) { if (project != null) { // there is no workspace in pipelines try { FilePath workspace = project.getSomeWorkspace(); if (workspace != null && workspace.exists()) { return validateRelativePath(sourceDirectory, workspace); } } catch (InterruptedException | IOException ignore) { // ignore and return ok } } return FormValidation.ok(); }
Example #4
Source File: KafkaKubernetesCloud.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); return new StandardListBoxModel().withEmptySelection() .withMatching( CredentialsMatchers.anyOf( CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class), CredentialsMatchers.instanceOf(FileCredentials.class), CredentialsMatchers.instanceOf(TokenProducer.class), CredentialsMatchers.instanceOf(StandardCertificateCredentials.class), CredentialsMatchers.instanceOf(StringCredentials.class)), CredentialsProvider.lookupCredentials(StandardCredentials.class, Jenkins.get(), ACL.SYSTEM, serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build() : Collections.EMPTY_LIST )); }
Example #5
Source File: ListGitBranchesParameterDefinition.java From list-git-branches-parameter-plugin with MIT License | 6 votes |
public FormValidation doCheckRemoteURL(StaplerRequest req, @AncestorInPath Item context, @QueryParameter String value) { String url = Util.fixEmptyAndTrim(value); if (url == null) { return FormValidation.error("Repository URL is required"); } if (url.indexOf('$') != -1) { return FormValidation.warning("This repository URL is parameterized, syntax validation skipped"); } try { new URIish(value); } catch (URISyntaxException e) { return FormValidation.error("Repository URL is illegal"); } return FormValidation.ok(); }
Example #6
Source File: AppCenterRecorder.java From appcenter-plugin with MIT License | 6 votes |
@SuppressWarnings("unused") public FormValidation doCheckPathToApp(@QueryParameter String value) { if (value.isEmpty()) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_missingPathToApp()); } final Validator pathToAppValidator = new PathToAppValidator(); if (!pathToAppValidator.isValid(value)) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_invalidPath()); } final Validator pathPlaceholderValidator = new PathPlaceholderValidator(); if (!pathPlaceholderValidator.isValid(value)) { return FormValidation.warning(Messages.AppCenterRecorder_DescriptorImpl_warnings_mustNotStartWithEnvVar()); } return FormValidation.ok(); }
Example #7
Source File: AppCenterRecorder.java From appcenter-plugin with MIT License | 6 votes |
@SuppressWarnings("unused") public FormValidation doCheckPathToDebugSymbols(@QueryParameter String value) { if (value.trim().isEmpty()) { return FormValidation.ok(); } final Validator pathToDebugSymbolsValidator = new PathToDebugSymbolsValidator(); if (!pathToDebugSymbolsValidator.isValid(value)) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_invalidPath()); } final Validator pathPlaceholderValidator = new PathPlaceholderValidator(); if (!pathPlaceholderValidator.isValid(value)) { return FormValidation.warning(Messages.AppCenterRecorder_DescriptorImpl_warnings_mustNotStartWithEnvVar()); } return FormValidation.ok(); }
Example #8
Source File: AppCenterRecorder.java From appcenter-plugin with MIT License | 6 votes |
@SuppressWarnings("unused") public FormValidation doCheckPathToReleaseNotes(@QueryParameter String value) { if (value.trim().isEmpty()) { return FormValidation.ok(); } final Validator pathToReleaseNotesValidator = new PathToReleaseNotesValidator(); if (!pathToReleaseNotesValidator.isValid(value)) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_invalidPath()); } final Validator pathPlaceholderValidator = new PathPlaceholderValidator(); if (!pathPlaceholderValidator.isValid(value)) { return FormValidation.warning(Messages.AppCenterRecorder_DescriptorImpl_warnings_mustNotStartWithEnvVar()); } return FormValidation.ok(); }
Example #9
Source File: ModelValidation.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Performs on-the-fly validation on the ant pattern for input files. * * @param project * the project * @param pattern * the file pattern * * @return the validation result */ public FormValidation doCheckPattern(@AncestorInPath final AbstractProject<?, ?> project, @QueryParameter final String pattern) { if (project != null) { // there is no workspace in pipelines try { FilePath workspace = project.getSomeWorkspace(); if (workspace != null && workspace.exists()) { return validatePatternInWorkspace(pattern, workspace); } } catch (InterruptedException | IOException ignore) { // ignore and return ok } } return FormValidation.ok(); }
Example #10
Source File: GitLabPersonalAccessTokenCreator.java From gitlab-branch-source-plugin with MIT License | 6 votes |
@SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl, @QueryParameter String credentialsId) { Jenkins jenkins = Jenkins.get(); if (!jenkins.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } return new StandardUsernameListBoxModel() .includeEmptyValue() .includeMatchingAs( ACL.SYSTEM, jenkins, StandardUsernamePasswordCredentials.class, fromUri(defaultIfBlank(serverUrl, GitLabServer.GITLAB_SERVER_URL)).build(), CredentialsMatchers.always() ).includeMatchingAs( Jenkins.getAuthentication(), jenkins, StandardUsernamePasswordCredentials.class, fromUri(defaultIfBlank(serverUrl, GitLabServer.GITLAB_SERVER_URL)).build(), CredentialsMatchers.always() ); }
Example #11
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
private ListBoxModel fillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String credentialsId) { StandardListBoxModel result = new StandardListBoxModel(); if (item == null) { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return result.includeCurrentValue(credentialsId); } } return result .includeMatchingAs( ACL.SYSTEM, Jenkins.get(), StandardUsernamePasswordCredentials.class, Collections.singletonList(KAFKA_SCHEME), CredentialsMatchers.always() ) .includeCurrentValue(credentialsId); }
Example #12
Source File: GitLabSCMSource.java From gitlab-branch-source-plugin with MIT License | 6 votes |
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath SCMSourceOwner context, @QueryParameter String serverName, @QueryParameter String credentialsId) { StandardListBoxModel result = new StandardListBoxModel(); if (context == null) { // must have admin if you want the list without a context if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { result.includeCurrentValue(credentialsId); return result; } } else { if (!context.hasPermission(Item.EXTENDED_READ) && !context.hasPermission(CredentialsProvider.USE_ITEM)) { // must be able to read the configuration or use the item credentials if you // want the list result.includeCurrentValue(credentialsId); return result; } } result.includeEmptyValue(); result.includeMatchingAs( context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM, context, StandardUsernameCredentials.class, fromUri(getServerUrlFromName(serverName)).build(), GitClient.CREDENTIALS_MATCHER); return result; }
Example #13
Source File: GitLabSCMSource.java From gitlab-branch-source-plugin with MIT License | 6 votes |
public int getProjectId(@QueryParameter String projectPath, @QueryParameter String serverName) { List<GitLabServer> gitLabServers = GitLabServers.get().getServers(); if (gitLabServers.size() == 0) { return -1; } try { GitLabApi gitLabApi; if (StringUtils.isBlank(serverName)) { gitLabApi = apiBuilder(gitLabServers.get(0).getName()); } else { gitLabApi = apiBuilder(serverName); } if (StringUtils.isNotBlank(projectPath)) { return gitLabApi.getProjectApi().getProject(projectPath).getId(); } } catch (GitLabApiException e) { return -1; } return -1; }
Example #14
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doTestZookeeperConnection(@QueryParameter("zookeeperURL") final String zookeeperURL) throws IOException, ServletException { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.error("Need admin permission to perform this action"); } try { String[] hostport = zookeeperURL.split(":"); String host = hostport[0]; int port = Integer.parseInt(hostport[1]); testConnection(host, port); return FormValidation.ok("Success"); } catch (Exception e) { return FormValidation.error("Connection error : " + e.getMessage()); } }
Example #15
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 6 votes |
@RequirePOST public FormValidation doTestBrokerConnection(@QueryParameter("brokerURL") final String brokerURL) throws IOException, ServletException { if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.error("Need admin permission to perform this action"); } try { String[] hostport = brokerURL.split(":"); String host = hostport[0]; int port = Integer.parseInt(hostport[1]); testConnection(host, port); return FormValidation.ok("Success"); } catch (Exception e) { return FormValidation.error("Connection error : " + e.getMessage()); } }
Example #16
Source File: AxivionSuite.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Shows the user all available credential id items. * * @param item * jenkins configuration * @param credentialsId * current used credentials * * @return a list view of all credential ids */ public ListBoxModel doFillCredentialsIdItems( @AncestorInPath final Item item, @QueryParameter final String credentialsId) { StandardListBoxModel result = new StandardListBoxModel(); if (item == null) { if (!new JenkinsFacade().hasPermission(Jenkins.ADMINISTER)) { return result.includeCurrentValue(credentialsId); } } else { if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) { return result.includeCurrentValue(credentialsId); } } return result.includeAs( ACL.SYSTEM, item, StandardUsernamePasswordCredentials.class, Collections.emptyList()) .includeCurrentValue(credentialsId); }
Example #17
Source File: GroovyParser.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Parses the example message with the specified regular expression and script. * * @param example * example that should be resolve to a warning * @param regexp * the regular expression * @param script * the script * * @return the validation result */ @RequirePOST public FormValidation doCheckExample(@QueryParameter final String example, @QueryParameter final String regexp, @QueryParameter final String script) { if (isNotAllowedToRunScripts()) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } if (StringUtils.isNotBlank(example) && StringUtils.isNotBlank(regexp) && StringUtils.isNotBlank(script)) { FormValidation response = parseExample(script, example, regexp, containsNewline(regexp)); if (example.length() <= MAX_EXAMPLE_SIZE) { return response; } return FormValidation.aggregate(Arrays.asList( FormValidation.warning(Messages.GroovyParser_long_examples_will_be_truncated()), response)); } else { return FormValidation.ok(); } }
Example #18
Source File: GroovyParser.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Performs on-the-fly validation on the Groovy script. * * @param script * the script * * @return the validation result */ @RequirePOST public FormValidation doCheckScript(@QueryParameter(required = true) final String script) { if (isNotAllowedToRunScripts()) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.GroovyParser_Error_Script_isEmpty()); } GroovyExpressionMatcher matcher = new GroovyExpressionMatcher(script); Script compiled = matcher.compile(); Ensure.that(compiled).isNotNull(); return FormValidation.ok(); } catch (CompilationFailedException exception) { return FormValidation.error( Messages.GroovyParser_Error_Script_invalid(exception.getLocalizedMessage())); } }
Example #19
Source File: ListGitBranchesParameterDefinition.java From list-git-branches-parameter-plugin with MIT License | 6 votes |
public ListBoxModel doFillValueItems(@AncestorInPath Job<?, ?> context, @QueryParameter String param) throws IOException, InterruptedException { ListBoxModel items = new ListBoxModel(); if (context != null && context.hasPermission(Item.BUILD)) { ParametersDefinitionProperty prop = context.getProperty(ParametersDefinitionProperty.class); if (prop != null) { ParameterDefinition def = prop.getParameterDefinition(param); if (def instanceof ListGitBranchesParameterDefinition) { Map<String, String> paramList = ((ListGitBranchesParameterDefinition) def).generateContents(context); for (Map.Entry<String, String> entry : paramList.entrySet()) { items.add(entry.getValue(), entry.getKey()); } } } } return items; }
Example #20
Source File: GitLabServer.java From gitlab-branch-source-plugin with MIT License | 6 votes |
/** * Stapler form completion. * * @param serverUrl the server URL. * @param credentialsId the credentials Id * @return the available credentials. */ @Restricted(NoExternalUse.class) // stapler @SuppressWarnings("unused") public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl, @QueryParameter String credentialsId) { Jenkins jenkins = Jenkins.get(); if (!jenkins.hasPermission(Jenkins.ADMINISTER)) { return new StandardListBoxModel().includeCurrentValue(credentialsId); } return new StandardListBoxModel() .includeEmptyValue() .includeMatchingAs(ACL.SYSTEM, jenkins, StandardCredentials.class, fromUri(serverUrl).build(), CREDENTIALS_MATCHER ); }
Example #21
Source File: AxivionSuite.java From warnings-ng-plugin with MIT License | 5 votes |
/** * Checks whether the given path is a correct os path. * * @param basedir * path to check * * @return {@link FormValidation#ok()} is a valid url */ @SuppressFBWarnings("PATH_TRAVERSAL_IN") public FormValidation doCheckBasedir(@QueryParameter final String basedir) { try { if (!basedir.contains("$")) { // path with a variable cannot be checked at this point Paths.get(basedir); } } catch (InvalidPathException e) { return FormValidation.error("You have to provide a valid path."); } return FormValidation.ok(); }
Example #22
Source File: AxivionSuite.java From warnings-ng-plugin with MIT License | 5 votes |
/** * Checks whether valid credentials are given. * * @param item * jenkins configuration * @param credentialsId * id of the stored credentials pair * * @return {@link FormValidation#ok()} if credentials exist and are valid */ public FormValidation doCheckCredentialsId( @AncestorInPath final Item item, @QueryParameter final String credentialsId) { if (StringUtils.isBlank(credentialsId)) { return FormValidation.error("You have to provide credentials."); } if (item == null) { if (!new JenkinsFacade().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.ok(); } } else { if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } } if (CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class, item, ACL.SYSTEM, Collections.emptyList()), CredentialsMatchers.withId(credentialsId)) == null) { return FormValidation.error("Cannot find currently selected credentials."); } return FormValidation.ok(); }
Example #23
Source File: AxivionSuite.java From warnings-ng-plugin with MIT License | 5 votes |
/** * Dashboard project url must be a valid url. * * @param projectUrl * url to a project inside an Axivion dashboard * * @return {@link FormValidation#ok()} is a valid url */ public FormValidation doCheckProjectUrl(@QueryParameter final String projectUrl) { try { new URL(projectUrl).toURI(); } catch (URISyntaxException | MalformedURLException ex) { return FormValidation.error("This is not a valid URL."); } return FormValidation.ok(); }
Example #24
Source File: OpenTasks.java From warnings-ng-plugin with MIT License | 5 votes |
/** * Validates the example text that will be scanned for open tasks. * * @param example * the text to be scanned for open tasks * @param high * tag identifiers indicating high priority * @param normal * tag identifiers indicating normal priority * @param low * tag identifiers indicating low priority * @param ignoreCase * if case should be ignored during matching * @param asRegexp * if the identifiers should be treated as regular expression * * @return validation result */ @SuppressWarnings("PMD.AvoidLiteralsInIfCondition") public FormValidation doCheckExample(@QueryParameter final String example, @QueryParameter final String high, @QueryParameter final String normal, @QueryParameter final String low, @QueryParameter final boolean ignoreCase, @QueryParameter final boolean asRegexp) { if (StringUtils.isEmpty(example)) { return FormValidation.ok(); } TaskScannerBuilder builder = new TaskScannerBuilder(); TaskScanner scanner = builder.setHighTasks(high) .setNormalTasks(normal) .setLowTasks(low) .setCaseMode(ignoreCase ? CaseMode.IGNORE_CASE : CaseMode.CASE_SENSITIVE) .setMatcherMode(asRegexp ? MatcherMode.REGEXP_MATCH : MatcherMode.STRING_MATCH).build(); if (scanner.isInvalidPattern()) { return FormValidation.error(scanner.getErrors()); } try (BufferedReader reader = new BufferedReader(new StringReader(example))) { Report tasks = scanner.scanTasks(reader.lines().iterator(), new IssueBuilder().setFileName("UI example")); if (tasks.isEmpty()) { return FormValidation.warning(Messages.OpenTasks_Validation_NoTask()); } else if (tasks.size() != 1) { return FormValidation.warning(Messages.OpenTasks_Validation_MultipleTasks(tasks.size())); } else { Issue task = tasks.get(0); return FormValidation.ok(Messages.OpenTasks_Validation_OneTask(task.getType(), task.getMessage())); } } catch (IOException e) { return FormValidation.error(e.getMessage()); // should never happen } }
Example #25
Source File: ModelValidation.java From warnings-ng-plugin with MIT License | 5 votes |
private FormValidation validateRelativePath( @QueryParameter final String sourceDirectory, final FilePath workspace) throws IOException { PathUtil pathUtil = new PathUtil(); if (pathUtil.isAbsolute(sourceDirectory)) { return FormValidation.ok(); } return workspace.validateRelativeDirectory(sourceDirectory); }
Example #26
Source File: DockerSwarmCloud.java From docker-swarm-plugin with MIT License | 5 votes |
public FormValidation doCheckJenkinsUrl(@QueryParameter String jenkinsUrl) { try { new URL(jenkinsUrl); return FormValidation.ok(); } catch (MalformedURLException e) { return FormValidation.error(e, "Needs valid http url"); } }
Example #27
Source File: DockerSwarmCloud.java From docker-swarm-plugin with MIT License | 5 votes |
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()); }
Example #28
Source File: NamedBranchBuildStrategyImpl.java From basic-branch-build-strategies-plugin with MIT License | 5 votes |
/** * Form validation for the regular expression. * * @param value the regular expression. * @return the validation results. */ @Restricted(NoExternalUse.class) // stapler public FormValidation doCheckRegex(@QueryParameter String value) { try { Pattern.compile(value); return FormValidation.ok(); } catch (PatternSyntaxException e) { return FormValidation.error(e.getMessage()); } }
Example #29
Source File: AppCenterRecorder.java From appcenter-plugin with MIT License | 5 votes |
@SuppressWarnings("unused") public FormValidation doCheckDistributionGroups(@QueryParameter String value) { if (value.isEmpty()) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_missingDistributionGroups()); } final Validator validator = new DistributionGroupsValidator(); if (!validator.isValid(value)) { return FormValidation.error(Messages.AppCenterRecorder_DescriptorImpl_errors_invalidDistributionGroups()); } return FormValidation.ok(); }
Example #30
Source File: DockerSwarmAgentTemplate.java From docker-swarm-plugin with MIT License | 5 votes |
public ListBoxModel doFillPullCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String pullCredentialsId) { if (item == null && !Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER) || item != null && !item.hasPermission(Item.EXTENDED_READ)) { return new StandardListBoxModel(); } final DockerRegistryEndpoint.DescriptorImpl descriptor = (DockerRegistryEndpoint.DescriptorImpl) Jenkins .getInstance().getDescriptorOrDie(DockerRegistryEndpoint.class); return descriptor.doFillCredentialsIdItems(item); }