hudson.model.Action源码实例Demo

类hudson.model.Action源码实例Demo

下面列出了hudson.model.Action 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@NonNull
@Override
protected List<Action> retrieveActions(SCMSourceEvent event, @NonNull TaskListener listener) {
    List<Action> result = new ArrayList<>();
    getGitlabProject();
    GitLabSCMSourceContext ctx = new GitLabSCMSourceContext(null, SCMHeadObserver.none()).withTraits(traits);
    String projectUrl = gitlabProject.getWebUrl();
    String name = StringUtils.isBlank(projectName) ? gitlabProject.getNameWithNamespace() : projectName;
    result.add(new ObjectMetadataAction(name, gitlabProject.getDescription(), projectUrl));
    String avatarUrl = gitlabProject.getAvatarUrl();
    if (!ctx.projectAvatarDisabled() && StringUtils.isNotBlank(avatarUrl)) {
        result.add(new GitLabAvatar(avatarUrl));
    }
    result.add(GitLabLink.toProject(projectUrl));
    return result;
}
 
@Nonnull
private List<Action> retrieve(@Nonnull SCMRevisionImpl revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    List<Action> actions = new ArrayList<>();

    String hash = revision.getHash();
    Action linkAction = GitLabLinkAction.toCommit(source.getProject(), hash);
    actions.add(linkAction);

    SCMHead head = revision.getHead();
    if (head instanceof GitLabSCMMergeRequestHead) {
        actions.add(createHeadMetadataAction(head.getName(), ((GitLabSCMMergeRequestHead) head).getSource(), hash, linkAction.getUrlName()));
    } else if (head instanceof GitLabSCMHead) {
        actions.add(createHeadMetadataAction(head.getName(), (GitLabSCMHead) head, hash, linkAction.getUrlName()));
    }

    if (event instanceof GitLabSCMEvent) {
        actions.add(new GitLabSCMCauseAction(((GitLabSCMEvent) event).getCause()));
    }

    return actions;
}
 
源代码3 项目: blueocean-plugin   文件: TryBlueOceanMenu.java
/**
 * {@inheritDoc}
 */
@Nonnull
@Override
public Collection<? extends Action> createFor(@Nonnull ModelObject target) {
    // we do not report actions as it might appear multiple times, we simply add it to Actionable
    BlueOceanUrlObjectFactory f = getFirst();
    if(f != null) {
        // TODO remove this if block once we are using a core > 2.126
        // Work around JENKINS-51584
        if (target instanceof hudson.model.Queue.Item) {
            return Collections.emptyList();
        }
        BlueOceanUrlObject blueOceanUrlObject = f.get(target);
        BlueOceanUrlAction a = new BlueOceanUrlAction(blueOceanUrlObject);
        return Collections.singleton(a);
    }
    return Collections.emptyList();
}
 
源代码4 项目: blueocean-plugin   文件: OrganizationImpl.java
/**
 * Give plugins chance to handle this API route.
 *
 * @param route URL path that needs handling. e.g. for requested url /rest/organizations/:id/xyz,  route param value will be 'xyz'
 * @return stapler object that can handle give route. Could be null
 */
public Object getDynamic(String route){
    //First look for OrganizationActions
    for(OrganizationRoute organizationRoute: ExtensionList.lookup(OrganizationRoute.class)){
        if(organizationRoute.getUrlName() != null && organizationRoute.getUrlName().equals(route)){
            return wrap(organizationRoute);
        }
    }

    // No OrganizationRoute found, now lookup in available actions from Jenkins instance serving root
    for(Action action:Jenkins.getInstance().getActions()) {
        String urlName = action.getUrlName();
        if (urlName != null && urlName.equals(route)) {
            return wrap(action);
        }
    }
    return null;
}
 
/**
 * Gets the {@link DockerTraceabilityRootAction} of Jenkins instance.
 * @return Instance or null if it is not available
 */
public static @CheckForNull DockerTraceabilityRootAction getInstance() {
    Jenkins j = Jenkins.getInstance();
    if (j == null) {
        return null;
    }
    
    @CheckForNull DockerTraceabilityRootAction action = null;
    for (Action rootAction : j.getActions()) {
        if (rootAction instanceof DockerTraceabilityRootAction) {
            action = (DockerTraceabilityRootAction) rootAction;
            break;
        }
    } 
    return action;
}
 
