maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r482909 - in /maven/plugins/trunk/maven-dependency-plugin/src: main/java/org/apache/maven/plugin/dependency/fromConfiguration/ main/java/org/apache/maven/plugin/dependency/utils/markers/ test/java/org/apache/maven/plugin/dependency/ test/ja...
Date Wed, 06 Dec 2006 05:43:14 GMT
Author: brianf
Date: Tue Dec  5 21:43:12 2006
New Revision: 482909

URL: http://svn.apache.org/viewvc?view=rev&rev=482909
Log:
added unit tests for unpack

Added:
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/
    maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml
  (with props)
Modified:
    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/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/main/java/org/apache/maven/plugin/dependency/utils/markers/DefaultFileMarkerHandler.java
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/SourcesFileMarkerHandler.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/fromConfiguration/TestCopyMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java

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=482909&r1=482908&r2=482909
==============================================================================
--- 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
Tue Dec  5 21:43:12 2006
@@ -54,7 +54,7 @@
      * @optional
      * @since 1.0
      */
-    protected File outputDirectory;
+    private File outputDirectory;
 
     /**
      * Overwrite release artifacts
@@ -63,7 +63,7 @@
      * @since 1.0
      * @parameter expression="${overWriteReleases}" default-value="false"
      */
-    protected boolean overWriteReleases;
+    private boolean overWriteReleases;
 
     /**
      * Overwrite snapshot artifacts
@@ -72,7 +72,7 @@
      * @since 1.0
      * @parameter expression="${overWriteSnapshots}" default-value="false"
      */
-    protected boolean overWriteSnapshots;
+    private boolean overWriteSnapshots;
 
     /**
      * Overwrite if newer
@@ -81,7 +81,7 @@
      * @since 2.0
      * @parameter expression="${overIfNewer}" default-value="true"
      */
-    protected boolean overWriteIfNewer;
+    private boolean overWriteIfNewer;
 
     /**
      * Collection of ArtifactItems to work on. (ArtifactItem contains groupId,
@@ -92,7 +92,7 @@
      * @required
      * @since 1.0
      */
-    protected ArrayList artifactItems;
+    private ArrayList artifactItems;
 
     abstract ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item );
 
@@ -264,5 +264,85 @@
             }
         }
         return result;
