mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-21 15:55:40 +00:00
[FIXED JENKINS-10366] choose most 'relevant' job for dependency graph if multiple jobs are building the same maven module
This commit is contained in:
1 parent
a70e867590
commit
b8aec882f2
1 file changed
+52
-2
@@ -404,9 +404,11 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
|
||||
for (MavenModule m : Jenkins.getInstance().getAllItems(MavenModule.class)) {
|
||||
if(m.isDisabled()) continue;
|
||||
ModuleDependency moduleDependency = m.asDependency();
|
||||
modules.put(moduleDependency,m);
|
||||
MavenModule old = modules.get(moduleDependency);
|
||||
MavenModule relevant = chooseMoreRelevantModule(old, m);
|
||||
modules.put(moduleDependency, relevant);
|
||||
if (hasDependenciesWithUnknownVersion) {
|
||||
modules.put(moduleDependency.withUnknownVersion(),m);
|
||||
modules.put(moduleDependency.withUnknownVersion(),relevant);
|
||||
}
|
||||
}
|
||||
data = new MavenDependencyComputationData(modules);
|
||||
@@ -477,6 +479,54 @@ public final class MavenModule extends AbstractMavenProject<MavenModule,MavenBui
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private MavenModule chooseMoreRelevantModule(MavenModule mm1, MavenModule mm2) {
|
||||
if (mm1 == null) {
|
||||
return mm2;
|
||||
}
|
||||
if (mm2 == null) {
|
||||
return mm1;
|
||||
}
|
||||
|
||||
int relevancy1 = getDependencyRelevancy(mm1);
|
||||
int relevancy2 = getDependencyRelevancy(mm2);
|
||||
|
||||
if (relevancy1 > relevancy2) {
|
||||
return mm1;
|
||||
} else if (relevancy2 > relevancy1) {
|
||||
return mm2;
|
||||
}
|
||||
|
||||
// arbitrary, but reproduceable
|
||||
if (mm1.getParent().getName().compareTo(mm2.getParent().getName()) < 0) {
|
||||
return mm2;
|
||||
} else { // should always mean > 0 as name is unique
|
||||
return mm1;
|
||||
}
|
||||
}
|
||||
|
||||
private int getDependencyRelevancy(MavenModule mm) {
|
||||
|
||||
int relevancy = 0;
|
||||
|
||||
for (String goal : Util.tokenize(mm.getGoals())) {
|
||||
if ("deploy".equals(goal) || "deploy:deploy".equals(goal)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
if ("install".equals(goal)) {
|
||||
relevancy = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (Publisher publisher : mm.getParent().getPublishers()) {
|
||||
if (publisher instanceof RedeployPublisher) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
return relevancy;
|
||||
}
|
||||
|
||||
private static class MavenDependencyComputationData {
|
||||
boolean withUnknownVersions = false;
|
||||
|
||||
Reference in new issue
Block a user