diff --git a/.mvn/maven.config b/.mvn/maven.config index 282d58718f3..7dd0bf2283f 100644 --- a/.mvn/maven.config +++ b/.mvn/maven.config @@ -1,4 +1,3 @@ --batch-mode --errors --strict-checksums --Dstyle.color=always \ No newline at end of file diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 66160aca2f7..e0fd16e62d2 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -194,7 +194,7 @@ org.openrewrite rewrite-java-11 - provided + test org.openrewrite @@ -271,11 +271,6 @@ refaster-support ${project.version} - - org.openrewrite - rewrite-templating - ${version.rewrite-templating} - -Xplugin:RefasterRuleCompiler diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/StringRulesRecipesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/StringRulesRecipesTest.java index 6389c7f1f1c..5121a065f7a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/StringRulesRecipesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/StringRulesRecipesTest.java @@ -1,16 +1,20 @@ package tech.picnic.errorprone.refasterrules; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.openrewrite.java.Assertions.java; -import com.google.errorprone.FileObjects; +import com.google.common.io.Resources; import java.io.IOException; -import javax.tools.JavaFileObject; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +// XXX: This class currently validates the OpenRewrite recipe generation by applying a single +// recipe. Generalize this setup to cover all generated recipes (for _all_ Refaster rule +// collections), ideally by reusing the `RefasterRulesTest` test resources. (This may introduce +// additional hurdles, as OpenRewrite removes obsolete imports, while Refaster doesn't.) final class StringRulesRecipesTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { @@ -21,30 +25,32 @@ public void defaults(RecipeSpec spec) { void stringValueOf() { // XXX: Use text blocks once supported. rewriteRun( - // language=java java( "import java.util.Objects;\n" + + '\n' + "class Test {\n" - + " String test(Object object) {\n" - + " return Objects.toString(object);\n" - + " }\n" - + "}", + + " String test(Object object) {\n" + + " return Objects.toString(object);\n" + + " }\n" + + '}', "class Test {\n" - + " String test(Object object) {\n" - + " return String.valueOf(object);\n" - + " }\n" - + "}")); + + " String test(Object object) {\n" + + " return String.valueOf(object);\n" + + " }\n" + + '}')); } - @Test @Disabled("Not all rules are currently supported") - void reuseStringRulesTestInputOutput() throws IOException { - String rule = "StringRules"; - JavaFileObject before = FileObjects.forResource(getClass(), rule + "TestInput.java"); - JavaFileObject after = FileObjects.forResource(getClass(), rule + "TestOutput.java"); + @Test + void allRules() throws IOException { rewriteRun( spec -> spec.parser(JavaParser.fromJavaVersion().classpath("guava", "refaster-test-support")), - java(before.getCharContent(true).toString(), after.getCharContent(true).toString())); + java( + loadResource("StringRulesTestInput.java"), loadResource("StringRulesTestOutput.java"))); + } + + private String loadResource(String resource) throws IOException { + return Resources.toString(Resources.getResource(getClass(), resource), UTF_8); } } diff --git a/pom.xml b/pom.xml index 2550b7bc6c3..5166dde86a6 100644 --- a/pom.xml +++ b/pom.xml @@ -456,6 +456,13 @@ + + + org.openrewrite + rewrite-templating + ${version.rewrite-templating} + org.openrewrite.recipe rewrite-recipe-bom @@ -943,6 +950,11 @@ mockito-errorprone ${version.mockito} + + org.openrewrite + rewrite-templating + ${version.rewrite-templating} + --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index 78d7c95e8e5..eb70ecc98c0 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -87,6 +87,21 @@ junit-jupiter-params test + + org.openrewrite + rewrite-core + test + + + org.openrewrite + rewrite-java + test + + + org.openrewrite + rewrite-templating + test + diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index ddfba52718a..03d91062a63 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -69,6 +69,21 @@ junit-jupiter-params test + + org.openrewrite + rewrite-core + test + + + org.openrewrite + rewrite-java + test + + + org.openrewrite + rewrite-templating + test +