Skip to content

Commit

Permalink
Pull up State to ConfigurableRewriteMojo for use in additional Mojo (#…
Browse files Browse the repository at this point in the history
…736)

As added in #726
  • Loading branch information
timtebeek committed Feb 9, 2024
1 parent 5698fca commit c7da33e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import io.micrometer.core.instrument.Metrics;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -75,34 +73,8 @@ public abstract class AbstractRewriteMojo extends ConfigurableRewriteMojo {
@Component
protected RepositorySystem repositorySystem;

@Parameter(defaultValue = "${session}", readonly = true)
protected MavenSession mavenSession;

@Parameter(defaultValue = "${plugin}", required = true, readonly = true)
protected PluginDescriptor pluginDescriptor;

private static final String RECIPE_NOT_FOUND_EXCEPTION_MSG = "Could not find recipe '%s' among available recipes";

protected enum State {
SKIPPED,
PROCESSED,
TO_BE_PROCESSED
}
private static final String OPENREWRITE_PROCESSED_MARKER = "openrewrite.processed";

protected void putState(State state) {
getPluginContext().put(OPENREWRITE_PROCESSED_MARKER, state.name());
}

private boolean hasState(MavenProject project) {
Map<String, Object> pluginContext = mavenSession.getPluginContext(pluginDescriptor, project);
return pluginContext.containsKey(OPENREWRITE_PROCESSED_MARKER);
}

protected boolean allProjectsMarked() {
return mavenSession.getProjects().stream().allMatch(this::hasState);
}

protected Environment environment() throws MojoExecutionException {
return environment(getRecipeArtifactCoordinatesClassloader());
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/openrewrite/maven/ConfigurableRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package org.openrewrite.maven;

import com.puppycrawl.tools.checkstyle.Checker;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
Expand Down Expand Up @@ -179,6 +181,32 @@ protected Set<String> getPlainTextMasks() {
@Parameter(property = "rewrite.runPerSubmodule", alias = "runPerSubmodule", defaultValue = "false")
protected boolean runPerSubmodule;

@Parameter(defaultValue = "${session}", readonly = true)
protected MavenSession mavenSession;

@Parameter(defaultValue = "${plugin}", required = true, readonly = true)
protected PluginDescriptor pluginDescriptor;

protected enum State {
SKIPPED,
PROCESSED,
TO_BE_PROCESSED
}
private static final String OPENREWRITE_PROCESSED_MARKER = "openrewrite.processed";

protected void putState(State state) {
getPluginContext().put(OPENREWRITE_PROCESSED_MARKER, state.name());
}

private boolean hasState(MavenProject project) {
Map<String, Object> pluginContext = mavenSession.getPluginContext(pluginDescriptor, project);
return pluginContext.containsKey(OPENREWRITE_PROCESSED_MARKER);
}

protected boolean allProjectsMarked() {
return mavenSession.getProjects().stream().allMatch(this::hasState);
}

@Nullable
@Parameter(property = "rewrite.recipeArtifactCoordinates")
private LinkedHashSet<String> recipeArtifactCoordinates;
Expand Down

0 comments on commit c7da33e

Please sign in to comment.