mirror of https://github.com/apache/maven.git
[MNG-6727] Using version range in parent and CI Friendly Version fails
This commit is contained in:
parent
6b607109d3
commit
1d473233f2
|
@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
@ -249,11 +250,11 @@ public class DefaultMavenProjectBuilderTest
|
|||
* @throws Exception in case of issue
|
||||
*/
|
||||
@Test
|
||||
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" );
|
||||
|
||||
ProjectBuildingException e = assertThrows(
|
||||
ProjectBuildingException.class,
|
||||
|
@ -261,7 +262,47 @@ public class DefaultMavenProjectBuilderTest
|
|||
"Expected 'ProjectBuildingException' not thrown." );
|
||||
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.
|
||||
*
|
||||
|
@ -307,11 +348,11 @@ public class DefaultMavenProjectBuilderTest
|
|||
* @throws Exception in case of issue
|
||||
*/
|
||||
@Test
|
||||
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" );
|
||||
|
||||
ProjectBuildingException e = assertThrows(
|
||||
ProjectBuildingException.class,
|
||||
|
@ -350,4 +391,91 @@ public class DefaultMavenProjectBuilderTest
|
|||
assertThat( project.getName(), is( "PROJECT NAME" ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache</groupId>
|
||||
<artifactId>apache</artifactId>
|
||||
<version>[1,1]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use ${project.parent.version} due to version range. -->
|
||||
<version>${pom.parent.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -6,7 +6,7 @@
|
|||
<version>[1,1]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use expressions from parent due to version range. -->
|
||||
<version>${some.property}</version>
|
||||
<!-- Must not use ${project.version} due to version range. -->
|
||||
<version>${project.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache</groupId>
|
||||
<artifactId>apache</artifactId>
|
||||
<version>[1,1]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use ${project.parent.version} due to version range. -->
|
||||
<version>${project.parent.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache</groupId>
|
||||
<artifactId>apache</artifactId>
|
||||
<version>[1,1]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use ${project.version} due to version range. -->
|
||||
<version>${project.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache</groupId>
|
||||
<artifactId>apache</artifactId>
|
||||
<version>[1,1]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<revision>1.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>parent-version-range-local</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>[1,10]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use ${project.parent.version} due to version range. -->
|
||||
<version>${project.parent.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -6,7 +6,7 @@
|
|||
<version>[1,10]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<!-- Must not use expressions from parent due to version range. -->
|
||||
<version>${some.property}</version>
|
||||
<!-- Must not use ${project.version} due to version range. -->
|
||||
<version>${project.version}</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>parent-version-range-local</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>parent-version-range-local</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>[1,10]</version>
|
||||
</parent>
|
||||
<artifactId>child</artifactId>
|
||||
<version>${revision}</version>
|
||||
<packaging>pom</packaging>
|
||||
<properties>
|
||||
<revision>1.0-SNAPSHOT</revision>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>parent-version-range-local</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1</version>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
|
@ -1320,7 +1320,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 )
|
||||
|
@ -1329,7 +1331,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 )
|
||||
|
@ -1360,6 +1362,14 @@ public class DefaultModelBuilder
|
|||
return new ModelData( candidateSource, candidateModel, groupId, artifactId, version );
|
||||
}
|
||||
|
||||
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, Source source )
|
||||
{
|
||||
if ( !( source instanceof ModelSource2 ) )
|
||||
|
@ -1441,7 +1451,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 )
|
||||
|
@ -1450,7 +1462,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 )
|
||||
|
|
Loading…
Reference in New Issue