hudson.model.Item Java Examples
The following examples show how to use
hudson.model.Item.
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: Connector.java From github-branch-source-plugin with MIT License | 6 votes |
/** * Populates a {@link ListBoxModel} with the checkout credentials appropriate for the supplied context against the * supplied API endpoint. * * @param context the context. * @param apiUri the api endpoint. * @return a {@link ListBoxModel}. */ @NonNull public static ListBoxModel listCheckoutCredentials(@CheckForNull Item context, String apiUri) { StandardListBoxModel result = new StandardListBoxModel(); result.includeEmptyValue(); result.add("- same as scan credentials -", GitHubSCMSource.DescriptorImpl.SAME); result.add("- anonymous -", GitHubSCMSource.DescriptorImpl.ANONYMOUS); return result.includeMatchingAs( context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM, context, StandardUsernameCredentials.class, githubDomainRequirements(apiUri), GitClient.CREDENTIALS_MATCHER ); }
Example #2
Source File: GitLabConnection.java From gitlab-plugin with GNU General Public License v2.0 | 6 votes |
@Restricted(NoExternalUse.class) private String getApiToken(String apiTokenId, Item item) { ItemGroup<?> context = null != item ? item.getParent() : Jenkins.get(); StandardCredentials credentials = CredentialsMatchers.firstOrNull( lookupCredentials( StandardCredentials.class, context, ACL.SYSTEM, URIRequirementBuilder.fromUri(url).build()), CredentialsMatchers.withId(apiTokenId)); if (credentials != null) { if (credentials instanceof GitLabApiToken) { return ((GitLabApiToken) credentials).getApiToken().getPlainText(); } if (credentials instanceof StringCredentials) { return ((StringCredentials) credentials).getSecret().getPlainText(); } } throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId); }
Example #3
Source File: CredentialsHelper.java From violation-comments-to-github-plugin with MIT License | 6 votes |
public static FormValidation doCheckFillCredentialsId( final Item item, final String credentialsId, final String uri) { if (item == null) { if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) { return FormValidation.ok(); } } else { if (!item.hasPermission(Item.EXTENDED_READ) && !item.hasPermission(CredentialsProvider.USE_ITEM)) { return FormValidation.ok(); } } if (isNullOrEmpty(credentialsId)) { return FormValidation.ok(); } if (!findCredentials(item, credentialsId, uri).isPresent()) { return FormValidation.error("Cannot find currently selected credentials"); } return FormValidation.ok(); }
Example #4
Source File: AbstractPipelineImpl.java From blueocean-plugin with MIT License | 6 votes |
/** * Returns full display name relative to the <code>BlueOrganization</code> base. Each display name is separated by * '/' and each display name is url encoded * * @param org the organization the item belongs to * @param item to return the full display name of * * @return full display name */ public static String getFullDisplayName(@Nullable BlueOrganization org, @Nonnull Item item) { ItemGroup<?> group = getBaseGroup(org); String[] displayNames = Functions.getRelativeDisplayNameFrom(item, group).split(" ยป "); StringBuilder encodedDisplayName=new StringBuilder(); for(int i=0;i<displayNames.length;i++) { if(i!=0) { encodedDisplayName.append(String.format("/%s", Util.rawEncode(displayNames[i]))); }else { encodedDisplayName.append(String.format("%s", Util.rawEncode(displayNames[i]))); } } return encodedDisplayName.toString(); }
Example #5
Source File: GiteaWebhookListener.java From gitea-plugin with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void onChange(Saveable o, XmlFile file) { if (!(o instanceof Item)) { // must be an Item return; } SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem((Item) o); if (item == null) { // more specifically must be an SCMTriggerItem return; } SCMTrigger trigger = item.getSCMTrigger(); if (trigger == null || trigger.isIgnorePostCommitHooks()) { // must have the trigger enabled and not opted out of post commit hooks return; } for (SCM scm : item.getSCMs()) { if (scm instanceof GitSCM) { // we have a winner GiteaWebhookListener.register(item, (GitSCM) scm); } } }
Example #6
Source File: FavoriteContainerImpl.java From blueocean-plugin with MIT License | 6 votes |
@Override public Iterator<BlueFavorite> iterator(int start, int limit) { List<BlueFavorite> favorites = new ArrayList<>(); Iterator<Item> favoritesIterator = Favorites.getFavorites(user.user).iterator(); Utils.skip(favoritesIterator, start); int count = 0; while(count < limit && favoritesIterator.hasNext()) { Item item = favoritesIterator.next(); if(item instanceof AbstractFolder) { continue; } BlueFavorite blueFavorite = FavoriteUtil.getFavorite(item); if(blueFavorite != null){ favorites.add(blueFavorite); count++; } } return favorites.iterator(); }
Example #7
Source File: MatrixProjectImpl.java From blueocean-plugin with MIT License | 5 votes |
@Override public MatrixProjectImpl getPipeline(Item item, Reachable parent, BlueOrganization organization) { if (item instanceof MatrixProject) { return new MatrixProjectImpl(organization, (MatrixProject) item, parent.getLink()); } return null; }
Example #8
Source File: AbstractPipelineImpl.java From blueocean-plugin with MIT License | 5 votes |
@Override public BluePipeline getPipeline(Item item, Reachable parent, BlueOrganization organization) { if (item instanceof Job) { return new AbstractPipelineImpl(organization, (Job) item); } return null; }
Example #9
Source File: GitHubSCMSource.java From github-branch-source-plugin with MIT License | 5 votes |
@RequirePOST @Restricted(NoExternalUse.class) public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri, @QueryParameter String scanCredentialsId) { return doCheckCredentialsId(context, apiUri, scanCredentialsId); }
Example #10
Source File: SelectJobsBallColorFolderIcon.java From multi-branch-project-plugin with MIT License | 5 votes |
/** * Form validation method. Similar to * {@link hudson.tasks.BuildTrigger.DescriptorImpl#doCheck(AbstractProject, String)}. * * @param folder the folder being configured * @param value the user-entered value * @return validation result */ public FormValidation doCheck(@AncestorInPath AbstractFolder folder, @QueryParameter String value) { // Require CONFIGURE permission on this project if (!folder.hasPermission(Item.CONFIGURE)) { return FormValidation.ok(); } boolean hasJobs = false; StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ","); while (tokens.hasMoreTokens()) { String jobName = tokens.nextToken().trim(); if (StringUtils.isNotBlank(jobName)) { Item item = Jenkins.getActiveInstance().getItem(jobName, (ItemGroup) folder, Item.class); if (item == null) { Job nearest = Items.findNearest(Job.class, jobName, folder); String alternative = nearest != null ? nearest.getRelativeNameFrom((ItemGroup) folder) : "?"; return FormValidation.error( hudson.tasks.Messages.BuildTrigger_NoSuchProject(jobName, alternative)); } if (!(item instanceof Job)) { return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NotBuildable(jobName)); } hasJobs = true; } } if (!hasJobs) { return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified()); } return FormValidation.ok(); }
Example #11
Source File: GitHubSCMBuilder.java From github-branch-source-plugin with MIT License | 5 votes |
/** * Returns a {@link RepositoryUriResolver} according to credentials configuration. * * @param context the context within which to resolve the credentials. * @param apiUri the API url * @param credentialsId the credentials. * @return a {@link RepositoryUriResolver} */ @NonNull public static RepositoryUriResolver uriResolver(@CheckForNull Item context, @NonNull String apiUri, @CheckForNull String credentialsId) { if (credentialsId == null) { return HTTPS; } else { StandardCredentials credentials = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials( StandardCredentials.class, context, context instanceof Queue.Task ? ((Queue.Task) context).getDefaultAuthentication() : ACL.SYSTEM, URIRequirementBuilder.create() .withHostname(RepositoryUriResolver.hostnameFromApiUri(apiUri)) .build() ), CredentialsMatchers.allOf( CredentialsMatchers.withId(credentialsId), CredentialsMatchers.instanceOf(StandardCredentials.class) ) ); if (credentials instanceof SSHUserPrivateKey) { return SSH; } else { // Defaults to HTTP/HTTPS return HTTPS; } } }
Example #12
Source File: GithubOrgFolderPermissionsTest.java From blueocean-plugin with MIT License | 5 votes |
@Test public void canNotCreateWhenHaveNoPermissionOnDefaultOrg() throws Exception { MockAuthorizationStrategy authz = new MockAuthorizationStrategy(); authz.grant(Item.READ, Jenkins.READ).everywhere().to(user); j.jenkins.setAuthorizationStrategy(authz); // refresh the JWT token otherwise all hell breaks loose. jwtToken = getJwtToken(j.jenkins, "vivek", "vivek"); createGithubPipeline(false); }
Example #13
Source File: OrganizationFactory.java From blueocean-plugin with MIT License | 5 votes |
@CheckForNull public final BlueOrganization getContainingOrg(Item i) { if (i instanceof ItemGroup) { return getContainingOrg((ItemGroup) i); } else { return getContainingOrg(i.getParent()); } }
Example #14
Source File: OpenShiftDeleterList.java From jenkins-plugin with Apache License 2.0 | 5 votes |
public ListBoxModel doFillInputTypeItems(@AncestorInPath Item item, @QueryParameter String key, @QueryParameter String type) { ListBoxModel ret = new ListBoxModel(); ret.add("Json contents", "json"); ret.add("API Object type : API Object key", "kv"); ret.add("Label", "label"); return ret; }
Example #15
Source File: DockerAPI.java From docker-plugin with MIT License | 5 votes |
@RequirePOST public FormValidation doTestConnection( @AncestorInPath Item context, @QueryParameter String uri, @QueryParameter String credentialsId, @QueryParameter String apiVersion, @QueryParameter int connectTimeout, @QueryParameter int readTimeout ) { throwIfNoPermission(context); final FormValidation credentialsIdCheckResult = doCheckCredentialsId(context, uri, credentialsId); if (credentialsIdCheckResult != FormValidation.ok()) { return FormValidation.error("Invalid credentials"); } try { final DockerServerEndpoint dsep = new DockerServerEndpoint(uri, credentialsId); final DockerAPI dapi = new DockerAPI(dsep, connectTimeout, readTimeout, apiVersion, null); try(final DockerClient dc = dapi.getClient()) { final VersionCmd vc = dc.versionCmd(); final Version v = vc.exec(); final String actualVersion = v.getVersion(); final String actualApiVersion = v.getApiVersion(); return FormValidation.ok("Version = " + actualVersion + ", API Version = " + actualApiVersion); } } catch (Exception e) { return FormValidation.error(e, e.getMessage()); } }
Example #16
Source File: TemplateImplementationProjectListener.java From ez-templates with Apache License 2.0 | 5 votes |
@Override public void onUpdated(Item item) { TemplateImplementationProperty property = getTemplateImplementationProperty(item); if (property != null) { try { TemplateUtils.handleTemplateImplementationSaved((AbstractProject) item, property); } catch (Exception e) { throw Throwables.propagate(e); } } }
Example #17
Source File: GitHubSCMSourceTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test @Issue("JENKINS-48035") public void testGitHubRepositoryNameContributor_When_not_MultiBranch() throws IOException { FreeStyleProject job = r.createProject(FreeStyleProject.class); Collection<GitHubRepositoryName> names = GitHubRepositoryNameContributor.parseAssociatedNames((Item) job); assertThat(names, Matchers.empty()); //And specifically... names = new ArrayList<>(); ExtensionList.lookup(GitHubRepositoryNameContributor.class).get(GitHubSCMSourceRepositoryNameContributor.class).parseAssociatedNames((Item) job, names); assertThat(names, Matchers.empty()); }
Example #18
Source File: DatabaseSyncItemListener.java From pipeline-maven-plugin with MIT License | 5 votes |
@Override public void onDeleted(Item item) { if (item instanceof WorkflowJob) { WorkflowJob pipeline = (WorkflowJob) item; onDeleted(pipeline); } else { LOGGER.log(Level.FINE, "Ignore onDeleted({0})", new Object[]{item}); } }
Example #19
Source File: PipelineContainerImpl.java From blueocean-plugin with MIT License | 5 votes |
@Override public BluePipeline get(String name) { Item item; item = itemGroup.getItem(name); if(item == null){ throw new ServiceException.NotFoundException(String.format("Pipeline %s not found", name)); } return BluePipelineFactory.getPipelineInstance(item, this); }
Example #20
Source File: BuildWebHookAction.java From gitlab-plugin with GNU General Public License v2.0 | 5 votes |
public void run() { GitLabPushTrigger trigger = GitLabPushTrigger.getFromJob((Job<?, ?>) project); if (trigger != null) { if (StringUtils.isEmpty(trigger.getSecretToken())) { checkPermission(Item.BUILD, project); } else if (!StringUtils.equals(trigger.getSecretToken(), secretToken)) { throw HttpResponses.errorWithoutStack(401, "Invalid token"); } performOnPost(trigger); } }
Example #21
Source File: GitHubBranchRepositoryNameContributor.java From github-integration-plugin with MIT License | 5 votes |
@Override public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) { if (!(item instanceof Job)) { return; } Job job = (Job) item; final GitHubBranchTrigger gitHubBranchTrigger = ghBranchTriggerFromJob(job); if (nonNull(gitHubBranchTrigger)) { result.add(gitHubBranchTrigger.getRepoFullName(job)); } }
Example #22
Source File: OrganizationFactory.java From blueocean-plugin with MIT License | 5 votes |
/** * Finds a nearest organization that contains the given {@link ItemGroup}. * * @return * null if the given object doesn't belong to any organization. */ @CheckForNull public BlueOrganization getContainingOrg(ItemGroup p) { while (true) { BlueOrganization n = of(p); if (n != null) { return n; } if (p instanceof Item) { p = ((Item) p).getParent(); } else { return null; // hit the top } } }
Example #23
Source File: MockFolder.java From jenkins-test-harness with MIT License | 5 votes |
@Override public void onCopiedFrom(Item src) { super.onCopiedFrom(src); for (TopLevelItem item : ((MockFolder) src).getItems()) { try { copy(item, item.getName()); } catch (IOException x) { assert false : x; } } }
Example #24
Source File: Functions.java From github-integration-plugin with MIT License | 5 votes |
/** * Can be useful to ignore disabled jobs on reregistering hooks * * @return predicate with true on apply if item is buildable */ public static <ITEM extends Item> Predicate<ITEM> isBuildable() { return item -> { if (item instanceof Job) { return ((Job) item).isBuildable(); } else if (item instanceof ComputedFolder) { return ((ComputedFolder) item).isBuildable(); } return item instanceof BuildableItem; }; }
Example #25
Source File: GitHubPRRepository.java From github-integration-plugin with MIT License | 5 votes |
@Override public FormValidation doBuild(StaplerRequest req) throws IOException { FormValidation result; try { if (!job.hasPermission(Item.BUILD)) { return FormValidation.error("Forbidden"); } final String prNumberParam = "prNumber"; int prId = 0; if (req.hasParameter(prNumberParam)) { prId = Integer.valueOf(req.getParameter(prNumberParam)); } if (prId == 0 || !getPulls().containsKey(prId)) { return FormValidation.error("No branch to build"); } final GitHubPRPullRequest localPR = getPulls().get(prId); final GitHubPRCause cause = new GitHubPRCause(localPR, null, this, false, "Manual run."); final JobRunnerForCause runner = new JobRunnerForCause(getJob(), ghPRTriggerFromJob(getJob())); final QueueTaskFuture<?> queueTaskFuture = runner.startJob(cause); if (nonNull(queueTaskFuture)) { result = FormValidation.ok("Build scheduled"); } else { result = FormValidation.warning("Build not scheduled"); } } catch (Exception e) { LOG.error("Can't start build", e.getMessage()); result = FormValidation.error(e, "Can't start build: " + e.getMessage()); } return result; }
Example #26
Source File: ContainerFilter.java From blueocean-plugin with MIT License | 5 votes |
/** * Filters the item list based on the current StaplerRequest */ public static <T extends Item> Collection<T> filter(Collection<T> items) { String[] filterNames = filterNames(); if(filterNames.length == 0){ return items; } return filter(items, filterNames); }
Example #27
Source File: ItemChangeListener.java From audit-log-plugin with MIT License | 5 votes |
/** * Fired right before a job is going to be deleted * * @param item is item to be deleted. */ @Override public void onDeleted(Item item) { DeleteItem itemDeleteEvent = LogEventFactory.getEvent(DeleteItem.class); itemDeleteEvent.setItemName(item.getName()); itemDeleteEvent.setItemUri(item.getUrl()); itemDeleteEvent.setTimestamp(formatDateISO(System.currentTimeMillis())); itemDeleteEvent.logEvent(); }
Example #28
Source File: GlobalKafkaConfiguration.java From remoting-kafka-plugin with MIT License | 5 votes |
public FormValidation doCheckSslKeyCredentialsId(@AncestorInPath Item item, @QueryParameter String value) { FormValidation checkedResult = checkCredentialsId(item, value); boolean isAdminOrNullItem = (item != null || Jenkins.get().hasPermission(Jenkins.ADMINISTER)); if (isAdminOrNullItem && checkedResult.equals(FormValidation.ok())) { this.sslKeyCredentialsId = value; } return checkedResult; }
Example #29
Source File: GitHubRepositoryEventSubscriber.java From github-branch-source-plugin with MIT License | 5 votes |
@Override protected boolean isApplicable(@Nullable Item item) { if (item instanceof SCMNavigatorOwner) { for (SCMNavigator navigator : ((SCMNavigatorOwner) item).getSCMNavigators()) { if (navigator instanceof GitHubSCMNavigator) { return true; // TODO allow navigators to opt-out } } } return false; }
Example #30
Source File: FreeStylePipeline.java From blueocean-plugin with MIT License | 5 votes |
@Override public Resource resolve(Item context, Reachable parent, Item target, BlueOrganization organization) { if(context == target && target instanceof FreeStyleProject) { return getPipeline(target, parent, organization); } return null; }