diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
index 008c6d3bdc..74a3a074e1 100644
--- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java
@@ -298,11 +298,11 @@ public class DefaultMavenProjectBuilderTest
*
* @throws Exception
*/
- public void testBuildParentVersionRangeLocallyWithChildVersionExpression() throws Exception
+ public void testBuildParentVersionRangeLocallyWithChildProjectVersionExpression() throws Exception
{
File f1 =
getTestFile(
- "src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml" );
+ "src/test/resources/projects/parent-version-range-local-child-project-version-expression/child/pom.xml" );
try
{
@@ -315,7 +315,47 @@ public class DefaultMavenProjectBuilderTest
assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
}
}
+
+ /**
+ * Tests whether local version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeLocallyWithChildProjectParentVersionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/child/pom.xml" );
+ try
+ {
+ getProject( f1 );
+ fail( "Expected 'ProjectBuildingException' not thrown." );
+ }
+ catch ( final ProjectBuildingException e )
+ {
+ assertNotNull( e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
+ }
+ }
+
+ /**
+ * Tests whether local version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeLocallyWithChildRevisionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-local-child-revision-expression/child/pom.xml" );
+
+ MavenProject mp = this.getProjectFromRemoteRepository( f1 );
+
+ assertEquals("1.0-SNAPSHOT", mp.getVersion());
+
+ }
+
/**
* Tests whether external version range parent references are build correctly.
*
@@ -363,11 +403,11 @@ public class DefaultMavenProjectBuilderTest
*
* @throws Exception
*/
- public void testBuildParentVersionRangeExternallyWithChildVersionExpression() throws Exception
+ public void testBuildParentVersionRangeExternallyWithChildProjectVersionExpression() throws Exception
{
File f1 =
getTestFile(
- "src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml" );
+ "src/test/resources/projects/parent-version-range-external-child-project-version-expression/pom.xml" );
try
{
@@ -381,4 +421,91 @@ public class DefaultMavenProjectBuilderTest
}
}
+ /**
+ * Tests whether external version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeExternallyWithChildPomVersionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-external-child-pom-version-expression/pom.xml" );
+
+ try
+ {
+ this.getProjectFromRemoteRepository( f1 );
+ fail( "Expected 'ProjectBuildingException' not thrown." );
+ }
+ catch ( final ProjectBuildingException e )
+ {
+ assertNotNull( e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
+ }
+ }
+
+ /**
+ * Tests whether external version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeExternallyWithChildPomParentVersionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-external-child-pom-parent-version-expression/pom.xml" );
+
+ try
+ {
+ this.getProjectFromRemoteRepository( f1 );
+ fail( "Expected 'ProjectBuildingException' not thrown." );
+ }
+ catch ( final ProjectBuildingException e )
+ {
+ assertNotNull( e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
+ }
+ }
+
+ /**
+ * Tests whether external version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeExternallyWithChildProjectParentVersionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-external-child-project-parent-version-expression/pom.xml" );
+
+ try
+ {
+ this.getProjectFromRemoteRepository( f1 );
+ fail( "Expected 'ProjectBuildingException' not thrown." );
+ }
+ catch ( final ProjectBuildingException e )
+ {
+ assertNotNull( e.getMessage() );
+ assertThat( e.getMessage(), containsString( "Version must be a constant" ) );
+ }
+ }
+
+ /**
+ * Tests whether external version range parent references are build correctly.
+ *
+ * @throws Exception
+ */
+ public void testBuildParentVersionRangeExternallyWithChildRevisionExpression() throws Exception
+ {
+ File f1 =
+ getTestFile(
+ "src/test/resources/projects/parent-version-range-external-child-revision-expression/pom.xml" );
+
+
+ MavenProject mp = this.getProjectFromRemoteRepository( f1 );
+
+ assertEquals("1.0-SNAPSHOT", mp.getVersion());
+
+
+ }
}
diff --git a/maven-core/src/test/resources/projects/parent-version-range-external-child-pom-parent-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-external-child-pom-parent-version-expression/pom.xml
new file mode 100644
index 0000000000..b37e54a9a9
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-external-child-pom-parent-version-expression/pom.xml
@@ -0,0 +1,12 @@
+
+ 4.0.0
+
+ org.apache
+ apache
+ [1,1]
+
+ child
+
+ ${pom.parent.version}
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-external-child-pom-version-expression/pom.xml
similarity index 69%
rename from maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
rename to maven-core/src/test/resources/projects/parent-version-range-external-child-pom-version-expression/pom.xml
index d07ad6eb56..bd30a9af8e 100644
--- a/maven-core/src/test/resources/projects/parent-version-range-external-child-version-expression/pom.xml
+++ b/maven-core/src/test/resources/projects/parent-version-range-external-child-pom-version-expression/pom.xml
@@ -6,7 +6,7 @@
[1,1]
child
-
- ${some.property}
+
+ ${project.version}
pom
diff --git a/maven-core/src/test/resources/projects/parent-version-range-external-child-project-parent-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-external-child-project-parent-version-expression/pom.xml
new file mode 100644
index 0000000000..a8cf950fa2
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-external-child-project-parent-version-expression/pom.xml
@@ -0,0 +1,12 @@
+
+ 4.0.0
+
+ org.apache
+ apache
+ [1,1]
+
+ child
+
+ ${project.parent.version}
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-external-child-project-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-external-child-project-version-expression/pom.xml
new file mode 100644
index 0000000000..bd30a9af8e
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-external-child-project-version-expression/pom.xml
@@ -0,0 +1,12 @@
+
+ 4.0.0
+
+ org.apache
+ apache
+ [1,1]
+
+ child
+
+ ${project.version}
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-external-child-revision-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-external-child-revision-expression/pom.xml
new file mode 100644
index 0000000000..aa724d854a
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-external-child-revision-expression/pom.xml
@@ -0,0 +1,14 @@
+
+ 4.0.0
+
+ org.apache
+ apache
+ [1,1]
+
+ child
+ ${revision}
+ pom
+
+ 1.0-SNAPSHOT
+
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/child/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/child/pom.xml
new file mode 100644
index 0000000000..ac42c932b5
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/child/pom.xml
@@ -0,0 +1,12 @@
+
+ 4.0.0
+
+ parent-version-range-local
+ parent
+ [1,10]
+
+ child
+
+ ${project.parent.version}
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/pom.xml
new file mode 100644
index 0000000000..858cf1c3f0
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-parent-version-expression/pom.xml
@@ -0,0 +1,7 @@
+
+ 4.0.0
+ parent-version-range-local
+ parent
+ 1
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/child/pom.xml
similarity index 70%
rename from maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
rename to maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/child/pom.xml
index 066a11ecdb..1435070a8b 100644
--- a/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/child/pom.xml
+++ b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/child/pom.xml
@@ -6,7 +6,7 @@
[1,10]
child
-
- ${some.property}
+
+ ${project.version}
pom
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/pom.xml
new file mode 100644
index 0000000000..858cf1c3f0
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-local-child-project-version-expression/pom.xml
@@ -0,0 +1,7 @@
+
+ 4.0.0
+ parent-version-range-local
+ parent
+ 1
+ pom
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-revision-expression/child/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-revision-expression/child/pom.xml
new file mode 100644
index 0000000000..b29b5d23bf
--- /dev/null
+++ b/maven-core/src/test/resources/projects/parent-version-range-local-child-revision-expression/child/pom.xml
@@ -0,0 +1,14 @@
+
+ 4.0.0
+
+ parent-version-range-local
+ parent
+ [1,10]
+
+ child
+ ${revision}
+ pom
+
+ 1.0-SNAPSHOT
+
+
diff --git a/maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml b/maven-core/src/test/resources/projects/parent-version-range-local-child-revision-expression/pom.xml
similarity index 100%
rename from maven-core/src/test/resources/projects/parent-version-range-local-child-version-expression/pom.xml
rename to maven-core/src/test/resources/projects/parent-version-range-local-child-revision-expression/pom.xml
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 813b76297f..551f17a898 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -1057,7 +1057,9 @@ public class DefaultModelBuilder
}
// Validate versions aren't inherited when using parent ranges the same way as when read externally.
- if ( childModel.getVersion() == null )
+ String rawChildModelVersion = childModel.getVersion();
+
+ if ( rawChildModelVersion == null )
{
// Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@@ -1066,7 +1068,7 @@ public class DefaultModelBuilder
}
else
{
- if ( childModel.getVersion().contains( "${" ) )
+ if ( rawChildVersionReferencesParent( rawChildModelVersion ) )
{
// Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@@ -1099,6 +1101,14 @@ public class DefaultModelBuilder
return parentData;
}
+ private boolean rawChildVersionReferencesParent( String rawChildModelVersion )
+ {
+ return rawChildModelVersion.equals( "${pom.version}" )
+ || rawChildModelVersion.equals( "${project.version}" )
+ || rawChildModelVersion.equals( "${pom.parent.version}" )
+ || rawChildModelVersion.equals( "${project.parent.version}" );
+ }
+
private ModelSource getParentPomFile( Model childModel, ModelSource source )
{
if ( !( source instanceof ModelSource2 ) )
@@ -1187,7 +1197,9 @@ public class DefaultModelBuilder
if ( !parent.getVersion().equals( version ) )
{
- if ( childModel.getVersion() == null )
+ String rawChildModelVersion = childModel.getVersion();
+
+ if ( rawChildModelVersion == null )
{
// Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@@ -1196,7 +1208,7 @@ public class DefaultModelBuilder
}
else
{
- if ( childModel.getVersion().contains( "${" ) )
+ if ( rawChildVersionReferencesParent( rawChildModelVersion ) )
{
// Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )