|
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.MojoMessage; |
| 34 | +import org.codehaus.plexus.build.connect.messages.ProjectMessage; |
| 35 | +import org.codehaus.plexus.build.connect.messages.ProjectsMessage; |
| 36 | + |
28 | 37 | import org.eclipse.m2e.core.embedder.ArtifactKey;
|
29 |
| -import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime; |
30 | 38 | import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments;
|
31 |
| -import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge; |
32 | 39 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenBuildConnection;
|
33 | 40 | import org.eclipse.m2e.internal.maven.listener.M2EMavenBuildDataBridge.MavenProjectBuildData;
|
34 | 41 |
|
@@ -70,23 +77,78 @@ public void launchesChanged(ILaunch[] launches) { // ignore
|
70 | 77 |
|
71 | 78 | static void openListenerConnection(ILaunch launch, VMArguments arguments) {
|
72 | 79 | 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()); |
| 80 | +// if(MavenLaunchUtils.getMavenRuntime(launch.getLaunchConfiguration()) instanceof MavenEmbeddedRuntime) { |
| 81 | +// |
| 82 | +// Map<ArtifactKey, MavenProjectBuildData> projects = new ConcurrentHashMap<>(); |
| 83 | +// |
| 84 | +// MavenBuildConnection connection = M2EMavenBuildDataBridge.prepareConnection( |
| 85 | +// launch.getLaunchConfiguration().getName(), |
| 86 | +// d -> projects.put(new ArtifactKey(d.groupId, d.artifactId, d.version, null), d)); |
| 87 | +// |
| 88 | +// if(LAUNCH_PROJECT_DATA.putIfAbsent(launch, new MavenBuildConnectionData(projects, connection)) != null) { |
| 89 | +// connection.close(); |
| 90 | +// throw new IllegalStateException( |
| 91 | +// "Maven bridge already created for launch of" + launch.getLaunchConfiguration().getName()); |
| 92 | +// } |
| 93 | +// |
| 94 | +// arguments.append(connection.getMavenVMArguments()); |
| 95 | +// } else { |
| 96 | + ServerConnection con = TcpBuildConnection.createServer(msg -> { |
| 97 | + if(msg instanceof InitMessage init) { |
| 98 | + System.out.println("Init..."); |
| 99 | + init.keys().forEach(k -> { |
| 100 | + System.out.println(k + ": " + init.getProperty(k)); |
| 101 | + }); |
| 102 | + Map<String, String> config = new HashMap<String, String>(); |
| 103 | + config.put(Configuration.CONFIG_SEND_PROJECTS, "true"); |
| 104 | + //TODO more... |
| 105 | + return config; |
| 106 | + } |
| 107 | + if(msg instanceof ProjectsMessage projects) { |
| 108 | + System.out.println("Projects in reactor"); |
| 109 | + projects.projects().forEach(pi -> { |
| 110 | + System.out.println(pi.getGroupId() + ":" + pi.getArtifactId() + ":" + pi.getVersion()); |
| 111 | + System.out.println(pi.getBaseDir()); |
| 112 | +// System.out.println(pi.getModel()); |
| 113 | + }); |
| 114 | + return null; |
| 115 | + } |
| 116 | + if(msg instanceof ProjectMessage project) { |
| 117 | + System.out.println("--- " + project.getType() + " ---"); |
| 118 | + System.out.println(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion()); |
| 119 | + System.out.println(project.getBaseDir()); |
| 120 | + return null; |
85 | 121 | }
|
86 |
| - arguments.append(connection.getMavenVMArguments()); |
| 122 | + if(msg instanceof MojoMessage mojo) { |
| 123 | + System.out.println("--- " + mojo.getType() + " ---"); |
| 124 | + System.out.println(mojo.getGroupId() + ":" + mojo.getArtifactId() + ":" + mojo.getVersion() + " - " |
| 125 | + + mojo.getLifecyclePhase() + " [" + mojo.getExecutionId() + "] " + mojo.getGoal()); |
| 126 | + return null; |
| 127 | + } |
| 128 | + |
| 129 | + System.out.println("Message: " + msg); |
| 130 | + return null; |
| 131 | + }); |
| 132 | + File location = getJarLocation(); |
| 133 | + if(location != null) { |
| 134 | + //TODO see bug https://issues.apache.org/jira/browse/MNG-8112 |
| 135 | +// arguments.appendProperty("maven.ext.class.path", location.getAbsolutePath()); |
87 | 136 | }
|
88 |
| - } catch(CoreException | IOException ex) { // ignore |
| 137 | + con.setupProcess(arguments::appendProperty); |
| 138 | +// } |
| 139 | + } catch(Exception ex) { // ignore |
| 140 | + ex.printStackTrace(); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + private static File getJarLocation() { |
| 145 | + try { |
| 146 | + return new File(TcpBuildConnection.class.getProtectionDomain().getCodeSource().getLocation().toURI()); |
| 147 | + } catch(Exception e) { |
89 | 148 | }
|
| 149 | + //TODO better way to find it?!? |
| 150 | + //Maybe just consume as a (wrapped) bundle as we only need it to start the server not on the maven classpath! |
| 151 | + return null; |
90 | 152 | }
|
91 | 153 |
|
92 | 154 | static MavenProjectBuildData getBuildProject(ILaunch launch, String groupId, String artifactId, String version) {
|
|
0 commit comments