Skip to content

Commit

Permalink
[JENKINS-8985] BuildTrigger modification to handle DependencyGroups.
Browse files Browse the repository at this point in the history
Pull individual Dependencys out of DependencyGroups we see in
BuildTrigger.execute and make sure to actually kick those builds off
as well, so that we can have two different dependencies (say, for
different parameters) from one upstream project to a single downstream
project.
  • Loading branch information
abayer committed May 20, 2011
1 parent 1e9720d commit 78c709e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -63,6 +63,9 @@
<li class=bug>
Fix unescaped apostrophe in French translation.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9699">issue 9699</a>)
<li class=bug>
Allow building multiple downstream dependencies on a single job via DependencyGraph and BuildTrigger.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-8985">issue 8985</a>)
<li class=rfe>
Set NODE_NAME for master node to "master"
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9671">issue 9671</a>)
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/hudson/model/DependencyGraph.java
Expand Up @@ -478,18 +478,22 @@ public int hashCode() {
/**
* Collect multiple dependencies between the same two projects.
*/
private static class DependencyGroup extends Dependency {
public static class DependencyGroup extends Dependency {
private Set<Dependency> group = new LinkedHashSet<Dependency>();

DependencyGroup(Dependency first) {
super(first.getUpstreamProject(), first.getDownstreamProject());
group.add(first);
}

void add(Dependency next) {
private void add(Dependency next) {
group.add(next);
}

public Set<Dependency> getGroup() {
return group;
}

@Override
public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
List<Action> actions) {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/hudson/tasks/BuildTrigger.java
Expand Up @@ -201,7 +201,19 @@ public int compare(Dependency lhs, Dependency rhs) {
}
});

List<Dependency> depsToBuild = new ArrayList<Dependency>();
for (Dependency dep : downstreamProjects) {
if (dep instanceof DependencyGraph.DependencyGroup) {
for (Dependency d : ((DependencyGraph.DependencyGroup)dep).getGroup()) {
depsToBuild.add(d);
}
}
else {
depsToBuild.add(dep);
}
}

for (Dependency dep : depsToBuild) {
AbstractProject p = dep.getDownstreamProject();
if (p.isDisabled()) {
logger.println(Messages.BuildTrigger_Disabled(p.getName()));
Expand Down

5 comments on commit 78c709e

@wolfs
Copy link
Member

@wolfs wolfs commented on 78c709e May 21, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we get rid of the DependencyGroup altogether and only use the generic dependency?

@abayer
Copy link
Member Author

@abayer abayer commented on 78c709e May 21, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still value in DependencyGroup - it lets us keep the true DependencyGraph to only one edge from each upstream project to each downstream project, which makes calculating build order, etc simpler, for example.

@wolfs
Copy link
Member

@wolfs wolfs commented on 78c709e May 21, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's probably true. But I think the DependencyGroup should be internal to the DependencyGraph class and not exposed. If it is exposed, like now, everybody needs to take care when calling shouldTriggerBuild of the dependency group. What do you think?

@abayer
Copy link
Member Author

@abayer abayer commented on 78c709e May 21, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd definitely be open to a better solution - I'm just not sure how to make it so that iterating across the downstream projects, say, will get all the elements in a dependency group rather than the dependency group itself transparently.

@wolfs
Copy link
Member

@wolfs wolfs commented on 78c709e May 22, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a solution: wolfs@e472fa0
If you say it's okay, I just commit it to master.

Please sign in to comment.