Skip to content

Commit 783f9ce

Browse files
stefanseifertkhmarbaise
authored andcommitted
#82 ensure version change affects only the current directory (and child directories), not the parent or sibling directories
1 parent a8d335f commit 783f9ce

File tree

10 files changed

+242
-51
lines changed

10 files changed

+242
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -fmodule-a1 -DnewVersion=2.5.0-SNAPSHOT
2+
invoker.nonRecursive=true
3+
invoker.buildResult=success
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>localdomain.localhost</groupId>
7+
<artifactId>module-a1</artifactId>
8+
<version>2.0.7-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>module-b1</artifactId>
11+
<packaging>pom</packaging>
12+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>localdomain.localhost</groupId>
7+
<artifactId>module-a1</artifactId>
8+
<version>2.0.7-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>module-b2</artifactId>
11+
<version>2.0.7-SNAPSHOT</version>
12+
<packaging>pom</packaging>
13+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>localdomain.localhost</groupId>
7+
<artifactId>module-a1</artifactId>
8+
<version>2.0.7-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>module-b3</artifactId>
11+
<version>2.0.7-SNAPSHOT</version>
12+
<packaging>pom</packaging>
13+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>localdomain.localhost</groupId>
5+
<artifactId>module-a1</artifactId>
6+
<packaging>pom</packaging>
7+
<version>2.0.7-SNAPSHOT</version>
8+
<modules>
9+
<module>module-b1</module>
10+
<module>module-b2</module>
11+
<module>module-b3</module>
12+
</modules>
13+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>localdomain.localhost</groupId>
5+
<artifactId>module-a2</artifactId>
6+
<packaging>pom</packaging>
7+
<version>1.0.3-SNAPSHOT</version>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>localdomain.localhost</groupId>
12+
<artifactId>module-b1</artifactId>
13+
<version>2.0.7-SNAPSHOT</version>
14+
</dependency>
15+
</dependencies>
16+
17+
</project>

src/it/it-set-018-issue-82/pom.xml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>localdomain.localhost</groupId>
6+
<artifactId>project-a</artifactId>
7+
<packaging>pom</packaging>
8+
<version>1.2.0-SNAPSHOT</version>
9+
<name>mversions-82</name>
10+
11+
<description>
12+
invoking versions:set on child pom - make sure no other child poms are affected
13+
</description>
14+
15+
<modules>
16+
<module>module-a1</module>
17+
<module>module-a2</module>
18+
</modules>
19+
20+
<build>
21+
<pluginManagement>
22+
<plugins>
23+
<plugin>
24+
<artifactId>maven-antrun-plugin</artifactId>
25+
<version>1.1</version>
26+
</plugin>
27+
<plugin>
28+
<artifactId>maven-assembly-plugin</artifactId>
29+
<version>2.2-beta-2</version>
30+
</plugin>
31+
<plugin>
32+
<artifactId>maven-clean-plugin</artifactId>
33+
<version>2.2</version>
34+
</plugin>
35+
<plugin>
36+
<artifactId>maven-compiler-plugin</artifactId>
37+
<version>2.0.2</version>
38+
</plugin>
39+
<plugin>
40+
<artifactId>maven-dependency-plugin</artifactId>
41+
<version>2.0</version>
42+
</plugin>
43+
<plugin>
44+
<artifactId>maven-deploy-plugin</artifactId>
45+
<version>2.3</version>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-ear-plugin</artifactId>
49+
<version>2.3.1</version>
50+
</plugin>
51+
<plugin>
52+
<artifactId>maven-ejb-plugin</artifactId>
53+
<version>2.1</version>
54+
</plugin>
55+
<plugin>
56+
<artifactId>maven-install-plugin</artifactId>
57+
<version>2.2</version>
58+
</plugin>
59+
<plugin>
60+
<artifactId>maven-jar-plugin</artifactId>
61+
<version>2.2</version>
62+
</plugin>
63+
<plugin>
64+
<artifactId>maven-javadoc-plugin</artifactId>
65+
<version>2.4</version>
66+
</plugin>
67+
<plugin>
68+
<artifactId>maven-plugin-plugin</artifactId>
69+
<version>2.4.1</version>
70+
</plugin>
71+
<plugin>
72+
<artifactId>maven-rar-plugin</artifactId>
73+
<version>2.2</version>
74+
</plugin>
75+
<plugin>
76+
<artifactId>maven-release-plugin</artifactId>
77+
<version>2.0-beta-7</version>
78+
</plugin>
79+
<plugin>
80+
<artifactId>maven-resources-plugin</artifactId>
81+
<version>2.2</version>
82+
</plugin>
83+
<plugin>
84+
<artifactId>maven-site-plugin</artifactId>
85+
<version>2.0</version>
86+
</plugin>
87+
<plugin>
88+
<artifactId>maven-source-plugin</artifactId>
89+
<version>2.0.4</version>
90+
</plugin>
91+
<plugin>
92+
<artifactId>maven-surefire-plugin</artifactId>
93+
<version>2.4.2</version>
94+
</plugin>
95+
<plugin>
96+
<artifactId>maven-war-plugin</artifactId>
97+
<version>2.1-alpha-1</version>
98+
</plugin>
99+
</plugins>
100+
</pluginManagement>
101+
</build>
102+
103+
</project>
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import org.apache.commons.lang.StringUtils
2+
3+
import javax.xml.parsers.DocumentBuilderFactory
4+
import javax.xml.xpath.XPathFactory
5+
6+
class Checker
7+
{
8+
def result = true;
9+
10+
def basedir;
11+
12+
public Checker(File basedir) {
13+
this.basedir = basedir;
14+
}
15+
16+
def readXPath( String pom, String xPathExpression )
17+
{
18+
def stream = new FileInputStream( new File( basedir, pom ) );
19+
try
20+
{
21+
return XPathFactory.newInstance()
22+
.newXPath()
23+
.evaluate( xPathExpression, DocumentBuilderFactory.newInstance()
24+
.newDocumentBuilder()
25+
.parse( stream ).documentElement );
26+
}
27+
finally
28+
{
29+
stream.close();
30+
}
31+
}
32+
33+
Checker check( String message, String pom, String xpath, String expected )
34+
{
35+
if ( result )
36+
{
37+
try
38+
{
39+
def actual = readXPath( pom, xpath )
40+
if ( !StringUtils.equals( expected, actual ) )
41+
{
42+
System.out.println( pom + " [xpath:" + xpath + "] expected '" + expected + "' found '" + actual + "' : " + message );
43+
result = false;
44+
}
45+
}
46+
catch ( Throwable t )
47+
{
48+
t.printStackTrace();
49+
result = false;
50+
}
51+
}
52+
return this;
53+
}
54+
}
55+
56+
return new Checker(basedir)
57+
.check( "root pom unchanged", "pom.xml", "/project/version", "1.2.0-SNAPSHOT" )
58+
.check( "module-a1 changed", "module-a1/pom.xml", "/project/version", "2.5.0-SNAPSHOT" )
59+
.check( "module-a1/module-b1 parent changed", "module-a1/module-b1/pom.xml", "/project/parent/version", "2.5.0-SNAPSHOT" )
60+
.check( "module-a1/module-b1 remains unspecified", "module-a1/module-b1/pom.xml", "/project/version", "" )
61+
.check( "module-a1/module-b2 parent changed", "module-a1/module-b2/pom.xml", "/project/parent/version", "2.5.0-SNAPSHOT" )
62+
.check( "module-a1/module-b2 version changed", "module-a1/module-b2/pom.xml", "/project/version", "2.5.0-SNAPSHOT" )
63+
.check( "module-a1/module-b3 parent changed", "module-a1/module-b3/pom.xml", "/project/parent/version", "2.5.0-SNAPSHOT" )
64+
.check( "module-a1/module-b3 version changed", "module-a1/module-b3/pom.xml", "/project/version", "2.5.0-SNAPSHOT" )
65+
.check( "module-a2 unchanged", "module-a2/pom.xml", "/project/version", "1.0.3-SNAPSHOT" )
66+
.check( "module-a2 dependency unchanged", "module-a2/pom.xml", "/project/dependencies/dependency/version", "2.0.7-SNAPSHOT" )
67+
.result;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ public void execute()
281281

