From 5129e2bf08cfc6619bd9f5ac1838992845659f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 11 Jul 2024 06:36:26 +0200 Subject: [PATCH 1/7] Add bnd-maven-plugin integration to m2e MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- org.eclipse.m2e.bnd.ui/.classpath | 7 +++++ org.eclipse.m2e.bnd.ui/.project | 28 +++++++++++++++++++ .../org.eclipse.core.resources.prefs | 2 ++ .../.settings/org.eclipse.jdt.core.prefs | 9 ++++++ org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF | 8 ++++++ org.eclipse.m2e.bnd.ui/build.properties | 4 +++ 6 files changed, 58 insertions(+) create mode 100644 org.eclipse.m2e.bnd.ui/.classpath create mode 100644 org.eclipse.m2e.bnd.ui/.project create mode 100644 org.eclipse.m2e.bnd.ui/.settings/org.eclipse.core.resources.prefs create mode 100644 org.eclipse.m2e.bnd.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF create mode 100644 org.eclipse.m2e.bnd.ui/build.properties diff --git a/org.eclipse.m2e.bnd.ui/.classpath b/org.eclipse.m2e.bnd.ui/.classpath new file mode 100644 index 0000000000..375961e4d6 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.m2e.bnd.ui/.project b/org.eclipse.m2e.bnd.ui/.project new file mode 100644 index 0000000000..a2c6f01b31 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/.project @@ -0,0 +1,28 @@ + + + org.eclipse.m2e.bnd.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.core.resources.prefs b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..23fa13b170 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..94fbedc2f6 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +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 +Bundle-Vendor: Eclipse +Automatic-Module-Name: org.eclipse.m2e.bnd.ui +Bundle-RequiredExecutionEnvironment: JavaSE-21 diff --git a/org.eclipse.m2e.bnd.ui/build.properties b/org.eclipse.m2e.bnd.ui/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . From fd9e4e0681f84cf6aba824b85246bb40a184b3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 11 Jul 2024 06:59:35 +0200 Subject: [PATCH 2/7] Add adapter skeleton to adapt eclipse (maven) project to bnd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- org.eclipse.m2e.bnd.ui/.project | 5 ++ .../org.eclipse.pde.ds.annotations.prefs | 7 +++ org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF | 7 +++ org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore | 1 + org.eclipse.m2e.bnd.ui/build.properties | 3 +- .../eclipse/m2e/bnd/ui/BndPluginAdapter.java | 49 +++++++++++++++++++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.m2e.bnd.ui/.settings/org.eclipse.pde.ds.annotations.prefs create mode 100644 org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore create mode 100644 org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java diff --git a/org.eclipse.m2e.bnd.ui/.project b/org.eclipse.m2e.bnd.ui/.project index a2c6f01b31..e7bfedc0a1 100644 --- a/org.eclipse.m2e.bnd.ui/.project +++ b/org.eclipse.m2e.bnd.ui/.project @@ -20,6 +20,11 @@ + + org.eclipse.pde.ds.core.builder + + + org.eclipse.pde.PluginNature diff --git a/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.pde.ds.annotations.prefs b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.pde.ds.annotations.prefs new file mode 100644 index 0000000000..5faf08b7d5 --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/.settings/org.eclipse.pde.ds.annotations.prefs @@ -0,0 +1,7 @@ +dsVersion=V1_4 +eclipse.preferences.version=1 +enabled=true +generateBundleActivationPolicyLazy=true +path=OSGI-INF +validationErrorLevel=error +validationErrorLevel.missingImplicitUnbindMethod=error diff --git a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF index 94fbedc2f6..ce43da95a7 100644 --- a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF @@ -3,6 +3,13 @@ Bundle-ManifestVersion: 2 Bundle-Name: bnd-maven-plugin integration Bundle-SymbolicName: org.eclipse.m2e.bnd.ui Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.equinox.common, + org.eclipse.core.resources, + biz.aQute.bndlib, + 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 diff --git a/org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore b/org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore new file mode 100644 index 0000000000..b878e882ac --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/OSGI-INF/.gitignore @@ -0,0 +1 @@ +/*.xml diff --git a/org.eclipse.m2e.bnd.ui/build.properties b/org.eclipse.m2e.bnd.ui/build.properties index 34d2e4d2da..c58ea2178c 100644 --- a/org.eclipse.m2e.bnd.ui/build.properties +++ b/org.eclipse.m2e.bnd.ui/build.properties @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + OSGI-INF/ diff --git a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java new file mode 100644 index 0000000000..96e20575ac --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java @@ -0,0 +1,49 @@ +package org.eclipse.m2e.bnd.ui; + +import java.util.List; +import java.util.Map; + +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; + +/** + * 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 getAdapter(Object adaptableObject, Class adapterType) { + if (adaptableObject instanceof IProject eclipseProject) { + IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class); + if (isRelevantProject(mavenProject)) { + System.out.println(eclipseProject.getName() + " uses bnd plugin!"); + } + } + return null; + } + + private boolean isRelevantProject(IMavenProjectFacade mavenProject) { + // TODO cache result inside IProject store + if (mavenProject != null) { + Map> 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; + } + +} From ddb603be9f55202a3be4b9e9d2b2c81ad0a9ed0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 11 Jul 2024 07:57:55 +0200 Subject: [PATCH 3/7] Setup basic properties and return as project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF | 4 +- .../eclipse/m2e/bnd/ui/BndPluginAdapter.java | 69 +++++++++++++++++-- target-platform/target-platform.target | 25 +++++-- 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF index ce43da95a7..70bd69be7a 100644 --- a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF @@ -3,9 +3,11 @@ 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.osgi;version="[7.0.0,8.0.0)" Require-Bundle: org.eclipse.equinox.common, org.eclipse.core.resources, - biz.aQute.bndlib, org.eclipse.m2e.core, org.eclipse.m2e.maven.runtime Service-Component: OSGI-INF/org.eclipse.m2e.bnd.ui.BndPluginAdapter.xml diff --git a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java index 96e20575ac..bad17e7aff 100644 --- a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java +++ b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java @@ -1,8 +1,22 @@ +/******************************************************************************* + * 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.util.List; import java.util.Map; +import java.util.Properties; +import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.AdapterTypes; import org.eclipse.core.runtime.Adapters; @@ -13,21 +27,63 @@ 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.osgi.Processor; /** * Adapts eclipse projects managed by m2e to bnd projects */ @Component @AdapterTypes(adaptableClass = IProject.class, adapterNames = Project.class) -public class BndPluginAdapter implements IAdapterFactory{ +public class BndPluginAdapter implements IAdapterFactory { @Override public T getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof IProject eclipseProject) { - IMavenProjectFacade mavenProject = Adapters.adapt(eclipseProject, IMavenProjectFacade.class); - if (isRelevantProject(mavenProject)) { - System.out.println(eclipseProject.getName() + " uses bnd plugin!"); + 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); + + // TODO propertiesFile = new BndConfiguration(project, + // mojoExecution).loadProperties(builder); + + Workspace standaloneWorkspace = Workspace.createStandaloneWorkspace(processor, + mavenProject.getPomFile().getParentFile().toURI()); + 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); + } + } + Project bndProject = new Project(standaloneWorkspace, null, null); + bndProject.setBase(null); + return adapterType.cast(bndProject); + } + } } + } catch (Exception e) { + e.printStackTrace(); } return null; } @@ -35,8 +91,7 @@ public T getAdapter(Object adaptableObject, Class adapterType) { private boolean isRelevantProject(IMavenProjectFacade mavenProject) { // TODO cache result inside IProject store if (mavenProject != null) { - Map> mapping = mavenProject - .getMojoExecutionMapping(); + Map> mapping = mavenProject.getMojoExecutionMapping(); for (MojoExecutionKey key : mapping.keySet()) { if ("biz.aQute.bnd".equals(key.groupId()) && "bnd-maven-plugin".equals(key.artifactId())) { return true; diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 96f134caac..09d151a2a1 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -33,17 +33,23 @@ +<<<<<<< Upstream, based on master +======= + + + + + +>>>>>>> a1e492d Setup basic properties and return as project - + + - - - - + @@ -67,6 +73,12 @@ + + biz.aQute.bnd + biz.aQute.bnd.maven + 7.0.0 + jar + com.google.code.gson gson @@ -105,8 +117,7 @@ - - + io.takari.m2e.workspace From cd90ffe4049d814566261ac295d82d7c02895535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 11 Jul 2024 09:02:04 +0200 Subject: [PATCH 4/7] Add mavenproject artifacts as implicit repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF | 4 +++- .../eclipse/m2e/bnd/ui/BndPluginAdapter.java | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF index 70bd69be7a..69c958f9ac 100644 --- a/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.bnd.ui/META-INF/MANIFEST.MF @@ -5,7 +5,9 @@ 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.osgi;version="[7.0.0,8.0.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, diff --git a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java index bad17e7aff..3dee965432 100644 --- a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java +++ b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/BndPluginAdapter.java @@ -12,10 +12,14 @@ *******************************************************************************/ 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; @@ -29,6 +33,7 @@ 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; /** @@ -60,12 +65,21 @@ public T getAdapter(Object adaptableObject, Class adapterType) { } } Processor processor = new Processor(processorProperties, false); - + Collection list = new ArrayList(); + 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 { @@ -76,6 +90,7 @@ public T getAdapter(Object adaptableObject, Class adapterType) { standaloneWorkspace.set("workspaceDescription", description); } } + standaloneWorkspace.refresh(); Project bndProject = new Project(standaloneWorkspace, null, null); bndProject.setBase(null); return adapterType.cast(bndProject); From b9662aad6b26543d8b46b4dae528064c08eaaa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 27 Oct 2024 13:06:56 +0100 Subject: [PATCH 5/7] Rebase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- target-platform/target-platform.target | 31 +++++++++++--------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 09d151a2a1..b3b0ff35d5 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -33,23 +33,17 @@ -<<<<<<< Upstream, based on master -======= - - - - - ->>>>>>> a1e492d Setup basic properties and return as project - - - + + + + + @@ -73,12 +67,6 @@ - - biz.aQute.bnd - biz.aQute.bnd.maven - 7.0.0 - jar - com.google.code.gson gson @@ -115,9 +103,16 @@ 3.17.0 jar + + biz.aQute.bnd + biz.aQute.bnd.maven + 7.0.0 + jar + - + + io.takari.m2e.workspace From 5ba1378319f7907a5893d50f5bd93fcde5bd1b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 27 Oct 2024 15:37:53 +0100 Subject: [PATCH 6/7] Add a first POC for bnd autocompletion on pom files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- org.eclipse.m2e.lemminx.bnd/.classpath | 41 ++++++ org.eclipse.m2e.lemminx.bnd/.project | 23 ++++ .../.settings/org.eclipse.jdt.core.prefs | 8 ++ .../.settings/org.eclipse.m2e.core.prefs | 4 + org.eclipse.m2e.lemminx.bnd/pom.xml | 47 +++++++ .../m2e/lemminx/bnd/BndLemminxPlugin.java | 122 ++++++++++++++++++ ....lemminx.services.extensions.IXMLExtension | 1 + pom.xml | 2 + 8 files changed, 248 insertions(+) create mode 100644 org.eclipse.m2e.lemminx.bnd/.classpath create mode 100644 org.eclipse.m2e.lemminx.bnd/.project create mode 100644 org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.m2e.core.prefs create mode 100644 org.eclipse.m2e.lemminx.bnd/pom.xml create mode 100644 org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java create mode 100644 org.eclipse.m2e.lemminx.bnd/src/main/resources/META-INF/services/org.eclipse.lemminx.services.extensions.IXMLExtension diff --git a/org.eclipse.m2e.lemminx.bnd/.classpath b/org.eclipse.m2e.lemminx.bnd/.classpath new file mode 100644 index 0000000000..5d5961d093 --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/.classpath @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.m2e.lemminx.bnd/.project b/org.eclipse.m2e.lemminx.bnd/.project new file mode 100644 index 0000000000..2e7c35044e --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/.project @@ -0,0 +1,23 @@ + + + org.eclipse.m2e.lemminx.bnd + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..68472858a2 --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..f897a7f1cb --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/org.eclipse.m2e.lemminx.bnd/pom.xml b/org.eclipse.m2e.lemminx.bnd/pom.xml new file mode 100644 index 0000000000..837ad3895b --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + + + + + org.eclipse.m2e.lemminx.bnd + org.eclipse.m2e.lemminx.bnd + 2.1.0-SNAPSHOT + M2E bnd lemminx extension + + + 17 + ${java.version} + + + + + + org.eclipse.lemminx + org.eclipse.lemminx + 0.28.0 + provided + + + biz.aQute.bnd + biz.aQute.bndlib + 7.0.0 + + + + + + lemminx-releases + https://repo.eclipse.org/content/repositories/lemminx-releases/ + + false + + + true + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java b/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java new file mode 100644 index 0000000000..cbc9ab8904 --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * 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.lemminx.bnd; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.lemminx.dom.DOMDocument; +import org.eclipse.lemminx.dom.DOMNode; +import org.eclipse.lemminx.services.extensions.IXMLExtension; +import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; +import org.eclipse.lemminx.services.extensions.completion.ICompletionParticipant; +import org.eclipse.lemminx.services.extensions.completion.ICompletionRequest; +import org.eclipse.lemminx.services.extensions.completion.ICompletionResponse; +import org.eclipse.lemminx.services.extensions.save.ISaveContext; +import org.eclipse.lsp4j.CompletionItem; +import org.eclipse.lsp4j.InitializeParams; +import org.eclipse.lsp4j.jsonrpc.CancelChecker; + +import aQute.bnd.help.Syntax; + +public class BndLemminxPlugin implements IXMLExtension { + + // TODO LemminxClasspathExtensionProvider that puts our jar on the classpath + + // bnd dependencies! + + @Override + public void start(InitializeParams params, XMLExtensionsRegistry registry) { + Logger logger = Logger.getLogger("bnd"); + logger.log(Level.INFO, "Hello From BND Extension"); + registry.registerCompletionParticipant(new ICompletionParticipant() { + + @Override + public void onAttributeName(boolean arg0, ICompletionRequest arg1, ICompletionResponse arg2, + CancelChecker arg3) throws Exception { + } + + @Override + public void onAttributeValue(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, + CancelChecker arg3) throws Exception { + } + + @Override + public void onDTDSystemId(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, + CancelChecker arg3) throws Exception { + } + + @Override + public void onTagOpen(ICompletionRequest arg0, ICompletionResponse arg1, CancelChecker arg2) + throws Exception { + } + + @Override + public void onXMLContent(ICompletionRequest completionRequest, ICompletionResponse response, + CancelChecker checker) throws Exception { + try { + // FIXME CDATA do not trigger completion: + // https://github.com/eclipse/lemminx/issues/1694 + DOMDocument xmlDocument = completionRequest.getXMLDocument(); + DOMNode node = xmlDocument.findNodeBefore(completionRequest.getOffset()); + if (isBndNode(node)) { + // FIXME get the text to give better completion proposals, see: + // https://github.com/eclipse/lemminx/issues/1695 +// if (node != null && node.getNodeName().equals("bnd")) { +// logger.log(Level.INFO, "text content=" + node.getTextContent()); +// String substring = xmlDocument.getText().substring(node.getStart(), node.getEnd()); +// logger.log(Level.INFO, "substring=" + substring); +// } else { +// logger.log(Level.INFO, +// "node=" + node + ", start=" + node.getStart() + ", end=" + node.getEnd() +// + " --> text content=" + node.getTextContent()); +// +// // Syntax.HELP.values().stream().map(syntax -> { +// } + Syntax.HELP.values().stream().forEach(syntax -> { + CompletionItem item = new CompletionItem(); + item.setLabel(syntax.getHeader()); + item.setInsertText(syntax.getHeader() + ": "); + response.addCompletionItem(item); + }); + } + } catch (Exception e) { + logger.log(Level.INFO, "err=" + e); + } + } + + private boolean isBndNode(DOMNode node) { + if (node != null) { + if (node.getNodeName().equals("bnd")) { + return true; + } + return isBndNode(node.getParentNode()); + } + return false; + } + + }); + } + + @Override + public void stop(XMLExtensionsRegistry registry) { + // TODO Auto-generated method stub + + } + + @Override + public void doSave(ISaveContext context) { + // TODO Auto-generated method stub + IXMLExtension.super.doSave(context); + } + +} \ No newline at end of file diff --git a/org.eclipse.m2e.lemminx.bnd/src/main/resources/META-INF/services/org.eclipse.lemminx.services.extensions.IXMLExtension b/org.eclipse.m2e.lemminx.bnd/src/main/resources/META-INF/services/org.eclipse.lemminx.services.extensions.IXMLExtension new file mode 100644 index 0000000000..08c100d454 --- /dev/null +++ b/org.eclipse.m2e.lemminx.bnd/src/main/resources/META-INF/services/org.eclipse.lemminx.services.extensions.IXMLExtension @@ -0,0 +1 @@ +org.eclipse.m2e.lemminx.bnd.BndLemminxPlugin \ No newline at end of file diff --git a/pom.xml b/pom.xml index a4930719f5..3549a3b272 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,8 @@ org.eclipse.m2e.apt.core org.eclipse.m2e.apt.ui org.eclipse.m2e.mavenarchiver + org.eclipse.m2e.bnd.ui + org.eclipse.m2e.lemminx.bnd org.eclipse.m2e.tests.common From 9e1f790f0d24a3a68926f116dd1554b17dd97b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 14 Nov 2024 09:55:21 +0100 Subject: [PATCH 7/7] Add example of extension in regular bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- org.eclipse.m2e.bnd.ui/build.properties | 1 + .../m2e/bnd/ui/lemminx/MyExtension.java | 21 +++++++++++++++++++ .../org.eclipse.pde.ds.annotations.prefs | 2 +- .../m2e/lemminx/bnd/BndLemminxPlugin.java | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/lemminx/MyExtension.java diff --git a/org.eclipse.m2e.bnd.ui/build.properties b/org.eclipse.m2e.bnd.ui/build.properties index c58ea2178c..d5ed28ecef 100644 --- a/org.eclipse.m2e.bnd.ui/build.properties +++ b/org.eclipse.m2e.bnd.ui/build.properties @@ -3,3 +3,4 @@ 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 diff --git a/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/lemminx/MyExtension.java b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/lemminx/MyExtension.java new file mode 100644 index 0000000000..659eaddd9a --- /dev/null +++ b/org.eclipse.m2e.bnd.ui/src/org/eclipse/m2e/bnd/ui/lemminx/MyExtension.java @@ -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 + + } + +} diff --git a/org.eclipse.m2e.core/.settings/org.eclipse.pde.ds.annotations.prefs b/org.eclipse.m2e.core/.settings/org.eclipse.pde.ds.annotations.prefs index 73a356b6d0..19be1e2fb6 100644 --- a/org.eclipse.m2e.core/.settings/org.eclipse.pde.ds.annotations.prefs +++ b/org.eclipse.m2e.core/.settings/org.eclipse.pde.ds.annotations.prefs @@ -1,5 +1,5 @@ classpath=true -dsVersion=V1_3 +dsVersion=V1_5 eclipse.preferences.version=1 enabled=true generateBundleActivationPolicyLazy=true diff --git a/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java b/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java index cbc9ab8904..5aa3aa0cb4 100644 --- a/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java +++ b/org.eclipse.m2e.lemminx.bnd/src/main/java/org/eclipse/m2e/lemminx/bnd/BndLemminxPlugin.java @@ -43,26 +43,32 @@ public void start(InitializeParams params, XMLExtensionsRegistry registry) { @Override public void onAttributeName(boolean arg0, ICompletionRequest arg1, ICompletionResponse arg2, CancelChecker arg3) throws Exception { + logger.log(Level.INFO, "onAttributeName"); } @Override public void onAttributeValue(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, CancelChecker arg3) throws Exception { + logger.log(Level.INFO, "onAttributeValue"); } @Override public void onDTDSystemId(String arg0, ICompletionRequest arg1, ICompletionResponse arg2, CancelChecker arg3) throws Exception { + logger.log(Level.INFO, "onDTDSystemId"); } @Override public void onTagOpen(ICompletionRequest arg0, ICompletionResponse arg1, CancelChecker arg2) throws Exception { + logger.log(Level.INFO, "onTagOpen"); } @Override public void onXMLContent(ICompletionRequest completionRequest, ICompletionResponse response, CancelChecker checker) throws Exception { + + logger.log(Level.INFO, "onXMLContent"); try { // FIXME CDATA do not trigger completion: // https://github.com/eclipse/lemminx/issues/1694