Skip to content

Conversation

laeubi
Copy link
Collaborator

@laeubi laeubi commented Feb 28, 2024

Maven Mojos (and maybe components) can create / fork processes, common examples would include:

  • ant-run plugin
  • maven-exec-plugin
  • maven-surefire

currently the IDE has no effective way to know about forked processes, so there is no way to visualize them (e.g. in a process manager) nor to take special actions on them (e.g. automatically request to open a debug port). For executions of tests, the IDE even may want to be notified about individual test runs while the process is running.

This now adds a new build-process API that mitigates the problem by allowing a mojo or component to make the IDE aware of subprocesses but is completely disabled if running outside an IDE. An integration can range from very basic, that is only notify that a process is running over to specialized callbacks that allows the IDE to intercept process creation in a generic way. An example implementation is provided for either resuse, extension or own implementation of such callbacks.

To reflect this new opportunity, the minor version is increase to 1.3 even though neither consumers nor providers of the API need to take immediate actions here.

Maven Mojos (and maybe components) can create / fork processes, common
examples would include:

- ant-run plugin
- maven-exec-plugin
- maven-surefire

currently the IDE has no effective way to know about forked processes,
so there is no way to visualize them (e.g. in a process manager) nor to
take special actions on them (e.g. automatically request to open a debug
port). For executions of tests, the IDE even may want to be notified
about individual test runs while the process is running.

This now adds a new build-process API that mitigates the problem by
allowing a mojo or component to make the IDE aware of subprocesses but
is completely disabled if running outside an IDE. An integration can
range from very basic, that is only notify that a process is running
over to specialized callbacks that allows the IDE to intercept process
creation in a generic way. An example implementation is provided for
either resuse, extension or own implementation of such callbacks.

To reflect this new opportunity, the minor version is increase to 1.3
even though neither consumers nor providers of the API need to take
immediate actions here.
@stbischof
Copy link

Sounds ver helpfull

@slachiewicz slachiewicz added the enhancement New feature or request label Dec 22, 2024
@slachiewicz slachiewicz requested a review from Copilot October 13, 2025 20:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a comprehensive process API to the plexus build API, enabling IDEs to interact with and monitor processes spawned by Maven mojos (like ant-run, maven-exec, and maven-surefire plugins). The API provides visualization capabilities, optional termination control, and specialized callbacks for different process types.

  • Introduces a new process management API with interfaces for BuildProcess, ProcessManager, and various callback types
  • Provides default implementations including a no-op ProcessManager and a ProcessBuilder-based context
  • Updates version from 1.2.1-SNAPSHOT to 1.3.0-SNAPSHOT to reflect the new API addition

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ProcessBuilderContext.java Implementation using ProcessBuilder to manage child processes with BuildProcess notification
DefaultProcessManager.java No-op default implementation that always returns null for new processes
ProcessManager.java Core interface for creating BuildProcess instances from contexts
ProcessCallback.java Interface for setting environment variables on processes
JavaCallback.java Specialized callback interface for Java VM processes
JUnitCallback.java Specialized callback interface for JUnit test executions
BuildProcessContext.java Context interface providing process name and termination capability
BuildProcess.java Interface representing a managed build process with lifecycle notifications
pom.xml Version bump to 1.3.0-SNAPSHOT
README.md Documentation updates explaining the new process API

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +76 to +85
if (allowTermination) {
do {
if (buildProcess.isTerminated()) {
// request termination
process.destroy();
break;
}
} while (!process.waitFor(200, TimeUnit.MILLISECONDS));
}
buildProcess.notifyFinished(process.waitFor());
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

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

Potential race condition: process.waitFor() is called twice - once in the while loop condition (line 83) and again here. The second call may return immediately with a cached result, but this creates unnecessary complexity and potential timing issues. Store the exit code from the first waitFor() call instead.

Suggested change
if (allowTermination) {
do {
if (buildProcess.isTerminated()) {
// request termination
process.destroy();
break;
}
} while (!process.waitFor(200, TimeUnit.MILLISECONDS));
}
buildProcess.notifyFinished(process.waitFor());
int exitCode;
if (allowTermination) {
while (true) {
if (buildProcess.isTerminated()) {
// request termination
process.destroy();
// Wait for process to actually terminate and get exit code
exitCode = process.waitFor();
break;
}
if (process.waitFor(200, TimeUnit.MILLISECONDS)) {
exitCode = process.exitValue();
break;
}
}
} else {
exitCode = process.waitFor();
}
buildProcess.notifyFinished(exitCode);

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants