You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2018/10/15 14:06:51 UTC

[sling-slingfeature-maven-plugin] branch issues/SLING-8013 created (now 1d45820)

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

pauls pushed a change to branch issues/SLING-8013
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git.


      at 1d45820  SLING-8013: Take all features into account when building repositories and allow to pick specific features plus extra artifacts.

This branch includes the following new commits:

     new 1d45820  SLING-8013: Take all features into account when building repositories and allow to pick specific features plus extra artifacts.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-slingfeature-maven-plugin] 01/01: SLING-8013: Take all features into account when building repositories and allow to pick specific features plus extra artifacts.

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch issues/SLING-8013
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit 1d45820afbda4ebf17bdfc8a6a3ac64c63bd4b5a
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Mon Oct 15 16:03:48 2018 +0200

    SLING-8013: Take all features into account when building repositories and allow to pick specific features plus extra artifacts.
---
 .../sling/feature/maven/mojos/RepositoryMojo.java  | 112 +++++++++++++++++----
 1 file changed, 92 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
index 4f04011..1d8830e 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
@@ -22,7 +22,10 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
@@ -35,6 +38,7 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
@@ -59,6 +63,12 @@ public class RepositoryMojo extends AbstractFeatureMojo {
     @Parameter(defaultValue = "artifacts")
     private String repositoryDir;
 
+    @Parameter
+    private List<Include> includes;
+
+    @Parameter
+    private List<Include> embed;
+
     @Component
     private ArtifactHandlerManager artifactHandlerManager;
 
@@ -74,21 +84,46 @@ public class RepositoryMojo extends AbstractFeatureMojo {
         final File artifactDir = new File(this.project.getBuild().getDirectory(), repositoryDir);
         this.getLog().info("Creating repository in '" + artifactDir.getPath() + "'...");
 
-        final Map<String, org.apache.sling.feature.Feature> features = ProjectHelper.getAssembledFeatures(this.project);
+        final Map<String, org.apache.sling.feature.Feature> features = ProjectHelper.getFeatures(this.project);
+        features.putAll(ProjectHelper.getAssembledFeatures(this.project));
 
-        for(final Feature f : features.values()) {
-            processFeature(artifactDir, f);
+        final Set<ArtifactId> includedIds = new HashSet<>();
+
+        if (includes != null && !includes.isEmpty()) {
+            for (Include include : includes) {
+                boolean found = false;
+                for (Feature f : features.values()) {
+                    if (f.getId().equals(include.getID())) {
+                        processFeature(artifactDir, f);
+                        found = true;
+                    }
+                }
+                if (!found) {
+                    processRemoteFeature(artifactDir, include.getID());
+                }
+            }
+        }
+        else {
+            for (final Feature f : features.values())
+            {
+                processFeature(artifactDir, f);
+            }
+        }
+        if (embed != null) {
+            for (Include include : embed) {
+                copyArtifactToRepository(include.getID(), artifactDir);
+            }
         }
     }
 
     private void processFeature(final File artifactDir, final Feature f) throws MojoExecutionException {
         for(final org.apache.sling.feature.Artifact artifact : f.getBundles()) {
-            copyArtifactToRepository(artifact, artifactDir);
+            copyArtifactToRepository(artifact.getId(), artifactDir);
         }
         for(final Extension ext : f.getExtensions()) {
             if ( ext.getType() == ExtensionType.ARTIFACTS ) {
                 for(final org.apache.sling.feature.Artifact artifact : ext.getArtifacts()) {
-                    copyArtifactToRepository(artifact, artifactDir);
+                    copyArtifactToRepository(artifact.getId(), artifactDir);
                 }
             }
         }
@@ -101,18 +136,22 @@ public class RepositoryMojo extends AbstractFeatureMojo {
             throw new MojoExecutionException("Unable to write feature file ", e);
         }
         if ( f.getInclude() != null ) {
-            final Artifact source = ProjectHelper.getOrResolveArtifact(this.project,
-                    this.mavenSession,
-                    this.artifactHandlerManager,
-                    this.resolver,
-                    f.getInclude().getId());
-
-            try (final Reader reader = new FileReader(source.getFile()) ) {
-                final Feature inc = FeatureJSONReader.read(reader, f.getId().toMvnId());
-                processFeature(artifactDir, inc);
-            } catch (final IOException e) {
-                throw new MojoExecutionException("Unable to read feature file ", e);
-            }
+            processRemoteFeature(artifactDir, f.getInclude().getId());
+        }
+    }
+
+    private void processRemoteFeature(final File artifactDir, final ArtifactId id) throws MojoExecutionException {
+        final Artifact source = ProjectHelper.getOrResolveArtifact(this.project,
+            this.mavenSession,
+            this.artifactHandlerManager,
+            this.resolver,
+            id);
+
+        try (final Reader reader = new FileReader(source.getFile()) ) {
+            final Feature inc = FeatureJSONReader.read(reader, id.toMvnId());
+            processFeature(artifactDir, inc);
+        } catch (final IOException e) {
+            throw new MojoExecutionException("Unable to read feature file ", e);
         }
     }
 
@@ -155,10 +194,10 @@ public class RepositoryMojo extends AbstractFeatureMojo {
      * Copy a single artifact to the repository
      * @throws MojoExecutionException
      */
-    private void copyArtifactToRepository(final org.apache.sling.feature.Artifact artifact,
+    private void copyArtifactToRepository(final ArtifactId artifactId,
             final File artifactDir)
     throws MojoExecutionException {
-        final File artifactFile = getRepositoryFile(artifactDir, artifact.getId());
+        final File artifactFile = getRepositoryFile(artifactDir, artifactId);
         // TODO - we could overwrite snapshots?
         if ( artifactFile.exists() ) {
             return;
@@ -167,7 +206,7 @@ public class RepositoryMojo extends AbstractFeatureMojo {
                 this.mavenSession,
                 this.artifactHandlerManager,
                 this.resolver,
-                artifact.getId());
+                artifactId);
 
         try {
             FileUtils.copyFile(source.getFile(), artifactFile);
@@ -175,4 +214,37 @@ public class RepositoryMojo extends AbstractFeatureMojo {
             throw new MojoExecutionException("Unable to copy artifact from " + source.getFile(), e);
         }
     }
+
+    public static class Include {
+        String groupId;
+        String artifactId;
+        String version;
+        String type;
+        String classifier;
+
+        public void setGroupId(String gid) {
+            groupId = gid;
+        }
+
+        public void setArtifactId(String aid) {
+            artifactId = aid;
+        }
+
+        public void setVersion(String ver) {
+            version = ver;
+        }
+
+        public void setType(String t) {
+            type = t;
+        }
+
+        public void setClassifier(String clf) {
+            classifier = clf;
+        }
+
+        public ArtifactId getID()
+        {
+            return new ArtifactId(groupId, artifactId, version, classifier, type);
+        }
+    }
 }