[ 
https://issues.apache.org/jira/browse/MASSEMBLY-832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17905190#comment-17905190
 ] 

ASF GitHub Bot commented on MASSEMBLY-832:
------------------------------------------

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.





> Consider dependency optional attribute when gather dependencies
> ---------------------------------------------------------------
>
>                 Key: MASSEMBLY-832
>                 URL: https://issues.apache.org/jira/browse/MASSEMBLY-832
>             Project: Maven Assembly Plugin
>          Issue Type: New Feature
>          Components: dependencySet
>    Affects Versions: 2.6
>         Environment: Maven 3.3
>            Reporter: Nikolas Falco
>            Priority: Minor
>
> In some scenario we would like to have the opportunity to skip optional 
> dependencies
> {code:xml}
> <assembly ...>
>   <id>dist</id>
>   <formats>
>     <format>zip</format>
>   </formats>
>     <includeBaseDirectory>false</includeBaseDirectory>
>     <moduleSets>
>       <moduleSet>
>         <!-- Enable access to all projects in the current multimodule build! 
> -->
>         <useAllReactorProjects>true</useAllReactorProjects>
>         <binaries>
>           <outputDirectory>3rdparty</outputDirectory>
>           <unpack>false</unpack>
>           <dependencySets>
>             <dependencySet>
>               <!-- option 1 -->
>               <considerOptional>true</considerOptional>
>               <!-- or option 2 -->
>               <includes>
>                 <!-- groupId:artifactId:type[:classifier][:optional]:version 
> -->
>                 <include>*:*:*:false:*</include>
>               </includes>
>            </dependencySet>
>          </dependencySets>
>        </binaries>
>     </moduleSet>
>   </moduleSets>
> </assembly>
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to