Skip to content

Commit

Permalink
Experiements with new build connection from plexus-build-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Feb 22, 2025
1 parent 9bab8e8 commit d5dbc59
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@

package org.eclipse.m2e.internal.launch;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchesListener2;

import org.codehaus.plexus.build.connect.Configuration;
import org.codehaus.plexus.build.connect.TcpBuildConnection;
import org.codehaus.plexus.build.connect.TcpBuildConnection.ServerConnection;
import org.codehaus.plexus.build.connect.messages.InitMessage;
import org.codehaus.plexus.build.connect.messages.ProjectMessage;
import org.codehaus.plexus.build.connect.messages.ProjectsMessage;

import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime;
import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments;
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge;
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection;
import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData;

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

static void openListenerConnection(ILaunch launch, VMArguments arguments) {
try {
if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) {

Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>();

MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection(
launch.getLaunchConfiguration().getName(),
d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d));

if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) {
connection.close();
throw new IllegalStateException(
"Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName());
// if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) {
//
// Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>();
//
// MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection(
// launch.getLaunchConfiguration().getName(),
// d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d));
//
// if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) {
// connection.close();
// throw new IllegalStateException(
// "Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName());
// }
//
// arguments.append(connection.getMavenVMArguments());
// } else {
ServerConnection con = TcpBuildConnection.createServer(msg -> {
if(msg instanceof InitMessage init) {
System.out.println("Init...");
init.keys().forEach(k -> {
System.out.println(k + ": " + init.getProperty(k));
});
Map<String, String> config = new HashMap<String, String>();
config.put(Configuration.CONFIG_SEND_PROJECTS, "true");
//TODO more...
return config;
}
if(msg instanceof ProjectsMessage projects) {
System.out.println("Projects in reactor");
projects.projects().forEach(pi -> {
System.out.println(pi.getGroupId() + ":" + pi.getArtifactId() + ":" + pi.getVersion());
System.out.println(pi.getBaseDir());
// System.out.println(pi.getModel());
});
return null;
}
if(msg instanceof ProjectMessage project) {
System.out.println("--- " + project.getType() + " ---");
System.out.println(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion());
System.out.println(project.getBaseDir());
return null;
}
arguments.append(connection.getMavenVMArguments());

System.out.println("Message: " + msg);
return null;
});
File location = getJarLocation();
if(location != null) {
//TODO see bug https://issues.apache.org/jira/browse/MNG-8112
// arguments.appendProperty("maven.ext.class.path", location.getAbsolutePath());
}
} catch(CoreException | IOException ex) { // ignore
con.setupProcess(arguments::appendProperty);
// }
} catch(Exception ex) { // ignore
ex.printStackTrace();
}
}

private static File getJarLocation() {
try {
return new File(TcpBuildConnection.class.getProtectionDomain().getCodeSource().getLocation().toURI());
} catch(Exception e) {
}
//TODO better way to find it?!?
//Maybe just consume as a (wrapped) bundle as we only need it to start the server not on the maven classpath!
return null;
}

static MavenProjectBuildData getBuildProject(ILaunch launch, String groupId, String artifactId, String version) {
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.m2e.maven.runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</parent>

<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
<version>3.9.900-SNAPSHOT</version>
<version>3.9.901-SNAPSHOT</version>
<packaging>jar</packaging>

<name>M2E Embedded Maven Runtime (includes Incubating components)</name>
Expand All @@ -30,7 +30,7 @@
<!-- maven core version -->
<maven-core.version>3.9.9</maven-core.version>
<!-- below are m2e-specific addons -->
<plexus-build-api.version>1.2.0</plexus-build-api.version>
<plexus-build-api.version>1.2.1-SNAPSHOT</plexus-build-api.version>
<jars.directory>target/jars</jars.directory>
<outputDirectory.sources>${project.build.directory}/classes-source</outputDirectory.sources>
<failIfMacSigningFailed>false</failIfMacSigningFailed>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<dependency>
<groupId>org.eclipse.m2e</groupId>
<artifactId>org.eclipse.m2e.maven.runtime</artifactId>
<version>3.9.900-SNAPSHOT</version>
<version>3.9.901-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down

0 comments on commit d5dbc59

Please sign in to comment.