Skip to content

Commit

Permalink
Merge pull request #10 from Edgar0119/master
Browse files Browse the repository at this point in the history
(Bug Fixed!)JENKINS-28709 Join Plugin ignores dependencies wrapped with flexible-…
  • Loading branch information
mdonohue committed May 31, 2016
2 parents 54908f8 + 29fdc19 commit 7ff6743
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -56,6 +56,12 @@
<version>2.12</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>flexible-publish</artifactId>
<version>0.15.2</version>
<optional>true</optional>
</dependency>
</dependencies>

<properties>
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/join/JoinTrigger.java
Expand Up @@ -64,12 +64,15 @@
import join.JoinAction.JoinCause;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkins_ci.plugins.flexible_publish.ConditionalPublisher;
import org.jenkins_ci.plugins.flexible_publish.FlexiblePublisher;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Level;
Expand Down Expand Up @@ -210,6 +213,52 @@ private List<AbstractProject<?,?>> getDownstreamExtDownstream(
return ret;
}

private Collection<? extends AbstractProject<?, ?>> getParameterizedDownstreamInFlexiblePublisher(
AbstractProject<?, ?> project) {

DescribableList<Publisher, Descriptor<Publisher>> publishers = project.getPublishersList();
List<AbstractProject<?, ?>> ret = new ArrayList<AbstractProject<?, ?>>();
Plugin flexiblePublisherPlugin = Jenkins.getInstance().getPlugin("flexible-publish");
Plugin parameterizedTrigger = Jenkins.getInstance().getPlugin("parameterized-trigger");

if (flexiblePublisherPlugin == null || parameterizedTrigger == null) {
return ret;
}

FlexiblePublisher flexiblePublisher = publishers.get(FlexiblePublisher.class);

if (flexiblePublisher != null ) {

for (ConditionalPublisher conditionalPublisher : flexiblePublisher.getPublishers()) {
for (BuildStep buildStep : conditionalPublisher.getPublisherList()) {
if (buildStep instanceof hudson.plugins.parameterizedtrigger.BuildTrigger) {

ret.addAll(GetProjectFromBuildTriggerConfigs(buildStep));
}
}
}
}

return ret;
}

private Collection<? extends AbstractProject<?, ?>> GetProjectFromBuildTriggerConfigs(
Object buildTrigger) {

List<AbstractProject<?, ?>> ret = new ArrayList<AbstractProject<?, ?>>();

for (hudson.model.Project p : Hudson.getInstance().getProjects()) {

for (BuildTriggerConfig config : ((hudson.plugins.parameterizedtrigger.BuildTrigger )buildTrigger).getConfigs()) {
if (p.getName().equals(config.getProjects())) {
ret.add(p);
}
}
}

return ret;
}

static boolean canDeclare(AbstractProject<?,?> owner) {
// Inner class added in Hudson 1.341
return true;
Expand All @@ -218,10 +267,12 @@ static boolean canDeclare(AbstractProject<?,?> owner) {

public List<AbstractProject<?,?>> getAllDownstream(AbstractProject<?,?> project, EnvVars env) {
List<AbstractProject<?,?>> downstream = getBuildTriggerDownstream(project);
downstream.addAll(getParameterizedDownstreamInFlexiblePublisher(project));
downstream.addAll(getParameterizedDownstreamProjects(project.getParent(), project.getPublishersList(), env));
downstream.addAll(getDownstreamExtDownstream(project.getParent(), project.getPublishersList()));
return downstream;
}


public List<AbstractProject<?,?>> getBuildTriggerDownstream(AbstractProject<?,?> project) {
ArrayList<AbstractProject<?,?>> ret = new ArrayList<AbstractProject<?,?>>();
Expand Down

0 comments on commit 7ff6743

Please sign in to comment.