|
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; |
| 19 | +import java.util.HashMap; |
18 | 20 | import java.util.Map; |
19 | 21 | import java.util.Objects; |
20 | 22 | import java.util.concurrent.ConcurrentHashMap; |
21 | 23 | import java.util.stream.Stream; |
22 | 24 |
|
23 | | -import org.eclipse.core.runtime.CoreException; |
24 | 25 | import org.eclipse.debug.core.DebugPlugin; |
25 | 26 | import org.eclipse.debug.core.ILaunch; |
26 | 27 | import org.eclipse.debug.core.ILaunchesListener2; |
27 | 28 |
|
| 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 | + |
28 | 36 | import org.eclipse.m2e.core.embedder.ArtifactKey; |
29 | | -import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime; |
30 | 37 | import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments; |
31 | | -import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge; |
32 | 38 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection; |
33 | 39 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData; |
34 | 40 |
|
@@ -70,23 +76,72 @@ public void launchesChanged(ILaunch[] launches) { // ignore |
70 | 76 |
|
71 | 77 | static void openListenerConnection(ILaunch launch, VMArguments arguments) { |
72 | 78 | 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; |
85 | 120 | } |
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()); |
87 | 129 | } |
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) { |
89 | 141 | } |
| 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; |
90 | 145 | } |
91 | 146 |
|
92 | 147 | static MavenProjectBuildData getBuildProject(ILaunch launch, String groupId, String artifactId, String version) { |
|
0 commit comments