Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rewrite-templating annotation processor to also produce OpenRewrite recipes #925

Merged
merged 28 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7404516
Always show color in Maven output
timtebeek Dec 14, 2023
54db453
Add rewrite-templating as annotation processor
timtebeek Dec 14, 2023
c09efe0
Verify generated `StringRulesRecipes` work
timtebeek Dec 16, 2023
e556b3f
Drop unused `version.rewrite`
timtebeek Dec 16, 2023
578f37d
Use rewrite-templating v1.3.9
timtebeek Dec 16, 2023
27ba49f
Declare used dependency
timtebeek Dec 16, 2023
4763cd3
Adopt rewrite-templating 1.3.11
timtebeek Dec 17, 2023
a80d259
Apply formatter to StringRulesRecipesTest
timtebeek Dec 17, 2023
ef9771a
Add a test that reuses StringRulesTestInput & Output
timtebeek Dec 17, 2023
6583807
Resolve license warnings
Stephan202 Dec 17, 2023
ac6f0c1
Resolve remaining build errors
Stephan202 Dec 17, 2023
7b99785
rewrite-templating 1.3.12
timtebeek Dec 17, 2023
5771567
Suggestions
Stephan202 Dec 18, 2023
7cca5a2
Prevent some noisy license plugin output
Stephan202 Dec 18, 2023
69841ef
TEST: Check whether only Windows builds break
Stephan202 Dec 18, 2023
b0b759c
Revert "TEST: Check whether only Windows builds break"
Stephan202 Dec 18, 2023
bb46973
TEST: Try to understand the constructed regex
Stephan202 Dec 18, 2023
d058310
TEST Check regex of failing module
Stephan202 Dec 18, 2023
7c65fea
Test with some heuristics
Stephan202 Dec 18, 2023
f522426
One more test: without artifact name assumption
Stephan202 Dec 18, 2023
f5e58c8
Revert debug change
Stephan202 Dec 18, 2023
477d626
rewrite-templating 1.3.13 to suppress all warnings
timtebeek Dec 20, 2023
6872eb8
rewrite-templating 1.3.14 & rewrite-recipe-bom 2.5.4
timtebeek Dec 23, 2023
025eb5e
Merge branch 'master' into add-rewite-templating
timtebeek Dec 23, 2023
9d972f4
Merge branch 'master' into add-rewite-templating
Stephan202 Dec 24, 2023
9c57f7d
Merge branch 'master' into add-rewite-templating
Stephan202 Dec 26, 2023
36736e6
Merge branch 'master' into add-rewite-templating
rickie Dec 31, 2023
ffe6fb5
Merge branch 'master' into add-rewite-templating
Stephan202 Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto</groupId>
Expand Down Expand Up @@ -181,6 +181,31 @@
<artifactId>mongodb-driver-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-11</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package tech.picnic.errorprone.refasterrules;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openrewrite.java.Assertions.java;

import com.google.common.io.Resources;
import java.io.IOException;
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 {
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new StringRulesRecipes());
}

@Test
void stringValueOf() {
// XXX: Use text blocks once supported.
rewriteRun(
java(
"import java.util.Objects;\n"
+ '\n'
+ "class Test {\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"
+ '}'));
}

@Disabled("Not all rules are currently supported")
@Test
void allRules() throws IOException {
rewriteRun(
spec ->
spec.parser(JavaParser.fromJavaVersion().classpath("guava", "refaster-test-support")),
java(
loadResource("StringRulesTestInput.java"), loadResource("StringRulesTestOutput.java")));
}

private String loadResource(String resource) throws IOException {
return Resources.toString(Resources.getResource(getClass(), resource), UTF_8);
}
}
49 changes: 48 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
<version.nopen-checker>1.0.1</version.nopen-checker>
<version.nullaway>0.10.18</version.nullaway>
<version.pitest-git>1.1.4</version.pitest-git>
<version.rewrite-templating>1.3.14</version.rewrite-templating>
<version.surefire>3.2.3</version.surefire>
</properties>

Expand Down Expand Up @@ -455,6 +456,20 @@
</exclusion>
</exclusions>
</dependency>
<!-- Specified as a workaround for
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<version>${version.rewrite-templating}</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
<version>2.5.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-bom</artifactId>
Expand Down Expand Up @@ -935,6 +950,11 @@
<artifactId>mockito-errorprone</artifactId>
<version>${version.mockito}</version>
</path>
<path>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<version>${version.rewrite-templating}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
Expand Down Expand Up @@ -1210,12 +1230,15 @@
non-distributed (i.e. Picnic-internal) deployable
artifacts (i.e. web services). -->
<includedLicense>Apache-2.0</includedLicense>
<includedLicense>BSD-2-Clause</includedLicense>
<includedLicense>BSD-3-Clause</includedLicense>
<includedLicense>CC0-1.0</includedLicense>
<includedLicense>CDDL-1.1</includedLicense>
<includedLicense>EPL-1.0</includedLicense>
<includedLicense>EPL-2.0</includedLicense>
<includedLicense>GPL-2.0-with-classpath-exception</includedLicense>
<includedLicense>ICU</includedLicense>
<includedLicense>LGPL-2.1+</includedLicense>
<includedLicense>LGPL-3.0+</includedLicense>
<includedLicense>MIT</includedLicense>
<includedLicense>MIT-0</includedLicense>
Expand All @@ -1238,10 +1261,20 @@
| The Apache Software License, Version 2.0
</licenseMerge>
<licenseMerge>
<!-- -->
<!-- XXX: Get projects referencing just "BSD"
to explicitly state the clause count. -->
BSD-2-Clause
| The BSD License
</licenseMerge>
<licenseMerge>
<!-- XXX: Get projects referencing just "BSD"
to explicitly state the clause count. -->
BSD-3-Clause
| 3-Clause BSD License
| BSD 3-clause
| BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
<!-- XXX: Typo; file ticket. -->
| BSD licence
| BSD License 3
| Eclipse Distribution License (New BSD License)
| New BSD License
Expand All @@ -1250,6 +1283,7 @@
<!-- -->
CC0-1.0
| CC0
| Public Domain, per Creative Commons CC0
</licenseMerge>
<licenseMerge>
<!-- -->
Expand All @@ -1268,6 +1302,12 @@
EPL-2.0
| Eclipse Public License - v 2.0
| Eclipse Public License v2.0
| EPL 2.0
</licenseMerge>
<licenseMerge>
<!-- -->
ICU
| Unicode/ICU License
</licenseMerge>
<licenseMerge>
<!-- -->
Expand All @@ -1279,6 +1319,12 @@
</licenseMerge>
<licenseMerge>
<!-- -->
LGPL-2.1+
| LGPL-2.1-or-later
</licenseMerge>
<licenseMerge>
<!-- XXX: Get projects referencing just "LGPL"
to explicitly state the license version. -->
LGPL-3.0+
| GNU Lesser Public License
</licenseMerge>
Expand All @@ -1288,6 +1334,7 @@
| MIT license
| MIT License
| The MIT License
| The MIT License (MIT)
</licenseMerge>
</licenseMerges>
<!-- Nearly no projects ship a "missing third party
Expand Down
15 changes: 15 additions & 0 deletions refaster-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
15 changes: 15 additions & 0 deletions refaster-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down