diff --git a/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java b/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java index 5555af91..4669e28a 100644 --- a/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java +++ b/src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java @@ -239,6 +239,7 @@ protected ResultsContainer listResults() throws MojoExecutionException { } Recipe recipe = env.activateRecipes(getActiveRecipes()); + inactiveRecipes(recipe); 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, " + @@ -300,6 +301,37 @@ protected ResultsContainer listResults() throws MojoExecutionException { } } + private void inactiveRecipes(Recipe rootRecipe) { + // processed recipe + Set processed = new HashSet<>(); + Queue queue = new LinkedList<>(); + queue.offer(rootRecipe); + while (!queue.isEmpty()) { + Recipe recipe = queue.poll(); + + if (processed.contains(recipe)) { + continue; + } + + Iterator iterator = recipe.getRecipeList().iterator(); + while (iterator.hasNext()) { + Recipe r = iterator.next(); + if (getInactiveRecipes().contains(r.getName())) { + try { + iterator.remove(); + } catch (UnsupportedOperationException uoe) { + // maybe unmodifiableCollection + getLog().warn("InactiveRecipe " + r.getName() + " for " + + recipe.getName() + " failed. ", uoe); + } + } + } + + recipe.getRecipeList().stream().forEach(r -> queue.offer(r)); + processed.add(recipe); + } + } + @Nullable protected URLClassLoader getRecipeArtifactCoordinatesClassloader() throws MojoExecutionException { if (getRecipeArtifactCoordinates().isEmpty()) { diff --git a/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java b/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java index 3bfa1e00..a4fb879d 100644 --- a/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java +++ b/src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java @@ -21,6 +21,13 @@ public abstract class ConfigurableRewriteMojo extends AbstractMojo { @Parameter(property = "rewrite.activeRecipes") protected String rewriteActiveRecipes; + @Parameter(property = "inactiveRecipes") + protected List inactiveRecipes = Collections.emptyList(); + + @Nullable + @Parameter(property = "rewrite.inactiveRecipes") + protected String rewriteInactiveRecipes; + @Parameter(property = "activeStyles") protected Set activeStyles = Collections.emptySet(); @@ -142,6 +149,9 @@ protected Set getPlainTextMasks() { @Nullable private volatile Set computedRecipes; + @Nullable + private volatile Set computedInactiveRecipes; + @Nullable private volatile Set computedStyles; @@ -169,6 +179,27 @@ protected Set getActiveRecipes() { return computedRecipes; } + protected Set getInactiveRecipes() { + if (computedInactiveRecipes == null) { + synchronized (this) { + if (computedInactiveRecipes == null) { + Set res = toLinkedHashSet(rewriteInactiveRecipes); + if (res.isEmpty()) { + res.addAll( + inactiveRecipes + .stream() + .filter(Objects::nonNull) + .collect(Collectors.toList()) + ); + } + computedInactiveRecipes = Collections.unmodifiableSet(res); + } + } + } + + return computedInactiveRecipes; + } + protected Set getActiveStyles() { if (computedStyles == null) { synchronized (this) {