You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2023/07/14 10:34:08 UTC

[sling-slingfeature-maven-plugin] branch master updated: SLING-11947 Convert Plexus to JSR 330 components

This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 15be440  SLING-11947 Convert Plexus to JSR 330 components
15be440 is described below

commit 15be440adfc046f859a68203a74eace080a1740e
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jul 12 19:50:27 2023 +0200

    SLING-11947 Convert Plexus to JSR 330 components
---
 pom.xml                                            | 51 ++++++++++++--
 .../DependencyLifecycleParticipant.java            | 28 +++++---
 .../maven/extensions/FeatureArtifactHandler.java   | 35 ++++++++++
 .../FeatureLifecycleMappingProvider.java           | 80 ++++++++++++++++++++++
 src/main/resources/META-INF/plexus/components.xml  | 51 --------------
 src/site/markdown/index.md                         | 24 ++++++-
 6 files changed, 202 insertions(+), 67 deletions(-)

diff --git a/pom.xml b/pom.xml
index 83a5290..cb7dbc4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,14 +49,14 @@
     <build>
         <plugins>
             <plugin>
-                <groupId>org.codehaus.plexus</groupId>
-                <artifactId>plexus-component-metadata</artifactId>
-                <version>2.1.0</version>
+                <groupId>org.eclipse.sisu</groupId>
+                <artifactId>sisu-maven-plugin</artifactId>
+                <version>0.3.5</version>
                 <executions>
                     <execution>
-                        <id>generate-metadata</id>
+                        <id>index-project</id>
                         <goals>
-                            <goal>generate-metadata</goal>
+                            <goal>main-index</goal>
                         </goals>
                     </execution>
                 </executions>
@@ -102,6 +102,42 @@
                     </excludes>
                 </configuration>
             </plugin>
+            <plugin><!-- prepare site content by filtering ${project.*} values -->
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>filter-site</id>
+                        <phase>pre-site</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/site-src</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>src/site</directory>
+                                    <filtering>true</filtering>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>default-testResources</id>
+                        <configuration>
+                            <!-- copy .gitignore as well -->
+                            <addDefaultExcludes>false</addDefaultExcludes>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-site-plugin</artifactId>
+                <configuration>
+                    <siteDirectory>${project.build.directory}/site-src</siteDirectory>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-invoker-plugin</artifactId>
@@ -275,6 +311,11 @@
             <artifactId>maven-plugin-annotations</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+            <scope>provided</scope>
+        </dependency>
         <!-- for converting Maven to OSGi versions -->
         <dependency>
             <groupId>biz.aQute.bnd</groupId>
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/DependencyLifecycleParticipant.java b/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
similarity index 82%
rename from src/main/java/org/apache/sling/feature/maven/mojos/DependencyLifecycleParticipant.java
rename to src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
index 48b6123..41dea45 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/DependencyLifecycleParticipant.java
+++ b/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
@@ -14,7 +14,11 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.sling.feature.maven.mojos;
+package org.apache.sling.feature.maven.extensions;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
 
 import org.apache.maven.AbstractMavenLifecycleParticipant;
 import org.apache.maven.MavenExecutionException;
@@ -26,14 +30,13 @@ import org.apache.maven.project.MavenProject;
 import org.apache.sling.feature.maven.Environment;
 import org.apache.sling.feature.maven.FeatureProjectInfo;
 import org.apache.sling.feature.maven.Preprocessor;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.Logger;
 
 /**
  * Maven lifecycle participant which adds the artifacts of the model to the dependencies.
  */
