Author: brianf
Date: Mon Nov 20 20:24:05 2006
New Revision: 477502

URL: http://svn.apache.org/viewvc?view=rev&rev=477502
Log:
added CopyMojo tests

Added:
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
Modified:
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyMojo.java
 Mon Nov 20 20:24:05 2006
@@ -111,7 +111,7 @@
      * @since 2.0
      * @parameter expression="${silent}" default-value="false"
      */
-    protected boolean silent;
+    public boolean silent;
 
     /**
      * Output absolute filename for resolved artifacts
@@ -224,4 +224,83 @@
         }
     }
 
+    /**
+     * @return Returns the factory.
+     */
+    public org.apache.maven.artifact.factory.ArtifactFactory getFactory()
+    {
+        return this.factory;
+    }
+
+    /**
+     * @param factory The factory to set.
+     */
+    public void setFactory( org.apache.maven.artifact.factory.ArtifactFactory 
factory )
+    {
+        this.factory = factory;
+    }
+
+    /**
+     * @return Returns the project.
+     */
+    public MavenProject getProject()
+    {
+        return this.project;
+    }
+
+    /**
+     * @return Returns the local.
+     */
+    public org.apache.maven.artifact.repository.ArtifactRepository getLocal()
+    {
+        return this.local;
+    }
+
+    /**
+     * @param local The local to set.
+     */
+    public void setLocal( 
org.apache.maven.artifact.repository.ArtifactRepository local )
+    {
+        this.local = local;
+    }
+
+    /**
+     * @return Returns the remoteRepos.
+     */
+    public java.util.List getRemoteRepos()
+    {
+        return this.remoteRepos;
+    }
+
+    /**
+     * @param remoteRepos The remoteRepos to set.
+     */
+    public void setRemoteRepos( java.util.List remoteRepos )
+    {
+        this.remoteRepos = remoteRepos;
+    }
+
+    /**
+     * @return Returns the resolver.
+     */
+    public org.apache.maven.artifact.resolver.ArtifactResolver getResolver()
+    {
+        return this.resolver;
+    }
+
+    /**
+     * @param resolver The resolver to set.
+     */
+    public void setResolver( 
org.apache.maven.artifact.resolver.ArtifactResolver resolver )
+    {
+        this.resolver = resolver;
+    }
+
+    /**
+     * @param archiverManager The archiverManager to set.
+     */
+    public void setArchiverManager( ArchiverManager archiverManager )
+    {
+        this.archiverManager = archiverManager;
+    }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.java
 Mon Nov 20 20:24:05 2006
@@ -30,6 +30,8 @@
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.AbstractDependencyMojo;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Abstract Parent class used by mojos that get Artifact information from the
@@ -86,13 +88,14 @@
      * @required
      * @since 1.0
      */
-    private ArrayList artifactItems;
+    protected ArrayList artifactItems;
 
     /**
      * Preprocesses the list of ArtifactItems. This method defaults the
      * outputDirectory if not set and creates the output Directory if it 
doesn't
      * exist.
-     * 
+     * @param removeVersion
+     *          remove the version from the filename.
      * @return An ArrayList of preprocessed ArtifactItems
      * 
      * @throws MojoExecutionException
@@ -100,7 +103,7 @@
      * 
      * @see ArtifactItem
      */
-    protected ArrayList getArtifactItems()
+    protected ArrayList getArtifactItems(boolean removeVersion)
         throws MojoExecutionException
     {
 
@@ -120,7 +123,7 @@
 
             //TODO:refactor this
             String overWrite = artifactItem.getOverWrite();
-            if ( overWrite == null )
+            if ( StringUtils.isEmpty(overWrite))
             {
                 artifactItem.setDoOverWrite(false);
             }
@@ -128,6 +131,12 @@
             {
                 artifactItem.setDoOverWrite( overWrite.equalsIgnoreCase( 
"true" ) );
             }
+            
+            if ( artifactItem.getDestFileName() == null )
+            {
+                
artifactItem.setDestFileName(DependencyUtil.getFormattedFileName( 
artifactItem.getArtifact(), removeVersion ));
+            }
+
         }
         return artifactItems;
     }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/ArtifactItem.java
 Mon Nov 20 20:24:05 2006
