Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete DownstreamJobListener and instead create NodeDownstreamBuildAction dynamically during graph processing based on DownstreamBuildAction #2540

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package io.jenkins.blueocean.listeners;

import hudson.Extension;
import hudson.model.Action;
import hudson.model.Actionable;
import hudson.model.InvisibleAction;
import hudson.model.Queue;
import hudson.model.Run;
import io.jenkins.blueocean.rest.Reachable;
import io.jenkins.blueocean.rest.hal.Link;
import io.jenkins.blueocean.rest.hal.LinkResolver;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.TransientActionFactory;
import org.jenkinsci.plugins.workflow.actions.FlowNodeAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.support.steps.build.DownstreamBuildAction;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.util.Objects;

/**
* Annotates a FlowNode to point to a downstream build triggered by said node. Applied by
* io.jenkins.blueocean.listeners.DownstreamJobListener in blueocean-pipeline-api-impl
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
*/
@ExportedBean
public class NodeDownstreamBuildAction extends InvisibleAction implements FlowNodeAction, Reachable {
private static final Logger LOGGER = Logger.getLogger(NodeDownstreamBuildAction.class.getName());

private final Link link;
private final String description;
Expand Down Expand Up @@ -57,4 +70,41 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(link, description);
}

@Extension
public static class FactoryImpl extends TransientActionFactory<FlowNode> {

@Override
public Class<FlowNode> type() {
return FlowNode.class;
}

@Override
public Collection<? extends Action> createFor(FlowNode node) {
try {
Queue.Executable executable = node.getExecution().getOwner().getExecutable();
if (executable instanceof Actionable) {
DownstreamBuildAction action = ((Actionable) executable).getAction(DownstreamBuildAction.class);
if (action != null) {
for (DownstreamBuildAction.DownstreamBuild downstreamBuild : action.getDownstreamBuilds()) {
if (downstreamBuild.getFlowNodeId().equals(node.getId())) {
Run<?, ?> downstream = downstreamBuild.getBuild();
dwnusbaum marked this conversation as resolved.
Show resolved Hide resolved
if (downstream != null) {
Link link = LinkResolver.resolveLink(downstream);
String description = downstream.getDescription();
if (description == null) {
description = downstream.getFullDisplayName();
}
return Collections.singleton(new NodeDownstreamBuildAction(link, description));
}
}
}
}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, null, e);
}
return Collections.emptySet();
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.401.x</artifactId>
<version>2401.v7a_d68f8d0b_09</version>
<version>2661.vb_b_60650f6d97</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
Loading