|
13 | 13 |
|
14 | 14 | package org.eclipse.m2e.internal.launch; |
15 | 15 |
|
| 16 | +import java.io.File; |
16 | 17 | import java.io.IOException; |
17 | 18 | import java.util.Arrays; |
18 | 19 | import java.util.Map; |
19 | 20 | import java.util.Objects; |
20 | 21 | import java.util.concurrent.ConcurrentHashMap; |
21 | 22 | import java.util.stream.Stream; |
22 | 23 |
|
23 | | -import org.eclipse.core.runtime.CoreException; |
24 | 24 | import org.eclipse.debug.core.DebugPlugin; |
25 | 25 | import org.eclipse.debug.core.ILaunch; |
26 | 26 | import org.eclipse.debug.core.ILaunchesListener2; |
27 | 27 |
|
| 28 | +import org.codehaus.plexus.build.connect.TcpBuildConnection; |
| 29 | +import org.codehaus.plexus.build.connect.TcpBuildConnection.ServerConnection; |
| 30 | + |
28 | 31 | import org.eclipse.m2e.core.embedder.ArtifactKey; |
29 | | -import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime; |
30 | 32 | import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments; |
31 | | -import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge; |
32 | 33 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection; |
33 | 34 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData; |
34 | 35 |
|
@@ -70,23 +71,50 @@ public void launchesChanged(ILaunch[] launches) { // ignore |
70 | 71 |
|
71 | 72 | static void openListenerConnection(ILaunch launch, VMArguments arguments) { |
72 | 73 | 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()); |
85 | | - } |
86 | | - arguments.append(connection.getMavenVMArguments()); |
| 74 | +// if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) { |
| 75 | +// |
| 76 | +// Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>(); |
| 77 | +// |
| 78 | +// MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection( |
| 79 | +// launch.getLaunchConfiguration().getName(), |
| 80 | +// d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d)); |
| 81 | +// |
| 82 | +// if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) { |
| 83 | +// connection.close(); |
| 84 | +// throw new IllegalStateException( |
| 85 | +// "Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName()); |
| 86 | +// } |
| 87 | +// |
| 88 | +// arguments.append(connection.getMavenVMArguments()); |
| 89 | +// } else { |
| 90 | + MavenRunState state = new MavenRunState(); |
| 91 | + ServerConnection con = TcpBuildConnection.createServer(msg -> { |
| 92 | + System.out.println(msg); |
| 93 | + return state.handleMessage(msg); |
| 94 | + }); |
| 95 | + state.getProject(new ArtifactKey("test", "me", "0.0.1-SNAPSHOT", null)).thenAccept(rp -> rp.onStart(() -> { |
| 96 | + System.out.println("project is started!!"); |
| 97 | + })); |
| 98 | + File location = getJarLocation(); |
| 99 | + if(location != null) { |
| 100 | + //TODO see bug https://issues.apache.org/jira/browse/MNG-8112 |
| 101 | + arguments.appendProperty("maven.ext.class.path", location.getAbsolutePath()); |
87 | 102 | } |
88 | | - } catch(CoreException | IOException ex) { // ignore |
| 103 | + con.setupProcess(arguments::appendProperty); |
| 104 | +// } |
| 105 | + } catch(Exception ex) { // ignore |
| 106 | + ex.printStackTrace(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + private static File getJarLocation() { |
| 111 | + try { |
| 112 | + return new File(TcpBuildConnection.class.getProtectionDomain().getCodeSource().getLocation().toURI()); |
| 113 | + } catch(Exception e) { |
89 | 114 | } |
| 115 | + //TODO better way to find it?!? |
| 116 | + //Maybe just consume as a (wrapped) bundle as we only need it to start the server not on the maven classpath! |
| 117 | + return null; |
90 | 118 | } |
91 | 119 |
|
92 | 120 | static MavenProjectBuildData getBuildProject(ILaunch launch, String groupId, String artifactId, String version) { |
|
0 commit comments