Skip to content

Commit

Permalink
Fixed #190 (#254)
Browse files Browse the repository at this point in the history
#190

Fixing issue in update-child-modules, where root module's version was
being used in all downstream children even when a child's parent was
different.

Fix was to stop updating local reactor model, as the module's version
was being replaced with a parent version in error, initial reactor model
doesn't require being updated locally.

Testing:
All initial and additional IT's passed running mvn clean verify.

Change-Id: I8682a450fe6c15af8483a80a40f52e2e57377c3e
  • Loading branch information
Julian Di Leonardo authored and olamy committed Feb 10, 2018
1 parent d34458d commit 05dad7d
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/it/it-update-child-modules-002/child/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-302</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-302-child</artifactId>
<version>4.0</version>
<packaging>pom</packaging>

<modules>
<module>subchild</module>
<module>subchild2</module>
</modules>

</project>
16 changes: 16 additions & 0 deletions src/it/it-update-child-modules-002/child/subchild/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-302-child</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-302-subchild</artifactId>
<version>2.0</version>
<packaging>pom</packaging>

</project>
16 changes: 16 additions & 0 deletions src/it/it-update-child-modules-002/child/subchild2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-302-child</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-302-subchild2</artifactId>
<version>2.0</version>
<packaging>pom</packaging>

</project>
18 changes: 18 additions & 0 deletions src/it/it-update-child-modules-002/child2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-302</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-302-child2</artifactId>
<version>4.0</version>
<packaging>pom</packaging>



</project>
19 changes: 19 additions & 0 deletions src/it/it-update-child-modules-002/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# first check that the root project builds ok
invoker.goals.1=-o validate
invoker.nonRecursive.1=true
invoker.buildResult.1=success

# second check that adding the child project into the mix breaks things
invoker.goals.2=-o validate
invoker.nonRecursive.2=false
invoker.buildResult.2=failure

# third fix the build with our plugin
invoker.goals.3=${project.groupId}:${project.artifactId}:${project.version}:update-child-modules
invoker.nonRecursive.3=true
invoker.buildResult.3=success

# forth, confirm that the build is fixed
invoker.goals.4=validate
invoker.nonRecursive.4=false
invoker.buildResult.4=success
99 changes: 99 additions & 0 deletions src/it/it-update-child-modules-002/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>localhost</groupId>
<artifactId>it-302</artifactId>
<version>5.0</version>
<packaging>pom</packaging>
<name>update-child-modules</name>

<modules>
<module>child</module>
<module>child2</module>
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3.1</version>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.4.1</version>
</plugin>
<plugin>
<artifactId>maven-rar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-7</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.0.4</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-alpha-1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
87 changes: 87 additions & 0 deletions src/it/it-update-child-modules-002/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.io.*;
import java.util.regex.*;

try
{
File file = new File( basedir, "child/pom.xml" );

BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
StringBuilder buf = new StringBuilder();
String line = in.readLine();
while ( line != null )
{
buf.append( line );
buf.append( " " );
line = in.readLine();
}

Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*5\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
Matcher m = p.matcher( buf.toString() );
if ( !m.find() )
{
System.out.println( "Updated parent of child module" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

try
{
File file = new File( basedir, "child/subchild/pom.xml" );

BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
StringBuilder buf = new StringBuilder();
String line = in.readLine();
while ( line != null )
{
buf.append( line );
buf.append( " " );
line = in.readLine();
}

Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*4\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
Matcher m = p.matcher( buf.toString() );
if ( !m.find() )
{
System.out.println( "Updated parent of subchild module" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}
try
{
File file = new File( basedir, "child/subchild2/pom.xml" );

BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
StringBuilder buf = new StringBuilder();
String line = in.readLine();
while ( line != null )
{
buf.append( line );
buf.append( " " );
line = in.readLine();
}

Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*4\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
Matcher m = p.matcher( buf.toString() );
if ( !m.find() )
{
System.out.println( "Updated parent of subchild2 module" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
public class UpdateChildModulesMojo
extends AbstractVersionsUpdaterMojo
{

/**
* The groupId that we are updating. Guarded by this.
*/
Expand Down Expand Up @@ -129,7 +128,7 @@ else if ( d1 > d2 )
}

getLog().debug( "Looking for modules which use "
+ ArtifactUtils.versionlessKey( sourceGroupId, sourceArtifactId ) + " as their parent" );
+ ArtifactUtils.versionlessKey( sourceGroupId, sourceArtifactId ) + " as their parent to update it to " + sourceVersion );

for ( Map.Entry<String, Model> target : PomHelper.getChildModels( reactor, sourceGroupId,
sourceArtifactId ).entrySet() )
Expand Down Expand Up @@ -169,8 +168,6 @@ else if ( d1 > d2 )
+ ArtifactUtils.versionlessKey( sourceGroupId, sourceArtifactId ) + ":"
+ sourceVersion );
process( moduleProjectFile );
// don't forget to update the cached model
targetModel.setVersion( sourceVersion );
didSomething = true;
}
}
Expand Down

0 comments on commit 05dad7d

Please sign in to comment.