-
Notifications
You must be signed in to change notification settings - Fork 357
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
Support parsing module-info.java
#4054
Comments
I tried - org.openrewrite.java.logging.slf4j.Slf4jBestPractices
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.slf4j.Logger error(..) The latter to match the original PR content. Still no changes applied to the code base. I asked at https://rewriteoss.slack.com/archives/C01A843MWG5/p1704459019395649 for a end-to-end test. So that one can set breakpoints and see how the whole system behaves. Currently, I am not able to set a breakpoint in the recipe and debug it with my code base. |
Turns out the issue is caused by missing type information, as explored through the platform: We should figure out why those types are missing, and that will then likely also solve recipe runs against those classes. |
ParameterizedLogging
and other recipes
The output of the gradle plugin is pretty clear:
Maybe related, when running
(Maybe kind of follow-up to openrewrite/rewrite-testing-frameworks#428) |
Thanks for that helpful hint @koppor ! It seems the issue arises on these lines then: We unhelpfully do not log what exception triggered that; perhaps we should to help fix this issue for you, as I have no idea why it would fail now. Perhaps you can add |
For googlers/noobs:
I get the patch to compile and included. However, the issue does NOT appear locally, only on Moderne. I think, I cannot deploy code to there. 🤣🤣 Interestingly, Moderne points to org.openrewrite.maven.MavenParser, but we are on gradle. For sure, a Maven parser is not able to parse Gradle files. How to tell Moderne that this is a gradle project? |
I'd missed that detail! You're absolutely right that this fails in a Moderne worker. 🙃 I've reran the recipe just now without issue though, so perhaps it was a one time issue? |
Result of today: 913 classes w/ missing type information: |
I did not see any exception today. (I should have screenshotted where to find a potential exception) |
We just fixed a rather nasty bug that lead to a lot of missing types that might factor in here as well I'll kick off a new ingestion run for JabRef in the next hour or so (needs a release first) such that we can see if there are improvements. |
I checked. No changes. I created an MWE with one (!) Java class and one dependency. The MWE is available at https://github.com/koppor/mwe-openrewrite-rewrite-gradle-plugin-issue-261/. I created a GitHub action to run the gradle plugin. Output at https://github.com/koppor/mwe-openrewrite-rewrite-gradle-plugin-issue-261/actions. The build.gradle even fits on a screen: plugins {
id 'java'
id 'org.openrewrite.rewrite' version '6.7.0'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.slf4j:slf4j-api:2.0.11'
}
rewrite {
activeRecipe(
'org.jabref.config.rewrite.cleanup'
)
exclusion (
"build.gradle",
)
failOnDryRunResults = true
} Note, this is groovy and not Kotlin! It must be some dumb configuration error. I know, there is no bom dependency above. The full project has (and it has that issue, too). |
I also tried with Branch: https://github.com/koppor/mwe-openrewrite-rewrite-gradle-plugin-issue-261/tree/mwe-kotlin |
What made you add the exclusion on build.gradle above? 🤔 Can't imagine that helping resolve dependencies and types.
Indeed the missing types issue is still there for Jabref; don't yet know why, but that will affect all recipe runs. :/ |
There were erros. However, did not happen today with current main of JabRef.
😇🙈 Will try to try later working one the MWE to get build.gradle included and reproducing the issue. |
Removed ignoring of diff --git a/src/main/java/org/jabref/cli/Launcher.java b/src/main/java/org/jabref/cli/Launcher.java
index 403a0b4..c1e3856 100644
--- a/src/main/java/org/jabref/cli/Launcher.java
+++ b/src/main/java/org/jabref/cli/Launcher.java
@@ -3,9 +3,9 @@ org.openrewrite.config.CompositeRecipe
import org.slf4j.Logger;
public class Launcher {
- private static Logger LOGGER;
+ private static /*~~(Identifier type is missing or malformed)~~>*/Logger LOGGER;
public static void main(String[] args) {
- LOGGER.info("Started main");
+ /*~~(Identifier type is missing or malformed)~~>*/LOGGER.info("Started main");
}
}
diff --git a/build.gradle b/build.gradle
index c062021..f3bae82 100644
--- a/build.gradle
+++ b/build.gradle
@@ -12,7 +12,7 @@ org.openrewrite.config.CompositeRecipe
}
rewrite {
- activeRecipe(
+ /*~~(MethodInvocation type is missing or malformed)~~>*/activeRecipe(
'org.jabref.config.rewrite.cleanup'
)
failOnDryRunResults = true |
So it's expected that That is really strange though that the |
Connecting with the debugger seems like the way forward. I would first check if the JavaParser gets properly created with the classpath and would thus set a breakpoint in the build plugin or the JavaParser.builder() method. |
Current state of investigation: When adding the test "locally" to the plugin source code, it determines "only" issues at diff --git a/build.gradle b/build.gradle
index cb9b3cf..cd51727 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ org.openrewrite.config.CompositeRecipe
repositories {
mavenCentral()
maven {
- url = uri("https://oss.sonatype.org/content/repositories/snapshots")
+ url = /*~~(MethodInvocation type is missing or malformed)~~>*/uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
@@ -14,6 +14,6 @@
implementation 'org.slf4j:slf4j-api:2.0.11'
}
rewrite {
- activeRecipe('org.jabref.config.rewrite.cleanup')
+ /*~~(MethodInvocation type is missing or malformed)~~>*/activeRecipe('org.jabref.config.rewrite.cleanup')
}
\ No newline at end of file
Thus, I am personally back in the helpless world of how to debug a gradle build without using the project of rewrite-gradle-plugin, but the MWE project. |
@koppor If you use |
Here you still use the rewrite-gradle-plugin project, but only to step through its code in the debugger. You would still be debugging what goes wrong when building your project. |
@knutwannheden I do not understand. Inside the plugin the MWE works. See openrewrite/rewrite-gradle-plugin#273. - It does not work when the release version is used. See https://github.com/koppor/mwe-openrewrite-rewrite-gradle-plugin-issue-261/actions/runs/7688550336/job/20949897316. I am reading https://medium.com/grandcentrix/how-to-debug-gradle-plugins-with-intellij-eef2ef681a7b, but I cannot get it to work in the MWE project to step into the source of the gradle plugin. |
I suspect this is in the JavaParser implementation and will thus also affect the Maven plugin. Have you checked if it can be reproduced using a unit test? That would be helpful to have. |
@knutwannheden You are right. I submitted openrewrite/rewrite-maven-plugin#737 for illustration that the issue also happens when using Maven. -- I thought, it could be because of the pre-conditions of classgraph because of JDK16+, but seeing my tests above with Java 11, it should be something different 😅. |
Had a brief look at this by adding a unit test to our JavaParserTest @Test
void moduleInfo(){
rewriteRun(
java(
"""
module demo {
requires java.base;
}
""",
spec -> spec.path("module-info.java")
)
);
} This already fails with
This is likely something to fix in the JavaParsers, as any issues there are likely to cause further issues downstream. I'll move this issue to reflect that we likely need a fix in openrewrite/rewrite instead. |
module-info.java
trips up the Gradle pluginmodule-info.java
trips up the JavaParser and Gradle/Maven plugin
I think, this is "OK".
I would be willing to help, but I think, my setup is not "good enough". I think, I need a gradle minimal project to really have the "correct" classpath. Then, I need the rewrite-gradle-plugin. Then, I need rewrite itself. I have no clue how to debug and to tell gradle to use a modified source. |
Hmm; can't say I've done any debugging of openrewrite/rewrite modifications through the gradle plugin before I think; Knut added some hints above; he or Shannon might know more as to the best way to go about that. Looking at this issue again I'm wondering if there's a simpler fix we can do in the short term: our parser does not support rewrite/rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java Lines 290 to 292 in 8988375
Any thoughts on that? Might just get you going, and the files should still be parsed by our plain text parser for the OSS plugins. |
It is definitely possible to debug locally. Since the issue is almost certainly within rewrite proper, I'll illustrate how to get a working environment and debug the Java parsers using the full MWE. From a process standpoint, I'd do the following:
NOTE: Make sure that in your MWE that the project repositories also includes |
My current workaround:
Then, all changes are applied well. |
Came up again on a new issue; I've gone back and updated the first issue to report problems parsing module-info.java in #1895 (comment) . There's value in the discussion above, so we can keep this one open too, but figure share this insight already. Based on an earlier attempt full support for parsing and modifying such files might be more effort, but skipping them to remove the need for the above workaround could be fairly straightforward. |
Quick thought: Maybe, it is "only" about adding a checkerFramework {
extraJavacArgs = [
'--module-path', compileOnly.asPath
]
} |
Had another quick look at this; it's indeed an issue with out Java 11+ parsers, and the tree model we map to. If we use the test from #4054 (comment) and run that with a breakpoint set in ReloadableJava17ParserVisitor#visitCompilationUnit, then we can see that the module declaration ends up in the We could instead there retrieve the module declaration, if present, and map that to new J tree elements for modules and directives, all with the proper handling for comments and whitespace. JCModuleDecl module = cu.getModule();
com.sun.tools.javac.util.List<JCDirective> directives = module.getDirectives();
... TODO: Map to new J tree elements ... That's likely quite a bit more work, and would have to be replicated across the Java 11, 17 and 21 parsers. Anyone welcome to pitch in on that; it's likely not complicated, just hasn't been done up to now. Alternatively we can do what was proposed previously: skip those module-info.java files in our JavaParsers; which could be a nice stop gap seeing as there's also not been any recipes specifically targeting We might then still need further work to get the type attribution to work; potentially including something similar to the |
Pending proper support in #4054 (comment)
Pending proper support in #4054 (comment)
Following this PR the parsers should at least no longer trip up; We can continue to track proper support here; after an earlier attempt failed to be merged |
module-info.java
trips up the JavaParser and Gradle/Maven pluginmodule-info.java
Thanks for working on this - module-info.java is something critical to our libraries, so looking forward to this working! |
I am using https://app.moderne.io/ (and also locally)
Go to https://app.moderne.io/, select "JabRef" and run
org.openrewrite.java.logging.slf4j.ParameterizedLogging
There are 0 results reported:
However, there should be more than 1:
That source code is also available at https://github.com/jabref/jabref/.
The text was updated successfully, but these errors were encountered: