From 7accb86b1fe3383c74f4a17025e52e543c4b717d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 26 Nov 2024 12:36:04 +0100 Subject: [PATCH] Consume lemminx as a bundle from the OSGi runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently lemminx is embedded into WWD what has some disadvantages: - the jar gets bigger - the embedded jar needs to be extracted before it can be used - version bumps are required for lemminx updates - lemminx can't be updated independent from WWD This now adds a require-bundle to the manifest (so we are getting a certain version we are compatible with) and uses the bundle wiring to get hold of the bundle and then transform it into a file path. Signed-off-by: Christoph Läubrich --- .../META-INF/MANIFEST.MF | 3 +- .../build.properties | 1 - org.eclipse.wildwebdeveloper.xml/pom.xml | 41 ------------------- .../xml/internal/XMLLanguageServer.java | 30 +++++++++++--- target-platform/target-platform.target | 19 ++++++++- 5 files changed, 44 insertions(+), 50 deletions(-) diff --git a/org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF b/org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF index 7dff209eb9..91d0edcbd2 100644 --- a/org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF +++ b/org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF @@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.tm4e.registry;bundle-version="0.3.0", org.eclipse.text, org.eclipse.jface.text;bundle-version="3.20.100", com.google.gson, - org.eclipse.tm4e.language_pack + org.eclipse.tm4e.language_pack, + org.eclipse.lemminx.uber-jar;bundle-version="[0.29.0,1.0.0)" Bundle-ActivationPolicy: lazy Bundle-Activator: org.eclipse.wildwebdeveloper.xml.internal.Activator Export-Package: org.eclipse.wildwebdeveloper.xml;x-friends:="org.eclipse.m2e.editor.lemminx", diff --git a/org.eclipse.wildwebdeveloper.xml/build.properties b/org.eclipse.wildwebdeveloper.xml/build.properties index eca7db35da..2901665a79 100644 --- a/org.eclipse.wildwebdeveloper.xml/build.properties +++ b/org.eclipse.wildwebdeveloper.xml/build.properties @@ -4,7 +4,6 @@ bin.includes = META-INF/,\ .,\ plugin.xml,\ plugin.properties,\ - language-servers/server/,\ language-configurations/,\ grammars/,\ snippets/,\ diff --git a/org.eclipse.wildwebdeveloper.xml/pom.xml b/org.eclipse.wildwebdeveloper.xml/pom.xml index f56e3d758c..b685d3401a 100644 --- a/org.eclipse.wildwebdeveloper.xml/pom.xml +++ b/org.eclipse.wildwebdeveloper.xml/pom.xml @@ -23,34 +23,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - 3.8.1 - - - fetch-lemminx - generate-resources - - copy - - - - - org.eclipse.lemminx - org.eclipse.lemminx - - 0.29.0 - - uber - - - language-servers/server - true - - - - org.eclipse.tycho tycho-packaging-plugin @@ -62,17 +34,4 @@ - - - - lemminx-releases - https://repo.eclipse.org/content/repositories/lemminx-releases/ - - false - - - true - - - diff --git a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServer.java b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServer.java index db79dbe8c5..5338e9e457 100644 --- a/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServer.java +++ b/org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServer.java @@ -16,7 +16,6 @@ import java.io.File; import java.io.IOException; import java.net.URI; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -42,8 +41,12 @@ import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider; import org.eclipse.lsp4j.DidChangeConfigurationParams; import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; +import org.osgi.framework.wiring.BundleWire; +import org.osgi.framework.wiring.BundleWiring; @SuppressWarnings("restriction") public class XMLLanguageServer extends ProcessStreamConnectionProvider { @@ -103,21 +106,36 @@ public XMLLanguageServer() { commands.add("-Duser.home=" + System.getProperty("user.home")); commands.add("-classpath"); try { - URL url = FileLocator - .toFileURL(getClass().getResource("/language-servers/server/org.eclipse.lemminx-uber.jar")); + Bundle lemminxBundle = getLemminxBundle(); + File file = FileLocator.getBundleFileLocation(lemminxBundle) + .orElseThrow(() -> new IllegalStateException("Can't determine lemminx file location")); List extensionJarPaths = getExtensionJarPaths(); - String uberJarPath = new java.io.File(url.getPath()).getAbsolutePath(); + String uberJarPath = file.getAbsolutePath(); jarPaths.add(uberJarPath); jarPaths.addAll(extensionJarPaths); commands.add(String.join(System.getProperty("path.separator"), jarPaths)); - commands.add("org.eclipse.lemminx.XMLServerLauncher"); + String mainClass = lemminxBundle.getHeaders().get("Main-Class"); + commands.add(mainClass); setCommands(commands); setWorkingDirectory(System.getProperty("user.dir")); - } catch (IOException e) { + } catch (RuntimeException e) { ILog.get().error(e.getMessage(), e); } } + private Bundle getLemminxBundle() { + Bundle self = FrameworkUtil.getBundle(getClass()); + BundleWiring wiring = self.adapt(BundleWiring.class); + List wires = wiring.getRequiredWires("osgi.wiring.bundle"); + for (BundleWire bundleWire : wires) { + Bundle bundle = bundleWire.getProvider().getBundle(); + if (bundle.getSymbolicName().equals("org.eclipse.lemminx.uber-jar")) { + return bundle; + } + } + throw new IllegalStateException("can't find the lemminx bundle!"); + } + private Collection getProxySettings() { Map res = new HashMap<>(); for (Entry entry : System.getProperties().entrySet()) { diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 3cd96c43f9..fbdbd81333 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -54,5 +54,22 @@ + + + + org.eclipse.lemminx + org.eclipse.lemminx + 0.29.0 + jar + uber + + + + + lemminx-releases + https://repo.eclipse.org/content/repositories/lemminx-releases/ + + + - + \ No newline at end of file