[MNG-6727] Using version range in parent and CI Friendly Version fails

This commit is contained in:
Guillaume Nodet 2022-02-01 14:26:54 +01:00 committed by GitHub
parent 83257bfde0
commit d79485ff23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 241 additions and 12 deletions

View File

@ -298,11 +298,11 @@ public class DefaultMavenProjectBuilderTest
* *
* @throws Exception * @throws Exception
*/ */
public void testBuildParentVersionRangeLocallyWithChildVersionExpression() throws Exception public void testBuildParentVersionRangeLocallyWithChildProjectVersionExpression() throws Exception
{ {
File f1 = File f1 =
getTestFile( 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 try
{ {
@ -315,7 +315,47 @@ public class DefaultMavenProjectBuilderTest
assertThat( e.getMessage(), containsString( "Version must be a constant" ) ); 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. * Tests whether external version range parent references are build correctly.
* *
@ -363,11 +403,11 @@ public class DefaultMavenProjectBuilderTest
* *
* @throws Exception * @throws Exception
*/ */
public void testBuildParentVersionRangeExternallyWithChildVersionExpression() throws Exception public void testBuildParentVersionRangeExternallyWithChildProjectVersionExpression() throws Exception
{ {
File f1 = File f1 =
getTestFile( 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 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());
}
} }

View File

@ -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>

View File

@ -6,7 +6,7 @@
<version>[1,1]</version> <version>[1,1]</version>
</parent> </parent>
<artifactId>child</artifactId> <artifactId>child</artifactId>
<!-- Must not use expressions from parent due to version range. --> <!-- Must not use ${project.version} due to version range. -->
<version>${some.property}</version> <version>${project.version}</version>
<packaging>pom</packaging> <packaging>pom</packaging>
</project> </project>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -6,7 +6,7 @@
<version>[1,10]</version> <version>[1,10]</version>
</parent> </parent>
<artifactId>child</artifactId> <artifactId>child</artifactId>
<!-- Must not use expressions from parent due to version range. --> <!-- Must not use ${project.version} due to version range. -->
<version>${some.property}</version> <version>${project.version}</version>
<packaging>pom</packaging> <packaging>pom</packaging>
</project> </project>

View File

@ -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>

View File

@ -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>

View File

@ -1057,7 +1057,9 @@ public class DefaultModelBuilder
} }
// Validate versions aren't inherited when using parent ranges the same way as when read externally. // 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. // Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 ) problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@ -1066,7 +1068,7 @@ public class DefaultModelBuilder
} }
else else
{ {
if ( childModel.getVersion().contains( "${" ) ) if ( rawChildVersionReferencesParent( rawChildModelVersion ) )
{ {
// Message below is checked for in the MNG-2199 core IT. // Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 ) problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@ -1099,6 +1101,14 @@ public class DefaultModelBuilder
return parentData; 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 ) private ModelSource getParentPomFile( Model childModel, ModelSource source )
{ {
if ( !( source instanceof ModelSource2 ) ) if ( !( source instanceof ModelSource2 ) )
@ -1187,7 +1197,9 @@ public class DefaultModelBuilder
if ( !parent.getVersion().equals( version ) ) 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. // Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 ) problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )
@ -1196,7 +1208,7 @@ public class DefaultModelBuilder
} }
else else
{ {
if ( childModel.getVersion().contains( "${" ) ) if ( rawChildVersionReferencesParent( rawChildModelVersion ) )
{ {
// Message below is checked for in the MNG-2199 core IT. // Message below is checked for in the MNG-2199 core IT.
problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 ) problems.add( new ModelProblemCollectorRequest( Severity.FATAL, Version.V31 )