Skip to content

Commit 199dc0c

Browse files
timtebeekclaudegithub-actions[bot]
authored
Verify support for multiple main source folders (#1031)
* Add support for multiple main source folders Similar to the support for additional test source folders added in PR #888, this change enables the rewrite-maven-plugin to process multiple main source directories configured via build-helper-maven-plugin or similar tools. Changes: - Modified MavenMojoProjectParser to iterate through all compile source roots using mavenProject.getCompileSourceRoots() instead of single source directory - Added integration test to verify recipes are applied to files in all main source directories - Follows the same pattern as the existing test source folder implementation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent dfc6c6b commit 199dc0c

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ void multi_source_sets_project(MavenExecutionResult result) {
5656
.contains("Changes have been made to %s by:".formatted(separatorsToSystem("project/src/test/java/sample/RegularTest.java")));
5757
}
5858

59+
@MavenGoal("generate-sources")
60+
@MavenTest
61+
@SystemProperties({
62+
@SystemProperty(value = "rewrite.activeRecipes", content = "org.openrewrite.java.format.SingleLineComments"),
63+
})
64+
void multi_main_source_sets_project(MavenExecutionResult result) {
65+
assertThat(result)
66+
.isSuccessful()
67+
.out()
68+
.warn()
69+
.contains("Changes have been made to project/src/main/java/sample/MainClass.java by:")
70+
.contains("Changes have been made to project/src/additional-main/java/sample/AdditionalMainClass.java by:");
71+
}
72+
5973
@MavenTest
6074
void single_project(MavenExecutionResult result) {
6175
assertThat(result)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_main_source_sets_project</artifactId>
8+
<version>1.0</version>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>build-helper-maven-plugin</artifactId>
22+
<version>3.6.0</version>
23+
<executions>
24+
<execution>
25+
<id>add additional main sources</id>
26+
<phase>generate-sources</phase>
27+
<goals>
28+
<goal>add-source</goal>
29+
</goals>
30+
<configuration>
31+
<sources>
32+
<source>src/additional-main/java</source>
33+
</sources>
34+
</configuration>
35+
</execution>
36+
</executions>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sample;
2+
3+
public class AdditionalMainClass {
4+
//This is a test class
5+
public void method() {
6+
System.out.println("Additional main source set");
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sample;
2+
3+
public class MainClass {
4+
//This is a test class
5+
public void method() {
6+
System.out.println("Main source set");
7+
}
8+
}

0 commit comments

Comments
 (0)