Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b4dbb22

Browse filesBrowse files
Christoph Läubrichlaeubi
authored andcommitted
Add a connect API for inter-process-communication between maven and IDE
Currently an IDE launching an external maven process is rather blind, it can only see if the process exit with success and maybe read the standard stream. A much more feature rich experience could been offered if the launching process can gather some information about the run, e.g. what process is currently executed, what mojo and if it failed. Also currently features of the build context can only be implemented if running inside the IDE process what has several implications. This now adds a connect API that allows an IDE to supply an extension to the maven process (e.g. via maven.ext.class.path) and set a system property (plexus.build.ipc.port) to communicate with the running maven process. Signed-off-by: Christoph Läubrich <christoph@laeubi-soft.de>
1 parent 747f1d5 commit b4dbb22
Copy full SHA for b4dbb22

File tree

Expand file treeCollapse file tree

12 files changed

+910
-8
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+910
-8
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Plexus Build API
2-
=======================
2+
================
33

44
[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-classworlds.svg?label=License)](http://www.apache.org/licenses/)
55
[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-build-api.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-build-api)
@@ -13,9 +13,8 @@ It supports
1313
- fine-grained error/info markers (referring to specific files in particular line numbers)
1414
- notifications about updated files
1515

16-
1716
Current Implementations
18-
-----
17+
-----------------------
1918

2019
### Default Implementation
2120

@@ -27,6 +26,13 @@ The default implementation shipping with this artifact is supposed to impose min
2726
Currently only versions up to 0.0.7 (with old Maven coordinates `org.sonatype.plexus:plexus-build-api`) are supported, this limitation is tracked in [Issue 944](https://github.com/eclipse-m2e/m2e-core/issues/944).
2827

2928
History
30-
-----
29+
-------
3130

3231
The project was relocated from <https://github.com/sonatype/sisu-build-api>. Also its Maven coordinates changed from `org.sonatype.plexus:plexus-build-api` to `org.codehaus.plexus:plexus-build-api`, the API is still the same, though.
32+
33+
## Provided APIs
34+
35+
### IDE connection to maven process
36+
37+
This API is usually not used by mojos but for IDE integration, if enabled as a maven-core extension plexus-build-api supply a way to communicate with the running maven build and get events.
38+
The default implementation open a tcp connections to a port specified by the system property `plexus.build.ipc.port` using key/value encoded message format. If no such value is given all messages are silently discarded.

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ See the Apache License Version 2.0 for the specific language governing permissio
6969
</exclusion>
7070
</exclusions>
7171
</dependency>
72+
<dependency>
73+
<groupId>org.apache.maven</groupId>
74+
<artifactId>maven-core</artifactId>
75+
<version>3.9.9</version>
76+
<scope>provided</scope>
77+
</dependency>
7278

7379
</dependencies>
7480

‎src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java

Copy file name to clipboardExpand all lines: src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Map;
2525
import java.util.concurrent.ConcurrentHashMap;
2626

27+
import org.codehaus.plexus.build.connect.BuildConnection;
28+
import org.codehaus.plexus.build.connect.messages.RefreshMessage;
2729
import org.codehaus.plexus.logging.AbstractLogEnabled;
2830
import org.codehaus.plexus.util.Scanner;
2931
import org.codehaus.plexus.util.io.CachingOutputStream;
@@ -56,15 +58,18 @@ public class DefaultBuildContext implements BuildContext {
5658

5759
private final Map<String, Object> contextMap = new ConcurrentHashMap<>();
5860
private org.sonatype.plexus.build.incremental.BuildContext legacy;
61+
private BuildConnection connection;
5962

6063
/**
61-
* @param legacy the legacy API we delegate to by default, this allow us to
62-
* support "older" plugins and implementors of the API while still
63-
* having a way to move forward!
64+
* @param legacy the legacy API we delegate to by default, this allow us to
65+
* support "older" plugins and implementors of the API while
66+
* still having a way to move forward!
67+
* @param connection the connection we use to forward refresh events
6468
*/
6569
@Inject
66-
public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy) {
70+
public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy, BuildConnection connection) {
6771
this.legacy = legacy;
72+
this.connection = connection;
6873
}
6974

7075
/** {@inheritDoc} */
@@ -117,6 +122,7 @@ public Scanner newScanner(File basedir) {
117122
/** {@inheritDoc} */
118123
public void refresh(File file) {
119124
legacy.refresh(file);
125+
connection.send(new RefreshMessage(file.toPath()));
120126
}
121127

122128
/** {@inheritDoc} */
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright (c) 2025 Christoph Läubrich All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
package org.codehaus.plexus.build.connect;
14+
15+
import org.codehaus.plexus.build.connect.messages.Message;
16+
17+
/**
18+
* A {@link BuildConnection} allow communication between a an IDE and a maven
19+
* build to observe the state of the build and act on certain events. This is
20+
* usually not used directly by mojos but invoked internally by other APIs.
21+
*/
22+
public interface BuildConnection {
23+
24+
/**
25+
* Send a message and returns the reply from the other endpoint, should only be
26+
* called from a maven thread!
27+
*
28+
* @param message the message to send
29+
* @return the reply message or <code>null</code> if this connection is not
30+
* enabled and the message was discarded.
31+
*/
32+
Message send(Message message);
33+
34+
/**
35+
* This method allows code to perform an eager check if a buildconnection is
36+
* present to send messages. This can be used to guard operations to prevent
37+
* allocate resources or objects if the message will be dropped.
38+
*
39+
* @return <code>true</code> if the connection can be used to send messages or
40+
* if they will be discarded
41+
*/
42+
boolean isEnabled();
43+
44+
/**
45+
* Obtains the current configuration, can only be called from a maven thread
46+
*
47+
* @return the active configuration
48+
*/
49+
Configuration getConfiguration();
50+
}
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright (c) 2025 Christoph Läubrich All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
package org.codehaus.plexus.build.connect;
14+
15+
import org.codehaus.plexus.build.connect.messages.Message;
16+
import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage;
17+
18+
/**
19+
* Provides access to the configuration provided by the server
20+
*/
21+
public interface Configuration {
22+
23+
/**
24+
* If this property is set to <code>true</code> in reply to a session start, a
25+
* {@link ProjectsReadMessage} will be send to the endpoint containing all
26+
* projects with their effective model
27+
*/
28+
public static final String CONFIG_SEND_AFTER_PROJECTS_READ = "afterProjectsRead";
29+
30+
/**
31+
* @return <code>true</code> if {@link #CONFIG_SEND_AFTER_PROJECTS_READ} is
32+
* provided
33+
*/
34+
public boolean isSendProjects();
35+
36+
/**
37+
* Creates a Configuration from a message
38+
*
39+
* @param message
40+
* @return the configuration backed by the message payload
41+
*/
42+
public static Configuration of(Message message) {
43+
return new Configuration() {
44+
45+
@Override
46+
public boolean isSendProjects() {
47+
return message.getBooleanProperty(CONFIG_SEND_AFTER_PROJECTS_READ, false);
48+
}
49+
};
50+
}
51+
}
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright (c) 2025 Christoph Läubrich All rights reserved.
3+
4+
This program is licensed to you under the Apache License Version 2.0,
5+
and you may not use this file except in compliance with the Apache License Version 2.0.
6+
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7+
8+
Unless required by applicable law or agreed to in writing,
9+
software distributed under the Apache License Version 2.0 is distributed on an
10+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12+
*/
13+
package org.codehaus.plexus.build.connect;
14+
15+
import javax.inject.Inject;
16+
import javax.inject.Named;
17+
import javax.inject.Singleton;
18+
19+
import org.apache.maven.AbstractMavenLifecycleParticipant;
20+
import org.apache.maven.MavenExecutionException;
21+
import org.apache.maven.execution.MavenSession;
22+
import org.codehaus.plexus.build.connect.messages.Message;
23+
import org.codehaus.plexus.build.connect.messages.ProjectsReadMessage;
24+
import org.codehaus.plexus.build.connect.messages.SessionMessage;
25+
26+
/**
27+
* Listen to session events and send them to the connection
28+
*/
29+
@Named
30+
@Singleton
31+
public class SessionListener extends AbstractMavenLifecycleParticipant {
32+
33+
@Inject
34+
private BuildConnection connection;
35+
36+
private boolean sendProjects;
37+
private boolean started;
38+
39+
@Override
40+
public void afterSessionStart(MavenSession session) throws MavenExecutionException {
41+
started = true;
42+
Message reply = connection.send(new SessionMessage(session, true));
43+
if (reply != null) {
44+
sendProjects = Configuration.of(reply).isSendProjects();
45+
}
46+
}
47+
48+
@Override
49+
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
50+
if (connection.isEnabled()) {
51+
if (!started) {
52+
afterSessionStart(session);
53+
}
54+
if (sendProjects) {
55+
connection.send(new ProjectsReadMessage(session.getAllProjects()));
56+
}
57+
}
58+
}
59+
60+
@Override
61+
public void afterSessionEnd(MavenSession session) throws MavenExecutionException {
62+
connection.send(new SessionMessage(session, false));
63+
started = false;
64+
}
65+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.