Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-9301] don't recalculate dependency graph in modules haven't …
…changed

Originally-Committed-As: 65678ad31dbc9a8199d0076a9edd124040db7883
  • Loading branch information
kutzi committed Jul 3, 2011
1 parent 6a66009 commit 9ba4f7a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/main/java/hudson/maven/MavenModule.java
Expand Up @@ -191,6 +191,15 @@ public List<MavenModule> getSubsidiaries() {
}
}
}

/**
* Returns if the given POM likely describes the same module with the same dependencies.
* Implementation needs not be 100% accurate in the true case, but it MUST return false
* if is not the same.
*/
public boolean isSameModule(PomInfo pom) {
return pom.isSimilar(this.moduleName, this.dependencies);
}

@Override
protected void doSetName(String name) {
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/hudson/maven/MavenModuleSetBuild.java
Expand Up @@ -842,6 +842,8 @@ private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVa
}
throw new AbortException();
}

boolean needsDependencyGraphRecalculation = false;

// update the module list
Map<ModuleName,MavenModule> modules = project.modules;
Expand All @@ -858,12 +860,16 @@ private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVa
if(mm!=null) {// found an existing matching module
if(debug)
logger.println("Reconfiguring "+mm);
if (!mm.isSameModule(pom)) {
needsDependencyGraphRecalculation = true;
}
mm.reconfigure(pom);
modules.put(pom.name,mm);
} else {// this looks like a new module
logger.println(Messages.MavenModuleSetBuild_DiscoveredModule(pom.name,pom.displayName));
mm = new MavenModule(project,pom,getNumber());
modules.put(mm.getModuleName(),mm);
needsDependencyGraphRecalculation = true;
}
sortedModules.add(mm);
mm.save();
Expand All @@ -877,12 +883,16 @@ private void parsePoms(BuildListener listener, PrintStream logger, EnvVars envVa
if(debug)
logger.println("Disabling "+om);
om.makeDisabled(true);
needsDependencyGraphRecalculation = true;
}
modules.putAll(old);
}

// we might have added new modules
Jenkins.getInstance().rebuildDependencyGraph();
if (needsDependencyGraphRecalculation) {
logger.println("Modules changed, recalculating dependency graph");
Jenkins.getInstance().rebuildDependencyGraph();
}

// module builds must start with this build's number
for (MavenModule m : modules.values())
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/hudson/maven/PomInfo.java
Expand Up @@ -155,7 +155,7 @@ public PomInfo(MavenProject project, PomInfo parent, String relPath) {
this.groupId = project.getGroupId();
this.artifactId = project.getArtifactId();
}

/**
* Creates {@link ModuleDependency} that represents this {@link PomInfo}.
*/
Expand Down Expand Up @@ -229,6 +229,15 @@ public boolean equals( Object obj )
&& StringUtils.equals( pomInfo.artifactId, this.artifactId );
}

/**
* Returns if groupId, artifactId and dependencies are the same.
*/
public boolean isSimilar(ModuleName moduleName, Set<ModuleDependency> dependencies) {
return StringUtils.equals(this.groupId, moduleName.groupId)
&& StringUtils.equals(this.artifactId, moduleName.artifactId)
&& this.dependencies.equals(dependencies);
}

/**
* for debug purpose
*/
Expand Down

0 comments on commit 9ba4f7a

Please sign in to comment.