282282
try
283283
{
284-
final MavenProject project =
285-
PomHelper.getLocalRoot( projectBuilder, getProject(), localRepository, null, getLog() );
284+
final MavenProject project = getProject();
286285

287286
getLog().info( "Local aggregation root: " + project.getBasedir() );
288287
Map<String, Model> reactorModels = PomHelper.getReactorModels( project, getLog() );

src/main/java/org/codehaus/mojo/versions/api/PomHelper.java

-49
Original file line numberDiff line numberDiff line change
@@ -1376,55 +1376,6 @@ public static String getGroupId( Model model )
13761376
return targetGroupId;
13771377
}
13781378

1379-
/**
1380-
* Finds the local root of the specified project.
1381-
*
1382-
* @param project The project to find the local root for.
1383-
* @param localRepository the local repo.
1384-
* @param globalProfileManager the global profile manager.
1385-
* @param logger The logger to log to.
1386-
* @return The local root (note this may be the project passed as an argument).
1387-
*/
1388-
public static MavenProject getLocalRoot( MavenProjectBuilder builder, MavenProject project,
1389-
ArtifactRepository localRepository, ProfileManager globalProfileManager,
1390-
Log logger )
1391-
{
1392-
logger.info( "Searching for local aggregator root..." );
1393-
while ( true )
1394-
{
1395-
final File parentDir = project.getBasedir().getParentFile();
1396-
if ( parentDir != null && parentDir.isDirectory() )
1397-
{
1398-
logger.debug( "Checking to see if " + parentDir + " is an aggregator parent" );
1399-
File parent = new File( parentDir, "pom.xml" );
1400-
if ( parent.isFile() )
1401-
{
1402-
try
1403-
{
1404-
final MavenProject parentProject =
1405-
builder.build( parent, localRepository, globalProfileManager );
1406-
if ( getAllChildModules( parentProject, logger ).contains( project.getBasedir().getName() ) )
1407-
{
1408-
logger.debug( parentDir + " is an aggregator parent" );
1409-
project = parentProject;
1410-
continue;
1411-
}
1412-
else
1413-
{
1414-
logger.debug( parentDir + " is not an aggregator parent" );
1415-
}
1416-
}
1417-
catch ( ProjectBuildingException e )
1418-
{
1419-
logger.warn( e );
1420-
}
1421-
}
1422-
}
1423-
logger.debug( "Local aggregation root is " + project.getBasedir() );
1424-
return project;
1425-
}
1426-
}
1427-
14281379
/**
14291380
* Builds a map of raw models keyed by module path.
14301381
*

0 commit comments

Comments
 (0)