Index: src/main/java/hudson/maven/MavenModule.java =================================================================== --- src/main/java/hudson/maven/MavenModule.java (revision 14198) +++ src/main/java/hudson/maven/MavenModule.java (working copy) @@ -23,6 +23,9 @@ import hudson.tasks.Publisher; import hudson.tasks.Maven.MavenInstallation; import hudson.util.DescribableList; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; import org.apache.maven.project.MavenProject; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -352,7 +355,7 @@ AbstractProject dest = getParent().isAggregatorStyleBuild() ? getParent() : this; for (ModuleDependency d : dependencies) { - MavenModule src = modules.get(d); + MavenModule src = findMatchingDependentModule(modules, d); if(src!=null) { if(src.getParent().isAggregatorStyleBuild()) graph.addDependency(src.getParent(),dest); @@ -362,6 +365,36 @@ } } + /** + * ModuleDependency objects have a string as a version. To support Maven2 version ranges, + * string comparison of these versions are not sufficient. + * + * The ModuleDependency objects in the modules map contain the version identifier of the + * modules/projects itself. In these cases, no version ranges are allowed. The second + * argument is a ModuleDependency coming from parsing the dependency section of a Maven POM. + * In here, version ranges are allowed. This method will perform a lookup in the modules + * collection, but based on the VersionRange.containsVersion(ArtifactVersion) method. + * + * @param modules the map matching a ModuleDependency with the corresponding MavenModule + * @param dependencyDescription a ModuleDependency describing the version + * @author Ringo De Smet + * @return the Hudson MavenModule that matches the dependency. + */ + private MavenModule findMatchingDependentModule( + final Map modules, + final ModuleDependency dependencyDescription) { + Set modulesVersionInfo = modules.keySet(); + ModuleDependency matchingDependency = (ModuleDependency) CollectionUtils + .find(modulesVersionInfo, new Predicate() { + + public boolean evaluate(Object moduleInfo) { + ModuleDependency moduleVersionInfo = (ModuleDependency) moduleInfo; + return dependencyDescription.contains(moduleVersionInfo); + } + }); + return modules.get(matchingDependency); + } + @Override protected void addTransientActionsFromBuild(MavenBuild build, Set added) { if(build==null) return; Index: src/main/java/hudson/maven/ModuleDependency.java =================================================================== --- src/main/java/hudson/maven/ModuleDependency.java (revision 14198) +++ src/main/java/hudson/maven/ModuleDependency.java (working copy) @@ -1,6 +1,10 @@ package hudson.maven; import org.apache.maven.project.MavenProject; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Extension; @@ -80,9 +84,33 @@ result = 31 * result + version.hashCode(); return result; } + + /** + * If my version string comes from a dependency in the Maven POM, it can + * represent a version range. If the argument represents a real version, + * this method will check if the group and artifact ID are the same, + * and if my version, converted to a VersionRange, contains the the version + * from the argument. + * + * @param otherDependency + * @return + */ + public boolean contains(ModuleDependency otherDependency) { + if (otherDependency == null) return false; + boolean result = groupId.equals(otherDependency.groupId); + result &= artifactId.equals(otherDependency.artifactId); + try { + VersionRange myRange = VersionRange.createFromVersionSpec(version); + ArtifactVersion otherVersion = new DefaultArtifactVersion(otherDependency.version); + result &= myRange.containsVersion(otherVersion); + } catch(InvalidVersionSpecificationException ivse) { + result = false; + } + return result; + } /** - * For compatibility reason, this value may be used in the verion field + * For compatibility reason, this value may be used in the version field * to indicate that the version is unknown. */ public static final String UNKNOWN = "*";