@NonNull
@Override
protected List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner,
    SCMNavigatorEvent event,
    @NonNull TaskListener listener) throws IOException, InterruptedException {
    getGitlabOwner();
    String fullName = gitlabOwner.getFullName();
    String webUrl = gitlabOwner.getWebUrl();
    String avatarUrl = gitlabOwner.getAvatarUrl();
    String description = null;
    if (gitlabOwner instanceof GitLabGroup) {
        description = ((GitLabGroup) gitlabOwner).getDescription();
    }
    List<Action> result = new ArrayList<>();
    result.add(new ObjectMetadataAction(
        Util.fixEmpty(fullName),
        description,
        webUrl)
    );
    if (StringUtils.isNotBlank(avatarUrl)) {
        result.add(new GitLabAvatar(avatarUrl));
    }
    result.add(GitLabLink.toGroup(webUrl));
    if (StringUtils.isBlank(webUrl)) {
        listener.getLogger().println("Web URL unspecified");
    } else {
        listener.getLogger().printf("%s URL: %s%n", gitlabOwner.getWord(),
            HyperlinkNote
                .encodeTo(webUrl, StringUtils.defaultIfBlank(fullName, webUrl)));
    }
    return result;
}
 
@Nonnull
@Override
protected List<Action> retrieveActions(@Nonnull SCMHead head,
                                       @CheckForNull SCMHeadEvent event,
                                       @Nonnull TaskListener listener)
        throws IOException, InterruptedException {
    List<Action> actions = new ArrayList<>();

    GHRepository remoteRepo = getRemoteRepo();

    boolean primary = false;
    GitHubLinkAction link = null;
    String desc = null;

    if (head instanceof GitHubBranchSCMHead) {
        // mark default branch item as primary
        primary = remoteRepo.getDefaultBranch().equals(head.getName());
        link = new GitHubBranchAction(remoteRepo, head.getName());
        desc = null;
    } else if (head instanceof GitHubTagSCMHead) {
        link = new GitHubTagAction(remoteRepo, head.getName());
        desc = null;
    } else if (head instanceof GitHubPRSCMHead) {
        GitHubPRSCMHead prHead = (GitHubPRSCMHead) head;
        link = new GitHubPRAction(remoteRepo, prHead.getPrNumber());
        desc = remoteRepo.getPullRequest(prHead.getPrNumber()).getTitle();
    }

    if (nonNull(link)) {
        actions.add(link);
    }

    actions.add(new ObjectMetadataAction(null, desc, isNull(link) ? null : link.getUrlName()));
    if (primary) {
        actions.add(new PrimaryInstanceMetadataAction());
    }

    return actions;
}
 
@Test
void shouldNeverReturnMultipleProjectActions() {
    AggregationAction action = new AggregationAction();
    action.onLoad(mock(Run.class));

    Collection<? extends Action> projectActions = action.getProjectActions();

    assertThat(projectActions).hasSize(1);
    assertThat(projectActions.iterator().next()).isInstanceOf(AggregatedTrendAction.class);
}
 
源代码9 项目: warnings-ng-plugin   文件: IntegrationTest.java
@SuppressWarnings({"illegalcatch", "OverlyBroadCatchBlock"})
protected Run<?, ?> buildWithResult(final ParameterizedJob<?, ?> job, final Result expectedResult) {
    try {
        Run<?, ?> build = getJenkins().assertBuildStatus(expectedResult,
                Objects.requireNonNull(job.scheduleBuild2(0, new Action[0])));
        printConsoleLog(build);
        return build;
    }
    catch (Exception e) {
        throw new AssertionError(e);
    }
}
 
@Override
public Collection<? extends Action> createFor(@Nonnull Job target) {
  Run build = target.getLastBuild();
  if (build == null) {
    return Collections.emptyList();
  } else {
    return Collections.singleton(new BuildFlowAction(build));
  }
}
 
