|
16 | 16 | import java.io.File;
|
17 | 17 | import java.io.IOException;
|
18 | 18 | import java.net.URI;
|
19 |
| -import java.net.URL; |
20 | 19 | import java.util.ArrayList;
|
21 | 20 | import java.util.Arrays;
|
22 | 21 | import java.util.Collection;
|
|
42 | 41 | import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
|
43 | 42 | import org.eclipse.lsp4j.DidChangeConfigurationParams;
|
44 | 43 | import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants;
|
| 44 | +import org.osgi.framework.Bundle; |
45 | 45 | import org.osgi.framework.BundleContext;
|
| 46 | +import org.osgi.framework.FrameworkUtil; |
46 | 47 | import org.osgi.framework.ServiceReference;
|
| 48 | +import org.osgi.framework.wiring.BundleWire; |
| 49 | +import org.osgi.framework.wiring.BundleWiring; |
47 | 50 |
|
48 | 51 | @SuppressWarnings("restriction")
|
49 | 52 | public class XMLLanguageServer extends ProcessStreamConnectionProvider {
|
@@ -103,21 +106,36 @@ public XMLLanguageServer() {
|
103 | 106 | commands.add("-Duser.home=" + System.getProperty("user.home"));
|
104 | 107 | commands.add("-classpath");
|
105 | 108 | try {
|
106 |
| - URL url = FileLocator |
107 |
| - .toFileURL(getClass().getResource("/language-servers/server/org.eclipse.lemminx-uber.jar")); |
| 109 | + Bundle lemminxBundle = getLemminxBundle(); |
| 110 | + File file = FileLocator.getBundleFileLocation(lemminxBundle) |
| 111 | + .orElseThrow(() -> new IllegalStateException("Can't determine lemminx file location")); |
108 | 112 | List<String> extensionJarPaths = getExtensionJarPaths();
|
109 |
| - String uberJarPath = new java.io.File(url.getPath()).getAbsolutePath(); |
| 113 | + String uberJarPath = file.getAbsolutePath(); |
110 | 114 | jarPaths.add(uberJarPath);
|
111 | 115 | jarPaths.addAll(extensionJarPaths);
|
112 | 116 | commands.add(String.join(System.getProperty("path.separator"), jarPaths));
|
113 |
| - commands.add("org.eclipse.lemminx.XMLServerLauncher"); |
| 117 | + String mainClass = lemminxBundle.getHeaders().get("Main-Class"); |
| 118 | + commands.add(mainClass); |
114 | 119 | setCommands(commands);
|
115 | 120 | setWorkingDirectory(System.getProperty("user.dir"));
|
116 |
| - } catch (IOException e) { |
| 121 | + } catch (RuntimeException e) { |
117 | 122 | ILog.get().error(e.getMessage(), e);
|
118 | 123 | }
|
119 | 124 | }
|
120 | 125 |
|
| 126 | + private Bundle getLemminxBundle() { |
| 127 | + Bundle self = FrameworkUtil.getBundle(getClass()); |
| 128 | + BundleWiring wiring = self.adapt(BundleWiring.class); |
| 129 | + List<BundleWire> wires = wiring.getRequiredWires("osgi.wiring.bundle"); |
| 130 | + for (BundleWire bundleWire : wires) { |
| 131 | + Bundle bundle = bundleWire.getProvider().getBundle(); |
| 132 | + if (bundle.getSymbolicName().equals("org.eclipse.lemminx.uber-jar")) { |
| 133 | + return bundle; |
| 134 | + } |
| 135 | + } |
| 136 | + throw new IllegalStateException("can't find the lemminx bundle!"); |
| 137 | + } |
| 138 | + |
121 | 139 | private Collection<? extends String> getProxySettings() {
|
122 | 140 | Map<String, String> res = new HashMap<>();
|
123 | 141 | for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
|
|
0 commit comments