Navigation Menu

Skip to content

Commit

Permalink
[FIXED JENKINS-12638] Make dependency graph calculation more efficien…
Browse files Browse the repository at this point in the history
…t by storing intermediate computational data with the DependencyGraph.
  • Loading branch information
tbingaman committed Feb 2, 2012
1 parent 5dfda57 commit cead62a
Showing 1 changed file with 49 additions and 22 deletions.
71 changes: 49 additions & 22 deletions src/main/java/hudson/ivy/IvyModule.java
Expand Up @@ -51,6 +51,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;
Expand Down Expand Up @@ -401,40 +402,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,
// if the build style is the aggregator build, define dependencies against project,
// not module.
AbstractProject downstream = getParent().isAggregatorStyleBuild() ? getParent() : this;
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;

Expand All @@ -457,6 +469,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))
Expand All @@ -465,6 +484,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();
Expand Down

0 comments on commit cead62a

Please sign in to comment.