Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bnd-maven-plugin integration to m2e #1788

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions org.eclipse.m2e.bnd.ui/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
33 changes: 33 additions & 0 deletions org.eclipse.m2e.bnd.ui/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.m2e.bnd.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
9 changes: 9 additions & 0 deletions org.eclipse.m2e.bnd.ui/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dsVersion=V1_4
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
path=OSGI-INF
validationErrorLevel=error
validationErrorLevel.missingImplicitUnbindMethod=error
19 changes: 19 additions & 0 deletions org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: bnd-maven-plugin integration
Bundle-SymbolicName: org.eclipse.m2e.bnd.ui
Bundle-Version: 1.0.0.qualifier
Import-Package: aQute.bnd.build;version="[4.5.0,5.0.0)",
aQute.bnd.maven.lib.configuration;version="1.2.0",
aQute.bnd.maven.lib.resolve;version="[1.3.0,2.0.0)",
aQute.bnd.osgi;version="[7.0.0,8.0.0)",
aQute.bnd.repository.fileset;version="[1.1.0,2.0.0)"
Require-Bundle: org.eclipse.equinox.common,
org.eclipse.core.resources,
org.eclipse.m2e.core,
org.eclipse.m2e.maven.runtime
Service-Component: OSGI-INF/org.eclipse.m2e.bnd.ui.BndPluginAdapter.xml
Bundle-Vendor: Eclipse
Automatic-Module-Name: org.eclipse.m2e.bnd.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-21
1 change: 1 addition & 0 deletions org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.xml
6 changes: 6 additions & 0 deletions org.eclipse.m2e.bnd.ui/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
OSGI-INF/
jars.extra.classpath = platform:/plugin/org.eclipse.wildwebdeveloper.xml/language-servers/server/org.eclipse.lemminx-uber.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 2024 Christoph Läubrich
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.bnd.ui;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.AdapterTypes;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.osgi.service.component.annotations.Component;

import aQute.bnd.build.Project;
import aQute.bnd.build.Workspace;
import aQute.bnd.maven.lib.configuration.BeanProperties;
import aQute.bnd.maven.lib.resolve.ImplicitFileSetRepository;
import aQute.bnd.osgi.Processor;

/**
* Adapts eclipse projects managed by m2e to bnd projects
*/
@Component
@AdapterTypes(adaptableClass = IProject.class, adapterNames = Project.class)
public class BndPluginAdapter implements IAdapterFactory {

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
try {
if (adaptableObject instanceof IProject eclipseProject) {
if (adapterType == Project.class) {
IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class);
if (isRelevantProject(mavenProject)) {
System.out.println(eclipseProject.getName() + " uses bnd plugin!");
BeanProperties beanProperties = new BeanProperties();
MavenProject mp = mavenProject.getMavenProject();
if (mp != null) {
beanProperties.put("project", mp);
}
// TODO beanProperties.put("settings", settings);
Properties processorProperties = new Properties(beanProperties);
if (mp != null) {
Properties projectProperties = mp.getProperties();
for (String key : projectProperties.stringPropertyNames()) {
processorProperties.setProperty(key, projectProperties.getProperty(key));
}
}
Processor processor = new Processor(processorProperties, false);
Collection<File> list = new ArrayList<File>();
if (mp != null) {
for (Artifact artifact : mp.getArtifacts()) {
list.add(artifact.getFile());
}
}
ImplicitFileSetRepository repository = new ImplicitFileSetRepository("Project Artifacts", list);
// TODO propertiesFile = new BndConfiguration(project,
// mojoExecution).loadProperties(builder);
// TODO
// aQute.bnd.maven.lib.resolve.BndrunContainer.getFileSetRepository(MavenProject)

Workspace standaloneWorkspace = Workspace.createStandaloneWorkspace(processor,
mavenProject.getPomFile().getParentFile().toURI());
standaloneWorkspace.addBasicPlugin(repository);
if (mp == null) {
standaloneWorkspace.set("workspaceName", mavenProject.getArtifactKey().toPortableString());
} else {
// TODO make part of IMavenProjectFacade
standaloneWorkspace.set("workspaceName", mp.getName());
String description = mp.getDescription();
if (description != null) {
standaloneWorkspace.set("workspaceDescription", description);
}
}
standaloneWorkspace.refresh();
Project bndProject = new Project(standaloneWorkspace, null, null);
bndProject.setBase(null);
return adapterType.cast(bndProject);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

private boolean isRelevantProject(IMavenProjectFacade mavenProject) {
// TODO cache result inside IProject store
if (mavenProject != null) {
Map<MojoExecutionKey, List<IPluginExecutionMetadata>> mapping = mavenProject.getMojoExecutionMapping();
for (MojoExecutionKey key : mapping.keySet()) {
if ("biz.aQute.bnd".equals(key.groupId()) && "bnd-maven-plugin".equals(key.artifactId())) {
return true;
}
}
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.eclipse.m2e.bnd.ui.lemminx;

import org.eclipse.lemminx.services.extensions.IXMLExtension;
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4j.InitializeParams;

public class MyExtension implements IXMLExtension {

@Override
public void start(InitializeParams arg0, XMLExtensionsRegistry arg1) {
// TODO Auto-generated method stub

}

@Override
public void stop(XMLExtensionsRegistry arg0) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
classpath=true
dsVersion=V1_3
dsVersion=V1_5
eclipse.preferences.version=1
enabled=true
generateBundleActivationPolicyLazy=true
Expand Down
41 changes: 41 additions & 0 deletions org.eclipse.m2e.lemminx.bnd/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions org.eclipse.m2e.lemminx.bnd/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.m2e.lemminx.bnd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
47 changes: 47 additions & 0 deletions org.eclipse.m2e.lemminx.bnd/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- <parent>-->
<!-- <groupId>org.eclipse.m2e</groupId>-->
<!-- <artifactId>m2e-core</artifactId>-->
<!-- <version>2.1.0-SNAPSHOT</version>-->
<!-- </parent>-->
<groupId>org.eclipse.m2e.lemminx.bnd</groupId>
<artifactId>org.eclipse.m2e.lemminx.bnd</artifactId>
<version>2.1.0-SNAPSHOT</version>
<name>M2E bnd lemminx extension</name>

<properties>
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
</properties>


<dependencies>
<dependency>
<groupId>org.eclipse.lemminx</groupId>
<artifactId>org.eclipse.lemminx</artifactId>
<version>0.28.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>7.0.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
<id>lemminx-releases</id>
<url>https://repo.eclipse.org/content/repositories/lemminx-releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
Loading
Loading