Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bade532

Browse files
committedFeb 22, 2025·
Experiements with new build connection from plexus-build-extension
1 parent 9bab8e8 commit bade532

File tree

3 files changed

+82
-20
lines changed

3 files changed

+82
-20
lines changed
 

‎org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenBuildProjectDataConnection.java

+79-17
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@
1313

1414
package org.eclipse.m2e.internal.launch;
1515

16+
import java.io.File;
1617
import java.io.IOException;
1718
import java.util.Arrays;
19+
import java.util.HashMap;
1820
import java.util.Map;
1921
import java.util.Objects;
2022
import java.util.concurrent.ConcurrentHashMap;
2123
import java.util.stream.Stream;
2224

23-
import org.eclipse.core.runtime.CoreException;
2425
import org.eclipse.debug.core.DebugPlugin;
2526
import org.eclipse.debug.core.ILaunch;
2627
import org.eclipse.debug.core.ILaunchesListener2;
2728

29+
import org.codehaus.plexus.build.connect.Configuration;
30+
import org.codehaus.plexus.build.connect.TcpBuildConnection;
31+
import org.codehaus.plexus.build.connect.TcpBuildConnection.ServerConnection;
32+
import org.codehaus.plexus.build.connect.messages.InitMessage;
33+
import org.codehaus.plexus.build.connect.messages.MojoMessage;
34+
import org.codehaus.plexus.build.connect.messages.ProjectMessage;
35+
import org.codehaus.plexus.build.connect.messages.ProjectsMessage;
36+
2837
import org.eclipse.m2e.core.embedder.ArtifactKey;
29-
import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime;
3038
import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments;
31-
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge;
3239
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection;
3340
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData;
3441

@@ -70,23 +77,78 @@ public void launchesChanged(ILaunch[] launches) { // ignore
7077

7178
static void openListenerConnection(ILaunch launch, VMArguments arguments) {
7279
try {
73-
if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) {
74-
75-
Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>();
76-
77-
MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection(
78-
launch.getLaunchConfiguration().getName(),
79-
d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d));
80-
81-
if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) {
82-
connection.close();
83-
throw new IllegalStateException(
84-
"Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName());
80+
// if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) {
81+
//
82+
// Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>();
83+
//
84+
// MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection(
85+
// launch.getLaunchConfiguration().getName(),
86+
// d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d));
87+
//
88+
// if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) {
89+
// connection.close();
90+
// throw new IllegalStateException(
91+
// "Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName());
92+
// }
93+
//
94+
// arguments.append(connection.getMavenVMArguments());
95+
// } else {
96+
ServerConnection con = TcpBuildConnection.createServer(msg -> {
97+
if(msg instanceof InitMessage init) {
98+
System.out.println("Init...");
99+
init.keys().forEach(k -> {
100+
System.out.println(k + ": " + init.getProperty(k));
101+
});
102+
Map<String, String> config = new HashMap<String, String>();
103+
config.put(Configuration.CONFIG_SEND_PROJECTS, "true");
104+
//TODO more...
105+
return config;
106+
}
107+
if(msg instanceof ProjectsMessage projects) {
108+
System.out.println("Projects in reactor");
109+
projects.projects().forEach(pi -> {
110+
System.out.println(pi.getGroupId() + ":" + pi.getArtifactId() + ":" + pi.getVersion());
111+
System.out.println(pi.getBaseDir());
112+
// System.out.println(pi.getModel());
113+
});
114+
return null;
115+
}
116+
if(msg instanceof ProjectMessage project) {
117+
System.out.println("--- " + project.getType() + " ---");
118+
System.out.println(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion());
119+
System.out.println(project.getBaseDir());
120+
return null;
85121
}
86-
arguments.append(connection.getMavenVMArguments());
122+
if(msg instanceof MojoMessage mojo) {
123+
System.out.println("--- " + mojo.getType() + " ---");
124+
System.out.println(mojo.getGroupId() + ":" + mojo.getArtifactId() + ":" + mojo.getVersion() + " - "
125+
+ mojo.getLifecyclePhase() + " [" + mojo.getExecutionId() + "] " + mojo.getGoal());
126+
return null;
127+
}
128+
129+
System.out.println("Message: " + msg);
130+
return null;
131+
});
132+
File location = getJarLocation();
133+
if(location != null) {
134+
//TODO see bug https://issues.apache.org/jira/browse/MNG-8112
135+
// arguments.appendProperty("maven.ext.class.path", location.getAbsolutePath());
87136
}
88-
} catch(CoreException | IOException ex) { // ignore
137+
con.setupProcess(arguments::appendProperty);
138+
// }
139+
} catch(Exception ex) { // ignore
140+
ex.printStackTrace();
141+
}
142+
}
143+
144+
private static File getJarLocation() {
145+
try {
146+
return new File(TcpBuildConnection.class.getProtectionDomain().getCodeSource().getLocation().toURI());
147+
} catch(Exception e) {
89148
}
149+
//TODO better way to find it?!?
150+
//Maybe just consume as a (wrapped) bundle as we only need it to start the server not on the maven classpath!
151+
return null;
90152
}
91153

92154
static MavenProjectBuildData getBuildProject(ILaunch launch, String groupId, String artifactId, String version) {

‎org.eclipse.m2e.maven.runtime/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</parent>
2222

2323
<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
24-
<version>3.9.900-SNAPSHOT</version>
24+
<version>3.9.901-SNAPSHOT</version>
2525
<packaging>jar</packaging>
2626

2727
<name>M2E Embedded Maven Runtime (includes Incubating components)</name>
@@ -30,7 +30,7 @@
3030
<!-- maven core version -->
3131
<maven-core.version>3.9.9</maven-core.version>
3232
<!-- below are m2e-specific addons -->
33-
<plexus-build-api.version>1.2.0</plexus-build-api.version>
33+
<plexus-build-api.version>1.2.1-SNAPSHOT</plexus-build-api.version>
3434
<jars.directory>target/jars</jars.directory>
3535
<outputDirectory.sources>${project.build.directory}/classes-source</outputDirectory.sources>
3636
<failIfMacSigningFailed>false</failIfMacSigningFailed>

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<dependency>
100100
<groupId>org.eclipse.m2e</groupId>
101101
<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
102-
<version>3.9.900-SNAPSHOT</version>
102+
<version>3.9.901-SNAPSHOT</version>
103103
</dependency>
104104
</dependencies>
105105

0 commit comments

Comments
 (0)
Please sign in to comment.