Skip to content
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 rewrite.inactiveRecipes #569

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <activeRecipes><recipe>com.fully.qualified.RecipeClassName</recipe></activeRecipes> in this plugin's <configuration> in your pom.xml, " +
Expand Down Expand Up @@ -300,6 +301,37 @@ protected ResultsContainer listResults() throws MojoExecutionException {
}
}

private void inactiveRecipes(Recipe rootRecipe) {
// processed recipe
Set<Recipe> processed = new HashSet<>();
Queue<Recipe> queue = new LinkedList<>();
queue.offer(rootRecipe);
while (!queue.isEmpty()) {
Recipe recipe = queue.poll();

if (processed.contains(recipe)) {
continue;
}

Iterator<Recipe> 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()) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public abstract class ConfigurableRewriteMojo extends AbstractMojo {
@Parameter(property = "rewrite.activeRecipes")
protected String rewriteActiveRecipes;

@Parameter(property = "inactiveRecipes")
protected List<String> inactiveRecipes = Collections.emptyList();

@Nullable
@Parameter(property = "rewrite.inactiveRecipes")
protected String rewriteInactiveRecipes;

@Parameter(property = "activeStyles")
protected Set<String> activeStyles = Collections.emptySet();

Expand Down Expand Up @@ -142,6 +149,9 @@ protected Set<String> getPlainTextMasks() {
@Nullable
private volatile Set<String> computedRecipes;

@Nullable
private volatile Set<String> computedInactiveRecipes;

@Nullable
private volatile Set<String> computedStyles;

Expand Down Expand Up @@ -169,6 +179,27 @@ protected Set<String> getActiveRecipes() {
return computedRecipes;
}

protected Set<String> getInactiveRecipes() {
if (computedInactiveRecipes == null) {
synchronized (this) {
if (computedInactiveRecipes == null) {
Set<String> res = toLinkedHashSet(rewriteInactiveRecipes);
if (res.isEmpty()) {
res.addAll(
inactiveRecipes
.stream()
.filter(Objects::nonNull)
.collect(Collectors.toList())
);
}
computedInactiveRecipes = Collections.unmodifiableSet(res);
}
}
}

return computedInactiveRecipes;
}

protected Set<String> getActiveStyles() {
if (computedStyles == null) {
synchronized (this) {
Expand Down