Open fabapp2 opened 7 months ago
@fabapp2 I will work on this, please assign it to me.
Thanks, Mahi
@fabapp2 I need to create RewritePluginOutputParser in separately in spring-rewrite-commons-plugin-invoker-maven and spring-rewrite-commons-plugin-invoker-gradle or spring-rewrite-commons-plugin-invoker-polyglot?
Could you please confirm?
Thanks, Mahi
@fabapp2 I need to create RewritePluginOutputParser in separately in spring-rewrite-commons-plugin-invoker-maven and spring-rewrite-commons-plugin-invoker-gradle or spring-rewrite-commons-plugin-invoker-polyglot?
Could you please confirm?
Thanks, Mahi
Hi @bsmahi
That's correct.
I don't see the need for a PolyglotParser
as it would use either RewriteGradlePluginOutputParser
or RewriteMavenPluginOutputParser
.
I didn't think much about the resulting data structure, but I it should allow to access the information provided in the concole output.
String consoleOutput = ...
RewriteMavenPluginOutputParser parser = ...
RewriteMavenPluginExecutionResult result = parser.parse(consoleOutput);
// was recipe run successful
boolean success = result.succeeded()
assertThat(success).isTrue();
// get changed files
List<ChangedResource> changedResources = result.getChangedResources();
assertThat(changedResources.get(0).getPath().toString()).isEqualTo("complete/pom.xml");
assertThat(changedResources.get(1).getPath().toString()).isEqualTo("complete/src/main/java/com/example/accessingdatarest/Person.java");
// get recipes that made changes to a file
assertThat(changedResources.get(0).getRecipesThatMadeChanges().stream().map(r -> r.getName()).toList()).containsExactly(
"org.openrewrite.maven.UpgradeParentVersion".
"org.openrewrite.java.migrate.UpgradeJavaVersion", // 11
"org.openrewrite.java.migrate.UpgradeJavaVersion", // 17
"org.openrewrite.maven.UpgradeParentVersion", // 3.0.x
"org.openrewrite.maven.UpgradeParentVersion". // 3.1.x
);
// details about recipe(s) that made changes:
List<AppliedRecipe> recipesThatMadeChanges = changedResources.get(1).getRecipesThatMadeChanges();
assertThat(recipesThatMadeChanges.get(1).getName()).isEqualTo("org.openrewrite.java.migrate.UpgradeJavaVersion");
assertThat(recipesThatMadeChanges.get(1).getParams()).hasSize(1);
assertThat(recipesThatMadeChanges.get(1).getParams()).contains("version")
assertThat(recipesThatMadeChanges.get(1).getParams().get("version")).isEqualTo(11);
assertThat(recipesThatMadeChanges.get(1).getParent().getName()).isEqualTo("org.openrewrite.java.migrate.JavaVersion11");
// get applied recipes
List<AppliedRecipe> appliedRecipes = result.getAppliedRecipes();
appliedRecipes.forEach(appliedRecipe -> {
String recipeName = appliedRecipe.getName();
List<ChangedResource> changedResources = appliedRecipe.getChangedResources();
changedResources.forEach(changedResource -> {
assertThat(changedResource.getAppliedRecipes()).contains(appliedRecipe);
});
});
Optional<AppliedRecipe> optUpgradeRecipe = result.getAppliedRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0");
assertThat(optUpgradeRecipe).isPresent();
AppliedRecipe upgradeRecipe = optUpgradeRecipe.get();
assertThat(upgradeRecipe.getChangedResources()).contains("complete/pom.xml", ""complete/src/main/java/com/example/accessingdatarest/Person.java");
So, we need a structure that allows navigating in both directions (recipes -> resources and resources -> recipes) and provides the hierarchy plus properties of the recipes.
Thoughts?
What needs to be done
The console output of OpenRewrite's Maven plugins should be parsed and made available.
The
PluginInvoker
implementation from #73 provides access to the output of the build.The MAven plugin prints information about the recipes that were applied. This is an example for the output of OR's Maven plugin:
A new component
RewritePluginOutputParser
should parse the output of OpenRewrite Maven plugin and provide an API to access the extracted information:What's next
RewritePlugin
implementations should provide access to the parsed dataThe return types can be made specific to the executed plugin goals that provide an API to the build information extracted from the plugin output. E.g.
PluginInvocationResult result = RewritePlugin.run()...
would become