Skip to content

Commit d5dbc59

Browse files
committed
Experiements with new build connection from plexus-build-extension
1 parent 9bab8e8 commit d5dbc59

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

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

+72-17
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@
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.ProjectMessage;
34+
import org.codehaus.plexus.build.connect.messages.ProjectsMessage;
35+
2836
import org.eclipse.m2e.core.embedder.ArtifactKey;
29-
import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime;
3037
import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments;
31-
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge;
3238
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection;
3339
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData;
3440

@@ -70,23 +76,72 @@ public void launchesChanged(ILaunch[] launches) { // ignore
7076

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

92147
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)