From 7f0c430159feb83489b96c3b6ee750a3b4f51231 Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Mon, 8 Jul 2024 14:33:14 -0300 Subject: [PATCH 1/9] Made possible to configure options on recipes --- .../maven/AbstractRewriteBaseRunMojo.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index 600fa558..ee4f2c78 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -16,11 +16,15 @@ package org.openrewrite.maven; import io.micrometer.core.instrument.Metrics; + +import org.apache.commons.lang3.ObjectUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.openrewrite.*; +import org.openrewrite.config.CompositeRecipe; +import org.openrewrite.config.DeclarativeRecipe; import org.openrewrite.config.Environment; import org.openrewrite.config.RecipeDescriptor; import org.openrewrite.internal.InMemoryLargeSourceSet; @@ -32,8 +36,11 @@ import org.openrewrite.style.NamedStyles; import org.openrewrite.xml.tree.Xml; +import com.google.common.base.Splitter; + import java.io.IOException; import java.io.UncheckedIOException; +import java.lang.reflect.Field; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Files; @@ -44,6 +51,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.UnaryOperator; +import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.Collections.emptyList; @@ -54,6 +62,10 @@ public abstract class AbstractRewriteBaseRunMojo extends AbstractRewriteMojo { @Parameter(property = "rewrite.exportDatatables", defaultValue = "false") protected boolean exportDatatables; + @Parameter(property = "rewrite.options") + protected Map options; + @Parameter(property = "rewrite.flatOptions") + protected String flatOptions; /** * Attempt to determine the root of the git repository for the given project. @@ -98,6 +110,16 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio return new ResultsContainer(repositoryRoot, emptyList()); } + if (ObjectUtils.isEmpty(options) && !ObjectUtils.isEmpty(flatOptions)) { + Splitter comma = Splitter.on(','); + Splitter collon = Splitter.on(':'); + + options = comma.splitToStream(flatOptions).map(pair -> collon.splitToList(pair)) + .collect(Collectors.toMap(values -> values.get(0), values -> values.get(1))); + } + + configureRecipeOptions(recipe); + getLog().info("Validating active recipes..."); List> validations = new ArrayList<>(); recipe.validateAll(ctx, validations); @@ -126,6 +148,62 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } } + private void configureRecipeOptions(Recipe recipe) throws MojoExecutionException { + if (recipe instanceof CompositeRecipe) { + CompositeRecipe composite = (CompositeRecipe) recipe; + for (Recipe child : composite.getRecipeList()) { + this.configureRecipeOptions(child); + } + } else if (recipe instanceof DeclarativeRecipe) { + DeclarativeRecipe declarativeRecipe = (DeclarativeRecipe) recipe; + for (Recipe child : declarativeRecipe.getRecipeList()) { + this.configureRecipeOptions(child); + } + } else { + List optionFields = Arrays.stream(recipe.getClass().getDeclaredFields()) + .filter(field -> options.containsKey(field.getName())).collect(Collectors.toList()); + + for (Field field : optionFields) { + updateOption(recipe, field, options.get(field.getName())); + } + } + } + + private void updateOption(Recipe recipe, Field field, String optionValue) throws MojoExecutionException { + Object convertedOptionValue = convertOptionValue(recipe, field.getName(), optionValue, field.getType()); + try { + field.setAccessible(true); + field.set(recipe, convertedOptionValue); + field.setAccessible(false); + } catch (IllegalArgumentException | IllegalAccessException e) { + throw new MojoExecutionException( + String.format("Unable to configure recipe '%s' option '%s' with value '%s'", + recipe.getClass().getSimpleName(), field.getName(), optionValue)); + } + } + + private Object convertOptionValue(Recipe recipe, String name, String optionValue, Class type) + throws MojoExecutionException { + if (optionValue == null) { + return null; + } + if (type.isAssignableFrom(String.class)) { + return optionValue; + } + if (type.isAssignableFrom(boolean.class) || type.isAssignableFrom(Boolean.class)) { + return Boolean.parseBoolean(optionValue); + } + if (type.isAssignableFrom(int.class) || type.isAssignableFrom(Integer.class)) { + return Integer.parseInt(optionValue); + } + if (type.isAssignableFrom(long.class) || type.isAssignableFrom(Long.class)) { + return Long.parseLong(optionValue); + } + + throw new MojoExecutionException( + String.format("Unable to convert option: %s value: %s to type: %s", recipe, name, optionValue, type)); + } + protected LargeSourceSet loadSourceSet(Path repositoryRoot, Environment env, ExecutionContext ctx) throws DependencyResolutionRequiredException, MojoExecutionException { List styles = loadStyles(project, env); From 13bfbc041a77050ad87b7ad335a054e3e17143b3 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 22 Jul 2024 14:21:05 +0200 Subject: [PATCH 2/9] Polish logged message for printed data tables --- .../java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index ee4f2c78..a4383541 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -222,7 +222,7 @@ protected List runRecipe(Recipe recipe, LargeSourceSet sourceSet, Execut if (exportDatatables) { String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss-SSS")); Path datatableDirectoryPath = Paths.get("target", "rewrite", "datatables", timestamp); - getLog().info(String.format("Printing Available Datatables to: %s", datatableDirectoryPath)); + getLog().info(String.format("Printing available datatables to: %s", datatableDirectoryPath)); recipeRun.exportDatatablesToCsv(datatableDirectoryPath, ctx); } From 1593c7139c0d636d17773bddb67d00ff24b8ac91 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 22 Jul 2024 22:01:35 +0200 Subject: [PATCH 3/9] Fail to configure recipes containing other recipes --- .../maven/AbstractRewriteBaseRunMojo.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index a4383541..1db9b6da 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -149,28 +149,26 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } private void configureRecipeOptions(Recipe recipe) throws MojoExecutionException { - if (recipe instanceof CompositeRecipe) { - CompositeRecipe composite = (CompositeRecipe) recipe; - for (Recipe child : composite.getRecipeList()) { - this.configureRecipeOptions(child); - } - } else if (recipe instanceof DeclarativeRecipe) { - DeclarativeRecipe declarativeRecipe = (DeclarativeRecipe) recipe; - for (Recipe child : declarativeRecipe.getRecipeList()) { - this.configureRecipeOptions(child); - } - } else { - List optionFields = Arrays.stream(recipe.getClass().getDeclaredFields()) - .filter(field -> options.containsKey(field.getName())).collect(Collectors.toList()); + if (recipe instanceof CompositeRecipe || + recipe instanceof DeclarativeRecipe || + recipe instanceof Recipe.DelegatingRecipe || + !recipe.getRecipeList().isEmpty()){ + // We don't (yet) support configuring potentially nested recipes, as recipes might occur more than once, + // and setting the same value twice might lead to unexpected behavior. + throw new MojoExecutionException( + "Recipes containing other recipes can not be configured from the command line"); + } + List optionFields = Arrays.stream(recipe.getClass().getDeclaredFields()) + .filter(field -> options.containsKey(field.getName())) + .collect(Collectors.toList()); - for (Field field : optionFields) { - updateOption(recipe, field, options.get(field.getName())); - } + for (Field field : optionFields) { + updateOption(recipe, field, options.get(field.getName())); } } - private void updateOption(Recipe recipe, Field field, String optionValue) throws MojoExecutionException { - Object convertedOptionValue = convertOptionValue(recipe, field.getName(), optionValue, field.getType()); + private void updateOption(Recipe recipe, Field field, @Nullable String optionValue) throws MojoExecutionException { + Object convertedOptionValue = convertOptionValue(field.getName(), optionValue, field.getType()); try { field.setAccessible(true); field.set(recipe, convertedOptionValue); @@ -182,7 +180,7 @@ private void updateOption(Recipe recipe, Field field, String optionValue) throws } } - private Object convertOptionValue(Recipe recipe, String name, String optionValue, Class type) + private @Nullable Object convertOptionValue(String name, @Nullable String optionValue, Class type) throws MojoExecutionException { if (optionValue == null) { return null; @@ -201,7 +199,7 @@ private Object convertOptionValue(Recipe recipe, String name, String optionValue } throw new MojoExecutionException( - String.format("Unable to convert option: %s value: %s to type: %s", recipe, name, optionValue, type)); + String.format("Unable to convert option: %s value: %s to type: %s", name, optionValue, type)); } protected LargeSourceSet loadSourceSet(Path repositoryRoot, Environment env, ExecutionContext ctx) throws DependencyResolutionRequiredException, MojoExecutionException { From 95c7ce0c940ec31857749d580edee6ae5cba7b52 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 22 Jul 2024 22:40:25 +0200 Subject: [PATCH 4/9] Only parse flat options, with limited external dependencies --- .../maven/AbstractRewriteBaseRunMojo.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index 1db9b6da..0e76964a 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -16,8 +16,6 @@ package org.openrewrite.maven; import io.micrometer.core.instrument.Metrics; - -import org.apache.commons.lang3.ObjectUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; @@ -29,6 +27,7 @@ import org.openrewrite.config.RecipeDescriptor; import org.openrewrite.internal.InMemoryLargeSourceSet; import org.openrewrite.internal.ListUtils; +import org.openrewrite.internal.StringUtils; import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.tree.J; import org.openrewrite.kotlin.tree.K; @@ -36,8 +35,6 @@ import org.openrewrite.style.NamedStyles; import org.openrewrite.xml.tree.Xml; -import com.google.common.base.Splitter; - import java.io.IOException; import java.io.UncheckedIOException; import java.lang.reflect.Field; @@ -51,7 +48,6 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.UnaryOperator; -import java.util.stream.Collectors; import java.util.stream.Stream; import static java.util.Collections.emptyList; @@ -62,10 +58,9 @@ public abstract class AbstractRewriteBaseRunMojo extends AbstractRewriteMojo { @Parameter(property = "rewrite.exportDatatables", defaultValue = "false") protected boolean exportDatatables; + @Parameter(property = "rewrite.options") - protected Map options; - @Parameter(property = "rewrite.flatOptions") - protected String flatOptions; + protected String options; /** * Attempt to determine the root of the git repository for the given project. @@ -110,16 +105,10 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio return new ResultsContainer(repositoryRoot, emptyList()); } - if (ObjectUtils.isEmpty(options) && !ObjectUtils.isEmpty(flatOptions)) { - Splitter comma = Splitter.on(','); - Splitter collon = Splitter.on(':'); - - options = comma.splitToStream(flatOptions).map(pair -> collon.splitToList(pair)) - .collect(Collectors.toMap(values -> values.get(0), values -> values.get(1))); + if (!StringUtils.isBlank(options)) { + configureRecipeOptions(recipe, options); } - configureRecipeOptions(recipe); - getLog().info("Validating active recipes..."); List> validations = new ArrayList<>(); recipe.validateAll(ctx, validations); @@ -148,27 +137,39 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } } - private void configureRecipeOptions(Recipe recipe) throws MojoExecutionException { + private static void configureRecipeOptions(Recipe recipe, String options) throws MojoExecutionException { if (recipe instanceof CompositeRecipe || recipe instanceof DeclarativeRecipe || recipe instanceof Recipe.DelegatingRecipe || - !recipe.getRecipeList().isEmpty()){ + !recipe.getRecipeList().isEmpty()) { // We don't (yet) support configuring potentially nested recipes, as recipes might occur more than once, // and setting the same value twice might lead to unexpected behavior. throw new MojoExecutionException( "Recipes containing other recipes can not be configured from the command line"); } - List optionFields = Arrays.stream(recipe.getClass().getDeclaredFields()) - .filter(field -> options.containsKey(field.getName())) - .collect(Collectors.toList()); - for (Field field : optionFields) { - updateOption(recipe, field, options.get(field.getName())); + Map optionValues = new HashMap<>(); + for (String option : options.split(",")) { + String[] parts = option.split(":", 2); + if (parts.length == 2) { + optionValues.put(parts[0], parts[1]); + } + } + for (Field field : recipe.getClass().getDeclaredFields()) { + String removed = optionValues.remove(field.getName()); + updateOption(recipe, field, removed); + } + if (!optionValues.isEmpty()) { + throw new MojoExecutionException( + String.format("Unknown recipe options: %s", String.join(", ", optionValues.keySet()))); } } - private void updateOption(Recipe recipe, Field field, @Nullable String optionValue) throws MojoExecutionException { + private static void updateOption(Recipe recipe, Field field, @Nullable String optionValue) throws MojoExecutionException { Object convertedOptionValue = convertOptionValue(field.getName(), optionValue, field.getType()); + if (convertedOptionValue == null) { + return; + } try { field.setAccessible(true); field.set(recipe, convertedOptionValue); @@ -180,7 +181,7 @@ private void updateOption(Recipe recipe, Field field, @Nullable String optionVal } } - private @Nullable Object convertOptionValue(String name, @Nullable String optionValue, Class type) + private static @Nullable Object convertOptionValue(String name, @Nullable String optionValue, Class type) throws MojoExecutionException { if (optionValue == null) { return null; From 5796b5d8ff2d08b6ef3f921d4d74526407ece9cf Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 22 Jul 2024 23:37:37 +0200 Subject: [PATCH 5/9] Unpack CompositeRecipe containing single recipe Due to https://github.com/openrewrite/rewrite/blob/ec09e19feba2ccff12cc20d0d684babde9aa7914/rewrite-core/src/main/java/org/openrewrite/config/Environment.java#L163 --- .../openrewrite/maven/AbstractRewriteBaseRunMojo.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index 0e76964a..f623f16d 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -60,6 +60,7 @@ public abstract class AbstractRewriteBaseRunMojo extends AbstractRewriteMojo { protected boolean exportDatatables; @Parameter(property = "rewrite.options") + @Nullable protected String options; /** @@ -138,6 +139,10 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } private static void configureRecipeOptions(Recipe recipe, String options) throws MojoExecutionException { + if (recipe instanceof CompositeRecipe && recipe.getRecipeList().size() == 1) { + // Unpack active recipe if it's a single recipe + recipe = recipe.getRecipeList().get(0); + } if (recipe instanceof CompositeRecipe || recipe instanceof DeclarativeRecipe || recipe instanceof Recipe.DelegatingRecipe || @@ -145,12 +150,12 @@ private static void configureRecipeOptions(Recipe recipe, String options) throws // We don't (yet) support configuring potentially nested recipes, as recipes might occur more than once, // and setting the same value twice might lead to unexpected behavior. throw new MojoExecutionException( - "Recipes containing other recipes can not be configured from the command line"); + "Recipes containing other recipes can not be configured from the command line: " + recipe); } Map optionValues = new HashMap<>(); for (String option : options.split(",")) { - String[] parts = option.split(":", 2); + String[] parts = option.split("=", 2); if (parts.length == 2) { optionValues.put(parts[0], parts[1]); } From e01200c8dd0f42783c778c0841a1d923102985d7 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 22 Jul 2024 23:37:54 +0200 Subject: [PATCH 6/9] Unit test handling of arguments --- .../org/openrewrite/maven/RewriteRunIT.java | 14 +++++++++- .../RewriteRunIT/command_line_options/pom.xml | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/test/resources-its/org/openrewrite/maven/RewriteRunIT/command_line_options/pom.xml diff --git a/src/test/java/org/openrewrite/maven/RewriteRunIT.java b/src/test/java/org/openrewrite/maven/RewriteRunIT.java index 2c94b03a..8d8ff285 100644 --- a/src/test/java/org/openrewrite/maven/RewriteRunIT.java +++ b/src/test/java/org/openrewrite/maven/RewriteRunIT.java @@ -76,6 +76,19 @@ void cloud_suitability_project(MavenExecutionResult result) { .anySatisfy(line -> assertThat(line).contains("some.jks")); } + @MavenTest + @SystemProperties({ + @SystemProperty(value = "rewrite.activeRecipes", content = "org.openrewrite.maven.RemovePlugin"), + @SystemProperty(value = "rewrite.options", content = "groupId=org.openrewrite.maven,artifactId=rewrite-maven-plugin") + }) + void command_line_options(MavenExecutionResult result) { + assertThat(result).isSuccessful().out().error().isEmpty(); + assertThat(result).isSuccessful().out().warn() + .contains("Changes have been made to target/maven-it/org/openrewrite/maven/RewriteRunIT/command_line_options/project/pom.xml by:") + .contains(" org.openrewrite.maven.RemovePlugin"); + assertThat(result.getMavenProjectResult().getModel().getBuild()).isNull(); + } + @MavenTest @Disabled("We should implement a simpler test to make sure that regular markers don't get added to source files") void java_upgrade_project(MavenExecutionResult result) { @@ -96,5 +109,4 @@ void java_compiler_plugin_project(MavenExecutionResult result) { .filteredOn(line -> line.contains("Changes have been made")) .hasSize(1); } - } diff --git a/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/command_line_options/pom.xml b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/command_line_options/pom.xml new file mode 100644 index 00000000..9c6118a6 --- /dev/null +++ b/src/test/resources-its/org/openrewrite/maven/RewriteRunIT/command_line_options/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + + org.openrewrite.maven + command_line_options + 1.0 + jar + RewriteRunIT#command_line_options + + + 1.8 + 1.8 + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + From f6d60427505aeb9211a61fba3c70c01d6ddd77c2 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Tue, 23 Jul 2024 14:08:32 +0200 Subject: [PATCH 7/9] Use a LinkedHashSet for options --- .../openrewrite/maven/AbstractRewriteBaseRunMojo.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index f623f16d..d9b482e6 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -27,7 +27,6 @@ import org.openrewrite.config.RecipeDescriptor; import org.openrewrite.internal.InMemoryLargeSourceSet; import org.openrewrite.internal.ListUtils; -import org.openrewrite.internal.StringUtils; import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.tree.J; import org.openrewrite.kotlin.tree.K; @@ -61,7 +60,7 @@ public abstract class AbstractRewriteBaseRunMojo extends AbstractRewriteMojo { @Parameter(property = "rewrite.options") @Nullable - protected String options; + protected LinkedHashSet options; /** * Attempt to determine the root of the git repository for the given project. @@ -106,7 +105,7 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio return new ResultsContainer(repositoryRoot, emptyList()); } - if (!StringUtils.isBlank(options)) { + if (options != null && !options.isEmpty()) { configureRecipeOptions(recipe, options); } @@ -138,7 +137,7 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } } - private static void configureRecipeOptions(Recipe recipe, String options) throws MojoExecutionException { + private static void configureRecipeOptions(Recipe recipe, Set options) throws MojoExecutionException { if (recipe instanceof CompositeRecipe && recipe.getRecipeList().size() == 1) { // Unpack active recipe if it's a single recipe recipe = recipe.getRecipeList().get(0); @@ -154,7 +153,7 @@ private static void configureRecipeOptions(Recipe recipe, String options) throws } Map optionValues = new HashMap<>(); - for (String option : options.split(",")) { + for (String option : options) { String[] parts = option.split("=", 2); if (parts.length == 2) { optionValues.put(parts[0], parts[1]); From 9c9061b89c1b21ad05a14beb87b890cc8c0eeb84 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 24 Jul 2024 11:40:19 +0200 Subject: [PATCH 8/9] Apply suggestions from code review --- .../org/openrewrite/maven/AbstractRewriteBaseRunMojo.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index d9b482e6..67734648 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -138,10 +138,6 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio } private static void configureRecipeOptions(Recipe recipe, Set options) throws MojoExecutionException { - if (recipe instanceof CompositeRecipe && recipe.getRecipeList().size() == 1) { - // Unpack active recipe if it's a single recipe - recipe = recipe.getRecipeList().get(0); - } if (recipe instanceof CompositeRecipe || recipe instanceof DeclarativeRecipe || recipe instanceof Recipe.DelegatingRecipe || From 6a5c1008bf450bab7f45f0d4a096fc0ad890e1ef Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Wed, 24 Jul 2024 14:33:00 +0200 Subject: [PATCH 9/9] Alter check for no recipe found --- .../org/openrewrite/maven/AbstractRewriteBaseRunMojo.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java index 5bf2abcf..35030088 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteBaseRunMojo.java @@ -98,10 +98,10 @@ protected ResultsContainer listResults(ExecutionContext ctx) throws MojoExecutio Environment env = environment(recipeArtifactCoordinatesClassloader); Recipe recipe = env.activateRecipes(getActiveRecipes()); - if (recipe.getRecipeList().isEmpty()) { - getLog().warn("No recipes were activated. " + - "Activate a recipe with com.fully.qualified.RecipeClassName in this plugin's in your pom.xml, " + - "or on the command line with -Drewrite.activeRecipes=com.fully.qualified.RecipeClassName"); + if (recipe.getName().equals("org.openrewrite.Recipe$Noop")) { + getLog().warn("No recipes were activated." + + " Activate a recipe with com.fully.qualified.RecipeClassName in this plugin's in your pom.xml," + + " or on the command line with -Drewrite.activeRecipes=com.fully.qualified.RecipeClassName"); return new ResultsContainer(repositoryRoot, emptyList()); }