Skip to content
Permalink
Browse files

[FIXED JENKINS-10301] Using new interface of Parameterized Trigger

Join trigger now requires Parameterized trigger > 2.10
  • Loading branch information...
wolfs committed Jul 11, 2011
1 parent dd08eba commit 8be8ddf78d9c64010ea904e0535df568b6e24210
Showing with 43 additions and 38 deletions.
  1. +1 −1 pom.xml
  2. +42 −37 src/main/java/join/JoinTrigger.java
@@ -28,7 +28,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>parameterized-trigger</artifactId>
<version>2.8</version>
<version>2.10</version>
<optional>true</optional>
</dependency>
<dependency>
@@ -23,6 +23,7 @@
*/
package join;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.Plugin;
@@ -110,27 +111,54 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
BuildTrigger buildTrigger = build.getProject().getPublishersList().get(BuildTrigger.class);
JoinAction joinAction = new JoinAction(this, buildTrigger, tryGetParameterizedDownstreamNames(build));
JoinAction joinAction = new JoinAction(this, buildTrigger, tryGetParameterizedDownstreamNames(build,listener));
build.addAction(joinAction);
joinAction.checkPendingDownstream(build, listener);
return true;
}

private ArrayList<String> tryGetParameterizedDownstreamNames(AbstractBuild<?, ?> build) {
private ArrayList<String> tryGetParameterizedDownstreamNames(AbstractBuild<?, ?> build, BuildListener listener) {
ArrayList<String> ret = new ArrayList<String>();
EnvVars env = null;
try {
env = build.getEnvironment(listener);
} catch (Exception e) {
listener.getLogger().print(e);
}

for (AbstractProject<?,?> project :
getParameterizedDownstreamProjects(build.getProject().getPublishersList(), env)) {
if (!project.isDisabled()) {
ret.add(project.getName());
}
}
return ret;
}

private List<BuildTriggerConfig> getBuildTriggerConfigs(
DescribableList<Publisher,Descriptor<Publisher>> publishers) {
List<BuildTriggerConfig> ret = new ArrayList<BuildTriggerConfig>();
Plugin parameterizedTrigger = Hudson.getInstance().getPlugin("parameterized-trigger");
if (parameterizedTrigger != null) {
hudson.plugins.parameterizedtrigger.BuildTrigger buildTrigger =
build.getProject().getPublishersList().get(hudson.plugins.parameterizedtrigger.BuildTrigger.class);
publishers.get(hudson.plugins.parameterizedtrigger.BuildTrigger.class);
if (buildTrigger != null) {
for(hudson.plugins.parameterizedtrigger.BuildTriggerConfig config : buildTrigger.getConfigs()) {
for(AbstractProject project : config.getProjectList()) {
if (!project.isDisabled()) {
ret.add(project.getName());
}
ret.add(config);
}
}
}
return ret;
}

private List<AbstractProject<?,?>> getParameterizedDownstreamProjects(
DescribableList<Publisher,Descriptor<Publisher>> publishers, EnvVars env) {
List<AbstractProject<?,?>> ret = new ArrayList<AbstractProject<?,?>>();
for(hudson.plugins.parameterizedtrigger.BuildTriggerConfig config :
getBuildTriggerConfigs(publishers)) {
for (AbstractProject<?,?> project : config.getProjectList(env)) {
ret.add(project);
}
}
return ret;
}
@@ -147,19 +175,13 @@ public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
if (downstreamProjects.isEmpty()) {
downstreamProjects.add(owner);
}
Plugin parameterizedTrigger = Hudson.getInstance().getPlugin("parameterized-trigger");

for (AbstractProject<?,?> downstreamProject: downstreamProjects) {
if (parameterizedTrigger != null) {
hudson.plugins.parameterizedtrigger.BuildTrigger paramBt =
joinPublishers.get(hudson.plugins.parameterizedtrigger.BuildTrigger.class);
if (paramBt != null) {
for (BuildTriggerConfig config : paramBt.getConfigs()) {
for (AbstractProject<?,?> joinProject : config.getProjectList()) {
ParameterizedJoinDependency dependency =
new ParameterizedJoinDependency(downstreamProject, joinProject, owner, config);
graph.addDependency(dependency);
}
}
for (BuildTriggerConfig config : getBuildTriggerConfigs(joinPublishers)) {
for (AbstractProject<?,?> joinProject : config.getProjectList(null)) {
ParameterizedJoinDependency dependency =
new ParameterizedJoinDependency(downstreamProject, joinProject, owner, config);
graph.addDependency(dependency);
}
}

@@ -179,27 +201,10 @@ static boolean canDeclare(AbstractProject<?,?> owner) {

public List<AbstractProject<?,?>> getAllDownstream(AbstractProject<?,?> project) {
List<AbstractProject<?,?>> downstream = getBuildTriggerDownstream(project);
downstream.addAll(getParameterizedDownstream(project));
downstream.addAll(getParameterizedDownstreamProjects(project.getPublishersList(), null));
return downstream;
}

public List<AbstractProject<?,?>> getParameterizedDownstream(AbstractProject<?,?> project) {
ArrayList<AbstractProject<?,?>> ret = new ArrayList<AbstractProject<?,?>>();
Plugin parameterizedTrigger = Hudson.getInstance().getPlugin("parameterized-trigger");
if (parameterizedTrigger != null) {
hudson.plugins.parameterizedtrigger.BuildTrigger buildTrigger =
project.getPublishersList().get(hudson.plugins.parameterizedtrigger.BuildTrigger.class);
if (buildTrigger != null) {
for(hudson.plugins.parameterizedtrigger.BuildTriggerConfig config : buildTrigger.getConfigs()) {
for(AbstractProject<?,?> downStreamProject : config.getProjectList()) {
ret.add(downStreamProject);
}
}
}
}
return ret;
}

public List<AbstractProject<?,?>> getBuildTriggerDownstream(AbstractProject<?,?> project) {
ArrayList<AbstractProject<?,?>> ret = new ArrayList<AbstractProject<?,?>>();
BuildTrigger buildTrigger = project.getPublishersList().get(BuildTrigger.class);

0 comments on commit 8be8ddf

Please sign in to comment.
You can’t perform that action at this time.