@@ -26,6 +26,7 @@
 /**
  * ArtifactItem represents information specified in the plugin configuration
  * section for each artifact.
+ * 
  * @since 1.0
  * @author brianf
  */
@@ -92,12 +93,27 @@
      * Force Overwrite
      */
     private boolean doOverWrite;
-    
+
     /**
      * Artifact Item
      */
     private Artifact artifact;
 
+    public ArtifactItem()
+    {
+        // default constructor
+    }
+
+    public ArtifactItem( Artifact artifact )
+    {
+        this.setArtifact(artifact);
+        this.setArtifactId(artifact.getArtifactId());
+        this.setClassifier(artifact.getClassifier());
+        this.setGroupId(artifact.getGroupId());
+        this.setType(artifact.getType());
+        this.setVersion(artifact.getVersion());
+    }
+
     /**
      * @return Returns the artifactId.
      */
@@ -185,14 +201,14 @@
 
     public String toString()
     {
-        String ver = (version == null)? "?" : version;
-        if (this.classifier == null)
+        String ver = ( version == null ) ? "?" : version;
+        if ( this.classifier == null )
         {
-            return groupId + ":" + artifactId + ":" + ver + ":" + type;   
+            return groupId + ":" + artifactId + ":" + ver + ":" + type;
         }
         else
         {
-            return groupId + ":" + artifactId + ":" + classifier + ":" + ver + 
":" + type;    
+            return groupId + ":" + artifactId + ":" + classifier + ":" + ver + 
":" + type;
         }
     }
 

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/CopyMojo.java
 Mon Nov 20 20:24:05 2006
@@ -17,7 +17,6 @@
  * under the License.    
  */
 
-
 package org.apache.maven.plugin.dependency.fromConfiguration;
 
 import java.io.File;
@@ -64,12 +63,12 @@
     public void execute()
         throws MojoExecutionException
     {
-        ArrayList artifactItems = getArtifactItems();
-        Iterator iter = artifactItems.iterator();
+        ArrayList theArtifactItems = getArtifactItems( this.stripVersion );
+        Iterator iter = theArtifactItems.iterator();
         while ( iter.hasNext() )
         {
             ArtifactItem artifactItem = (ArtifactItem) iter.next();
-            copyArtifact( artifactItem, this.stripVersion );
+            copyArtifact( artifactItem);
         }
     }
 
@@ -79,31 +78,18 @@
      * 
      * @param artifactItem
      *            containing the information about the Artifact to copy.
-     * @param removeVersion
-     *            specifies if the version should be removed from the file name
-     *            when copying.
      * @throws MojoExecutionException
      *             with a message if an error occurs.
      * 
      * @see DependencyUtil#copyFile(File, File, Log)
      * @see DependencyUtil#getFormattedFileName(Artifact, boolean)
      */
-    protected void copyArtifact( ArtifactItem artifactItem, boolean 
removeVersion )
+    protected void copyArtifact( ArtifactItem artifactItem )
         throws MojoExecutionException
     {
         Artifact artifact = artifactItem.getArtifact();
 
-        String destFileName = null;
-        if ( artifactItem.getDestFileName() != null )
-        {
-            destFileName = artifactItem.getDestFileName();
-        }
-        else
-        {
-            destFileName = DependencyUtil.getFormattedFileName( artifact, 
removeVersion );
-        }
-
-        File destFile = new File( artifactItem.getOutputDirectory(), 
destFileName );
+        File destFile = new File( artifactItem.getOutputDirectory(), 
artifactItem.getDestFileName() );
 
         // TODO: refactor this to use the filters.
         if ( !artifactItem.isDoOverWrite() )
@@ -117,7 +103,7 @@
                 artifactItem.setDoOverWrite( this.overWriteReleases );
             }
         }
