Skip to content

Commit db98d89

Browse files
committed
Add bnd-maven-plugin integration to m2e
PDE now offers so called "shared components" (based on bndtools) we can leverage them to give a better user experience in m2e without needing the user to have bndtools (or pde) installed at all. Signed-off-by: Christoph Läubrich <[email protected]> Add adapter skeleton to adapt eclipse (maven) project to bnd Signed-off-by: Christoph Läubrich <[email protected]> Setup basic properties and return as project Signed-off-by: Christoph Läubrich <[email protected]> Add mavenproject artifacts as implicit repository Signed-off-by: Christoph Läubrich <[email protected]> Rebase Signed-off-by: Christoph Läubrich <[email protected]> Add a first POC for bnd autocompletion on pom files Signed-off-by: Christoph Läubrich <[email protected]> Add example of extension in regular bundle Signed-off-by: Christoph Läubrich <[email protected]>
1 parent 19c8f09 commit db98d89

File tree

20 files changed

+485
-1
lines changed

20 files changed

+485
-1
lines changed

org.eclipse.m2e.bnd.ui/.classpath

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>

org.eclipse.m2e.bnd.ui/.project

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>org.eclipse.m2e.bnd.ui</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+
<buildCommand>
24+
<name>org.eclipse.pde.ds.core.builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.pde.PluginNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dsVersion=V1_4
2+
eclipse.preferences.version=1
3+
enabled=true
4+
generateBundleActivationPolicyLazy=true
5+
path=OSGI-INF
6+
validationErrorLevel=error
7+
validationErrorLevel.missingImplicitUnbindMethod=error
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: bnd-maven-plugin integration
4+
Bundle-SymbolicName: org.eclipse.m2e.bnd.ui
5+
Bundle-Version: 1.0.0.qualifier
6+
Import-Package: aQute.bnd.build;version="[4.5.0,5.0.0)",
7+
aQute.bnd.maven.lib.configuration;version="1.2.0",
8+
aQute.bnd.maven.lib.resolve;version="[1.3.0,2.0.0)",
9+
aQute.bnd.osgi;version="[7.0.0,8.0.0)",
10+
aQute.bnd.repository.fileset;version="[1.1.0,2.0.0)"
11+
Require-Bundle: org.eclipse.equinox.common,
12+
org.eclipse.core.resources,
13+
org.eclipse.m2e.core,
14+
org.eclipse.m2e.maven.runtime
15+
Service-Component: OSGI-INF/org.eclipse.m2e.bnd.ui.BndPluginAdapter.xml
16+
Bundle-Vendor: Eclipse
17+
Automatic-Module-Name: org.eclipse.m2e.bnd.ui
18+
Bundle-ActivationPolicy: lazy
19+
Bundle-RequiredExecutionEnvironment: JavaSE-21
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*.xml
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+
OSGI-INF/
6+
jars.extra.classpath = platform:/plugin/org.eclipse.wildwebdeveloper.xml/language-servers/server/org.eclipse.lemminx-uber.jar
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Christoph Läubrich
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.m2e.bnd.ui;
14+
15+
import java.io.File;
16+
import java.util.ArrayList;
17+
import java.util.Collection;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Properties;
21+
22+
import org.apache.maven.artifact.Artifact;
23+
import org.apache.maven.project.MavenProject;
24+
import org.eclipse.core.resources.IProject;
25+
import org.eclipse.core.runtime.AdapterTypes;
26+
import org.eclipse.core.runtime.Adapters;
27+
import org.eclipse.core.runtime.IAdapterFactory;
28+
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
29+
import org.eclipse.m2e.core.project.IMavenProjectFacade;
30+
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
31+
import org.osgi.service.component.annotations.Component;
32+
33+
import aQute.bnd.build.Project;
34+
import aQute.bnd.build.Workspace;
35+
import aQute.bnd.maven.lib.configuration.BeanProperties;
36+
import aQute.bnd.maven.lib.resolve.ImplicitFileSetRepository;
37+
import aQute.bnd.osgi.Processor;
38+
39+
/**
40+
* Adapts eclipse projects managed by m2e to bnd projects
41+
*/
42+
@Component
43+
@AdapterTypes(adaptableClass = IProject.class, adapterNames = Project.class)
44+
public class BndPluginAdapter implements IAdapterFactory {
45+
46+
@Override
47+
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
48+
try {
49+
if (adaptableObject instanceof IProject eclipseProject) {
50+
if (adapterType == Project.class) {
51+
IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class);
52+
if (isRelevantProject(mavenProject)) {
53+
System.out.println(eclipseProject.getName() + " uses bnd plugin!");
54+
BeanProperties beanProperties = new BeanProperties();
55+
MavenProject mp = mavenProject.getMavenProject();
56+
if (mp != null) {
57+
beanProperties.put("project", mp);
58+
}
59+
// TODO beanProperties.put("settings", settings);
60+
Properties processorProperties = new Properties(beanProperties);
61+
if (mp != null) {
62+
Properties projectProperties = mp.getProperties();
63+
for (String key : projectProperties.stringPropertyNames()) {
64+
processorProperties.setProperty(key, projectProperties.getProperty(key));
65+
}
66+
}
67+
Processor processor = new Processor(processorProperties, false);
68+
Collection<File> list = new ArrayList<File>();
69+
if (mp != null) {
70+
for (Artifact artifact : mp.getArtifacts()) {
71+
list.add(artifact.getFile());
72+
}
73+
}
74+
ImplicitFileSetRepository repository = new ImplicitFileSetRepository("Project Artifacts", list);
75+
// TODO propertiesFile = new BndConfiguration(project,
76+
// mojoExecution).loadProperties(builder);
77+
// TODO
78+
// aQute.bnd.maven.lib.resolve.BndrunContainer.getFileSetRepository(MavenProject)
79+
80+
Workspace standaloneWorkspace = Workspace.createStandaloneWorkspace(processor,
81+
mavenProject.getPomFile().getParentFile().toURI());
82+
standaloneWorkspace.addBasicPlugin(repository);
83+
if (mp == null) {
84+
standaloneWorkspace.set("workspaceName", mavenProject.getArtifactKey().toPortableString());
85+
} else {
86+
// TODO make part of IMavenProjectFacade
87+
standaloneWorkspace.set("workspaceName", mp.getName());
88+
String description = mp.getDescription();
89+
if (description != null) {
90+
standaloneWorkspace.set("workspaceDescription", description);
91+
}
92+
}
93+
standaloneWorkspace.refresh();
94+
Project bndProject = new Project(standaloneWorkspace, null, null);
95+
bndProject.setBase(null);
96+
return adapterType.cast(bndProject);
97+
}
98+
}
99+
}
100+
} catch (Exception e) {
101+
e.printStackTrace();
102+
}
103+
return null;
104+
}
105+
106+
private boolean isRelevantProject(IMavenProjectFacade mavenProject) {
107+
// TODO cache result inside IProject store
108+
if (mavenProject != null) {
109+
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mapping = mavenProject.getMojoExecutionMapping();
110+
for (MojoExecutionKey key : mapping.keySet()) {
111+
if ("biz.aQute.bnd".equals(key.groupId()) && "bnd-maven-plugin".equals(key.artifactId())) {
112+
return true;
113+
}
114+
}
115+
}
116+
return false;
117+
}
118+
119+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.eclipse.m2e.bnd.ui.lemminx;
2+
3+
import org.eclipse.lemminx.services.extensions.IXMLExtension;
4+
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry;
5+
import org.eclipse.lsp4j.InitializeParams;
6+
7+
public class MyExtension implements IXMLExtension {
8+
9+
@Override
10+
public void start(InitializeParams arg0, XMLExtensionsRegistry arg1) {
11+
// TODO Auto-generated method stub
12+
13+
}
14+
15+
@Override
16+
public void stop(XMLExtensionsRegistry arg0) {
17+
// TODO Auto-generated method stub
18+
19+
}
20+
21+
}

0 commit comments

Comments
 (0)