From 638fcc5ac4dfcb4d83a2d2c7c8df0d056c99e438 Mon Sep 17 00:00:00 2001 From: Niels de Bruin Date: Thu, 31 Oct 2024 12:32:29 +0100 Subject: [PATCH] Add support for multiple test sources sets --- .../maven/MavenMojoProjectParser.java | 5 +- .../org/openrewrite/maven/RewriteRunIT.java | 15 +++++ .../multi_source_sets_project/pom.xml | 60 +++++++++++++++++++ .../java/sample/SomeIntegrationTest.java | 10 ++++ .../src/test/java/sample/CoolTest.java | 8 +++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/pom.xml create mode 100644 src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/SomeIntegrationTest.java create mode 100644 src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/CoolTest.java diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 61e2a092..56cb52d4 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -458,7 +458,10 @@ private Stream processTestSources( javaParserBuilder.classpath(testDependencies).typeCache(typeCache); kotlinParserBuilder.classpath(testDependencies).typeCache(new JavaTypeCache()); - List testJavaSources = listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getTestSourceDirectory())); + Set testJavaSources = new LinkedHashSet<>(listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getTestSourceDirectory()))); + for (String p : mavenProject.getTestCompileSourceRoots()) { + testJavaSources.addAll(listJavaSources(mavenProject.getBasedir().toPath().resolve(p))); + } alreadyParsed.addAll(testJavaSources); // scan Kotlin files diff --git a/src/test/java/org/openrewrite/maven/RewriteRunIT.java b/src/test/java/org/openrewrite/maven/RewriteRunIT.java index 2f525e6b..078a1278 100644 --- a/src/test/java/org/openrewrite/maven/RewriteRunIT.java +++ b/src/test/java/org/openrewrite/maven/RewriteRunIT.java @@ -39,6 +39,21 @@ void multi_module_project(MavenExecutionResult result) { .anySatisfy(line -> assertThat(line).contains("org.openrewrite.staticanalysis.SimplifyBooleanExpression")); } + @MavenTest + @SystemProperties({ + @SystemProperty(value = "rewrite.activeRecipes", content = "org.openrewrite.java.search.FindTypes"), + @SystemProperty(value = "rewrite.options", content = "fullyQualifiedTypeName=org.junit.jupiter.api.Test") + }) + @Disabled + void multi_source_sets_project(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out() + .warn() + .contains("Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/integration-test/java/sample/SomeIntegrationTest.java by:") + .contains("Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/test/java/sample/CoolTest.java by:"); + } + @MavenTest void single_project(MavenExecutionResult result) { assertThat(result) diff --git a/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/pom.xml b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/pom.xml new file mode 100644 index 00000000..1dcf8955 --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.openrewrite.maven + multi_source_sets_project + 1.0 + pom + + + 1.8 + 1.8 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter + 5.9.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.9.1 + test + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.0 + + + add integration test sources + generate-test-sources + + add-test-source + + + + src/integration-test/java + + + + + + + + diff --git a/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/SomeIntegrationTest.java b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/SomeIntegrationTest.java new file mode 100644 index 00000000..6dc0a07b --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/SomeIntegrationTest.java @@ -0,0 +1,10 @@ +package sample; + +import org.junit.jupiter.api.Test; + +class SomeIntegrationTest { + @Test + void testBar() { + + } +} \ No newline at end of file diff --git a/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/CoolTest.java b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/CoolTest.java new file mode 100644 index 00000000..8a5bc355 --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/CoolTest.java @@ -0,0 +1,8 @@ +package sample; + +import org.junit.jupiter.api.Test; + +class CoolTest { + @Test + void testBar() {} +} \ No newline at end of file