源代码11 项目: gitea-plugin   文件: GiteaSCMNavigator.java
@NonNull
@Override
protected List<Action> retrieveActions(@NonNull SCMNavigatorOwner owner, SCMNavigatorEvent event,
                                       @NonNull TaskListener listener) throws IOException, InterruptedException {
    if (this.giteaOwner == null) {
        try (GiteaConnection c = gitea(owner).open()) {
            this.giteaOwner = c.fetchUser(repoOwner);
            if (StringUtils.isBlank(giteaOwner.getEmail())) {
                this.giteaOwner = c.fetchOrganization(repoOwner);
            }
        }
    }
    List<Action> result = new ArrayList<>();
    String objectUrl = UriTemplate.buildFromTemplate(serverUrl)
            .path("owner")
            .build()
            .set("owner", repoOwner)
            .expand();
    result.add(new ObjectMetadataAction(
            Util.fixEmpty(giteaOwner.getFullName()),
            null,
            objectUrl)
    );
    if (StringUtils.isNotBlank(giteaOwner.getAvatarUrl())) {
        result.add(new GiteaAvatar(giteaOwner.getAvatarUrl()));
    }
    result.add(new GiteaLink("icon-gitea-org", objectUrl));
    if (giteaOwner instanceof GiteaOrganization) {
        String website = ((GiteaOrganization) giteaOwner).getWebsite();
        if (StringUtils.isBlank(website)) {
            listener.getLogger().println("Organization website: unspecified");
        } else {
            listener.getLogger().printf("Organization website: %s%n",
                    HyperlinkNote.encodeTo(website, StringUtils.defaultIfBlank(giteaOwner.getFullName(), website)));
        }
    }
    return result;
}
 
@Test
    public void createForNullTrigger() {
//        when(job.getTrigger(GitHubPRTrigger.class)).thenReturn(null);
        PowerMockito.mockStatic(JobHelper.class);
        given(ghPRTriggerFromJob(job))
                .willReturn(null);

        Collection<? extends Action> repoCollection = new GitHubPRRepositoryFactory().createFor(job);
        Assert.assertTrue(repoCollection instanceof List);
        Assert.assertTrue(repoCollection.isEmpty());
    }
 
@Nonnull
@Override
public Collection<? extends Action> createFor(@Nonnull Job job) {
    try {
        if (nonNull(ghBranchTriggerFromJob(job))) {
            return Collections.singleton(forProject(job));
        }
    } catch (Exception ex) {
        LOGGER.warn("Bad configured project {} - {}", job.getFullName(), ex.getMessage(), ex);
    }

    return Collections.emptyList();
}
 
@Nonnull
List<Action> retrieve(@CheckForNull SCMSourceEvent event, @Nonnull TaskListener listener) throws IOException {
    GitLabProject project = source.getProject();
    return asList(
            new ObjectMetadataAction(project.getNameWithNamespace(), project.getDescription(), project.getWebUrl()),
            new GitLabProjectAvatarMetadataAction(project.getId(), source.getSourceSettings().getConnectionName()),
            GitLabLinkAction.toProject(project));
}
 
@Nonnull
List<Action> retrieve(@Nonnull SCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    if (head instanceof GitLabSCMHead) {
        return retrieve((GitLabSCMHead) head, event, listener);
    }

    return emptyList();
}
 
@Nonnull
private List<Action> retrieve(@Nonnull GitLabSCMHead head, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    List<Action> actions = new ArrayList<>();

    actions.add(new GitLabSCMPublishAction(head, source.getSourceSettings()));

    Action linkAction;

    if (head instanceof ChangeRequestSCMHead) {
        GitLabMergeRequest mr = retrieveMergeRequest((ChangeRequestSCMHead) head, listener);
        linkAction = GitLabLinkAction.toMergeRequest(mr.getWebUrl());
        actions.add(createAuthorMetadataAction(mr));
        actions.add(createHeadMetadataAction(((GitLabSCMMergeRequestHead) head).getDescription(), ((GitLabSCMMergeRequestHead) head).getSource(), null, linkAction.getUrlName()));
        if (acceptMergeRequest(head)) {
            boolean removeSourceBranch = mr.getRemoveSourceBranch() || removeSourceBranch(head);
            actions.add(new GitLabSCMAcceptMergeRequestAction(mr, mr.getIid(), source.getSourceSettings().getMergeCommitMessage(), removeSourceBranch));
        }
    } else {
        linkAction = (head instanceof TagSCMHead) ? GitLabLinkAction.toTag(source.getProject(), head.getName()) : GitLabLinkAction.toBranch(source.getProject(), head.getName());
        if (head instanceof GitLabSCMBranchHead && StringUtils.equals(source.getProject().getDefaultBranch(), head.getName())) {
            actions.add(new PrimaryInstanceMetadataAction());
        }
    }

    actions.add(linkAction);
    return actions;
}
 
