elharo commented on code in PR #49:
URL: 
https://github.com/apache/maven-assembly-plugin/pull/49#discussion_r1882167522


##########
src/main/mdo/assembly-component.mdo:
##########
@@ -568,6 +568,15 @@
           build should be included in this dependency set. Default value is 
false. (Since 2.2)
           ]]></description>
         </field>
+        <field>
+          <name>useOptionalDependencies</name>
+          <version>2.1.0+</version>
+          <type>boolean</type>

Review Comment:
   Is this a boolean or a list? What if someone wants to inlcude some optional 
dependencies and not others?



##########
src/test/java/org/apache/maven/plugins/assembly/archive/task/AddDependencySetsTaskTest.java:
##########
@@ -425,6 +426,60 @@ public void 
testGetDependencyArtifacts_ShouldFilterOneDependencyArtifactViaInclu
         assertSame( am1, result.iterator().next() );
     }
 
+    @Test
+    public void 
testGetDependencyArtifacts_ShouldFilterOptionalArtifactsByDefault() throws 
Exception
+    {
+        Artifact am1 = mockArtifact(1);
+        when(am1.isOptional()).thenReturn(true);
+        Artifact am2 = mockArtifact(2);
+        Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(new 
DependencySet(), ImmutableSet.of(am1, am2));
+        assertEquals(1, resolvedArtifacts.size());
+        assertSame(am2, resolvedArtifacts.iterator().next());
+    }
+
+    @Test
+    public void 
testGetDependencyArtifacts_ShouldFilterOptionalArtifactsExplicitly() throws 
Exception
+    {
+        Artifact am1 = mockArtifact(1);
+        when(am1.isOptional()).thenReturn(true);
+        Artifact am2 = mockArtifact(2);
+        DependencySet dependencySet = new DependencySet();
+        dependencySet.setUseOptionalDependencies(false);
+
+        Set<Artifact> resolvedArtifacts = 
resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2));
+        assertEquals(1, resolvedArtifacts.size());
+        assertSame(am2, resolvedArtifacts.iterator().next());
+    }
+
+    @Test
+    public void 
testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsExplicitly() throws 
Exception
+    {
+        Artifact am1 = mockArtifact(1);
+        when(am1.isOptional()).thenReturn(true);
+        Artifact am2 = mockArtifact(2);
+        DependencySet dependencySet = new DependencySet();
+        dependencySet.setUseOptionalDependencies(true);
+        
+        Set<Artifact> resolvedArtifacts = 
resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2));
+        assertEquals(2, resolvedArtifacts.size());
+    }
+
+    private static Artifact mockArtifact( int id )
+    {
+        Artifact a = mock(Artifact.class);
+        when(a.getId()).thenReturn("group:artifact" + id + ":1.0:jar");
+        return a;
+    }
+
+    private Set<Artifact> resolveDependencyArtifacts( DependencySet 
dependencySet, Set<Artifact> artifacts ) throws Exception
+    {
+        MavenProject project = new MavenProject(new Model());
+        Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");

Review Comment:
   no logging at all please. Use a SilentLogger



##########
src/main/mdo/assembly-component.mdo:
##########
@@ -568,6 +568,15 @@
           build should be included in this dependency set. Default value is 
false. (Since 2.2)
           ]]></description>
         </field>
+        <field>
+          <name>useOptionalDependencies</name>
+          <version>2.1.0+</version>
+          <type>boolean</type>
+          <defaultValue>false</defaultValue>

Review Comment:
   I wonder if the defallt here should be true to avoid changing existing 
behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to