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

Adding runPerSubmodule configuration option to maven plugin. #360

Merged
merged 1 commit into from
May 11, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public class AbstractRewriteDryRunMojo extends AbstractRewriteMojo {
public void execute() throws MojoExecutionException {
MavenOptsHelper.checkAndLogMissingJvmModuleExports(getLog());

//Defer execution of rewrite's parsing and recipe execution until the last project.
if (!project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) {
//If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin
//is being run on the last project.
if (!runPerSubmodule && !project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) {
return;
}

Expand Down Expand Up @@ -90,6 +91,8 @@ public void execute() throws MojoExecutionException {
Path outPath;
if (reportOutputDirectory != null) {
outPath = Paths.get(reportOutputDirectory);
} else if (runPerSubmodule) {
outPath = Paths.get(project.getBuild().getDirectory()).resolve("rewrite");
} else {
outPath = Paths.get(mavenSession.getTopLevelProject().getBuild().getDirectory()).resolve("rewrite");
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,16 @@ protected ResultsContainer listResults() throws MojoExecutionException {

//Parse and collect source files from each project in the maven session.
MavenMojoProjectParser projectParser = new MavenMojoProjectParser(getLog(), baseDir, pomCacheEnabled, pomCacheDirectory, runtime, skipMavenParsing, getExclusions(), sizeThresholdMb, mavenSession, settingsDecrypter);

List<SourceFile> sourceFiles = new ArrayList<>();
for (MavenProject project : mavenSession.getProjects()) {
if (runPerSubmodule) {
//If running per submodule, parse the source files for only the current project.
sourceFiles.addAll(projectParser.listSourceFiles(project, styles, ctx));
} else {
//If running across all project, iterate and parse source files from each project
for (MavenProject projectIndex : mavenSession.getProjects()) {
sourceFiles.addAll(projectParser.listSourceFiles(projectIndex, styles, ctx));
}
}

getLog().info("Running recipe(s)...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite.maven;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.openrewrite.Result;

import java.io.BufferedWriter;
Expand All @@ -31,12 +32,14 @@
* Base mojo for rewrite:run and rewrite:runNoFork.
*/
public class AbstractRewriteRunMojo extends AbstractRewriteMojo {

@Override
public void execute() throws MojoExecutionException {
MavenOptsHelper.checkAndLogMissingJvmModuleExports(getLog());

//Defer execution of rewrite's parsing and recipe execution until the last project.
if (!project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) {
//If the plugin is configured to run over all projects (at the end of the build) only proceed if the plugin
//is being run on the last project.
if (!runPerSubmodule && !project.getId().equals(mavenSession.getProjects().get(mavenSession.getProjects().size() - 1).getId())) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ protected Set<String> getExclusions() {
@Parameter(property = "rewrite.failOnInvalidActiveRecipes", alias = "failOnInvalidActiveRecipes", defaultValue = "false")
protected boolean failOnInvalidActiveRecipes;

@Parameter(property = "rewrite.runPerSubmodule", alias = "runPerSubmodule", defaultValue = "false")
protected boolean runPerSubmodule;

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