@Nonnull
List<Action> retrieve(@Nonnull SCMRevision revision, @CheckForNull SCMHeadEvent event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    if (revision instanceof SCMRevisionImpl) {
        return retrieve((SCMRevisionImpl) revision, event, listener);
    }

    return emptyList();
}
 
源代码18 项目: blueocean-plugin   文件: Export.java
@Override
public Object getValue(Property property, Object model, ExportConfig config) throws IOException {
    if(model instanceof Action){
        try {
            return property.getValue(model);
        } catch (Throwable e) {
            printError(model.getClass(), e);
            return SKIP;
        }
    } else if (model instanceof Item || model instanceof Run) {
        // We should skip any models that are Jenkins Item or Run objects as these are known to be evil
        return SKIP;
    }
    return ExportInterceptor.DEFAULT.getValue(property, model, config);
}
 
源代码19 项目: blueocean-plugin   文件: ActionProxiesImpl.java
/**
 * Finds all the actions and proxys them so long as they are annotated with ExportedBean
 * @param actions to proxy
 * @param parent reachable
 * @return actionProxies
 */
public static Collection<BlueActionProxy> getActionProxies(List<? extends Action> actions, Reachable parent){
    if(isTreeRequest()){
        return getActionProxies(actions, Predicates.<Action>alwaysFalse(), parent);
    }
    return Collections.emptyList();

}
 
源代码20 项目: blueocean-plugin   文件: AbstractRunImpl.java
/**
 * Handles HTTP path handled by actions or other extensions
 *
 * @param token path token that an action or extension can handle
 *
 * @return action or extension that handles this path.
 */
public Object getDynamic(String token) {
    for (Action a : run.getAllActions()) {
        if (token.equals(a.getUrlName()))
            return new GenericResource<>(a);
    }

    return null;
}
 
源代码21 项目: blueocean-plugin   文件: PipelineNodeImpl.java
@Override
public Collection<BlueActionProxy> getActions() {

    HashSet<Action> actions = new HashSet<>();

    // Actions attached to the node we use for the graph
    actions.addAll(node.getNode().getActions());

    // Actions from any child nodes
    actions.addAll(node.getPipelineActions(NodeDownstreamBuildAction.class));

    return ActionProxiesImpl.getActionProxies(actions,
                                              input -> input instanceof LogAction || input instanceof NodeDownstreamBuildAction,
                                              this);
}
 
源代码22 项目: blueocean-plugin   文件: FlowNodeWrapper.java
/**
 * Returns Action instances that were attached to the associated FlowNode, or to any of its children
 * not represented in the graph.
 * Filters by class to mimic Item.getActions(class).
 */
public <T extends Action> Collection<T> getPipelineActions(Class<T> clazz) {
    if (pipelineActions == null) {
        return Collections.emptyList();
    }
    ArrayList<T> filtered = new ArrayList<>();
    for (Action a : pipelineActions) {
        if (clazz.isInstance(a)) {
            filtered.add(clazz.cast(a));
        }
    }
    return filtered;
}
 
@CheckForNull
public static GitHubPRRepository getRepo(Collection<? extends Action> repoCollection) {
    GitHubPRRepository repo = null;
    for (Iterator<GitHubPRRepository> iterator = (Iterator<GitHubPRRepository>) repoCollection.iterator(); iterator.hasNext(); ) {
        repo = iterator.next();
    }
    return repo;
}
 
/**
 * Find any Actions on this node, and add them to the pipelineActions collection until we can attach
 * them to a FlowNodeWrapper.
 */
