Skip to content

Commit

Permalink
[MNG-6727] Using version range in parent and CI Friendly Version fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Feb 1, 2022
1 parent 83257bf commit d79485f
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 12 deletions.
Expand Up @@ -298,11 +298,11 @@ public void testBuildParentVersionRangeLocallyWithoutChildVersion() throws Excep
*
* @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
{
Expand All @@ -315,7 +315,47 @@ public void testBuildParentVersionRangeLocallyWithChildVersionExpression() throw
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.
*
Expand Down Expand Up @@ -363,11 +403,34 @@ public void testBuildParentVersionRangeExternallyWithoutChildVersion() throws Ex
*
* @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
{
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 testBuildParentVersionRangeExternallyWithChildPomVersionExpression() throws Exception
{
File f1 =
getTestFile(
"src/test/resources/projects/parent-version-range-external-child-pom-version-expression/pom.xml" );

try
{
Expand All @@ -381,4 +444,68 @@ public void testBuildParentVersionRangeExternallyWithChildVersionExpression() th
}
}

/**
* 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>
Expand Up @@ -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>
@@ -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>
Expand Up @@ -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>
Expand Up @@ -1057,7 +1057,9 @@ private ModelData readParentLocally( Model childModel, ModelSource childSource,
}

// 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 )
Expand All @@ -1066,7 +1068,7 @@ private ModelData readParentLocally( Model childModel, ModelSource childSource,
}
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 )
Expand Down Expand Up @@ -1099,6 +1101,14 @@ private ModelData readParentLocally( Model childModel, ModelSource childSource,
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 ) )
Expand Down Expand Up @@ -1187,7 +1197,9 @@ public int getValidationLevel()

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 )
Expand All @@ -1196,7 +1208,7 @@ public int getValidationLevel()
}
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 )
Expand Down

0 comments on commit d79485f

Please sign in to comment.