Also pick up optional

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1694116 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNode.java b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNode.java
index 04f48c6..018de20 100644
--- a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNode.java
+++ b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNode.java
@@ -47,6 +47,7 @@
         mavenDependency.setClassifier( artifact.getClassifier() );

         mavenDependency.setType( artifact.getType() );

         mavenDependency.setScope( artifact.getScope() );

+        mavenDependency.setOptional( artifact.isOptional() );

 

         return mavenDependency;

     }

diff --git a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNode.java b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNode.java
index 3cb49b9..5e82737 100644
--- a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNode.java
+++ b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNode.java
@@ -57,6 +57,11 @@
         mavenDependency.setClassifier( nodeDependency.getArtifact().getClassifier() );

         mavenDependency.setType( nodeDependency.getArtifact().getProperty( ArtifactProperties.TYPE, null ) );

         mavenDependency.setScope( nodeDependency.getScope() );

+        // Eclipse Aether supports three-valued logic

+        if ( nodeDependency.getOptional() != null )

+        {

+            mavenDependency.setOptional( nodeDependency.isOptional() );

+        }

 

         return mavenDependency;

     }

diff --git a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNode.java b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNode.java
index a66935f..484b725 100644
--- a/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNode.java
+++ b/src/main/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNode.java
@@ -58,6 +58,7 @@
         mavenDependency.setClassifier( nodeDependency.getArtifact().getClassifier() );

         mavenDependency.setType( nodeDependency.getArtifact().getProperty( ArtifactProperties.TYPE, null ) );

         mavenDependency.setScope( nodeDependency.getScope() );

+        mavenDependency.setOptional( nodeDependency.isOptional() );

 

         return mavenDependency;

     }

diff --git a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNodeTest.java b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNodeTest.java
index 7a77413..001de81 100644
--- a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNodeTest.java
+++ b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/ArtifactIncludeNodeTest.java
@@ -22,9 +22,11 @@
 import static org.junit.Assert.assertEquals;

 

 import org.apache.maven.artifact.Artifact;

+import org.apache.maven.artifact.versioning.VersionRange;

 import org.apache.maven.model.Dependency;

 import org.apache.maven.plugin.testing.ArtifactStubFactory;

 import org.apache.maven.shared.artifact.filter.resolve.Node;

+import org.eclipse.aether.graph.DependencyNode;

 import org.junit.Test;

 

 public class ArtifactIncludeNodeTest

@@ -90,21 +92,71 @@
         assertEquals( "s", dependency.getScope() );

     }

 

+    @Test

+    public void testOptional() throws Exception

