Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-9845] reduce memory consumption of dependency graph ca…
…lculation: include maven dependencies with 'unknown' version only if needed.

Originally-Committed-As: c297835ab7371756e092667b3556a957fd2801e2
  • Loading branch information
kutzi committed Jun 2, 2011
1 parent 84bf627 commit 8757527
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/main/java/hudson/maven/MavenModule.java
Expand Up @@ -392,22 +392,38 @@ protected void buildDependencyGraph(DependencyGraph graph) {
if(isDisabled() || getParent().ignoreUpstremChanges()) return;

MavenDependencyComputationData data = graph.getComputationalData(MavenDependencyComputationData.class);


// Build a map of all Maven modules in this Jenkins instance as dependencies.

// When we load old data that doesn't record version in dependency, we'd like
// to emulate the old behavior that tries to identify the upstream by ignoring the version.
// Do this by putting groupId:artifactId:UNKNOWN to the modules list, but
// ONLY if we find a such an old MavenModule in this Jenkins instance.
boolean hasDependenciesWithUnknownVersion = hasDependenciesWithUnknownVersion();
if (data == null) {
Map<ModuleDependency,MavenModule> modules = new HashMap<ModuleDependency,MavenModule>();

// when we load old data that doesn't record version in dependency, we'd like
// to emulate the old behavior that it tries to identify the upstream by ignoring the version.
// do this by always putting groupId:artifactId:UNKNOWN to the modules list.

for (MavenModule m : Hudson.getInstance().getAllItems(MavenModule.class)) {
if(m.isDisabled()) continue;
ModuleDependency moduleDependency = m.asDependency();
modules.put(moduleDependency,m);
modules.put(moduleDependency.withUnknownVersion(),m);
if (hasDependenciesWithUnknownVersion) {
modules.put(moduleDependency.withUnknownVersion(),m);
}
}
data = new MavenDependencyComputationData(modules);
data.withUnknownVersions = hasDependenciesWithUnknownVersion;
graph.putComputationalData(MavenDependencyComputationData.class, data);
} else {
if (hasDependenciesWithUnknownVersion && !data.withUnknownVersions) {
// found 'old' MavenModule: add dependencies with unknown versions now
for (MavenModule m : Hudson.getInstance().getAllItems(MavenModule.class)) {
if(m.isDisabled()) continue;
ModuleDependency moduleDependency = m.asDependency().withUnknownVersion();
data.allModules.put(moduleDependency,m);
}
data.withUnknownVersions = true;
}
}

// In case two modules with the same name are defined, modules in the same MavenModuleSet
Expand All @@ -424,7 +440,9 @@ protected void buildDependencyGraph(DependencyGraph graph) {
if(m.isDisabled()) continue;
ModuleDependency moduleDependency = m.asDependency();
myParentsModules.put(moduleDependency,m);
myParentsModules.put(moduleDependency.withUnknownVersion(),m);
if (hasDependenciesWithUnknownVersion) {
myParentsModules.put(moduleDependency.withUnknownVersion(),m);
}
}

//data.modulesPerParent.put(getParent(), myParentsModules);
Expand All @@ -449,7 +467,21 @@ protected void buildDependencyGraph(DependencyGraph graph) {
}
}

/**
* Check if this module has dependencies recorded without a concrete version -
* which shouldn't happen for any module which was at least build once with Jenkins >= 1.207.
*/
private boolean hasDependenciesWithUnknownVersion() {
for (ModuleDependency dep : dependencies) {
if (ModuleDependency.UNKNOWN.equals(dep.version)) {
return true;
}
}
return false;
}

private static class MavenDependencyComputationData {
boolean withUnknownVersions = false;
Map<ModuleDependency,MavenModule> allModules;

//Map<MavenModuleSet, Map<ModuleDependency,MavenModule>> modulesPerParent = new HashMap<MavenModuleSet, Map<ModuleDependency,MavenModule>>();
Expand Down

0 comments on commit 8757527

Please sign in to comment.