Skip to content

Commit a1e492d

Browse files
committed
Setup basic properties and return as project
Signed-off-by: Christoph Läubrich <[email protected]>
1 parent f3d03b5 commit a1e492d

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ 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+
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.osgi;version="[7.0.0,8.0.0)"
69
Require-Bundle: org.eclipse.equinox.common,
710
org.eclipse.core.resources,
8-
biz.aQute.bndlib,
911
org.eclipse.m2e.core,
1012
org.eclipse.m2e.maven.runtime
1113
Service-Component: OSGI-INF/org.eclipse.m2e.bnd.ui.BndPluginAdapter.xml

org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
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+
*******************************************************************************/
113
package org.eclipse.m2e.bnd.ui;
214

315
import java.util.List;
416
import java.util.Map;
17+
import java.util.Properties;
518

19+
import org.apache.maven.project.MavenProject;
620
import org.eclipse.core.resources.IProject;
721
import org.eclipse.core.runtime.AdapterTypes;
822
import org.eclipse.core.runtime.Adapters;
@@ -13,30 +27,71 @@
1327
import org.osgi.service.component.annotations.Component;
1428

1529
import aQute.bnd.build.Project;
30+
import aQute.bnd.build.Workspace;
31+
import aQute.bnd.maven.lib.configuration.BeanProperties;
32+
import aQute.bnd.osgi.Processor;
1633

1734
/**
1835
* Adapts eclipse projects managed by m2e to bnd projects
1936
*/
2037
@Component
2138
@AdapterTypes(adaptableClass = IProject.class, adapterNames = Project.class)
22-
public class BndPluginAdapter implements IAdapterFactory{
39+
public class BndPluginAdapter implements IAdapterFactory {
2340

2441
@Override
2542
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!");
43+
try {
44+
if (adaptableObject instanceof IProject eclipseProject) {
45+
if (adapterType == Project.class) {
46+
IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class);
47+
if (isRelevantProject(mavenProject)) {
48+
System.out.println(eclipseProject.getName() + " uses bnd plugin!");
49+
BeanProperties beanProperties = new BeanProperties();
50+
MavenProject mp = mavenProject.getMavenProject();
51+
if (mp != null) {
52+
beanProperties.put("project", mp);
53+
}
54+
// TODO beanProperties.put("settings", settings);
55+
Properties processorProperties = new Properties(beanProperties);
56+
if (mp != null) {
57+
Properties projectProperties = mp.getProperties();
58+
for (String key : projectProperties.stringPropertyNames()) {
59+
processorProperties.setProperty(key, projectProperties.getProperty(key));
60+
}
61+
}
62+
Processor processor = new Processor(processorProperties, false);
63+
64+
// TODO propertiesFile = new BndConfiguration(project,
65+
// mojoExecution).loadProperties(builder);
66+
67+
Workspace standaloneWorkspace = Workspace.createStandaloneWorkspace(processor,
68+
mavenProject.getPomFile().getParentFile().toURI());
69+
if (mp == null) {
70+
standaloneWorkspace.set("workspaceName", mavenProject.getArtifactKey().toPortableString());
71+
} else {
72+
// TODO make part of IMavenProjectFacade
73+
standaloneWorkspace.set("workspaceName", mp.getName());
74+
String description = mp.getDescription();
75+
if (description != null) {
76+
standaloneWorkspace.set("workspaceDescription", description);
77+
}
78+
}
79+
Project bndProject = new Project(standaloneWorkspace, null, null);
80+
bndProject.setBase(null);
81+
return adapterType.cast(bndProject);
82+
}
83+
}
3084
}
85+
} catch (Exception e) {
86+
e.printStackTrace();
3187
}
3288
return null;
3389
}
3490

3591
private boolean isRelevantProject(IMavenProjectFacade mavenProject) {
3692
// TODO cache result inside IProject store
3793
if (mavenProject != null) {
38-
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mapping = mavenProject
39-
.getMojoExecutionMapping();
94+
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mapping = mavenProject.getMojoExecutionMapping();
4095
for (MojoExecutionKey key : mapping.keySet()) {
4196
if ("biz.aQute.bnd".equals(key.groupId()) && "bnd-maven-plugin".equals(key.artifactId())) {
4297
return true;

target-platform/target-platform.target

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
<unit id="org.eclipse.wst.xsd.core" version="0.0.0"/>
3434
</location>
3535
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
36-
<repository location="https://download.eclipse.org/wildwebdeveloper/releases/1.3.6/"/>
37-
<repository location="https://download.eclipse.org/tm4e/releases/0.12.0/"/>
36+
<repository location="https://download.eclipse.org/cbi/updates/license/"/>
37+
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
38+
</location>
39+
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
3840
<repository location="https://download.eclipse.org/lsp4e/releases/0.26.2/"/>
3941
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.23.1/"/>
4042
<repository location="https://download.eclipse.org/mylyn/updates/release/4.3.0/"/>
41-
<unit id="org.eclipse.wildwebdeveloper.xml.feature.feature.group" version="0.0.0"/>
43+
<repository location="https://download.eclipse.org/tm4e/releases/0.12.0/"/>
44+
<repository location="https://download.eclipse.org/wildwebdeveloper/releases/1.3.6/"/>
4245
<unit id="org.eclipse.lsp4e" version="0.0.0"/>
43-
</location>
44-
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
45-
<repository location="https://download.eclipse.org/cbi/updates/license/"/>
46-
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
46+
<unit id="org.eclipse.wildwebdeveloper.xml.feature.feature.group" version="0.0.0"/>
4747
</location>
4848
<location includeDependencyDepth="infinite" includeDependencyScopes="compile" includeSource="true" label="Logging" missingManifest="error" type="Maven">
4949
<dependencies>
@@ -63,6 +63,12 @@
6363
</location>
6464
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" label="Misc" missingManifest="error" type="Maven">
6565
<dependencies>
66+
<dependency>
67+
<groupId>biz.aQute.bnd</groupId>
68+
<artifactId>biz.aQute.bnd.maven</artifactId>
69+
<version>7.0.0</version>
70+
<type>jar</type>
71+
</dependency>
6672
<dependency>
6773
<groupId>com.google.code.gson</groupId>
6874
<artifactId>gson</artifactId>
@@ -101,8 +107,7 @@
101107
</dependency>
102108
</dependencies>
103109
</location>
104-
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="false" label="M2E Workspace CLI" missingManifest="error" type="Maven">
105-
<!-- Dedicated location to *NOT* include sources -->
110+
<location includeDependencyDepth="none" includeDependencyScopes="compile" label="M2E Workspace CLI" missingManifest="error" type="Maven">
106111
<dependencies>
107112
<dependency>
108113
<groupId>io.takari.m2e.workspace</groupId>

0 commit comments

Comments
 (0)