Skip to content

Commit 7bce2bf

Browse files
author
Julian Di Leonardo
committed
Fixed mojohaus#190
mojohaus#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
1 parent f9a9cfe commit 7bce2bf

File tree

8 files changed

+277
-4
lines changed

8 files changed

+277
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>it-302</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
11+
<groupId>localhost</groupId>
12+
<artifactId>it-302-child</artifactId>
13+
<version>4.0</version>
14+
<packaging>pom</packaging>
15+
16+
<modules>
17+
<module>subchild</module>
18+
<module>subchild2</module>
19+
</modules>
20+
21+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>it-302-child</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
11+
<groupId>localhost</groupId>
12+
<artifactId>it-302-subchild</artifactId>
13+
<version>2.0</version>
14+
<packaging>pom</packaging>
15+
16+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>it-302-child</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
11+
<groupId>localhost</groupId>
12+
<artifactId>it-302-subchild2</artifactId>
13+
<version>2.0</version>
14+
<packaging>pom</packaging>
15+
16+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>it-302</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
11+
<groupId>localhost</groupId>
12+
<artifactId>it-302-child2</artifactId>
13+
<version>4.0</version>
14+
<packaging>pom</packaging>
15+
16+
17+
18+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# first check that the root project builds ok
2+
invoker.goals.1=-o validate
3+
invoker.nonRecursive.1=true
4+
invoker.buildResult.1=success
5+
6+
# second check that adding the child project into the mix breaks things
7+
invoker.goals.2=-o validate
8+
invoker.nonRecursive.2=false
9+
invoker.buildResult.2=failure
10+
11+
# third fix the build with our plugin
12+
invoker.goals.3=${project.groupId}:${project.artifactId}:${project.version}:update-child-modules
13+
invoker.nonRecursive.3=true
14+
invoker.buildResult.3=success
15+
16+
# forth, confirm that the build is fixed
17+
invoker.goals.4=validate
18+
invoker.nonRecursive.4=false
19+
invoker.buildResult.4=success
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>localhost</groupId>
6+
<artifactId>it-302</artifactId>
7+
<version>5.0</version>
8+
<packaging>pom</packaging>
9+
<name>update-child-modules</name>
10+
11+
<modules>
12+
<module>child</module>
13+
<module>child2</module>
14+
</modules>
15+
16+
<build>
17+
<pluginManagement>
18+
<plugins>
19+
<plugin>
20+
<artifactId>maven-antrun-plugin</artifactId>
21+
<version>1.1</version>
22+
</plugin>
23+
<plugin>
24+
<artifactId>maven-assembly-plugin</artifactId>
25+
<version>2.2-beta-2</version>
26+
</plugin>
27+
<plugin>
28+
<artifactId>maven-clean-plugin</artifactId>
29+
<version>2.2</version>
30+
</plugin>
31+
<plugin>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>2.0.2</version>
34+
</plugin>
35+
<plugin>
36+
<artifactId>maven-dependency-plugin</artifactId>
37+
<version>2.0</version>
38+
</plugin>
39+
<plugin>
40+
<artifactId>maven-deploy-plugin</artifactId>
41+
<version>2.3</version>
42+
</plugin>
43+
<plugin>
44+
<artifactId>maven-ear-plugin</artifactId>
45+
<version>2.3.1</version>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-ejb-plugin</artifactId>
49+
<version>2.1</version>
50+
</plugin>
51+
<plugin>
52+
<artifactId>maven-install-plugin</artifactId>
53+
<version>2.2</version>
54+
</plugin>
55+
<plugin>
56+
<artifactId>maven-jar-plugin</artifactId>
57+
<version>2.2</version>
58+
</plugin>
59+
<plugin>
60+
<artifactId>maven-javadoc-plugin</artifactId>
61+
<version>2.4</version>
62+
</plugin>
63+
<plugin>
64+
<artifactId>maven-plugin-plugin</artifactId>
65+
<version>2.4.1</version>
66+
</plugin>
67+
<plugin>
68+
<artifactId>maven-rar-plugin</artifactId>
69+
<version>2.2</version>
70+
</plugin>
71+
<plugin>
72+
<artifactId>maven-release-plugin</artifactId>
73+
<version>2.0-beta-7</version>
74+
</plugin>
75+
<plugin>
76+
<artifactId>maven-resources-plugin</artifactId>
77+
<version>2.2</version>
78+
</plugin>
79+
<plugin>
80+
<artifactId>maven-site-plugin</artifactId>
81+
<version>2.0</version>
82+
</plugin>
83+
<plugin>
84+
<artifactId>maven-source-plugin</artifactId>
85+
<version>2.0.4</version>
86+
</plugin>
87+
<plugin>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>2.4.2</version>
90+
</plugin>
91+
<plugin>
92+
<artifactId>maven-war-plugin</artifactId>
93+
<version>2.1-alpha-1</version>
94+
</plugin>
95+
</plugins>
96+
</pluginManagement>
97+
</build>
98+
99+
</project>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import java.io.*;
2+
import java.util.regex.*;
3+
4+
try
5+
{
6+
File file = new File( basedir, "child/pom.xml" );
7+
8+
BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
9+
StringBuilder buf = new StringBuilder();
10+
String line = in.readLine();
11+
while ( line != null )
12+
{
13+
buf.append( line );
14+
buf.append( " " );
15+
line = in.readLine();
16+
}
17+
18+
Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*5\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
19+
Matcher m = p.matcher( buf.toString() );
20+
if ( !m.find() )
21+
{
22+
System.out.println( "Updated parent of child module" );
23+
return false;
24+
}
25+
}
26+
catch( Throwable t )
27+
{
28+
t.printStackTrace();
29+
return false;
30+
}
31+
32+
try
33+
{
34+
File file = new File( basedir, "child/subchild/pom.xml" );
35+
36+
BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
37+
StringBuilder buf = new StringBuilder();
38+
String line = in.readLine();
39+
while ( line != null )
40+
{
41+
buf.append( line );
42+
buf.append( " " );
43+
line = in.readLine();
44+
}
45+
46+
Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*4\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
47+
Matcher m = p.matcher( buf.toString() );
48+
if ( !m.find() )
49+
{
50+
System.out.println( "Updated parent of subchild module" );
51+
return false;
52+
}
53+
}
54+
catch( Throwable t )
55+
{
56+
t.printStackTrace();
57+
return false;
58+
}
59+
try
60+
{
61+
File file = new File( basedir, "child/subchild2/pom.xml" );
62+
63+
BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) );
64+
StringBuilder buf = new StringBuilder();
65+
String line = in.readLine();
66+
while ( line != null )
67+
{
68+
buf.append( line );
69+
buf.append( " " );
70+
line = in.readLine();
71+
}
72+
73+
Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*4\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" );
74+
Matcher m = p.matcher( buf.toString() );
75+
if ( !m.find() )
76+
{
77+
System.out.println( "Updated parent of subchild2 module" );
78+
return false;
79+
}
80+
}
81+
catch( Throwable t )
82+
{
83+
t.printStackTrace();
84+
return false;
85+
}
86+
87+
return true;

src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
public class UpdateChildModulesMojo
5050
extends AbstractVersionsUpdaterMojo
5151
{
52-
5352
/**
5453
* The groupId that we are updating. Guarded by this.
5554
*/
@@ -132,7 +131,7 @@ else if ( d1 > d2 )
132131
}
133132

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

137136
Iterator j =
138137
PomHelper.getChildModels( reactor, sourceGroupId, sourceArtifactId ).entrySet().iterator();
@@ -175,8 +174,6 @@ else if ( d1 > d2 )
175174
+ ArtifactUtils.versionlessKey( sourceGroupId, sourceArtifactId ) + ":"
176175
+ sourceVersion );
177176
process( moduleProjectFile );
178-
// don't forget to update the cached model
179-
targetModel.setVersion( sourceVersion );
180177
didSomething = true;
181178
}
182179
}

0 commit comments

Comments
 (0)