Skip to content

Commit 7accb86

Browse files
laeubiChristoph Läubrich
authored and
Christoph Läubrich
committed
Consume lemminx as a bundle from the OSGi runtime
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]>
1 parent bb939bf commit 7accb86

File tree

5 files changed

+44
-50
lines changed

5 files changed

+44
-50
lines changed

org.eclipse.wildwebdeveloper.xml/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Require-Bundle: org.eclipse.tm4e.registry;bundle-version="0.3.0",
2323
org.eclipse.text,
2424
org.eclipse.jface.text;bundle-version="3.20.100",
2525
com.google.gson,
26-
org.eclipse.tm4e.language_pack
26+
org.eclipse.tm4e.language_pack,
27+
org.eclipse.lemminx.uber-jar;bundle-version="[0.29.0,1.0.0)"
2728
Bundle-ActivationPolicy: lazy
2829
Bundle-Activator: org.eclipse.wildwebdeveloper.xml.internal.Activator
2930
Export-Package: org.eclipse.wildwebdeveloper.xml;x-friends:="org.eclipse.m2e.editor.lemminx",

org.eclipse.wildwebdeveloper.xml/build.properties

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ bin.includes = META-INF/,\
44
.,\
55
plugin.xml,\
66
plugin.properties,\
7-
language-servers/server/,\
87
language-configurations/,\
98
grammars/,\
109
snippets/,\

org.eclipse.wildwebdeveloper.xml/pom.xml

-41
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@
2323
</filesets>
2424
</configuration>
2525
</plugin>
26-
<plugin>
27-
<groupId>org.apache.maven.plugins</groupId>
28-
<artifactId>maven-dependency-plugin</artifactId>
29-
<version>3.8.1</version>
30-
<executions>
31-
<execution>
32-
<id>fetch-lemminx</id>
33-
<phase>generate-resources</phase>
34-
<goals>
35-
<goal>copy</goal>
36-
</goals>
37-
<configuration>
38-
<artifactItems>
39-
<artifactItem>
40-
<groupId>org.eclipse.lemminx</groupId>
41-
<artifactId>org.eclipse.lemminx</artifactId>
42-
<!-- Bumping to version with API breakage needs to bump bundle version at least by +0.1.0 -->
43-
<version>0.29.0</version>
44-
<!-- classifier:uber includes all dependencies -->
45-
<classifier>uber</classifier>
46-
</artifactItem>
47-
</artifactItems>
48-
<outputDirectory>language-servers/server</outputDirectory>
49-
<stripVersion>true</stripVersion>
50-
</configuration>
51-
</execution>
52-
</executions>
53-
</plugin>
5426
<plugin>
5527
<groupId>org.eclipse.tycho</groupId>
5628
<artifactId>tycho-packaging-plugin</artifactId>
@@ -62,17 +34,4 @@
6234
</plugin>
6335
</plugins>
6436
</build>
65-
66-
<repositories>
67-
<repository>
68-
<id>lemminx-releases</id>
69-
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
70-
<snapshots>
71-
<enabled>false</enabled>
72-
</snapshots>
73-
<releases>
74-
<enabled>true</enabled>
75-
</releases>
76-
</repository>
77-
</repositories>
7837
</project>

org.eclipse.wildwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServer.java

+24-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.io.File;
1717
import java.io.IOException;
1818
import java.net.URI;
19-
import java.net.URL;
2019
import java.util.ArrayList;
2120
import java.util.Arrays;
2221
import java.util.Collection;
@@ -42,8 +41,12 @@
4241
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
4342
import org.eclipse.lsp4j.DidChangeConfigurationParams;
4443
import org.eclipse.wildwebdeveloper.xml.internal.ui.preferences.XMLPreferenceServerConstants;
44+
import org.osgi.framework.Bundle;
4545
import org.osgi.framework.BundleContext;
46+
import org.osgi.framework.FrameworkUtil;
4647
import org.osgi.framework.ServiceReference;
48+
import org.osgi.framework.wiring.BundleWire;
49+
import org.osgi.framework.wiring.BundleWiring;
4750

4851
@SuppressWarnings("restriction")
4952
public class XMLLanguageServer extends ProcessStreamConnectionProvider {
@@ -103,21 +106,36 @@ public XMLLanguageServer() {
103106
commands.add("-Duser.home=" + System.getProperty("user.home"));
104107
commands.add("-classpath");
105108
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"));
108112
List<String> extensionJarPaths = getExtensionJarPaths();
109-
String uberJarPath = new java.io.File(url.getPath()).getAbsolutePath();
113+
String uberJarPath = file.getAbsolutePath();
110114
jarPaths.add(uberJarPath);
111115
jarPaths.addAll(extensionJarPaths);
112116
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);
114119
setCommands(commands);
115120
setWorkingDirectory(System.getProperty("user.dir"));
116-
} catch (IOException e) {
121+
} catch (RuntimeException e) {
117122
ILog.get().error(e.getMessage(), e);
118123
}
119124
}
120125

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+
121139
private Collection<? extends String> getProxySettings() {
122140
Map<String, String> res = new HashMap<>();
123141
for (Entry<Object, Object> entry : System.getProperties().entrySet()) {

target-platform/target-platform.target

+18-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,22 @@
5454
</dependency>
5555
</dependencies>
5656
</location>
57+
<location includeDependencyDepth="none" includeDependencyScopes="compile" label="LemMinX" missingManifest="error" type="Maven">
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.eclipse.lemminx</groupId>
61+
<artifactId>org.eclipse.lemminx</artifactId>
62+
<version>0.29.0</version>
63+
<type>jar</type>
64+
<classifier>uber</classifier>
65+
</dependency>
66+
</dependencies>
67+
<repositories>
68+
<repository>
69+
<id>lemminx-releases</id>
70+
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
71+
</repository>
72+
</repositories>
73+
</location>
5774
</locations>
58-
</target>
75+
</target>

0 commit comments

Comments
 (0)