-
Notifications
You must be signed in to change notification settings - Fork 89
feat: Add project parser for OpenRewrite #832
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 tasks
Two implementations currently exist: - RewriteMavenProjectParser - RewriteProjectParser RewriteMavenProjectParser creates Maven Plexus container to retrieve the Maven instance. A Maven instance is used to call `clean` and `package` while registering a listener to the lifecycle event when the goals are finished. The MavenSession provided to the listener allows executing the same OR classes as used when running in the rewrite-maven plugin. The created AST should be exactly the same as with the Maven plugin. RewriteProjectParser replicates the RewriteMavenProjectParser while split into smaller components. The RewriteMavenProjectParser is used to create the target AST which should be identically when parsing the same project with RewriteProjectParser. The RewriteProjectParser is meant to replace the RewriteMavenProjectParser.
0247fbb
to
14405e7
Compare
46e8727
to
f497c26
Compare
Two implementations currently exist: - RewriteMavenProjectParser - RewriteProjectParser RewriteMavenProjectParser creates Maven Plexus container to retrieve the Maven instance. A Maven instance is used to call `clean` and `package` while registering a listener to the lifecycle event when the goals are finished. The MavenSession provided to the listener allows executing the same OR classes as used when running in the rewrite-maven plugin. The created AST should be exactly the same as with the Maven plugin. RewriteProjectParser replicates the RewriteMavenProjectParser while split into smaller components. The RewriteMavenProjectParser is used to create the target AST which should be identically when parsing the same project with RewriteProjectParser. The RewriteProjectParser is meant to replace the RewriteMavenProjectParser.
…esult - RewriteProjectParser uses Maven's GraphBuilder to analyze the build file. This requires file access and thus binds the component to the File system. - Fix assertions about resulting ExecutionContext
… when all tests run together
3011a73
to
5d9d30e
Compare
BoykoAlex
approved these changes
Jul 24, 2023
25 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: sbm-support-rewrite
Issue is related to the sbm-support-rewrite compionent
type: enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a first implementation of a Project parser to parse Java projects using Maven to OpenRewrite AST.
The AST together with the provided
ExecutionContext
can then be used to execute OpenRewrite recipes.To find OpenRewrite recipes, a
RewriteRecipeDiscovery
component can be used to discover existing recipes, e.g. from the classpath.The parser hooks into the Maven execution and provides the AST as it would be created when running the OpenRewrite Maven plugin.
This implementation programmatically starts the Maven goals
clean
andinstall
and hooks into the execution with a listener providing access to theMavenSession
andMavenProject
.These instances are used to call the
MavenMojoProjectParser
which does the heavy lifting of parsing theMavenProject
to OpenRewrite's AST.This implementation requires file IO. An attempt to use
JIMFS
was unsuccessful because at multiple placesFile
is used which is not supported byJIMFS
.Replacing the Maven classes that depend on
File
(ordering the Maven modules in a newBuildFileGraph
impl.) would free the parser from access toFile
allowing the usage of potentially in-memoryResources
s.In
MavenMojoProjectParser:402
the results of a call toMavenParser.parse()
are collected into aList<SourceFile>
. This is a problem when a pom contains a parser error which will be returned asParseError
which is aSourceFile
but can't be casted intoXml.Document
and thus a CCE is thrown. From this exception it is impossible to understand which pom had a problem.The
ParsingListener
that can be registered is called for each parsed resource. This would not allow a countdown of resources as the total number of resources is unknown.