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 akurtakov committed Dec 3, 2024
1 parent a3ea5af commit add237d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
org.eclipse.jdt.core.compiler.ignoreUnnamedModuleForSplitPackage=enabled
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper.xml.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.wildwebdeveloper.xml.feature"
label="%name"
version="1.3.6.qualifier"
version="1.3.7.qualifier"
provider-name="Eclipse Wild Web Developer project"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.wildwebdeveloper.xml.feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>eclipse-feature</packaging>
<version>1.3.6-SNAPSHOT</version>
<version>1.3.7-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down
5 changes: 3 additions & 2 deletions org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wildwebdeveloper.xml;singleton:=true
Bundle-Version: 1.3.6.qualifier
Bundle-Version: 1.3.7.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Automatic-Module-Name: org.eclipse.wildwebdeveloper.xml
Expand All @@ -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
55 changes: 1 addition & 54 deletions org.eclipse.wildwebdeveloper.xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,10 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<packaging>eclipse-plugin</packaging>
<version>1.3.6-SNAPSHOT</version>
<version>1.3.7-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>language-servers/</directory>
<includes>*.tgz</includes>
</fileset>
</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 +22,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 add237d

Please sign in to comment.