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

Delaying execution to the end of multi-module project #720

Merged
merged 1 commit into from
Jan 22, 2024
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 @@ -54,7 +54,7 @@ public void execute() throws MojoExecutionException {

// 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())) {
if (!runPerSubmodule && !isLastProjectInReactor()) {
return;
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/openrewrite/maven/AbstractRewriteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ Config getConfig() throws IOException {
return null;
}

/**
* Is this project the last project in the reactor?
*
* @return true if last project (including only project)
*/
protected boolean isLastProjectInReactor() {
List<MavenProject> sortedProjects = mavenSession.getProjectDependencyGraph().getSortedProjects();

MavenProject lastProject = sortedProjects.isEmpty()
? mavenSession.getCurrentProject()
: sortedProjects.get(sortedProjects.size() - 1);

if (getLog().isDebugEnabled()) {
getLog().debug("Current project: '" + mavenSession.getCurrentProject().getName() +
"', Last project to execute based on dependency graph: '" + lastProject.getName() + "'");
}

return mavenSession.getCurrentProject().equals(lastProject);
}

protected Environment environment(@Nullable ClassLoader recipeClassLoader) throws MojoExecutionException {
Environment.Builder env = Environment.builder(project.getProperties());
if (recipeClassLoader == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void execute() throws MojoExecutionException {

// 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())) {
if (!runPerSubmodule && !isLastProjectInReactor()) {
return;
}

Expand Down