Skip to content

Commit

Permalink
Resolves mojohaus#848: Fixing module resolution with nonstandard file…
Browse files Browse the repository at this point in the history
…names
  • Loading branch information
jarmoniuk committed Dec 14, 2022
1 parent efec55e commit 60cda6a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
Expand Up @@ -106,7 +106,9 @@ public static Model getRawModel(MavenProject project) throws IOException {
public static Model getRawModel(File moduleProjectFile) throws IOException {
try (Reader reader =
new BufferedReader(new InputStreamReader(Files.newInputStream(moduleProjectFile.toPath())))) {
return getRawModel(reader);
Model result = getRawModel(reader);
result.setPomFile(moduleProjectFile);
return result;
}
}

Expand Down
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:set
invoker.mavenOpts = -DnewVersion=TEST
15 changes: 15 additions & 0 deletions versions-maven-plugin/src/it/it-set-issue-848/moduleA/moduleA.xml
@@ -0,0 +1,15 @@
<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>default-group</groupId>
<artifactId>default-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>moduleA</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

</project>
15 changes: 15 additions & 0 deletions versions-maven-plugin/src/it/it-set-issue-848/moduleB/pom.xml
@@ -0,0 +1,15 @@
<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>default-group</groupId>
<artifactId>default-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>moduleB</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

</project>
15 changes: 15 additions & 0 deletions versions-maven-plugin/src/it/it-set-issue-848/pom.xml
@@ -0,0 +1,15 @@
<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>default-group</groupId>
<artifactId>default-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>moduleA/moduleA.xml</module>
<module>moduleB/pom.xml</module>
</modules>

</project>
3 changes: 3 additions & 0 deletions versions-maven-plugin/src/it/it-set-issue-848/verify.groovy
@@ -0,0 +1,3 @@
assert new File( basedir, "pom.xml" ).text.contains( 'TEST' )
assert new File( basedir, "moduleA/moduleA.xml" ).text.contains( 'TEST' )
assert new File( basedir, "moduleB/pom.xml" ).text.contains( 'TEST' )
Expand Up @@ -283,8 +283,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (removeSnapshot && !nextSnapshot) {
String version = getVersion();
if (version.endsWith(SNAPSHOT)) {
String release = version.substring(0, version.indexOf(SNAPSHOT));
newVersion = release;
newVersion = version.substring(0, version.indexOf(SNAPSHOT));
getLog().info("SNAPSHOT found. BEFORE " + version + " --> AFTER: " + newVersion);
}
}
Expand Down Expand Up @@ -371,8 +370,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
reactor.values().parallelStream()
.map(m -> PomHelper.getModelEntry(reactor, PomHelper.getGroupId(m), PomHelper.getArtifactId(m)))
.filter(Objects::nonNull)
.map(Map.Entry::getKey)
.map(f -> getModuleProjectFile(project, f))
.map(Map.Entry::getValue)
.map(Model::getPomFile)
.forEach(files::add);
}

Expand Down Expand Up @@ -435,7 +434,7 @@ private void applyChange(
Map.Entry<String, Model> current = PomHelper.getModelEntry(reactor, groupId, artifactId);
if (current != null) {
current.getValue().setVersion(newVersion);
files.add(getModuleProjectFile(project, current.getKey()));
files.add(current.getValue().getPomFile());
}

for (Map.Entry<String, Model> sourceEntry : reactor.entrySet()) {
Expand Down Expand Up @@ -463,7 +462,7 @@ private void applyChange(
continue;
}

files.add(getModuleProjectFile(project, sourcePath));
files.add(sourceModel.getPomFile());

getLog().debug("Looking for modules which use "
+ ArtifactUtils.versionlessKey(sourceGroupId, sourceArtifactId) + " as their parent");
Expand Down Expand Up @@ -514,20 +513,6 @@ private void applyChange(
}
}

private static File getModuleProjectFile(MavenProject project, String relativePath) {
final File moduleDir = new File(project.getBasedir(), relativePath);
final File projectBaseDir = project.getBasedir();

if (projectBaseDir.equals(moduleDir)) {
return project.getFile();
} else if (moduleDir.isDirectory()) {
return new File(moduleDir, "pom.xml");
}
// i don't think this should ever happen... but just in case
// the module references the file-name
return moduleDir;
}

/**
* Updates the pom file.
*
Expand Down

0 comments on commit 60cda6a

Please sign in to comment.