提交 c297835a 编写于 作者: C Christoph Kutzinski

[FIXED JENKINS-9845] reduce memory consumption of dependency graph...

[FIXED JENKINS-9845] reduce memory consumption of dependency graph calculation: include maven dependencies with 'unknown' version only if needed.
上级 16f6c7a3
......@@ -71,6 +71,9 @@ Upcoming changes</a>
<li class=rfe>
Run maven jobs as headless process. on OSX this avoid jumping Dock icon to take focus.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9785">issue 9785</a>)
<li class=rfe>
Reduce memory consumption of dependency calculation in maven jobs.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9845">issue 9845</a>)
</ul>
</div><!--=TRUNK-END=-->
......
......@@ -392,22 +392,38 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
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
......@@ -424,7 +440,9 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
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);
......@@ -449,7 +467,21 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
}
}
/**
* 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>>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册