Skip to content
Open
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
24 changes: 22 additions & 2 deletions src/main/java/org/apache/maven/plugins/install/InstallMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private enum State {
}

private static final String INSTALL_PROCESSED_MARKER = InstallMojo.class.getName() + ".processed";
private static final String PROJECTS_USING_PLUGIN_KEY = InstallMojo.class.getName() + ".projectsUsingPlugin";

public InstallMojo() {}

Expand All @@ -120,6 +121,26 @@ private boolean hasState(Project project) {
return pluginContext.containsKey(INSTALL_PROCESSED_MARKER);
}

/**
* Returns the list of reactor projects that have this plugin configured, cached on first call.
* The list is invariant during a build and is stored in the current project's plugin
* context to avoid recomputing it on every module invocation (O(N) total instead of O(N²)).
*/
@SuppressWarnings("unchecked")
private List<Project> getProjectsUsingPlugin() {
List<Project> allProjects = session.getProjects();
if (allProjects.isEmpty()) {
return List.of();
}
Map<String, Object> ctx = session.getPluginContext(allProjects.get(0));
List<Project> cached = (List<Project>) ctx.get(PROJECTS_USING_PLUGIN_KEY);
if (cached == null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work properly when Maven processes modules in parallel? I do not see any locking.

cached = allProjects.stream().filter(this::usingPlugin).collect(Collectors.toList());
ctx.put(PROJECTS_USING_PLUGIN_KEY, cached);
}
return cached;
}

private boolean usingPlugin(Project project) {
Plugin plugin = project.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-install-plugin");
return plugin != null
Expand All @@ -144,8 +165,7 @@ public void execute() {
}
}

List<Project> projectsUsingPlugin =
session.getProjects().stream().filter(this::usingPlugin).collect(Collectors.toList());
List<Project> projectsUsingPlugin = getProjectsUsingPlugin();
if (allProjectsMarked(projectsUsingPlugin)) {
for (Project reactorProject : projectsUsingPlugin) {
State state = getState(reactorProject);
Expand Down
Loading