Skip to content

Commit f3d03b5

Browse files
committed
Add adapter skeleton to adapt eclipse (maven) project to bnd
Signed-off-by: Christoph Läubrich <[email protected]>
1 parent 48f833e commit f3d03b5

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<arguments>
2121
</arguments>
2222
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.pde.ds.core.builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
2328
</buildSpec>
2429
<natures>
2530
<nature>org.eclipse.pde.PluginNature</nature>
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

org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: bnd-maven-plugin integration
44
Bundle-SymbolicName: org.eclipse.m2e.bnd.ui
55
Bundle-Version: 1.0.0.qualifier
6+
Require-Bundle: org.eclipse.equinox.common,
7+
org.eclipse.core.resources,
8+
biz.aQute.bndlib,
9+
org.eclipse.m2e.core,
10+
org.eclipse.m2e.maven.runtime
11+
Service-Component: OSGI-INF/org.eclipse.m2e.bnd.ui.BndPluginAdapter.xml
612
Bundle-Vendor: Eclipse
713
Automatic-Module-Name: org.eclipse.m2e.bnd.ui
14+
Bundle-ActivationPolicy: lazy
815
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source.. = src/
22
output.. = bin/
33
bin.includes = META-INF/,\
4-
.
4+
.,\
5+
OSGI-INF/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.eclipse.m2e.bnd.ui;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
import org.eclipse.core.resources.IProject;
7+
import org.eclipse.core.runtime.AdapterTypes;
8+
import org.eclipse.core.runtime.Adapters;
9+
import org.eclipse.core.runtime.IAdapterFactory;
10+
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
11+
import org.eclipse.m2e.core.project.IMavenProjectFacade;
12+
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
13+
import org.osgi.service.component.annotations.Component;
14+
15+
import aQute.bnd.build.Project;
16+
17+
/**
18+
* Adapts eclipse projects managed by m2e to bnd projects
19+
*/
20+
@Component
21+
@AdapterTypes(adaptableClass = IProject.class, adapterNames = Project.class)
22+
public class BndPluginAdapter implements IAdapterFactory{
23+
24+
@Override
25+
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
26+
if (adaptableObject instanceof IProject eclipseProject) {
27+
IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class);
28+
if (isRelevantProject(mavenProject)) {
29+
System.out.println(eclipseProject.getName() + " uses bnd plugin!");
30+
}
31+
}
32+
return null;
33+
}
34+
35+
private boolean isRelevantProject(IMavenProjectFacade mavenProject) {
36+
// TODO cache result inside IProject store
37+
if (mavenProject != null) {
38+
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mapping = mavenProject
39+
.getMojoExecutionMapping();
40+
for (MojoExecutionKey key : mapping.keySet()) {
41+
if ("biz.aQute.bnd".equals(key.groupId()) && "bnd-maven-plugin".equals(key.artifactId())) {
42+
return true;
43+
}
44+
}
45+
}
46+
return false;
47+
}
48+
49+
}

0 commit comments

Comments
 (0)