Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make dependency graph calculation more efficient by storing intermedi…

…ate computational data with the DependencyGraph.
  • Loading branch information...
commit 6718e7381f0e074d124056aecd2c31b553e95454 1 parent 2c4dbfa
@tbingaman tbingaman authored
Showing with 51 additions and 19 deletions.
  1. +51 −19 src/main/java/hudson/ivy/IvyModule.java
View
70 src/main/java/hudson/ivy/IvyModule.java
@@ -53,6 +53,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -403,35 +404,51 @@ protected void buildDependencyGraph(DependencyGraph graph) {
// addition to the triggers generated by ivy dependencies.
publishers.buildDependencyGraph(this,graph);
- if (isDisabled() || (getParent().ignoreUpstreamChanges() && getParent().isAggregatorStyleBuild()))
+ if (!isBuildable() || (getParent().ignoreUpstreamChanges() && getParent().isAggregatorStyleBuild()))
return;
- Map<ModuleDependency, IvyModule> modules = new HashMap<ModuleDependency, IvyModule>();
- if (!getParent().ignoreUpstreamChanges()) {
- for (IvyModule m : Hudson.getInstance().getAllItems(IvyModule.class)) {
- if (m.isDisabled() || !m.getParent().isAllowedToTriggerDownstream())
- continue;
- modules.put(m.asDependency(), m);
- modules.put(m.asDependency().withUnknownRevision(), m);
+ IvyDependencyComputationData data = graph.getComputationalData(IvyDependencyComputationData.class);
+
+ // Build a map of all Ivy modules in this Jenkins instance as dependencies.
+ if (!getParent().ignoreUpstreamChanges() && data == null) {
+ Map<ModuleDependency, IvyModule> modules = new HashMap<ModuleDependency, IvyModule>();
+ for (IvyModule m : getAllIvyModules()) {
+ if(!m.isBuildable() || !m.getParent().isAllowedToTriggerDownstream()) continue;
+ ModuleDependency moduleDependency = m.asDependency();
+ modules.put(moduleDependency, m);
+ modules.put(moduleDependency.withUnknownRevision(), m);
}
+ data = new IvyDependencyComputationData(modules);
+ graph.putComputationalData(IvyDependencyComputationData.class, data);
}
- // Even if ignoreUpstreamChanges is true we still need to calculate the
- // dependencies between the modules of this project. Also, in case two
- // modules with the same name are defined, modules in the same
- // IvyModuleSet takes precedence.
+ // In case two modules with the same name are defined, modules in the same IvyModuleSet
+ // take precedence.
+ Map<ModuleDependency, IvyModule> myParentsModules = new HashMap<ModuleDependency, IvyModule>();
for (IvyModule m : getParent().getModules()) {
- if (m.isDisabled())
- continue;
- modules.put(m.asDependency(), m);
- modules.put(m.asDependency().withUnknownRevision(), m);
+ if(m.isDisabled()) continue;
+ ModuleDependency moduleDependency = m.asDependency();
+ myParentsModules.put(moduleDependency,m);
+ myParentsModules.put(moduleDependency.withUnknownRevision(),m);
}
+ // if the build style is the aggregator build, define dependencies against project,
+ // not module.
+ AbstractProject<?, ?> downstream = getParent().isAggregatorStyleBuild() ? getParent() : this;
+
for (ModuleDependency d : dependencies) {
- IvyModule src = modules.get(d);
- if (src == null)
- src = modules.get(d.withUnknownRevision());
+ IvyModule src = myParentsModules.get(d);
+ if (src == null) {
+ src = myParentsModules.get(d.withUnknownRevision());
+ }
+ if(src == null && !getParent().ignoreUpstreamChanges()) {
+ src = data.allModules.get(d);
+ if (src == null) {
+ src = data.allModules.get(d.withUnknownRevision());
+ }
+ }
+
if (src == null)
continue;
@@ -460,6 +477,13 @@ protected void buildDependencyGraph(DependencyGraph graph) {
}
}
+ /**
+ * Returns all Ivy modules in this Jenkins instance.
+ */
+ protected Collection<IvyModule> getAllIvyModules() {
+ return Hudson.getInstance().getAllItems(IvyModule.class);
+ }
+
private boolean hasDependency(DependencyGraph graph, AbstractProject upstream, AbstractProject downstream) {
for (Dependency dep : graph.getDownstreamDependencies(upstream)) {
if (dep instanceof IvyDependency && dep.getDownstreamProject().equals(downstream))
@@ -468,6 +492,14 @@ private boolean hasDependency(DependencyGraph graph, AbstractProject upstream, A
return false;
}
+ private static class IvyDependencyComputationData {
+ Map<ModuleDependency, IvyModule> allModules;
+
+ public IvyDependencyComputationData(Map<ModuleDependency, IvyModule> modules) {
+ this.allModules = modules;
+ }
+ }
+
@Override
public CauseOfBlockage getCauseOfBlockage() {
CauseOfBlockage cob = super.getCauseOfBlockage();
Please sign in to comment.
Something went wrong with that request. Please try again.