+    }
+
+    /**
+     * @return Returns the artifactItems.
+     */
+    public ArrayList getArtifactItems()
+    {
+        return this.artifactItems;
+    }
+
+    /**
+     * @param theArtifactItems The artifactItems to set.
+     */
+    public void setArtifactItems( ArrayList theArtifactItems )
+    {
+        this.artifactItems = theArtifactItems;
+    }
+
+    /**
+     * @return Returns the outputDirectory.
+     */
+    public File getOutputDirectory()
+    {
+        return this.outputDirectory;
+    }
+
+    /**
+     * @param theOutputDirectory The outputDirectory to set.
+     */
+    public void setOutputDirectory( File theOutputDirectory )
+    {
+        this.outputDirectory = theOutputDirectory;
+    }
+
+    /**
+     * @return Returns the overWriteIfNewer.
+     */
+    public boolean isOverWriteIfNewer()
+    {
+        return this.overWriteIfNewer;
+    }
+
+    /**
+     * @param theOverWriteIfNewer The overWriteIfNewer to set.
+     */
+    public void setOverWriteIfNewer( boolean theOverWriteIfNewer )
+    {
+        this.overWriteIfNewer = theOverWriteIfNewer;
+    }
+
+    /**
+     * @return Returns the overWriteReleases.
+     */
+    public boolean isOverWriteReleases()
+    {
+        return this.overWriteReleases;
+    }
+
+    /**
+     * @param theOverWriteReleases The overWriteReleases to set.
+     */
+    public void setOverWriteReleases( boolean theOverWriteReleases )
+    {
+        this.overWriteReleases = theOverWriteReleases;
+    }
+
+    /**
+     * @return Returns the overWriteSnapshots.
+     */
+    public boolean isOverWriteSnapshots()
+    {
+        return this.overWriteSnapshots;
+    }
+
+    /**
+     * @param theOverWriteSnapshots The overWriteSnapshots to set.
+     */
+    public void setOverWriteSnapshots( boolean theOverWriteSnapshots )
+    {
+        this.overWriteSnapshots = theOverWriteSnapshots;
     }
 }

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=482909&r1=482908&r2=482909
==============================================================================
--- 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
Tue Dec  5 21:43:12 2006
@@ -100,9 +100,9 @@
 
     protected ArtifactItemFilter getMarkedArtifactFilter( ArtifactItem item )
     {
-        ArtifactItemFilter destinationNameOverrideFilter = new DestFileFilter( this.overWriteReleases,
-                                                                               this.overWriteSnapshots,
-                                                                               this.overWriteIfNewer,
false, false,
+        ArtifactItemFilter destinationNameOverrideFilter = new DestFileFilter( this.isOverWriteReleases(),
+                                                                               this.isOverWriteSnapshots(),
+                                                                               this.isOverWriteIfNewer(),
false, false,
                                                                                this.stripVersion,
item
                                                                                    .getOutputDirectory()
);
         return destinationNameOverrideFilter;

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=482909&r1=482908&r2=482909
==============================================================================
--- 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
Tue Dec  5 21:43:12 2006
@@ -109,6 +109,24 @@
     {
         MarkerHandler handler = new DefaultFileMarkerHandler( item.getArtifact(), this.markersDirectory
);
 
-        return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
handler );
+        return new MarkerFileFilter( this.isOverWriteReleases(), this.isOverWriteSnapshots(),
+                                     this.isOverWriteIfNewer(), handler );
+    }
+
+    /**
+     * @return Returns the markersDirectory.
+     */
+    public File getMarkersDirectory()
+    {
+        return this.markersDirectory;
+    }
+
+    /**
+     * @param theMarkersDirectory
+     *            The markersDirectory to set.
+     */
+    public void setMarkersDirectory( File theMarkersDirectory )
+    {
+        this.markersDirectory = theMarkersDirectory;
     }
 }

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/DefaultFileMarkerHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/DefaultFileMarkerHandler.java?view=diff&rev=482909&r1=482908&r2=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/DefaultFileMarkerHandler.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/DefaultFileMarkerHandler.java
Tue Dec  5 21:43:12 2006
@@ -101,7 +101,14 @@
     {
         File marker = getMarkerFile();
         // create marker file
-        marker.getParentFile().mkdirs();
+        try
+        {
+            marker.getParentFile().mkdirs();
+        }
+        catch ( NullPointerException e )
+        {
+            // parent is null, ignore it.
+        }
         try
         {
             marker.createNewFile();

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/SourcesFileMarkerHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/SourcesFileMarkerHandler.java?view=diff&rev=482909&r1=482908&r2=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/SourcesFileMarkerHandler.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/markers/SourcesFileMarkerHandler.java
Tue Dec  5 21:43:12 2006
@@ -135,7 +135,14 @@
         // get the other file if it exists.
         File clearMarker = getMarkerFile( !this.resolved );
         // create marker file
+        try {
         marker.getParentFile().mkdirs();
+        }
+        catch (NullPointerException e)
+        {
+            //parent is null, ignore it.
+        }
+        
         try
         {
             marker.createNewFile();

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=482909&r1=482908&r2=482909
==============================================================================
--- 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
Tue Dec  5 21:43:12 2006
@@ -52,7 +52,7 @@
         // mojo.silent = true;
 
         // it needs to get the archivermanager
-        stubFactory.setUnpackableFile( mojo.archiverManager );
+        stubFactory.setUnpackableFile( mojo.getArchiverManager() );
         // i'm using one file repeatedly to archive so I can test the name
         // programmatically.
         stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar

Modified: 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=diff&rev=482909&r1=482908&r2=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestCopyMojo.java
Tue Dec  5 21:43:12 2006
@@ -52,7 +52,7 @@
 
         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.setOutputDirectory(new File( this.testDir, "outputDirectory" ));
         // mojo.silent = true;
 
         assertNotNull( mojo );
@@ -84,12 +84,12 @@
         ArrayList list = new ArrayList( 1 );
         list.add( item );
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         ArtifactItem result = getSingleArtifactItem( false );
-        assertEquals( mojo.outputDirectory, result.getOutputDirectory() );
+        assertEquals( mojo.getOutputDirectory(), result.getOutputDirectory() );
 
-        File output = new File( mojo.outputDirectory, "override" );
+        File output = new File( mojo.getOutputDirectory(), "override" );
         item.setOutputDirectory( output );
         result = getSingleArtifactItem( false );
         assertEquals( output, result.getOutputDirectory() );
@@ -122,7 +122,7 @@
     {
         ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts()
);
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         mojo.execute();
 
@@ -134,9 +134,9 @@
     {
         ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts()
);
         ArtifactItem item = (ArtifactItem) list.get( 0 );
-        item.setOutputDirectory( new File( mojo.outputDirectory, "testOverride" ) );
+        item.setOutputDirectory( new File( mojo.getOutputDirectory(), "testOverride" ) );
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         mojo.execute();
 
@@ -148,10 +148,10 @@
     {
         ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts()
);
         ArtifactItem item = (ArtifactItem) list.get( 0 );
-        item.setOutputDirectory( new File( mojo.outputDirectory, "testOverride" ) );
+        item.setOutputDirectory( new File( mojo.getOutputDirectory(), "testOverride" ) );
         mojo.setStripVersion( true );
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         mojo.execute();
 
@@ -163,7 +163,7 @@
     {
         ArrayList list = stubFactory.getArtifactItems( stubFactory.getReleaseAndSnapshotArtifacts()
);
         mojo.setStripVersion( true );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         mojo.execute();
 
@@ -175,7 +175,7 @@
     {
         ArrayList list = stubFactory.getArtifactItems( stubFactory.getReleaseAndSnapshotArtifacts()
);
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         mojo.execute();
 
@@ -194,7 +194,7 @@
 
         ArrayList list = new ArrayList();
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         try
         {
@@ -242,7 +242,7 @@
 
         ArrayList list = new ArrayList();
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         MavenProject project = mojo.getProject();
         project.setDependencies( getDependencyList( item ) );
@@ -264,7 +264,7 @@
 
         ArrayList list = new ArrayList();
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         MavenProject project = mojo.getProject();
         project.setDependencies( getDependencyList( item ) );
@@ -320,7 +320,7 @@
         ArrayList list = new ArrayList();
         list.add( item );
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
 
@@ -353,7 +353,7 @@
         ArrayList list = new ArrayList();
         list.add( item );
 
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
 
@@ -388,7 +388,7 @@
 
         ArrayList list = new ArrayList();
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
         // init classifier things
         mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
@@ -438,9 +438,9 @@
 
         ArrayList list = new ArrayList( 1 );
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
-        mojo.overWriteIfNewer = false;
+       mojo.setOverWriteIfNewer(false);
 
         mojo.execute();
 
@@ -469,9 +469,9 @@
 
         ArrayList list = new ArrayList( 1 );
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
-        mojo.overWriteIfNewer = false;
+       mojo.setOverWriteIfNewer(false);
 
         mojo.execute();
 
@@ -500,10 +500,10 @@
 
         ArrayList list = new ArrayList( 1 );
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
-        mojo.overWriteIfNewer = false;
-        mojo.overWriteReleases = true;
+       mojo.setOverWriteIfNewer(false);
+        mojo.setOverWriteReleases(true);
         mojo.execute();
 
         File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
@@ -528,11 +528,11 @@
 
         ArrayList list = new ArrayList( 1 );
         list.add( item );
-        mojo.artifactItems = list;
+        mojo.setArtifactItems(list);
 
-        mojo.overWriteIfNewer = false;
-        mojo.overWriteReleases = false;
-        mojo.overWriteSnapshots = true;
+       mojo.setOverWriteIfNewer(false);
+        mojo.setOverWriteReleases(false);
+       mojo.setOverWriteSnapshots(true);
         mojo.execute();
 
         File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
@@ -557,8 +557,8 @@
 
         ArrayList list = new ArrayList( 1 );
         list.add( item );
-        mojo.artifactItems = list;
-        mojo.overWriteIfNewer = true;
+        mojo.setArtifactItems(list);
+       mojo.setOverWriteIfNewer(true);
         mojo.execute();
 
         File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java?view=auto&rev=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
(added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/fromConfiguration/TestUnpackMojo.java
Tue Dec  5 21:43:12 2006
@@ -0,0 +1,551 @@
+package org.apache.maven.plugin.dependency.fromConfiguration;
+
+/* 
+ * 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.    
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Dependency;
+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;
+import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
+import org.apache.maven.project.MavenProject;
+
+public class TestUnpackMojo
+    extends AbstractDependencyMojoTestCase
+{
+
+    UnpackMojo mojo;
+
+    public TestUnpackMojo()
+    {
+        super();
+    }
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp( "unpack", true );
+
+        File testPom = new File( getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml"
);
+        mojo = (UnpackMojo) lookupMojo( "unpack", testPom );
+        mojo.setOutputDirectory( new File( this.testDir, "outputDirectory" ) );
+        mojo.setMarkersDirectory( new File( this.testDir, "markers" ) );
+        // mojo.silent = true;
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.getProject() );
+        // MavenProject project = mojo.getProject();
+        // init classifier things
+        // it needs to get the archivermanager
+        stubFactory.setUnpackableFile( mojo.getArchiverManager() );
+        // i'm using one file repeatedly to archive so I can test the name
+        // programmatically.
+        stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar
+            + "target/test-classes/unit/unpack-dependencies-test/test.txt" ) );
+
+        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.setArtifactItems( list );
+
+        ArtifactItem result = getSingleArtifactItem( false );
+        assertEquals( mojo.getOutputDirectory(), result.getOutputDirectory() );
+
+        File output = new File( mojo.getOutputDirectory(), "override" );
+        item.setOutputDirectory( output );
+        result = getSingleArtifactItem( false );
+        assertEquals( output, result.getOutputDirectory() );
+    }
+
+    public void assertMarkerFiles( Collection items, boolean exist )
+    {
+        Iterator iter = items.iterator();
+        while ( iter.hasNext() )
+        {
+            assertMarkerFile( exist, (ArtifactItem) iter.next() );
+        }
+    }
+
+    public void assertMarkerFile( boolean val, ArtifactItem item )
+    {
+        DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( item.getArtifact(),
mojo.getMarkersDirectory() );
+        try
+        {
+            assertEquals( val, handle.isMarkerSet() );
+        }
+        catch ( MojoExecutionException e )
+        {
+            fail( e.getLongMessage() );
+        }
+    }
+
+    public void testUnpackFile()
+        throws IOException, MojoExecutionException
+    {
+        ArrayList list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts()
);
+
+        mojo.setArtifactItems( list );
+
+        mojo.execute();
+
+        assertMarkerFiles( 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.getOutputDirectory(), "testOverride" ) );
+
+        mojo.setArtifactItems( list );
+
+        mojo.execute();
+
+        assertMarkerFiles( list, true );
+    }
+
+    public void testMissingVersionNotFound()
+        throws MojoExecutionException
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "" );
+        item.setGroupId( "groupId" );
+        item.setType( "type" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        try
+        {
+            mojo.execute();
+            fail( "Expected Exception Here." );
+        }
+        catch ( MojoExecutionException e )
+        {
+            // caught the expected exception.
+        }
+    }
+
+    public List getDependencyList( ArtifactItem item )
+    {
+        Dependency dep = new Dependency();
+        dep.setArtifactId( item.getArtifactId() );
+        dep.setClassifier( item.getClassifier() );
+        dep.setGroupId( item.getGroupId() );
+        dep.setType( item.getType() );
+        dep.setVersion( "2.0-SNAPSHOT" );
+
+        Dependency dep2 = new Dependency();
+        dep2.setArtifactId( item.getArtifactId() );
+        dep2.setClassifier( "classifier" );
+        dep2.setGroupId( item.getGroupId() );
+        dep2.setType( item.getType() );
+        dep2.setVersion( "2.1" );
+
+        List list = new ArrayList( 2 );
+        list.add( dep2 );
+        list.add( dep );
+
+        return list;
+    }
+
+    public void testMissingVersionFromDependencies()
+        throws MojoExecutionException
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "" );
+        item.setGroupId( "groupId" );
+        item.setType( "jar" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        MavenProject project = mojo.getProject();
+        project.setDependencies( getDependencyList( item ) );
+
+        mojo.execute();
+        assertMarkerFile( true, item );
+        assertEquals( "2.0-SNAPSHOT", item.getVersion() );
+    }
+
+    public void testMissingVersionFromDependenciesWithClassifier()
+        throws MojoExecutionException
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "classifier" );
+        item.setGroupId( "groupId" );
+        item.setType( "war" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        MavenProject project = mojo.getProject();
+        project.setDependencies( getDependencyList( item ) );
+
+        mojo.execute();
+        assertMarkerFile( true, item );
+        assertEquals( "2.1", item.getVersion() );
+    }
+
+    public List getDependencyMgtList( ArtifactItem item )
+    {
+        Dependency dep = new Dependency();
+        dep.setArtifactId( item.getArtifactId() );
+        dep.setClassifier( item.getClassifier() );
+        dep.setGroupId( item.getGroupId() );
+        dep.setType( item.getType() );
+        dep.setVersion( "3.0-SNAPSHOT" );
+
+        Dependency dep2 = new Dependency();
+        dep2.setArtifactId( item.getArtifactId() );
+        dep2.setClassifier( "classifier" );
+        dep2.setGroupId( item.getGroupId() );
+        dep2.setType( item.getType() );
+        dep2.setVersion( "3.1" );
+
+        List list = new ArrayList( 2 );
+        list.add( dep2 );
+        list.add( dep );
+
+        return list;
+    }
+
+    public void testMissingVersionFromDependencyMgt()
+        throws MojoExecutionException
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "" );
+        item.setGroupId( "groupId" );
+        item.setType( "jar" );
+
+        MavenProject project = mojo.getProject();
+        project.setDependencies( getDependencyList( item ) );
+
+        item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId-2" );
+        item.setClassifier( "" );
+        item.setGroupId( "groupId" );
+        item.setType( "jar" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+
+        mojo.setArtifactItems( list );
+
+        project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
+
+        mojo.execute();
+        assertMarkerFile( true, item );
+        assertEquals( "3.0-SNAPSHOT", item.getVersion() );
+    }
+
+    public void testMissingVersionFromDependencyMgtWithClassifier()
+        throws MojoExecutionException
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "classifier" );
+        item.setGroupId( "groupId" );
+        item.setType( "jar" );
+
+        MavenProject project = mojo.getProject();
+        project.setDependencies( getDependencyList( item ) );
+
+        item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId-2" );
+        item.setClassifier( "classifier" );
+        item.setGroupId( "groupId" );
+        item.setType( "jar" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+
+        mojo.setArtifactItems( list );
+
+        project.getDependencyManagement().setDependencies( getDependencyMgtList( item ) );
+
+        mojo.execute();
+
+        assertMarkerFile( true, item );
+        assertEquals( "3.1", item.getVersion() );
+    }
+
+    public void testArtifactNotFound()
+        throws Exception
+    {
+        dotestArtifactExceptions( false, true );
+    }
+
+    public void testArtifactResolutionException()
+        throws Exception
+    {
+        dotestArtifactExceptions( true, false );
+    }
+
+    public void dotestArtifactExceptions( boolean are, boolean anfe )
+        throws Exception
+    {
+        ArtifactItem item = new ArtifactItem();
+
+        item.setArtifactId( "artifactId" );
+        item.setClassifier( "" );
+        item.setGroupId( "groupId" );
+        item.setType( "type" );
+        item.setVersion( "1.0" );
+
+        ArrayList list = new ArrayList();
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        // init classifier things
+        mojo.setFactory( DependencyTestUtils.getArtifactFactory() );
+        mojo.setResolver( new StubArtifactResolver( null, are, anfe ) );
+        mojo.setLocal( new StubArtifactRepository( this.testDir.getAbsolutePath() ) );
+
+        try
+        {
+            mojo.execute();
+            fail( "ExpectedException" );
+        }
+        catch ( MojoExecutionException e )
+        {
+            if ( are )
+            {
+                assertEquals( "Unable to resolve artifact.", e.getMessage() );
+            }
+            else
+            {
+                assertEquals( "Unable to find artifact.", e.getMessage() );
+            }
+        }
+    }
+
+    public void testNoArtifactItems()
+    {
+        try
+        {
+            mojo.getArtifactItems( false );
+            fail( "Expected Exception" );
+        }
+        catch ( MojoExecutionException e )
+        {
+            assertEquals( "There are no artifactItems configured.", e.getMessage() );
+        }
+
+    }
+/*
+    public void testCopyDontOverWriteReleases()
+        throws IOException, MojoExecutionException, InterruptedException
+    {
+        stubFactory.setCreateFiles( true );
+        Artifact release = stubFactory.getReleaseArtifact();
+        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        ArtifactItem item = new ArtifactItem( release );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        mojo.setOverWriteIfNewer( false );
+
+        mojo.execute();
+
+        File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+        Thread.sleep( 100 );
+        // round up to the next second
+        long time = System.currentTimeMillis() + 1000;
+        time = time - ( time % 1000 );
+        copiedFile.setLastModified( time );
+        Thread.sleep( 100 );
+
+        mojo.execute();
+
+        assertEquals( time, copiedFile.lastModified() );
+    }
+
+    public void testCopyDontOverWriteSnapshots()
+        throws IOException, MojoExecutionException, InterruptedException
+    {
+        stubFactory.setCreateFiles( true );
+        Artifact artifact = stubFactory.getSnapshotArtifact();
+        artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        ArtifactItem item = new ArtifactItem( artifact );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        mojo.setOverWriteIfNewer( false );
+
+        mojo.execute();
+
+        File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+        Thread.sleep( 100 );
+        // round up to the next second
+        long time = System.currentTimeMillis() + 1000;
+        time = time - ( time % 1000 );
+        copiedFile.setLastModified( time );
+        Thread.sleep( 100 );
+
+        mojo.execute();
+
+        assertEquals( time, copiedFile.lastModified() );
+    }
+
+    public void testCopyOverWriteReleases()
+        throws IOException, MojoExecutionException, InterruptedException
+    {
+        stubFactory.setCreateFiles( true );
+        Artifact release = stubFactory.getReleaseArtifact();
+        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        ArtifactItem item = new ArtifactItem( release );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        mojo.setOverWriteIfNewer( false );
+        mojo.setOverWriteReleases( true );
+        mojo.execute();
+
+        File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+        // round up to the next second
+        long time = System.currentTimeMillis() - 2000;
+        copiedFile.setLastModified( time );
+
+        mojo.execute();
+
+        assertTrue( time < copiedFile.lastModified() );
+    }
+
+    public void testCopyOverWriteSnapshot()
+        throws IOException, MojoExecutionException, InterruptedException
+    {
+        stubFactory.setCreateFiles( true );
+        Artifact artifact = stubFactory.getSnapshotArtifact();
+        artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        ArtifactItem item = new ArtifactItem( artifact );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+        mojo.setArtifactItems( list );
+
+        mojo.setOverWriteIfNewer( false );
+        mojo.setOverWriteReleases( false );
+        mojo.setOverWriteSnapshots( true );
+        mojo.execute();
+
+        File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+        // round up to the next second
+        long time = System.currentTimeMillis() - 2000;
+        copiedFile.setLastModified( time );
+
+        mojo.execute();
+
+        assertTrue( time < copiedFile.lastModified() );
+    }
+
+    public void testCopyOverWriteIfNewer()
+        throws IOException, MojoExecutionException, InterruptedException
+    {
+        stubFactory.setCreateFiles( true );
+        Artifact artifact = stubFactory.getSnapshotArtifact();
+        artifact.getFile().setLastModified( System.currentTimeMillis() - 2000 );
+
+        ArtifactItem item = new ArtifactItem( artifact );
+
+        ArrayList list = new ArrayList( 1 );
+        list.add( item );
+        mojo.setArtifactItems( list );
+        mojo.setOverWriteIfNewer( true );
+        mojo.execute();
+
+        File copiedFile = new File( item.getOutputDirectory(), item.getDestFileName() );
+
+        // set dest to be old
+        long time = System.currentTimeMillis() - 10000;
+        copiedFile.setLastModified( time );
+
+        // set source to be newer
+        artifact.getFile().setLastModified( time + 4000 );
+        mojo.execute();
+
+        assertTrue( time < copiedFile.lastModified() );
+    }
+    */
+}
+// TODO: test overwrite / overwrite if newer / overwrite release / overwrite
+// snapshot
+

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java?view=diff&rev=482909&r1=482908&r2=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestDefaultMarkerFileHandler.java
Tue Dec  5 21:43:12 2006
@@ -176,4 +176,12 @@
         handler.setMarkerFilesDirectory( outputFolder );
         assertSame( outputFolder, handler.getMarkerFilesDirectory() );
     }
+    
+    public void testNullParent() throws MojoExecutionException
+    {
+        DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(null,null);
+        handler.setArtifact( (Artifact) artifacts.get( 0 ) );
+        handler.setMarker();
+        assertTrue(handler.isMarkerSet());
+    }
 }

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java?view=diff&rev=482909&r1=482908&r2=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/markers/TestSourcesMarkerFileHandler.java
Tue Dec  5 21:43:12 2006
@@ -271,4 +271,19 @@
         handler.setResolved( false );
         assertFalse( handler.isResolved() );
     }
+    
+    public void testNullParent() throws MojoExecutionException
+    {
+        DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(null,null,false);
+        handler.setArtifact( (Artifact) artifacts.get( 0 ) );
+        handler.setMarker();
+        assertTrue(handler.isMarkerSet());
+    }
+    public void testNullParentResolved() throws MojoExecutionException
+    {
+        DefaultFileMarkerHandler handler = new SourcesFileMarkerHandler(null,null,true);
+        handler.setArtifact( (Artifact) artifacts.get( 0 ) );
+        handler.setMarker();
+        assertTrue(handler.isMarkerSet());
+    }
 }

Added: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml?view=auto&rev=482909
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml
(added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml
Tue Dec  5 21:43:12 2006
@@ -0,0 +1,38 @@
+<!--
+ * 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. 
+ *
+-->
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+          <configuration>
+              <project implementation="org.apache.maven.plugin.dependency.testUtils.stubs.DependencyProjectStub"/>
+          </configuration>
+      </plugin>
+    </plugins>
+  </build>
+    <dependencies>
+        <dependency>
+          <groupId>org.apache.maven</groupId>
+          <artifactId>maven-artifact</artifactId>
+          <version>2.0.4</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-test/plugin-config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message