+    {

+        Node node = new ArtifactIncludeNode( newArtifact( "g:a:pom:v", null, null ) );

+        

+        assertEquals( "false", node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

+        

+        node = new ArtifactIncludeNode( newArtifact( "g:a:pom:v", null, true ) );

+        assertEquals( "true", node.getDependency().getOptional()  );

+        assertEquals( true, node.getDependency().isOptional()  );

+

+        node = new ArtifactIncludeNode( newArtifact( "g:a:pom:v", null, false ) );

+        assertEquals( "false", node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

+    }

+

     private Artifact newArtifact( String coor, String scope )

         throws Exception

     {

+        return newArtifact( coor, scope, null );

+    }

+

+    private Artifact newArtifact( String coor, String scope, Boolean optional )

+        throws Exception

+    {

         String[] gav = coor.split( ":" );

+        String groupId = gav[0];

+        String artifactId = gav[1];

+        String version = null;

+        String classifier = null;

+        String type = null;

+

         if ( gav.length == 3 )

         {

-            return artifactFactory.createArtifact( gav[0], gav[1], gav[2], scope );

+            version = gav[2];

         }

         else if ( gav.length == 4 )

         {

-            return artifactFactory.createArtifact( gav[0], gav[1], gav[3], scope, gav[2], null );

+            type = gav[2];

+            version = gav[3];

+        }        

+        else if ( gav.length == 5 )

+        {

+            type = gav[2];

+            classifier = gav[3];

+            version = gav[4];

+        }        

+        

+        if( optional != null )

+        {

+            VersionRange versionRange = VersionRange.createFromVersion( version );

+            return artifactFactory.createArtifact( groupId, artifactId, versionRange, scope, type, classifier, optional );

+        }

+        else if ( gav.length == 3 )

+        {

+            return artifactFactory.createArtifact( groupId, artifactId, version, scope );

+        }

+        else if ( gav.length == 4 )

+        {

+            return artifactFactory.createArtifact( groupId, artifactId, version, scope, type, null );

         }

         else if ( gav.length == 5 )

         {

-            return artifactFactory.createArtifact( gav[0], gav[1], gav[4], scope, gav[2], gav[3] );

+            return artifactFactory.createArtifact( groupId, artifactId, version, scope, type, classifier );

         }

         else

         {

diff --git a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNodeTest.java b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNodeTest.java
index 66b4d2a..0edb4f6 100644
--- a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNodeTest.java
+++ b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/EclipseAetherNodeTest.java
@@ -74,8 +74,32 @@
         assertEquals( null, mavenDependency.getType() );

         assertEquals( "s", mavenDependency.getScope() );

     }

-    private DependencyNode newDependencyNode( String string, String scope )

+

+    @Test

+    public void testOptional()

     {

-        return new DefaultDependencyNode( new Dependency( new DefaultArtifact( string ), scope ) );

+        Node node = new EclipseAetherNode( newDependencyNode( "g:a:v", null, null ) );

+        

+        assertEquals( null, node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

+        

+        node = new EclipseAetherNode( newDependencyNode( "g:a:v", null, true ) );

+        assertEquals( "true", node.getDependency().getOptional()  );

+        assertEquals( true, node.getDependency().isOptional()  );

+

+        node = new EclipseAetherNode( newDependencyNode( "g:a:v", null, false ) );

+        assertEquals( "false", node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

     }

+

+    private DependencyNode newDependencyNode( String coor, String scope )

+    {

+        return new DefaultDependencyNode( new Dependency( new DefaultArtifact( coor ), scope ) );

+    }

+    

+    private DependencyNode newDependencyNode( String coor, String scope, Boolean optional )

+    {

+        return new DefaultDependencyNode( new Dependency( new DefaultArtifact( coor ), scope, optional ) );

+    }

+

 }

diff --git a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNodeTest.java b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNodeTest.java
index a6ae0c8..37a1a4e 100644
--- a/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNodeTest.java
+++ b/src/test/java/org/apache/maven/shared/artifact/filter/resolve/transform/SonatypeAetherNodeTest.java
@@ -75,8 +75,31 @@
         assertEquals( "s", mavenDependency.getScope() );

     }

     

+    @Test

+    public void testOptional()

+    {

+        Node node = new SonatypeAetherNode( newDependencyNode( "g:a:v", null ) );

+        

+        assertEquals( "false", node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

+        

+        node = new SonatypeAetherNode( newDependencyNode( "g:a:v", null, true ) );

+        assertEquals( "true", node.getDependency().getOptional()  );

+        assertEquals( true, node.getDependency().isOptional()  );

+

+        node = new SonatypeAetherNode( newDependencyNode( "g:a:v", null, false ) );

+        assertEquals( "false", node.getDependency().getOptional()  );

+        assertEquals( false, node.getDependency().isOptional()  );

+    }

+

     private DependencyNode newDependencyNode( String string, String scope )

     {

         return new DefaultDependencyNode( new Dependency( new DefaultArtifact( string ), scope ) );

     }

+    

+    private DependencyNode newDependencyNode( String coor, String scope, boolean optional )

+    {

+        return new DefaultDependencyNode( new Dependency( new DefaultArtifact( coor ), scope, optional ) );

+    }

+

 }