Skip to content

Commit

Permalink
[Issue #48] detect root project location also in special cases:
Browse files Browse the repository at this point in the history
- maven is executed on a submodule
- projects aggregation root and parent is not the same
- child modules may reside in deeper nested folders without a pom.xml in between
  • Loading branch information
stefanseifert committed Jun 2, 2020
1 parent d73b14e commit 933dccf
Show file tree
Hide file tree
Showing 21 changed files with 377 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals = validate
invoker.buildResult = success
invoker.project = modules/submodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

<artifactId>project</artifactId>
<packaging>jar</packaging>

<name>rootlocation sub project</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>rootlocation</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-root</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>rootlocation search top root</name>
<description>
Tests that rootlocation finds the highest basedir.
</description>

<modules>
<module>parent</module>
<module>modules/submodule</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" )
assert file.exists()

String text = file.getText("utf-8")

def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation-in-submodule-deeperlevel-separate-parent"

return true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals = validate
invoker.buildResult = success
invoker.project = modules/submodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<artifactId>build-helper-rootlocation-modules</artifactId>
<packaging>pom</packaging>

<modules>
<module>submodule</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

<artifactId>project</artifactId>
<packaging>jar</packaging>

<name>rootlocation sub project</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>rootlocation</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
27 changes: 27 additions & 0 deletions src/it/rootlocation-in-submodule-nested-separate-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-root</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>rootlocation search top root</name>
<description>
Tests that rootlocation finds the highest basedir.
</description>

<modules>
<module>parent</module>
<module>modules</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" )
assert file.exists()

String text = file.getText("utf-8")

def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation-in-submodule-nested-separate-parent"

return true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals = validate
invoker.buildResult = success
invoker.project = submodule
27 changes: 27 additions & 0 deletions src/it/rootlocation-in-submodule-separate-parent/parent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<goals>
<goal>rootlocation</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
27 changes: 27 additions & 0 deletions src/it/rootlocation-in-submodule-separate-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-root</artifactId>
<version>1-SNAPSHOT</version>
<packaging>pom</packaging>

<name>rootlocation search top root</name>
<description>
Tests that rootlocation finds the highest basedir.
</description>

<modules>
<module>parent</module>
<module>submodule</module>
</modules>

</project>
17 changes: 17 additions & 0 deletions src/it/rootlocation-in-submodule-separate-parent/submodule/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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>

<parent>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-rootlocation-parent</artifactId>
<version>1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<artifactId>project</artifactId>
<packaging>jar</packaging>

<name>rootlocation sub project</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
File file = new File( basedir, "build.log" )
assert file.exists()

String text = file.getText("utf-8")

def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation-in-submodule-separate-parent"

return true
3 changes: 2 additions & 1 deletion src/it/rootlocation-in-submodule/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ assert file.exists()

String text = file.getText("utf-8")

assert text.matches('(?ms)(.*?)define property rootlocation = "(.*)[/\\\\]rootlocation-in-submodule"(.*?)')
def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation-in-submodule"

return true
4 changes: 3 additions & 1 deletion src/it/rootlocation-run-only-at-exec-root/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ assert file.exists()

String text = file.getText("utf-8")

assert text.matches('(?ms)(.*?)define property rootlocation = "(.*)[/\\\\]rootlocation-run-only-at-exec-root"(.*?)')
def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation-run-only-at-exec-root"

assert text.contains("Skip getting the rootlocation in this project because it's not the Execution Root")

return true
3 changes: 2 additions & 1 deletion src/it/rootlocation/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ assert file.exists()

String text = file.getText("utf-8")

assert text.matches('(?ms)(.*?)define property rootlocation = "(.*)[/\\\\]rootlocation"(.*?)')
def rootFolderName = (text =~ /(?ms)(.*?)define property rootlocation = "(.*?)[\/\\]([^\/\\"]+)"(.*?)/)[0][3]
assert rootFolderName == "rootlocation"

return true
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractDefinePropertyMojo
* The maven project
*/
@Parameter( readonly = true, defaultValue = "${project}" )
private MavenProject project;
protected MavenProject project;

protected void defineProperty( String name, String value )
{
Expand Down
Loading

0 comments on commit 933dccf

Please sign in to comment.