提交 2c469b37 编写于 作者: O Olivier Lamy

Merge pull request #609 from alexkoon/master

[JENKINS-15367] Fix Maven downstream resolution when declared as a specific version.
......@@ -35,7 +35,6 @@ import org.apache.maven.model.Extension;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -161,6 +160,15 @@ public final class ModuleDependency implements Serializable {
return result;
}
/**
* Returns true if the version specification is a version range per maven version range syntax.
*
* @return true if version specification is a range.
*/
public boolean isVersionRange() {
return version.startsWith("[") || version.startsWith("(");
}
public VersionRange getVersionAsRange() throws InvalidVersionSpecificationException {
if (range==null)
range = VersionRange.createFromVersionSpec(version);
......@@ -204,7 +212,8 @@ public final class ModuleDependency implements Serializable {
/**
* Checks whether this ModuleDependency is satisfied by the dependency of the given ModuleDependency.
* This caters for versions where the version string defines a version range.
* If the version string is a defined version, then it does a comparison. If the version string
* is a version range if parses this and caters for this.
*
* @param other The dependency to check for.
* @return true if contained false otherwise.
......@@ -214,7 +223,9 @@ public final class ModuleDependency implements Serializable {
return false;
try {
return getVersionAsRange().containsVersion(other.parseVersion());
return isVersionRange()
? getVersionAsRange().containsVersion(other.parseVersion())
: parseVersion().compareTo(other.parseVersion()) == 0;
} catch (InvalidVersionSpecificationException ivse) {
return false;
}
......
......@@ -235,6 +235,52 @@ public class MavenModuleTest {
Assert.assertSame(dependZ.getVersion(), ((MavenModule) upstreamB.get(0)).getVersion());
}
/**
* This tests a project that has a dependency on a specific version of X.
* The project X has moved on and so should not have any dependencies on ProjectA.
*/
@Test
public void testProjectWithSpecifiedVersionAndNoDependencies() {
MavenProject projectA = createMavenProject("ProjectA", "test", "projectA", "1.0-SNAPSHOT", "jar");
Dependency dependencyA = createDependency("test", "library", "1.0");
projectA.getDependencies().add(dependencyA);
MavenProject dependX = createMavenProject("DependX-1.1", "test", "library", "1.2-SNAPSHOT", "jar");
MavenModuleSet parent = mock(MavenModuleSet.class);
when(parent.isAggregatorStyleBuild()).thenReturn(Boolean.FALSE);
//Now create maven modules for all the projects
MavenModule mavenModuleA = mockMavenModule(projectA);
MavenModule mavenModuleX = mockMavenModule(dependX);
Collection<AbstractProject<?,?>> allModules = Lists.<AbstractProject<?,?>>newArrayList(mavenModuleA,
mavenModuleX);
for (AbstractProject<?, ?> module : allModules) {
MavenModule mm = (MavenModule) module;
enhanceMavenModuleMock(mm, parent, allModules);
}
DependencyGraph graph = MockHelper.mockDependencyGraph(allModules);
doCallRealMethod().when(graph).getDownstream(Matchers.any(AbstractProject.class));
doCallRealMethod().when(graph).getUpstream(Matchers.any(AbstractProject.class));
doCallRealMethod().when(graph).compare(Matchers.<AbstractProject>any(), Matchers.<AbstractProject>any());
graph.build();
List<AbstractProject> downstreamA = graph.getDownstream(mavenModuleA);
List<AbstractProject> upstreamA = graph.getUpstream(mavenModuleA);
Assert.assertEquals(0, downstreamA.size());
Assert.assertEquals(0, upstreamA.size());
List<AbstractProject> downstreamX = graph.getDownstream(mavenModuleX);
List<AbstractProject> upstreamX = graph.getUpstream(mavenModuleX);
Assert.assertEquals(0, downstreamX.size());
Assert.assertEquals(0, upstreamX.size());
}
private TestComponents createTestComponents(String libraryVersion) {
MavenProject appProject = createMavenProject("testapp", "test", "application", "1.0-SNAPSHOT", "jar");
Dependency dependency = createDependency("test", "library", libraryVersion);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册