Skip to content

Commit 081faee

Browse files
committed
Provide auto completion for bnd instructions in maven xml documents
The bnd-maven and felix-bundle plugin provide a way to use bnd-instructions to build OSGi bundles. As this is a complex syntax that can not be expressed as regular maven-mojo configuration lemminx-maven can not supply any useful completions. This adds a new lemminx-extension that provides such completions in a very basic way to support people writing such custom configuration. Signed-off-by: Christoph Läubrich <[email protected]>
1 parent dfe7688 commit 081faee

File tree

12 files changed

+273
-0
lines changed

12 files changed

+273
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.4.0" name="org.eclipse.m2e.bnd.ui.BndPluginAdapter">
3+
<property name="adaptableClass" type="String" value="org.eclipse.core.resources.IProject"/>
4+
<property name="adapterNames" type="String" value="aQute.bnd.build.Project"/>
5+
<service>
6+
<provide interface="org.eclipse.core.runtime.IAdapterFactory"/>
7+
</service>
8+
<implementation class="org.eclipse.m2e.bnd.ui.BndPluginAdapter"/>
9+
</scr:component>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.m2e.editor.lemminx.bnd</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
3+
org.eclipse.jdt.core.compiler.compliance=21
4+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
5+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
8+
org.eclipse.jdt.core.compiler.release=enabled
9+
org.eclipse.jdt.core.compiler.source=21
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Lemminx Bnd Extension
4+
Bundle-SymbolicName: org.eclipse.m2e.editor.lemminx.bnd;singleton:=true
5+
Bundle-Version: 1.0.0.qualifier
6+
Require-Bundle: org.eclipse.wildwebdeveloper.xml
7+
Bundle-Vendor: Eclipse
8+
Automatic-Module-Name: org.eclipse.m2e.editor.lemminx.bnd
9+
Bundle-RequiredExecutionEnvironment: JavaSE-21
10+
Import-Package: aQute.bnd.help;version="[2.0.0,3.0.0)",
11+
org.eclipse.core.runtime;version="[3.7.0,4.0.0)",
12+
org.osgi.framework;version="[1.10.0,2.0.0)",
13+
org.osgi.framework.wiring;version="[1.2.0,2.0.0)",
14+
org.osgi.resource;version="[1.0.0,2.0.0)"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.m2e.editor.lemminx.bnd.BndLemminxPlugin
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.,\
5+
plugin.xml
6+
jars.extra.classpath = platform:/plugin/org.eclipse.wildwebdeveloper.xml/language-servers/server/org.eclipse.lemminx-uber.jar
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension
5+
point="org.eclipse.wildwebdeveloper.xml.lemminxExtension">
6+
<classpathExtensionProvider
7+
provider="org.eclipse.m2e.editor.lemminx.bnd.BndClasspathExtensionProvider">
8+
</classpathExtensionProvider>
9+
</extension>
10+
11+
</plugin>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Christoph Läubrich and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
package org.eclipse.m2e.editor.lemminx.bnd;
12+
13+
import java.io.File;
14+
import java.util.ArrayList;
15+
import java.util.LinkedHashSet;
16+
import java.util.List;
17+
import java.util.Set;
18+
19+
import org.eclipse.core.runtime.FileLocator;
20+
import org.osgi.framework.Bundle;
21+
import org.osgi.framework.FrameworkUtil;
22+
import org.osgi.framework.wiring.BundleWire;
23+
import org.osgi.framework.wiring.BundleWiring;
24+
25+
import aQute.bnd.help.Syntax;
26+
27+
/**
28+
* register additional jars and the extension bundle
29+
*/
30+
@SuppressWarnings("restriction")
31+
public class BndClasspathExtensionProvider
32+
implements org.eclipse.wildwebdeveloper.xml.LemminxClasspathExtensionProvider {
33+
34+
@Override
35+
public List<File> get() {
36+
List<File> list = new ArrayList<>();
37+
Set<Bundle> bundleRequirements = new LinkedHashSet<>();
38+
bundleRequirements.add((FrameworkUtil.getBundle(getClass())));
39+
collectBundles(FrameworkUtil.getBundle(Syntax.class), bundleRequirements);
40+
for (Bundle bundle : bundleRequirements) {
41+
FileLocator.getBundleFileLocation(bundle).ifPresent(file -> {
42+
if (file.isDirectory()) {
43+
// For bundles from the workspace launch include the bin folder for classes
44+
File outputFolder = new File(file, "bin");
45+
if (outputFolder.exists()) {
46+
list.add(outputFolder);
47+
}
48+
}
49+
list.add(file);
50+
});
51+
}
52+
return list;
53+
}
54+
55+
private void collectBundles(Bundle bundle, Set<Bundle> bundleRequirements) {
56+
if (isValid(bundle) && bundleRequirements.add(bundle)) {
57+
BundleWiring wiring = bundle.adapt(BundleWiring.class);
58+
List<BundleWire> wires = wiring.getRequiredWires("osgi.wiring.package");
59+
for (BundleWire bundleWire : wires) {
60+
collectBundles(bundleWire.getProvider().getBundle(), bundleRequirements);
61+
}
62+
}
63+
64+
}
65+
66+
private boolean isValid(Bundle bundle) {
67+
if (bundle == null) {
68+
return false;
69+
}
70+
String bsn = bundle.getSymbolicName();
71+
if ("slf4j.api".equals(bsn)) {
72+
// slf4j is already provided
73+
return false;
74+
}
75+
return true;
76+
}
77+
78+
}

0 commit comments

Comments
 (0)