Skip to content

Commit

Permalink
Consume lemminx as a bundle from the OSGi runtime
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
laeubi authored and Christoph Läubrich committed Nov 27, 2024
1 parent bb939bf commit 7accb86
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 50 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion org.eclipse.wildwebdeveloper.xml/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
plugin.properties,\
language-servers/server/,\
language-configurations/,\
grammars/,\
snippets/,\
Expand Down
41 changes: 0 additions & 41 deletions org.eclipse.wildwebdeveloper.xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,6 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<id>fetch-lemminx</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.eclipse.lemminx</groupId>
<artifactId>org.eclipse.lemminx</artifactId>
<!-- Bumping to version with API breakage needs to bump bundle version at least by +0.1.0 -->
<version>0.29.0</version>
<!-- classifier:uber includes all dependencies -->
<classifier>uber</classifier>
</artifactItem>
</artifactItems>
<outputDirectory>language-servers/server</outputDirectory>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
Expand All @@ -62,17 +34,4 @@
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>lemminx-releases</id>
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<String> 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<BundleWire> 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<? extends String> getProxySettings() {
Map<String, String> res = new HashMap<>();
for (Entry<Object, Object> entry : System.getProperties().entrySet()) {
Expand Down
19 changes: 18 additions & 1 deletion target-platform/target-platform.target
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,22 @@
</dependency>
</dependencies>
</location>
<location includeDependencyDepth="none" includeDependencyScopes="compile" label="LemMinX" missingManifest="error" type="Maven">
<dependencies>
<dependency>
<groupId>org.eclipse.lemminx</groupId>
<artifactId>org.eclipse.lemminx</artifactId>
<version>0.29.0</version>
<type>jar</type>
<classifier>uber</classifier>
</dependency>
</dependencies>
<repositories>
<repository>
<id>lemminx-releases</id>
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
</repository>
</repositories>
</location>
</locations>
</target>
</target>

0 comments on commit 7accb86

Please sign in to comment.