maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1748774 - in /maven/shared/trunk/maven-common-artifact-filters/src: main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ test/java/org/apache/maven/shared/artifact/filter/resolve/transform/
Date Thu, 16 Jun 2016 21:44:31 GMT
Author: rfscholte
Date: Thu Jun 16 21:44:31 2016
New Revision: 1748774

URL: http://svn.apache.org/viewvc?rev=1748774&view=rev
Log:
Support null-scope handling when transforming to (old) ArtifactScopeFilter

Modified:
    maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformer.java
    maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformerTest.java

Modified: maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformer.java?rev=1748774&r1=1748773&r2=1748774&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformer.java
(original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformer.java
Thu Jun 16 21:44:31 2016
@@ -49,6 +49,21 @@ import org.apache.maven.shared.artifact.
  */
 public class ArtifactIncludeFilterTransformer implements FilterTransformer<ArtifactFilter>
 {
+    
+    private boolean includeNullScope = true;
+    
+    /**
+     * Used by {@link #transform(ScopeFilter)}
+     * 
+     * When filtering on artifacts it is possible that the scope is unknown.
+     * Decide if artifact should be included is its scoop is {@code null}, default is {@code
true}
+     * 
+     * @param includeNullScope set to {@code false} if {@code null}-scoped Artifacts should
not be included
+     */
+    public void setIncludeNullScope( boolean includeNullScope )
+    {
+        this.includeNullScope = includeNullScope;
+    }
 
     @Override
     public ArtifactFilter transform( final ScopeFilter scopeFilter )
@@ -58,6 +73,11 @@ public class ArtifactIncludeFilterTransf
             @Override
             public boolean include( Artifact artifact )
             {
+                if ( artifact.getScope() == null )
+                {
+                    return includeNullScope;
+                }
+                
                 boolean isIncluded;
                 
                 if ( scopeFilter.getIncluded() != null )

Modified: maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformerTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformerTest.java?rev=1748774&r1=1748773&r2=1748774&view=diff
==============================================================================
--- maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformerTest.java
(original)
+++ maven/shared/trunk/maven-common-artifact-filters/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeFilterTransformerTest.java
Thu Jun 16 21:44:31 2016
@@ -42,15 +42,22 @@ import org.apache.maven.shared.artifact.
 import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter;
 import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
 import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
+import org.junit.Before;
 import org.junit.Test;
 
 public class ArtifactIncludeFilterTransformerTest
 {
 
-    private ArtifactIncludeFilterTransformer transformer = new ArtifactIncludeFilterTransformer();
+    private ArtifactIncludeFilterTransformer transformer;
 
     private ArtifactStubFactory artifactFactory = new ArtifactStubFactory();
 
+    @Before
+    public void setUp()
+    {
+        transformer = new ArtifactIncludeFilterTransformer();
+    }
+    
     @Test
     public void testTransformAndFilter()
         throws Exception
@@ -107,7 +114,7 @@ public class ArtifactIncludeFilterTransf
     {
         ScopeFilter filter = ScopeFilter.including( Collections.singletonList( "runtime"
) );
 
-        ArtifactFilter dependencyFilter = (ArtifactFilter) filter.transform( transformer
);
+        ArtifactFilter dependencyFilter = filter.transform( transformer );
 
         assertTrue( dependencyFilter.include( newArtifact( "g:a:v", "runtime" ) ) );
 
@@ -115,6 +122,21 @@ public class ArtifactIncludeFilterTransf
 
         assertFalse( dependencyFilter.include( newArtifact( "g:a:v", "test" ) ) );
     }
+    
+    @Test
+    public void testTransformScopeFilterIncludeNullScope() throws Exception
+    {
+        ScopeFilter filter = ScopeFilter.including();
+
+        Artifact artifact = newArtifact( "g:a:v", null );
+
+        // default
+        assertTrue( filter.transform( transformer ).include( artifact ) );
+
+        transformer.setIncludeNullScope( false );
+        
+        assertFalse( filter.transform( transformer ).include( artifact ) );
+    }
 
     @Test
     public void testTransformPatternExclusionsFilter()



Mime
View raw message