diff --git a/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java b/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java index 3b4f2e9f..e35393f6 100644 --- a/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java +++ b/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java @@ -193,6 +193,7 @@ protected enum State { private static final String OPENREWRITE_PROCESSED_MARKER = "openrewrite.processed"; protected void putState(State state) { + //noinspection unchecked getPluginContext().put(OPENREWRITE_PROCESSED_MARKER, state.name()); } diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 61e2a092..068de35f 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())); + List testJavaSources = new ArrayList<>(); + for (String p : mavenProject.getTestCompileSourceRoots()) { + testJavaSources.addAll(listJavaSources(mavenProject.getBasedir().toPath().resolve(p))); + } alreadyParsed.addAll(testJavaSources); // scan Kotlin files diff --git a/src/main/java/org/openrewrite/maven/MeterRegistryProvider.java b/src/main/java/org/openrewrite/maven/MeterRegistryProvider.java index 8ac4d51c..09a37130 100644 --- a/src/main/java/org/openrewrite/maven/MeterRegistryProvider.java +++ b/src/main/java/org/openrewrite/maven/MeterRegistryProvider.java @@ -25,24 +25,24 @@ import io.rsocket.transport.ClientTransport; import io.rsocket.transport.netty.client.TcpClientTransport; import io.rsocket.transport.netty.client.WebsocketClientTransport; -import org.apache.maven.plugin.logging.Log; -import org.jspecify.annotations.Nullable; +import org.apache.maven.plugin.logging.Log; +import org.jspecify.annotations.Nullable; import reactor.netty.http.client.HttpClient; import reactor.netty.tcp.TcpClient; import reactor.util.retry.Retry; import java.net.URI; import java.time.Duration; -import java.util.Base64; - +import java.util.Base64; + public class MeterRegistryProvider implements AutoCloseable { - private final Log log; + private final Log log; @Nullable - private final String uriString; + private final String uriString; @Nullable - private final String username; + private final String username; @Nullable private final String password; @@ -115,6 +115,7 @@ private MeterRegistry buildRegistry() { } private ClientTransport getWebsocketClientTransport(TcpClient tcpClient) { + //noinspection deprecation HttpClient httpClient = HttpClient.from(tcpClient).wiretap(true); if (username != null && password != null) { httpClient = httpClient.headers(h -> h.add("Authorization", "Basic: " + Base64.getUrlEncoder() diff --git a/src/test/java/org/openrewrite/maven/RewriteRunIT.java b/src/test/java/org/openrewrite/maven/RewriteRunIT.java index 2f525e6b..6f405018 100644 --- a/src/test/java/org/openrewrite/maven/RewriteRunIT.java +++ b/src/test/java/org/openrewrite/maven/RewriteRunIT.java @@ -39,6 +39,23 @@ 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") + }) + @MavenGoal("generate-test-sources") + 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/IntegrationTest.java by:", + "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/project/src/test/java/sample/RegularTest.java by:" + ); + } + @MavenTest void single_project(MavenExecutionResult result) { assertThat(result) @@ -113,16 +130,16 @@ void java_compiler_plugin_project(MavenExecutionResult result) { @SystemProperty(value = "rewrite.additionalPlainTextMasks", content = "**/*.ext,**/.in-root") void plaintext_masks(MavenExecutionResult result) { assertThat(result) - .isSuccessful() - .out() - .warn() - .contains( - "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/in-src.ext by:", - "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/.in-root by:", - "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/from-default-list.py by:", - "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/Dummy.java by:" - ) - .doesNotContain("in-root.ignored"); + .isSuccessful() + .out() + .warn() + .contains( + "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/in-src.ext by:", + "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/.in-root by:", + "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/from-default-list.py by:", + "Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/plaintext_masks/project/src/main/java/sample/Dummy.java by:" + ) + .doesNotContain("in-root.ignored"); } } 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..f39adc58 --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/pom.xml @@ -0,0 +1,55 @@ + + + 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 + + + + + + + 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/IntegrationTest.java b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/IntegrationTest.java new file mode 100644 index 00000000..1c25fa0c --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/integration-test/java/sample/IntegrationTest.java @@ -0,0 +1,8 @@ +package sample; + +import org.junit.jupiter.api.Test; + +class IntegrationTest { + @Test + void testBar() {} +} diff --git a/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/RegularTest.java b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/RegularTest.java new file mode 100644 index 00000000..45dc60f4 --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/multi_source_sets_project/src/test/java/sample/RegularTest.java @@ -0,0 +1,8 @@ +package sample; + +import org.junit.jupiter.api.Test; + +class RegularTest { + @Test + void testBar() {} +}