jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1828391 - in /jackrabbit/commons/filevault-package-maven-plugin/trunk: ./ src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ src/test/java/org/apache/jackrabbit/filevault/maven/packaging/
Date Thu, 05 Apr 2018 00:31:24 GMT
Author: tripod
Date: Thu Apr  5 00:31:23 2018
New Revision: 1828391

URL: http://svn.apache.org/viewvc?rev=1828391&view=rev
Log:
JCRVLT-274 Support multiple types and classifiers as filter within embedded/subpackage section
(Fixes #12)

Added:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbedded.java
      - copied, changed from r1828296, jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java
Modified:
    jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/CheckSignatureMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/Embedded.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
    jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml?rev=1828391&r1=1828390&r2=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml (original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/pom.xml Thu Apr  5 00:31:23 2018
@@ -383,7 +383,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.10</version>
+            <version>4.12</version>
             <scope>test</scope>
         </dependency>
         <dependency>

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/CheckSignatureMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/CheckSignatureMojo.java?rev=1828391&r1=1828390&r2=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/CheckSignatureMojo.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/CheckSignatureMojo.java
Thu Apr  5 00:31:23 2018
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.filevault.
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -179,7 +178,7 @@ public class CheckSignatureMojo extends
     private Collection<File> getEmbeddeds() throws MojoFailureException {
         Set<File> files = new HashSet<File>();
         for (Embedded emb : embeddeds) {
-            final List<Artifact> artifacts = emb.getMatchingArtifacts(project);
+            final Collection<Artifact> artifacts = emb.getMatchingArtifacts(project);
             if (artifacts.isEmpty()) {
                 if (failOnMissingEmbed) {
                     throw new MojoFailureException(

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/Embedded.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/Embedded.java?rev=1828391&r1=1828390&r2=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/Embedded.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/Embedded.java
Thu Apr  5 00:31:23 2018
@@ -16,15 +16,6 @@
  */
 package org.apache.jackrabbit.filevault.maven.packaging;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jackrabbit.filevault.maven.packaging.impl.StringFilterSet;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.project.MavenProject;
-
 /**
  * The {@code Embedded} class represents an embedded artifact dependency
  * from the project descriptor. Such an embedding is declared in
@@ -35,35 +26,14 @@ import org.apache.maven.project.MavenPro
  *     &lt;groupId&gt;artifact.groupId.pattern&lt;/groupId&gt;
  *     &lt;artifactId&gt;artifact.artifactId.pattern&lt;/artifactId&gt;
  *     &lt;scope&gt;compile&lt;/scope&gt;
- *     &lt;type&gt;jar&lt;/type&gt;
- *     &lt;classifier&gt;sources&lt;/classifier&gt;
+ *     &lt;type&gt;artifact.type.pattern&lt;/type&gt;
+ *     &lt;classifier&gt;artifact.classifier.pattern&lt;/classifier&gt;
  *     &lt;filter&gt;true&lt;/filter&gt;
  *     &lt;target&gt;/libs/sling/install&lt;/target&gt;
  * &lt;/embedded&gt;
  * </pre>
  */
-public class Embedded {
-
-    /**
-     * A group filter string, consisted of one or several comma separated patterns.
-     */
-    private final StringFilterSet groupId = new StringFilterSet();
-
-    /**
-     * A artifact filter string, consisted of one or several comma separated patterns.
-     */
-    private final StringFilterSet artifactId = new StringFilterSet();
-
-    private ScopeArtifactFilter scope;
-
-    private String type;
-
-    private String classifier;
-
-    /**
-     * If {@code true} a filter entry will be generated for all embedded artifacts.
-     */
-    private boolean filter;
+public class Embedded extends SimpleEmbedded{
 
     /**
      * Target location.
@@ -75,28 +45,6 @@ public class Embedded {
      */
     private String destFileName;
 
-    private boolean excludeTransitive;
-
-    public void setGroupId(String groupId) {
-        this.groupId.addEntries(groupId);
-    }
-
-    public void setArtifactId(String artifactId) {
-        this.artifactId.addEntries(artifactId);
-    }
-
-    public void setScope(String scope) {
-        this.scope = new ScopeArtifactFilter(scope);
-    }
-
-    public void setAddFilter(boolean filter) {
-        this.filter = filter;
-    }
-
-    public boolean isFilter() {
-        return filter;
-    }
-
     public String getDestFileName() {
         return destFileName;
     }
@@ -118,50 +66,10 @@ public class Embedded {
         return target;
     }
 
-    public void setExcludeTransitive(boolean excludeTransitive) {
-        this.excludeTransitive = excludeTransitive;
-    }
-
-    public boolean isExcludeTransitive() {
-        return excludeTransitive;
-    }
-
-    public List<Artifact> getMatchingArtifacts(final MavenProject project) {
-
-        // get artifacts depending on whether we exclude transitives or not
-        final Set<Artifact> deps;
-        if (excludeTransitive) {
-            // only direct dependencies, transitives excluded
-            deps = project.getDependencyArtifacts();
-        } else {
-            // all dependencies, transitives included
-            deps = project.getArtifacts();
-        }
-
-        final List<Artifact> matches = new ArrayList<Artifact>();
-        for (Artifact artifact : deps) {
-            if (groupId.contains(artifact.getGroupId())
-                    && artifactId.contains(artifact.getArtifactId())
-                    && (scope == null || scope.include(artifact))
-                    && (type == null || type.equals(artifact.getType()))
-                    && (classifier == null || classifier.equals(artifact.getClassifier())))
{
-                matches.add(artifact);
-            }
-        }
-        return matches;
-    }
-
     public String toString() {
         final StringBuilder builder = new StringBuilder();
         builder.append("Embedded: ");
-        builder.append("groupId=").append(groupId).append(",");
-        builder.append("artifactId=").append(artifactId).append(",");
-
-        if (scope != null) {
-            builder.append("scope=").append(scope).append(",");
-        }
-        builder.append("filter=").append(filter);
-        builder.append(",excludeTransitive=").append(excludeTransitive);
+        super.toString(builder);
         if (target != null) {
             builder.append(",target=").append(target);
         }
@@ -170,4 +78,5 @@ public class Embedded {
         }
         return builder.toString();
     }
+
 }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java?rev=1828391&r1=1828390&r2=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/GenerateMetadataMojo.java
Thu Apr  5 00:31:23 2018
@@ -25,6 +25,7 @@ import java.nio.file.Files;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -277,16 +278,21 @@ public class GenerateMetadataMojo extend
      * Each {@code <embedded>} element may configure any of the following fields
      *  <p>
      * <table>
-     * <tr><td>groupId</td><td>String</td><td>Filter
criterion against the group id of a project dependency. A pattern of format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
Each {@code filter} is a string which is either an exclude (if it starts with a {@code ~})
or an include otherwise. If the first {@code filter} is an include the pattern acts as whitelist,
otherwise as blacklist. The last matching filter determines the outcome. Only matching group
ids are being considered for being embedded.</td></tr>
-     * <tr><td>artifactId</td><td>String</td><td>Filter
criterion against the artifact ids of a project dependency. A pattern of format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
Each {@code filter} is a string which is either an exclude (if it starts with a {@code ~})
or an include otherwise. If the first {@code filter} is an include the pattern acts as whitelist,
otherwise as blacklist. The last matching filter determines the outcome. Only matching artifacts
ids are being considered for being embedded.</td></tr>
+     * <tr><td>groupId</td><td>String</td><td>Filter
criterion against the group id of a project dependency. A pattern as described below.</td></tr>
+     * <tr><td>artifactId</td><td>String</td><td>Filter
criterion against the artifact id of a project dependency. A pattern as described below.</td></tr>
      * <tr><td>scope</td><td>ScopeArtifactFilter</td><td>Filter
criterion against the <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">scope
of a project dependency</a>. Possible values are <ul><li>{@code test}, which
allows every scope</li><li>{@code compile+runtime} which allows every scope except
{@code test}</li><li>{@code runtime+system} which allows every scope except {@code
test} and {@code provided}</li><li>{@code compile} which allows only scope {@code
compile}, {@code provided} and {@code system}</li><li>{@code runtime} which only
allows scope {@code runtime} and {@code compile}.</td></tr>
-     * <tr><td>type</td><td>String</td><td>Filter criterion
against the type of a project dependency. The value given here must be equal to the project
dependency's type.</td></tr>
-     * <tr><td>classifier</td><td>String</td><td>Filter
criterion against the classifier of a project dependency. The value given here must be equal
to the project dependency's classifier.</td></tr>
+     * <tr><td>type</td><td>String</td><td>Filter criterion
against the type of a project dependency. A pattern as described below.</td></tr>
+     * <tr><td>classifier</td><td>String</td><td>Filter
criterion against the classifier of a project dependency. A pattern as described below.</td></tr>
      * <tr><td>filter</td><td>Boolean</td><td>If set
to {@code true} adds the embedded artifact location to the package's filter.</td></tr>
      * <tr><td>target</td><td>String</td><td>The parent
folder location in the package where to place the embedded artifact. Falls back to {@link
#embeddedTarget} if not set.</td></tr>
      * </table>
      * </pre>
      * All fields are optional. All filter criteria is concatenated with AND logic (i.e.
every criterion must match for a specific dependency to be embedded).
+     * <br>
+     * All filter patterns follow the format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
+     * Each {@code filter} is a string which is either an exclude (if it starts with a {@code
~}) or an include otherwise. If the first {@code filter} is an include the pattern acts as
whitelist, 
+     * otherwise as blacklist. The last matching filter determines the outcome. Only matching
dependencies are being considered for being embedded.</td></tr>
+     * <br>
      * <i>The difference between {@link #embeddeds} and {@link #subPackages} is that
for the former an explicit target is given while for the latter the target is being computed
from the artifact's vault property file.</i>
      */
     @Parameter
@@ -305,15 +311,20 @@ public class GenerateMetadataMojo extend
      * from the project descriptor. Each {@code <subPackage>} element may configure
any of the following fields
      *  <p>
      * <table>
-     * <tr><td>groupId</td><td>String</td><td>Filter
criterion against the group id of a project dependency. A pattern of format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
Each {@code filter} is a string which is either an exclude (if it starts with a {@code ~})
or an include otherwise. If the first {@code filter} is an include the pattern acts as whitelist,
otherwise as blacklist. The last matching filter determines the outcome. Only matching group
ids are being considered for being embedded.</td></tr>
-     * <tr><td>artifactId</td><td>String</td><td>Filter
criterion against the artifact ids of a project dependency. A pattern of format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
Each {@code filter} is a string which is either an exclude (if it starts with a {@code ~})
or an include otherwise. If the first {@code filter} is an include the pattern acts as whitelist,
otherwise as blacklist. The last matching filter determines the outcome. Only matching artifacts
ids are being considered for being embedded.</td></tr>
+     * <tr><td>groupId</td><td>String</td><td>Filter
criterion against the group id of a project dependency. A pattern as described below.</td></tr>
+     * <tr><td>artifactId</td><td>String</td><td>Filter
criterion against the artifact ids of a project dependency. A pattern as described below.</td></tr>
      * <tr><td>scope</td><td>ScopeArtifactFilter</td><td>Filter
criterion against the <a href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope">scope
of a project dependency</a>. Possible values are <ul><li>{@code test}, which
allows every scope</li><li>{@code compile+runtime} which allows every scope except
{@code test}</li><li>{@code runtime+system} which allows every scope except {@code
test} and {@code provided}</li><li>{@code compile} which allows only scope {@code
compile}, {@code provided} and {@code system}</li><li>{@code runtime} which only
allows scope {@code runtime} and {@code compile}.</td></tr>
-     * <tr><td>type</td><td>String</td><td>Filter criterion
against the type of a project dependency. The value given here must be equal to the project
dependency's type. In most cases should be "content-package" or "zip".</td></tr>
-     * <tr><td>classifier</td><td>String</td><td>Filter
criterion against the classifier of a project dependency. The value given here must be equal
to the project dependency's classifier.</td></tr>
+     * <tr><td>type</td><td>String</td><td>Filter criterion
against the type of a project dependency.A pattern as described below.</td></tr>
+     * <tr><td>classifier</td><td>String</td><td>Filter
criterion against the classifier of a project dependency. A pattern as described below.</td></tr>
      * <tr><td>filter</td><td>Boolean</td><td>If set
to {@code true} adds the embedded artifact location to the package's filter</td></tr>
      * </table>
      * </pre>
-     * All fields are optional. All filter criteria is concatenated with AND logic (i.e.
every criterion must match for a specific dependency to be embedded).
+     * All fields are optional. All filter criteria is concatenated with AND logic (i.e.
every criterion must match for a specific dependency to be embedded as a sub package).
+     * <br>
+     * All filter patterns follow the format {@code &lt;filter&gt;{,&lt;filter&gt;}}.
+     * Each {@code filter} within a filter pattern is a string which is either an exclude
(if it starts with a {@code ~}) or an include otherwise. If the first {@code filter} is an
include the pattern acts as whitelist, 
+     * otherwise as blacklist. The last matching filter determines the outcome. Only matching
dependencies are being considered for being embedded.
+     * <br>
      * <i>The difference between {@link #embeddeds} and {@link #subPackages} is that
for the former an explicit target is given while for the latter the target is being computed
from the artifact's vault property file.</i>
      */
     @Parameter
@@ -790,7 +801,7 @@ public class GenerateMetadataMojo extend
     private Map<String, File> getEmbeddeds() throws IOException, MojoFailureException
{
         Map<String, File> fileMap = new HashMap<>();
         for (Embedded emb : embeddeds) {
-            final List<Artifact> artifacts = emb.getMatchingArtifacts(project);
+            final Collection<Artifact> artifacts = emb.getMatchingArtifacts(project);
             if (artifacts.isEmpty()) {
                 if (failOnMissingEmbed) {
                     throw new MojoFailureException("Embedded artifact specified " + emb +
", but no matching dependency artifact found. Add the missing dependency or fix the embed
definition.");
@@ -848,7 +859,7 @@ public class GenerateMetadataMojo extend
     private Map<String, File> getSubPackages() throws IOException {
         Map<String, File> fileMap = new HashMap<>();
         for (SubPackage pack : subPackages) {
-            final List<Artifact> artifacts = pack.getMatchingArtifacts(project);
+            final Collection<Artifact> artifacts = pack.getMatchingArtifacts(project);
             if (artifacts.isEmpty()) {
                 getLog().warn("No matching artifacts for " + pack);
                 continue;

Copied: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbedded.java
(from r1828296, jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java)
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbedded.java?p2=jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbedded.java&p1=jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java&r1=1828296&r2=1828391&rev=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbedded.java
Thu Apr  5 00:31:23 2018
@@ -17,47 +17,41 @@
 package org.apache.jackrabbit.filevault.maven.packaging;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 import org.apache.jackrabbit.filevault.maven.packaging.impl.StringFilterSet;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.project.MavenProject;
 
-/**
- * The {@code SubPackage} class represents an subpackage artifact dependency
- * from the project descriptor. Such a package is declared in
- * {@code &lt;subPackages&gt;} elements inside the list style
- * {@code &lt;subPackage&gt;} element as follows:
- * <pre>
- * &lt;subPackage&gt;
- *     &lt;groupId&gt;artifact.groupId.pattern&lt;/groupId&gt;
- *     &lt;artifactId&gt;artifact.artifactId.pattern&lt;/artifactId&gt;
- *     &lt;scope&gt;compile&lt;/scope&gt;
- *     &lt;type&gt;jar&lt;/type&gt;
- *     &lt;classifier&gt;sources&lt;/classifier&gt;
- *     &lt;filter&gt;true&lt;/filter&gt;
- * &lt;/subPackage&gt;
- * </pre>
- */
-public class SubPackage {
+public class SimpleEmbedded {
 
     /**
-     * A group filter string, consisted of one or several comma separated patterns.
+     * A group filter string, consists of one or several comma separated patterns.
      */
     private final StringFilterSet groupId = new StringFilterSet();
 
     /**
-     * A artifact filter string, consisted of one or several comma separated patterns.
+     * A artifact filter string, consists of one or several comma separated patterns.
      */
     private final StringFilterSet artifactId = new StringFilterSet();
 
     private ScopeArtifactFilter scope;
 
-    private String type;
+    /**
+     * A type filter string, consists of one or several comma separated patterns.
+     */
+    private StringFilterSet type = new StringFilterSet();
 
-    private String classifier;
+    /**
+     * A classifier filter string, consists of one or several comma separated patterns.
+     */
+    private StringFilterSet classifier = new StringFilterSet();
 
     /**
      * If {@code true} a filter entry will be generated for all embedded artifacts.
@@ -65,7 +59,7 @@ public class SubPackage {
     private boolean filter;
 
     private boolean excludeTransitive;
-
+    
     public void setGroupId(String groupId) {
         this.groupId.addEntries(groupId);
     }
@@ -78,6 +72,14 @@ public class SubPackage {
         this.scope = new ScopeArtifactFilter(scope);
     }
 
+    public void setType(String type) {
+        this.type.addEntries(type);
+    }
+
+    public void setClassifier(String classifier) {
+        this.classifier.addEntries(classifier);
+    }
+
     public void setAddFilter(boolean filter) {
         this.filter = filter;
     }
@@ -85,7 +87,7 @@ public class SubPackage {
     public boolean isFilter() {
         return filter;
     }
-
+    
     public void setExcludeTransitive(boolean excludeTransitive) {
         this.excludeTransitive = excludeTransitive;
     }
@@ -93,11 +95,11 @@ public class SubPackage {
     public boolean isExcludeTransitive() {
         return excludeTransitive;
     }
-
-    public List<Artifact> getMatchingArtifacts(final MavenProject project) {
+    
+    public Collection<Artifact> getMatchingArtifacts(final MavenProject project) {
 
         // get artifacts depending on whether we exclude transitives or not
-        final Set deps;
+        final Set<Artifact> deps;
         if (excludeTransitive) {
             // only direct dependencies, transitives excluded
             deps = project.getDependencyArtifacts();
@@ -105,32 +107,46 @@ public class SubPackage {
             // all dependencies, transitives included
             deps = project.getArtifacts();
         }
+        return getMatchingArtifacts(deps);
+    }
 
+    public Collection<Artifact> getMatchingArtifacts(final Collection<Artifact>
deps) {
         final List<Artifact> matches = new ArrayList<Artifact>();
-        for (Object dep : deps) {
-            final Artifact artifact = (Artifact) dep;
+        for (Artifact artifact : deps) {
             if (groupId.contains(artifact.getGroupId())
                     && artifactId.contains(artifact.getArtifactId())
                     && (scope == null || scope.include(artifact))
-                    && (type == null || type.equals(artifact.getType()))
-                    && (classifier == null || classifier.equals(artifact.getClassifier())))
{
+                    && (type == null || type.contains(artifact.getType()))
+                    && (classifier == null || classifier.contains(artifact.getClassifier())))
{
                 matches.add(artifact);
             }
         }
         return matches;
     }
 
-    public String toString() {
-        final StringBuilder builder = new StringBuilder();
-        builder.append("Sub Packages: ");
+    @Nonnull
+    public StringBuilder toString(@Nullable StringBuilder builder) {
+        if (builder == null) {
+            builder = new StringBuilder();
+        }
         builder.append("groupId=").append(groupId).append(",");
         builder.append("artifactId=").append(artifactId).append(",");
 
         if (scope != null) {
             builder.append("scope=").append(scope).append(",");
         }
+        if (type != null) {
+            builder.append("type=").append(type).append(",");
+        }
+        if (classifier != null) {
+            builder.append("classifier=").append(classifier).append(",");
+        }
         builder.append("filter=").append(filter);
         builder.append(",excludeTransitive=").append(excludeTransitive);
-        return builder.toString();
+        return builder;
+    }
+
+    public String toString() {
+        return toString(null).toString();
     }
 }

Modified: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java?rev=1828391&r1=1828390&r2=1828391&view=diff
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java
(original)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/SubPackage.java
Thu Apr  5 00:31:23 2018
@@ -16,15 +16,6 @@
  */
 package org.apache.jackrabbit.filevault.maven.packaging;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.jackrabbit.filevault.maven.packaging.impl.StringFilterSet;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.project.MavenProject;
-
 /**
  * The {@code SubPackage} class represents an subpackage artifact dependency
  * from the project descriptor. Such a package is declared in
@@ -35,102 +26,18 @@ import org.apache.maven.project.MavenPro
  *     &lt;groupId&gt;artifact.groupId.pattern&lt;/groupId&gt;
  *     &lt;artifactId&gt;artifact.artifactId.pattern&lt;/artifactId&gt;
  *     &lt;scope&gt;compile&lt;/scope&gt;
- *     &lt;type&gt;jar&lt;/type&gt;
- *     &lt;classifier&gt;sources&lt;/classifier&gt;
+ *     &lt;type&gt;artifact.type.pattern&lt;/type&gt;
+ *     &lt;classifier&gt;artifact.classifier.pattern&lt;/classifier&gt;
  *     &lt;filter&gt;true&lt;/filter&gt;
  * &lt;/subPackage&gt;
  * </pre>
  */
-public class SubPackage {
-
-    /**
-     * A group filter string, consisted of one or several comma separated patterns.
-     */
-    private final StringFilterSet groupId = new StringFilterSet();
-
-    /**
-     * A artifact filter string, consisted of one or several comma separated patterns.
-     */
-    private final StringFilterSet artifactId = new StringFilterSet();
-
-    private ScopeArtifactFilter scope;
-
-    private String type;
-
-    private String classifier;
-
-    /**
-     * If {@code true} a filter entry will be generated for all embedded artifacts.
-     */
-    private boolean filter;
-
-    private boolean excludeTransitive;
-
-    public void setGroupId(String groupId) {
-        this.groupId.addEntries(groupId);
-    }
-
-    public void setArtifactId(String artifactId) {
-        this.artifactId.addEntries(artifactId);
-    }
-
-    public void setScope(String scope) {
-        this.scope = new ScopeArtifactFilter(scope);
-    }
-
-    public void setAddFilter(boolean filter) {
-        this.filter = filter;
-    }
-
-    public boolean isFilter() {
-        return filter;
-    }
-
-    public void setExcludeTransitive(boolean excludeTransitive) {
-        this.excludeTransitive = excludeTransitive;
-    }
-
-    public boolean isExcludeTransitive() {
-        return excludeTransitive;
-    }
-
-    public List<Artifact> getMatchingArtifacts(final MavenProject project) {
-
-        // get artifacts depending on whether we exclude transitives or not
-        final Set deps;
-        if (excludeTransitive) {
-            // only direct dependencies, transitives excluded
-            deps = project.getDependencyArtifacts();
-        } else {
-            // all dependencies, transitives included
-            deps = project.getArtifacts();
-        }
-
-        final List<Artifact> matches = new ArrayList<Artifact>();
-        for (Object dep : deps) {
-            final Artifact artifact = (Artifact) dep;
-            if (groupId.contains(artifact.getGroupId())
-                    && artifactId.contains(artifact.getArtifactId())
-                    && (scope == null || scope.include(artifact))
-                    && (type == null || type.equals(artifact.getType()))
-                    && (classifier == null || classifier.equals(artifact.getClassifier())))
{
-                matches.add(artifact);
-            }
-        }
-        return matches;
-    }
+public class SubPackage extends SimpleEmbedded {
 
     public String toString() {
         final StringBuilder builder = new StringBuilder();
         builder.append("Sub Packages: ");
-        builder.append("groupId=").append(groupId).append(",");
-        builder.append("artifactId=").append(artifactId).append(",");
-
-        if (scope != null) {
-            builder.append("scope=").append(scope).append(",");
-        }
-        builder.append("filter=").append(filter);
-        builder.append(",excludeTransitive=").append(excludeTransitive);
+        super.toString(builder);
         return builder.toString();
     }
 }

Added: jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java?rev=1828391&view=auto
==============================================================================
--- jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java
(added)
+++ jackrabbit/commons/filevault-package-maven-plugin/trunk/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/SimpleEmbeddedTest.java
Thu Apr  5 00:31:23 2018
@@ -0,0 +1,114 @@
+/*
+ * 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.jackrabbit.filevault.maven.packaging;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SimpleEmbeddedTest {
+    
+    private SimpleEmbedded embedded;
+    
+    private List<Artifact> artifacts;
+    
+    @Before
+    public void setUp() {
+        embedded = new SimpleEmbedded();
+        artifacts = new ArrayList<>();
+        // the order is important here!
+        artifacts.add(new SimpleArtifact("mygroupid", "artifact1", "compile"));
+        artifacts.add(new SimpleArtifact("mygroupid", "artifact2", "provided")); 
+        artifacts.add(new SimpleArtifact("myothergroupid", "artifact3", "test"));
+        artifacts.add(new SimpleArtifact("myothergroupid", "artifact1", "test"));
+        artifacts.add(new SimpleArtifact("mygroupid", "artifact1", "test", "bundle"));
+        artifacts.add(new SimpleArtifact("mygroupid", "artifact2", "provided", "bundle"));
+        artifacts.add(new SimpleArtifact("mygroupid", "artifact2", "compile", "bundle", "myclassifier"));
+    }
+    
+    @Test
+    public void testGroupIdOnlyFilter() {
+        embedded.setGroupId("mygroupid");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.get(0),
artifacts.get(1), artifacts.get(4), artifacts.get(5), artifacts.get(6)));
+    }
+
+    @Test
+    public void testArtifactIdOnlyFilter() {
+        embedded.setArtifactId("artifact1");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.get(0),
artifacts.get(3), artifacts.get(4)));
+    }
+
+    @Test
+    public void testTypeBundleOnlyFilter() {
+        embedded.setType("bundle");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.contains(artifacts.get(4),
artifacts.get(5), artifacts.get(6)));
+    }
+
+    @Test
+    public void testTypeBundleOrJarOnlyFilter() {
+        // in addition filter for jar
+        embedded.setType("jar");
+        embedded.setType("bundle");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.toArray()));
+    }
+
+    @Test
+    public void testClassifierOnlyFilter() {
+        // in addition filter for jar
+        embedded.setClassifier("myclassifier");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.contains(artifacts.get(6)));
+    }
+
+    @Test
+    public void testScopeOnlyFilter() {
+        // should contain all artifacts with scope "compile", "runtime" or "system"
+        embedded.setScope("compile");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.get(0),
artifacts.get(1), artifacts.get(5), artifacts.get(6)));
+    }
+
+    @Test
+    public void testComplexFilter() {
+        embedded.setType("bundle");
+        embedded.setArtifactId("artifact1");
+        embedded.setGroupId("mygroupid");
+        Assert.assertThat(embedded.getMatchingArtifacts(artifacts), Matchers.containsInAnyOrder(artifacts.get(4)));
+    }
+
+    private final static class SimpleArtifact extends DefaultArtifact {
+        private SimpleArtifact(String groupId, String artifactId) {
+            this(groupId, artifactId, null);
+        }
+
+        private SimpleArtifact(String groupId, String artifactId, String scope) {
+            this(groupId, artifactId, scope, null);
+        }
+
+        private SimpleArtifact(String groupId, String artifactId, String scope, String type)
{
+            this(groupId, artifactId, scope, type, null);
+        }
+        
+        private SimpleArtifact(String groupId, String artifactId, String scope, String type,
String classifier) {
+            super(groupId, artifactId, "1.0", scope, type == null ? "jar" : type, classifier
== null ? "" : classifier, null);
+        }
+    }
+}



Mime
View raw message