-        
+
         File artifactFile = artifact.getFile();
         if ( artifactItem.isDoOverWrite()
             || ( !destFile.exists() || ( overWriteIfNewer && 
artifactFile.lastModified() < destFile.lastModified() ) ) )
@@ -128,6 +114,22 @@
         {
             this.getLog().info( artifactFile + " already exists." );
         }
+    }
+
+    /**
+     * @return Returns the stripVersion.
+     */
+    public boolean isStripVersion()
+    {
+        return this.stripVersion;
+    }
+
+    /**
+     * @param stripVersion The stripVersion to set.
+     */
+    public void setStripVersion( boolean stripVersion )
+    {
+        this.stripVersion = stripVersion;
     }
 
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/fromConfiguration/UnpackMojo.java
 Mon Nov 20 20:24:05 2006
@@ -67,7 +67,7 @@
     public void execute()
         throws MojoExecutionException
     {
-        ArrayList artifactItems = getArtifactItems();
+        ArrayList artifactItems = getArtifactItems(false);
         Iterator iter = artifactItems.iterator();
         while ( iter.hasNext() )
         {

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
 Mon Nov 20 20:24:05 2006
@@ -52,8 +52,8 @@
         // mojo.silent = true;
 
         assertNotNull( mojo );
-        assertNotNull( mojo.project );
-        MavenProject project = mojo.project;
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
 
         Set artifacts = this.stubFactory.getScopedArtifacts();
         Set directArtifacts = 
this.stubFactory.getReleaseAndSnapshotArtifacts();
@@ -440,9 +440,9 @@
         mojo.type = testType;
 
         // init classifier things
-        mojo.factory = DependencyTestUtils.getArtifactFactory();
-        mojo.resolver = new StubArtifactResolver( stubFactory, false, false );
-        mojo.local = new StubArtifactRepository( 
this.testDir.getAbsolutePath() );
+        mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+        mojo.setResolver( new StubArtifactResolver( stubFactory, false, false 
) );
+        mojo.setLocal( new StubArtifactRepository( 
this.testDir.getAbsolutePath() ) );
 
         mojo.execute();
 

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestResolveMojo.java
 Mon Nov 20 20:24:05 2006
@@ -46,9 +46,11 @@
     {
         File testPom = new File( getBasedir(), 
"target/test-classes/unit/resolve-test/plugin-config.xml" );
         ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( 
"resolve", testPom );
+
         assertNotNull( mojo );
-        assertNotNull( mojo.project );
-        MavenProject project = mojo.project;
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
+        
         mojo.silent = true;
         Set artifacts = this.stubFactory.getScopedArtifacts();
         Set directArtifacts = 
this.stubFactory.getReleaseAndSnapshotArtifacts();

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestUnpackDependenciesMojo.java
 Mon Nov 20 20:24:05 2006
@@ -59,8 +59,8 @@
             + "target/test-classes/unit/unpack-dependencies-test/test.txt" ) );
 
         assertNotNull( mojo );
-        assertNotNull( mojo.project );
-        MavenProject project = mojo.project;
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
 
         Set artifacts = this.stubFactory.getScopedArtifacts();
         Set directArtifacts = 
this.stubFactory.getReleaseAndSnapshotArtifacts();
@@ -85,7 +85,7 @@
 
         File destFile = new File( folder, stubFactory.getUnpackableFileName( 
artifact ) );
 
-     /*
+        /*
          * System.out.println( "Checking file: " + destFile.getPath() ); if (
          * val != destFile.exists() ) { System.out.println( "FAIL!" ); }
          */
@@ -371,9 +371,9 @@
         mojo.classifier = "jdk";
         mojo.type = "java-sources";
         // init classifier things
-        mojo.factory = DependencyTestUtils.getArtifactFactory();
-        mojo.resolver = new StubArtifactResolver( null, are, anfe );
-        mojo.local = new StubArtifactRepository( 
this.testDir.getAbsolutePath() );
+        mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+        mojo.setResolver( new StubArtifactResolver( null, are, anfe ) );
+        mojo.setLocal( new StubArtifactRepository( 
this.testDir.getAbsolutePath() ) );
 
         try
         {

Added: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java?view=auto&rev=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
 (added)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestArtifactItem.java
 Mon Nov 20 20:24:05 2006
@@ -0,0 +1,57 @@
+/* 
+ * 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.maven.plugin.dependency.fromConfiguration;
+
+import java.io.IOException;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+
+public class TestArtifactItem
+    extends AbstractDependencyMojoTestCase
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        setUp("artifactItems",false);
+    }
+
+    public void testArtifactItemConstructor() throws IOException
+    {
+        Artifact artifact = stubFactory.createArtifact( "g", "a", "1.0", 
Artifact.SCOPE_COMPILE, "jar", "one" );
+       
+        ArtifactItem item = new ArtifactItem(artifact);
+        
+        assertEquals(item.getArtifact(),artifact);
+        assertEquals(item.getArtifactId(),artifact.getArtifactId());
+        assertEquals(item.getGroupId(),artifact.getGroupId());
+        assertEquals(item.getVersion(),artifact.getVersion());
+        assertEquals(item.getClassifier(),artifact.getClassifier());
+        assertEquals(item.getType(),artifact.getType());
+    }
+    
+    public void testArtifactItemDefaultType()
+    {
+        ArtifactItem item = new ArtifactItem();
+        //check type default
+        assertEquals( "jar", item.getType() );
+    }
+
+}

Added: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java?view=auto&rev=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
 (added)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
 Mon Nov 20 20:24:05 2006
@@ -0,0 +1,178 @@
+/* 
+ * 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.maven.plugin.dependency.fromConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
+import 
org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactRepository;
+import org.apache.maven.plugin.dependency.testUtils.stubs.StubArtifactResolver;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
+
+public class TestCopyMojo
+    extends AbstractDependencyMojoTestCase
+{
+
+    CopyMojo mojo;
+
+    public TestCopyMojo()
+    {
+        super();
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp( "copy", false );
+
+        File testPom = new File( getBasedir(), 
"target/test-classes/unit/copy-test/plugin-config.xml" );
+        mojo = (CopyMojo) lookupMojo( "copy", testPom );
+        mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
+        mojo.silent = true;
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.getProject() );
+        // MavenProject project = mojo.getProject();
+        // init classifier things
+        mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+        mojo.setResolver( new StubArtifactResolver( stubFactory, false, false 
) );
+        mojo.setLocal( new StubArtifactRepository( 
this.testDir.getAbsolutePath() ) );
+    }
+
+    public ArtifactItem getSingleArtifactItem( boolean removeVersion )
+        throws MojoExecutionException
+    {
+        ArrayList list = mojo.getArtifactItems( removeVersion );
+        return (ArtifactItem) list.get( 0 );
+    }
+
+    public void testGetArtifactItems()
+        throws MojoExecutionException
+    {
+
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifact" );
+        item.setGroupId( "groupId" );
+        item.setVersion( "1.0" );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+
+        mojo.artifactItems = list;
+
+        ArtifactItem result = getSingleArtifactItem( false );
+        assertFalse( result.isDoOverWrite() );
+
+        item.setOverWrite( "true" );
+        result = getSingleArtifactItem( false );
+        assertTrue( result.isDoOverWrite() );
+        assertEquals(mojo.outputDirectory,result.getOutputDirectory());
+
+        item.setOverWrite( "false" );
+        result = getSingleArtifactItem( false );
+        assertFalse( result.isDoOverWrite() );
+
+        item.setOverWrite( "" );
+        result = getSingleArtifactItem( false );
+        assertFalse( result.isDoOverWrite() );
+        
+        item.setOverWrite( "blah" );
+        File output = new File(mojo.outputDirectory,"override");
+        item.setOutputDirectory(output);
+        result = getSingleArtifactItem( false );
+        assertFalse( result.isDoOverWrite() );
+        assertEquals(output,result.getOutputDirectory());
+    }
+
+    public void assertFilesExist( Collection items, boolean exist )
+    {
+        Iterator iter = items.iterator();
+        while ( iter.hasNext() )
+        {
+            assertFileExists( (ArtifactItem) iter.next(), exist );
+        }
+    }
+
+    public void assertFileExists( ArtifactItem item, boolean exist )
+    {
+        File file = new File( item.getOutputDirectory(), 
item.getDestFileName() );
+        assertEquals( exist, file.exists() );
+    }
+
+    public void testMojoDefaults()
+    {
+        CopyMojo mojo = new CopyMojo();
+
+        assertFalse( mojo.isStripVersion() );
+    }
+
+    public void testCopyFile()
+        throws IOException, MojoExecutionException
+    {
+        ArrayList list = stubFactory.getArtifactItems( 
stubFactory.getClassifiedArtifacts() );
+
+        mojo.artifactItems = list;
+
+        mojo.execute();
+
+        assertFilesExist( list, true );
+    }
+
+    public void testCopyToLocation()
+        throws IOException, MojoExecutionException
+    {
+        ArrayList list = stubFactory.getArtifactItems( 
stubFactory.getClassifiedArtifacts() );
+        ArtifactItem item = (ArtifactItem) list.get( 0 );
+        item.setOutputDirectory( new File( mojo.outputDirectory, 
"testOverride" ) );
+
+        mojo.artifactItems = list;
+
+        mojo.execute();
+
+        assertFilesExist( list, true );
+    }
+
+    public void testCopyStripVersion()
+        throws IOException, MojoExecutionException
+    {
+        ArrayList list = stubFactory.getArtifactItems( 
stubFactory.getClassifiedArtifacts() );
+        ArtifactItem item = (ArtifactItem) list.get( 0 );
+        item.setOutputDirectory( new File( mojo.outputDirectory, 
"testOverride" ) );
+        mojo.setStripVersion( true );
+
+        mojo.artifactItems = list;
+
+        mojo.execute();
+
+        assertFilesExist( list, true );
+    }
+
+    // TODO: test overwrite / overwrite if newer / overwrite release / 
overwrite
+    // snapshot
+    // TODO: test non classifier
+    // TODO: test missing version - from dependency and from dependency
+    // management
+}

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/ArtifactStubFactory.java
 Mon Nov 20 20:24:05 2006
@@ -20,7 +20,11 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
@@ -28,6 +32,7 @@
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
 import org.apache.maven.plugin.dependency.utils.SilentLog;
 import org.codehaus.plexus.archiver.Archiver;
@@ -95,6 +100,9 @@
         return artifact;
     }
 
+    /*
+     * Creates a file that can be copied or unpacked based on the passed in 
artifact
+     */
     public void setArtifactFile( Artifact artifact )
         throws IOException
     {
@@ -294,5 +302,22 @@
     public void setSrcFile( File srcFile )
     {
         this.srcFile = srcFile;
+    }
+    
+    public ArtifactItem getArtifactItem(Artifact artifact)
+    {
+     ArtifactItem item = new ArtifactItem(artifact);
+     return item;
+    }
+    
+    public ArrayList getArtifactItems(Collection artifacts)
+    {
+        ArrayList list = new ArrayList();
+        Iterator iter = artifacts.iterator();
+        while (iter.hasNext())
+        {
+           list.add(getArtifactItem((Artifact) iter.next()));
+        }
+        return list;
     }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java?view=diff&rev=477502&r1=477501&r2=477502
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/testUtils/stubs/StubArtifactResolver.java
 Mon Nov 20 20:24:05 2006
@@ -52,6 +52,10 @@
         this.factory = factory;
     }
 
+    /*
+     * Creates dummy file and sets it in the artifact to simulate resolution 
(non-Javadoc)
+     * @see 
org.apache.maven.artifact.resolver.ArtifactResolver#resolve(org.apache.maven.artifact.Artifact,
 java.util.List, org.apache.maven.artifact.repository.ArtifactRepository)
+     */
     public void resolve( Artifact artifact, List remoteRepositories, 
ArtifactRepository localRepository )
         throws ArtifactResolutionException, ArtifactNotFoundException
     {


Reply via email to