protected void accumulatePipelineActions(FlowNode node) {
    final List<Action> actions = node.getActions(Action.class);
    pipelineActions.addAll(actions);
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("\t\taccumulating actions - added %d, total is %d", actions.size(), pipelineActions.size()));
    }
}
 
/**
 * Empty the pipelineActions buffer, returning its contents.
 */
protected Set<Action> drainPipelineActions() {
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("\t\tdraining accumulated actions - total is %d", pipelineActions.size()));
    }

    if (pipelineActions.size() == 0) {
        return Collections.emptySet();
    }

    Set<Action> drainedActions = pipelineActions;
    pipelineActions = new HashSet<>();
    return drainedActions;
}
 
源代码26 项目: blueocean-plugin   文件: PipelineNodeUtil.java
@CheckForNull
public static TagsAction getSyntheticStage(@Nullable FlowNode node){
    if(node != null) {
        for (Action action : node.getActions()) {
            if (action instanceof TagsAction && ((TagsAction) action).getTagValue(SyntheticStage.TAG_NAME) != null) {
                return (TagsAction) action;
            }
        }
    }
    return null;
}
 
@Nonnull
@Override
protected List<Action> retrieveActions(@Nonnull SCMRevision revision, @CheckForNull SCMHeadEvent event,
                                       @Nonnull TaskListener listener) throws IOException, InterruptedException {
    GitHubSCMRevision gitHubSCMRevision = (GitHubSCMRevision) revision;
    GitHubCause<?> cause = gitHubSCMRevision.getCause();
    if (nonNull(cause)) {
        List<ParameterValue> params = new ArrayList<>();
        cause.fillParameters(params);
        return Arrays.asList(new CauseAction(cause), new GitHubParametersAction(params));
    }

    return Collections.emptyList();
}
 
@Test
public void taskCompleted_should_resubmit_task_if_offline_and_cause_disconnect() {
    when(computer.getExecutors()).thenReturn(Arrays.asList(executor1));
    when(computer.getOfflineCause()).thenReturn(new OfflineCause.ChannelTermination(null));
    new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher)
            .afterDisconnect(computer, taskListener);
    verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.<Action>emptyList()));
    verifyZeroInteractions(queue);
}
 
@Test
public void taskCompleted_should_resubmit_task_for_all_executors() {
    when(computer.getOfflineCause()).thenReturn(new OfflineCause.ChannelTermination(null));
    new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher)
            .afterDisconnect(computer, taskListener);
    verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.<Action>emptyList()));
    verify(queue).schedule2(eq(task2), anyInt(), eq(Collections.<Action>emptyList()));
    verifyZeroInteractions(queue);
}
 
@Test
public void containerIDs_CRUD() throws Exception {
    // TODO: replace by a helper method from the branch
    JenkinsRule.WebClient client = j.createWebClient();
    @CheckForNull DockerTraceabilityRootAction action = null;
    for (Action rootAction : j.getInstance().getActions()) {
        if (rootAction instanceof DockerTraceabilityRootAction) {
            action = (DockerTraceabilityRootAction) rootAction;
            break;
        }
    }    
    assertNotNull(action);
    
    final String id1 = FingerprintTestUtil.generateDockerId("1");
    final String id2 = FingerprintTestUtil.generateDockerId("2");
    final String id3 = FingerprintTestUtil.generateDockerId("3");
    
    // Check consistency of create/update commands
    action.addContainerID(id1);
    assertEquals(1, action.getContainerIDs().size());
    action.addContainerID(id2);
    assertEquals(2, action.getContainerIDs().size());
    action.addContainerID(id2);
    assertEquals(2, action.getContainerIDs().size());
    
    // Remove data using API. First entry is non-existent
    action.doDeleteContainer(id3);
    assertEquals(2, action.getContainerIDs().size());
    action.doDeleteContainer(id1);
    assertEquals(1, action.getContainerIDs().size());
    action.doDeleteContainer(id1);
    assertEquals(1, action.getContainerIDs().size());
    
    // Reload the data and ensure the status has been persisted correctly
    action = new DockerTraceabilityRootAction();
    assertEquals(1, action.getContainerIDs().size());
    for (String id : action.getContainerIDs()) {
        assertEquals(id2, id);
    }
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法