-
Notifications
You must be signed in to change notification settings - Fork 78
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 NoGuavaByteStreams Refaster recipe using Java 9+ #399
Conversation
Still to do:
|
@@ -16,7 +16,7 @@ dependencies { | |||
testImplementation("org.projectlombok:lombok:latest.release") | |||
|
|||
annotationProcessor("org.openrewrite:rewrite-templating:$rewriteVersion") | |||
compileOnly("com.google.errorprone:error_prone_core:2.19.1:with-dependencies") { | |||
compileOnly("com.google.errorprone:error_prone_core:2.19.1") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise the recipe will pick error_prone_support
as the lib that provides the Guava classes, and put that in the generated template classpath leading to mismatches.
Right now generated recipes use a lambda containing the input and output code, which is used to lookup the associated before/after template classes. But when the before or after template uses code that can only run on Java 11+ that might not work on Java 8 anymore. As an example; the generated
There's some rough work in rewrite-templating to no longer use those lamdbas for lookup, but instead inline the generated JavaTemplates such that it all compiles on Java 8; that likely needs to land first before we can merge this PR. |
src/test/java/org/openrewrite/java/migrate/guava/NoGuavaByteStreamsTest.java
Show resolved
Hide resolved
src/test/java/org/openrewrite/java/migrate/guava/NoGuavaByteStreamsTest.java
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Still a minor challenge to solve with the generated classes now compiled using Java 17:
At the very least we want the generated sources to be compiled with Java 8, now that there's no references to Java 9+ classes in there. |
Predictably adding something like this then breaks on the Java 9+ constructs tasks.named<JavaCompile>("compileRefasterJava").configure {
options.release = 8
} But it's not immediately clear to me how to use Java 17 only for the |
Can we use |
To me the question is rather why it's an annotation processor at all (except for historical reasons in how refaster templates have evolved). If it were just normal "application code" being called from the maven or gradle plugin, it would still be able to scan the classpath and to find all the annotated classes and then to process them. Being called at the right time (i.e. before the compilation of the recipes) would just be a matter of the maven and gradle plugin attaching to the right phases. And without the annotation processor, there would be no overlap in what levels of Java are needed for compilation of generated code. Compilation of everything could happen with 8, just the JVM running this would need to be 17 to use the template processor bytecode. Or am I completely missing something in this picture? |
Closing this PR for now, as we're unlikely to figure out a way to include recipes generated for Refaster templates that require Java 9+ |
What's your motivation?
Anything in particular you'd like reviewers to focus on?
Added a new source set for that Java 9+ classes needed for these replacements;
The input refaster templates should not make it into the jar, but the generated recipes should.
Any additional context
Possible requires this PR such that there's no recipes produced with lambdas using Java 9+
InputStreamRules
Refaster rule collection PicnicSupermarket/error-prone-support#963