From d5dbc593bf50113006c20121e337d42fa08ee359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 22 Feb 2025 11:38:15 +0100 Subject: [PATCH] Experiements with new build connection from plexus-build-extension --- .../MavenBuildProjectDataConnection.java | 89 +++++++++++++++---- org.eclipse.m2e.maven.runtime/pom.xml | 4 +- pom.xml | 2 +- 3 files changed, 75 insertions(+), 20 deletions(-) diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenBuildProjectDataConnection.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenBuildProjectDataConnection.java index cd9abfbcd0..661e8e7695 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenBuildProjectDataConnection.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenBuildProjectDataConnection.java @@ -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; @@ -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 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 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 config = new HashMap(); + 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) { diff --git a/org.eclipse.m2e.maven.runtime/pom.xml b/org.eclipse.m2e.maven.runtime/pom.xml index 8c9c800819..8cb8262963 100644 --- a/org.eclipse.m2e.maven.runtime/pom.xml +++ b/org.eclipse.m2e.maven.runtime/pom.xml @@ -21,7 +21,7 @@ org.eclipse.m2e.maven.runtime - 3.9.900-SNAPSHOT + 3.9.901-SNAPSHOT jar M2E Embedded Maven Runtime (includes Incubating components) @@ -30,7 +30,7 @@ 3.9.9 - 1.2.0 + 1.2.1-SNAPSHOT target/jars ${project.build.directory}/classes-source false diff --git a/pom.xml b/pom.xml index 3ffe83e7c3..e44d1cb5e5 100644 --- a/pom.xml +++ b/pom.xml @@ -99,7 +99,7 @@ org.eclipse.m2e org.eclipse.m2e.maven.runtime - 3.9.900-SNAPSHOT + 3.9.901-SNAPSHOT