Skip to content

Commit 451f3ba

Browse files
Maven multi modules resources not handled correctly (#1067)
* Maven multi modules resources not handled correctly * Update assertions * Adopt suggested alternative * Update src/test/java/org/openrewrite/maven/RewriteRunIT.java Co-authored-by: Shannon Pamperl <[email protected]> * Fix compilation and assertion after applied suggestion --------- Co-authored-by: Shannon Pamperl <[email protected]>
1 parent af2655c commit 451f3ba

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,13 @@ private OmniParser omniParser(Set<Path> alreadyParsed, MavenProject mavenProject
926926
}
927927

928928
private Collection<String> mergeExclusions(MavenProject mavenProject) {
929+
Path projectPath = mavenProject.getBasedir().toPath();
929930
return Stream.concat(
930931
pathsToOtherMavenProjects(mavenProject).stream()
931-
.map(subproject -> separatorsToUnix(baseDir.relativize(mavenProject.getBasedir().toPath()).toString())),
932-
exclusions.stream()).collect(toList());
932+
.filter(otherProjectPath -> !projectPath.startsWith(otherProjectPath))
933+
.map(subproject -> separatorsToUnix(baseDir.relativize(subproject).toString())),
934+
exclusions.stream()
935+
).collect(toList());
933936
}
934937

935938
private Collection<PathMatcher> pathMatchers(Path basePath, Collection<String> pathExpressions) {

src/test/java/org/openrewrite/maven/RewriteRunIT.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.stream.Stream;
2929

3030
import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat;
31-
import static org.assertj.core.api.Assertions.assertThat;
3231
import static org.openrewrite.PathUtils.separatorsToSystem;
3332

3433
@MavenGoal("${project.groupId}:${project.artifactId}:${project.version}:run")
@@ -47,6 +46,16 @@ void multi_module_project(MavenExecutionResult result) {
4746
.anySatisfy(line -> assertThat(line).contains("org.openrewrite.staticanalysis.SimplifyBooleanExpression"));
4847
}
4948

49+
@MavenTest
50+
void multi_module_resources(MavenExecutionResult result) {
51+
assertThat(result)
52+
.isSuccessful()
53+
.out()
54+
.warn()
55+
.contains("Changes have been made to %s by:".formatted(separatorsToSystem("project/a/src/main/resources/example.xml")))
56+
.contains(" org.openrewrite.xml.ChangeTagName: {elementName=/foo, newName=bar}");
57+
}
58+
5059
@MavenGoal("generate-test-sources")
5160
@MavenTest
5261
@SystemProperties({
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.openrewrite.maven</groupId>
8+
<artifactId>multi_module_resources</artifactId>
9+
<version>1.0</version>
10+
</parent>
11+
12+
<artifactId>a</artifactId>
13+
14+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<foo>bar</foo>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.openrewrite.maven</groupId>
7+
<artifactId>multi_module_resources</artifactId>
8+
<version>1.0</version>
9+
<packaging>pom</packaging>
10+
11+
<modules>
12+
<module>a</module>
13+
</modules>
14+
15+
<properties>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>@project.groupId@</groupId>
25+
<artifactId>@project.artifactId@</artifactId>
26+
<version>@project.version@</version>
27+
<configuration>
28+
<activeRecipes>
29+
<recipe>bug.report.ChangeTag</recipe>
30+
</activeRecipes>
31+
<configLocation>
32+
${maven.multiModuleProjectDirectory}/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_module_resources/rewrite.yml
33+
</configLocation>
34+
</configuration>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.openrewrite.recipe</groupId>
38+
<artifactId>rewrite-static-analysis</artifactId>
39+
<version>1.0.4</version>
40+
</dependency>
41+
</dependencies>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: bug.report.ChangeTag
4+
displayName: Change XML tag name
5+
recipeList:
6+
- org.openrewrite.xml.ChangeTagName:
7+
elementName: /foo
8+
newName: bar

0 commit comments

Comments
 (0)