-@Component(role = AbstractMavenLifecycleParticipant.class, hint = "featureparticipant")
+@Named("featureparticipant")
+@Singleton
 public class DependencyLifecycleParticipant extends AbstractMavenLifecycleParticipant {
 
     /**
@@ -41,18 +44,23 @@ public class DependencyLifecycleParticipant extends AbstractMavenLifecyclePartic
      */
     private static final String PLUGIN_ID = "org.apache.sling:slingfeature-maven-plugin";
 
-    @Requirement
-    private Logger logger;
+    private final Logger logger;
 
-    @Requirement
-    private ArtifactHandlerManager artifactHandlerManager;
+    private final ArtifactHandlerManager artifactHandlerManager;
 
     /**
      * Used to look up Artifacts in the remote repository.
      *
      */
-    @Requirement
-    private ArtifactResolver resolver;
+    private final ArtifactResolver resolver;
+
+    @Inject
+    public DependencyLifecycleParticipant(Logger logger, ArtifactHandlerManager artifactHandlerManager, ArtifactResolver resolver) {
+        super();
+        this.logger = logger;
+        this.artifactHandlerManager = artifactHandlerManager;
+        this.resolver = resolver;
+    }
 
     @Override
     public void afterProjectsRead(final MavenSession session) throws MavenExecutionException {
diff --git a/src/main/java/org/apache/sling/feature/maven/extensions/FeatureArtifactHandler.java b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureArtifactHandler.java
new file mode 100644
index 0000000..1c44303
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureArtifactHandler.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.sling.feature.maven.extensions;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+
+@Singleton
+@Named("slingosgifeature")
+public class FeatureArtifactHandler extends DefaultArtifactHandler {
+
+    public FeatureArtifactHandler() {
+        super("slingosgifeature");
+        setIncludesDependencies(false);
+        setExtension("slingosgifeature");
+        setLanguage("json");
+        setAddedToClasspath(false);
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
new file mode 100644
index 0000000..303f0d6
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.feature.maven.extensions;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.apache.maven.lifecycle.mapping.Lifecycle;
+import org.apache.maven.lifecycle.mapping.LifecycleMapping;
+import org.apache.maven.lifecycle.mapping.LifecyclePhase;
+
+@Singleton
+@Named("slingosgifeature")
+public class FeatureLifecycleMappingProvider implements Provider<LifecycleMapping> {
+
+    private static final String DEFAULT_LIFECYCLE_KEY = "default";
+    private static final Map<String, LifecyclePhase> BINDINGS;
+    static {
+        BINDINGS = new HashMap<>();
+        BINDINGS.put("install", new LifecyclePhase("org.apache.sling:slingfeature-maven-plugin:attach-features,org.apache.maven.plugins:maven-install-plugin:install"));
+        BINDINGS.put("deploy", new LifecyclePhase("org.apache.maven.plugins:maven-deploy-plugin:deploy"));
+    }
+
+    private final Lifecycle defaultLifecycle;
+
+    private final LifecycleMapping lifecycleMapping;
+
+    public FeatureLifecycleMappingProvider() {
+        this.defaultLifecycle = new Lifecycle();
+        this.defaultLifecycle.setId(DEFAULT_LIFECYCLE_KEY);
+        this.defaultLifecycle.setLifecyclePhases(BINDINGS);
+
+        this.lifecycleMapping = new LifecycleMapping() {
+            @Override
+            public Map<String, Lifecycle> getLifecycles() {
+                return Collections.singletonMap(DEFAULT_LIFECYCLE_KEY, defaultLifecycle);
+            }
+
+            @Override
+            public List<String> getOptionalMojos(String lifecycle) {
+                return null;
+            }
+
+            @Override
+            public Map<String, String> getPhases(String lifecycle) {
+                if (DEFAULT_LIFECYCLE_KEY.equals(lifecycle)) {
+                    return defaultLifecycle.getPhases();
+                } else {
+                    return null;
+                }
+            }
+        };
+    }
+
+    @Override
+    public LifecycleMapping get() {
+        return lifecycleMapping;
+    }
+
+}
diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index ec16393..0000000
--- a/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<component-set>
-  <components>
-    <component>
-      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
-      <role-hint>slingosgifeature</role-hint>
-      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
-      <configuration>
-        <lifecycles>
-          <lifecycle>
-            <id>default</id>
-            <phases>
-              <install>org.apache.sling:slingfeature-maven-plugin:attach-features,
-                       org.apache.maven.plugins:maven-install-plugin:install</install>
-              <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
-            </phases>
-          </lifecycle>
-        </lifecycles>
-      </configuration>
-    </component>
-    <component>
-      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
-      <role-hint>slingosgifeature</role-hint>
-      <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
-      <configuration>
-        <type>slingosgifeature</type>
-        <includesDependencies>false</includesDependencies>
-        <language>json</language>
-        <extension>slingosgifeature</extension>
-        <addedToClasspath>false</addedToClasspath>
-      </configuration>
-    </component>
-  </components>
-</component-set>
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index afe6a1c..159af25 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -5,5 +5,27 @@ Maven Plugin for building OSGi features and applications.
 
 See [Goals](plugin-info.html) for a list of supported goals.
 
-### Usage
+## Usage
+
+As this Maven plugin comes with [Maven extensions](https://maven.apache.org/guides/mini/guide-using-extensions.html) (for defining custom bindings for `default` lifecycle and a custom artifact handler for type/packaging `slingosgifeature` as well as a `AbstractMavenLifecycleParticipant`) it needs to be loaded accordingly
+
+```
+<plugin>
+  <groupId>${project.groupId}</groupId>
+  <artifactId>${project.artifactId}</artifactId>
+  <version>${project.version}</version>
+  <extensions>true</extensions>
+</plugin>
+```
+
 Additional Documentation can be found in the [README](https://github.com/apache/sling-slingfeature-maven-plugin/blob/master/README.md) page.
+
+## Plugin bindings for `slingosgifeature` packaging
+
+```
+<phases>
+  <install>org.apache.sling:slingfeature-maven-plugin:attach-features,
+           org.apache.maven.plugins:maven-install-plugin:install</install>
+  <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
+</phases>
+```
\ No newline at end of file