Author: brianf
Date: Sat Oct 14 21:43:05 2006
New Revision: 464113

URL: http://svn.apache.org/viewvc?view=rev&rev=464113
Log:
added more unit tests to unpack-dependencies

Added:
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.txt
Removed:
    
maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.zip
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/utils/SilentLog.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.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/TestUnpackDependenciesMojo.java
    
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.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=464113&r1=464112&r2=464113
==============================================================================
--- 
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
 Sat Oct 14 21:43:05 2006
@@ -119,4 +119,12 @@
         return this.log;
     }
 
+    /**
+     * @return Returns the archiverManager.
+     */
+    public ArchiverManager getArchiverManager()
+    {
+        return this.archiverManager;
+    }
+
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/SilentLog.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/SilentLog.java?view=diff&rev=464113&r1=464112&r2=464113
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/SilentLog.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/utils/SilentLog.java
 Sat Oct 14 21:43:05 2006
@@ -1,9 +1,10 @@
 package org.apache.maven.plugin.dependency.utils;
 
 import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.logging.Logger;
 
 public class SilentLog
-    implements Log
+    implements Log, Logger
 {
 
     public boolean isDebugEnabled()
@@ -72,5 +73,89 @@
 
     public void error( Throwable error )
     {
+    }
+
+    public void debug( String message )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void debug( String message, Throwable throwable )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void info( String message )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void info( String message, Throwable throwable )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void warn( String message )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void warn( String message, Throwable throwable )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void error( String message )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void error( String message, Throwable throwable )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void fatalError( String message )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void fatalError( String message, Throwable throwable )
+    {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public boolean isFatalErrorEnabled()
+    {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public Logger getChildLogger( String name )
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public int getThreshold()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public String getName()
+    {
+        // TODO Auto-generated method stub
+        return null;
     }
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java?view=diff&rev=464113&r1=464112&r2=464113
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/AbstractDependencyMojoTestCase.java
 Sat Oct 14 21:43:05 2006
@@ -27,7 +27,7 @@
         super.setUp();
         testDir = new File( getBasedir(), "target" + File.separatorChar + 
"unit-tests" + File.separatorChar
             + testDirStr + File.separatorChar );
-        DependencyTestUtils.removeDirectory(testDir);
+        DependencyTestUtils.removeDirectory( testDir );
         assertFalse( testDir.exists() );
 
         stubFactory = new ArtifactStubFactory( this.testDir, createFiles );
@@ -46,7 +46,7 @@
             {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
-                fail( "Trying to remove directory:" + 
testDir+"\r\n"+e.toString() );
+                fail( "Trying to remove directory:" + testDir + "\r\n" + 
e.toString() );
             }
             assertFalse( testDir.exists() );
         }

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=464113&r1=464112&r2=464113
==============================================================================
--- 
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
 Sat Oct 14 21:43:05 2006
@@ -554,9 +554,11 @@
 
         assertTrue( time < copiedFile.lastModified() );
     }
-    
-    public void testGetDependencies() throws MojoExecutionException
+
+    public void testGetDependencies()
+        throws MojoExecutionException
     {
-        
assertEquals(mojo.getDependencies(true).toString(),mojo.getDependencySets(true).getResolvedDependencies().toString());
+        assertEquals( mojo.getDependencies( true ).toString(), 
mojo.getDependencySets( true ).getResolvedDependencies()
+            .toString() );
     }
 }

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=464113&r1=464112&r2=464113
==============================================================================
--- 
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
 Sat Oct 14 21:43:05 2006
@@ -34,9 +34,12 @@
         mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
         // mojo.silent = true;
 
-        // i'm using one file repeatedly to unpack.
+        // it needs to get the archivermanager
+        stubFactory.setUnpackableFile( mojo );
+        // 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.zip" ) );
+            + "target/test-classes/unit/unpack-dependencies-test/test.txt" ) );
 
         assertNotNull( mojo );
         assertNotNull( mojo.project );
@@ -52,48 +55,38 @@
 
     }
 
-    public void assertNoMarkerFile( Artifact artifact )
+    public void assertUnpacked( Artifact artifact )
     {
-        DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( 
artifact, mojo.markersDirectory );
-        try
-        {
-            assertFalse( handle.isMarkerSet() );
-        }
-        catch ( MojoExecutionException e )
-        {
-            fail( e.getLongMessage() );
-        }
+        assertUnpacked( true, artifact );
+    }
+
+    public void assertUnpacked( boolean val, Artifact artifact )
+    {
+        File folder = DependencyUtil.getFormattedOutputDirectory( 
mojo.useSubDirectoryPerType,
+                                                                  
mojo.useSubDirectoryPerArtifact,
+                                                                  
mojo.outputDirectory, artifact );
+
+        File destFile = new File( folder, stubFactory.getUnpackableFileName( 
artifact ) );
+        /*
+         * System.out.println( "Checking file: " + destFile.getPath() ); if (
+         * val != destFile.exists() ) { System.out.println("FAIL!"); }
+         */
+        assertEquals( val, destFile.exists() );
+        assertMarkerFile( val, artifact );
     }
 
-    public void assertMarkerFile( Artifact artifact )
+    public void assertMarkerFile( boolean val, Artifact artifact )
     {
         DefaultFileMarkerHandler handle = new DefaultFileMarkerHandler( 
artifact, mojo.markersDirectory );
         try
         {
-            assertTrue( handle.isMarkerSet() );
+            assertEquals( val, handle.isMarkerSet() );
         }
         catch ( MojoExecutionException e )
         {
             fail( e.getLongMessage() );
         }
     }
-    
-    public void assertMarkerFile(boolean val, Artifact artifact)
-    {
-        if (val)
-        {
-            assertMarkerFile(artifact);
-        }
-        else
-        {
-            assertNoMarkerFile(artifact);
-        }
-    }
-
-    public void testNull()
-    {
-
-    }
 
     public void testUnpackDependenciesMojo()
         throws Exception
@@ -103,7 +96,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            assertMarkerFile( artifact );
+            assertUnpacked( artifact );
         }
     }
 
@@ -116,7 +109,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            assertMarkerFile( artifact );
+            assertUnpacked( artifact );
         }
     }
 
@@ -133,8 +126,7 @@
         {
             Artifact artifact = (Artifact) iter.next();
 
-            assertMarkerFile(!artifact.getType().equalsIgnoreCase( "jar" 
),artifact );
-            
+            assertUnpacked( !artifact.getType().equalsIgnoreCase( "jar" ), 
artifact );
         }
     }
 
@@ -155,7 +147,8 @@
         {
             Artifact artifact = (Artifact) iter.next();
 
-            assertMarkerFile(artifact.getType().equalsIgnoreCase( "jar" 
),artifact );        }
+            assertUnpacked( artifact.getType().equalsIgnoreCase( "jar" ), 
artifact );
+        }
     }
 
     public void testUnpackDependenciesMojoSubPerType()
@@ -170,10 +163,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File folder = DependencyUtil.getFormattedOutputDirectory( true, 
false, mojo.outputDirectory, artifact );
-            File file = new File( folder, fileName );
-            assertMarkerFile(artifact);
+            assertUnpacked( artifact );
         }
     }
 
@@ -187,10 +177,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File folder = DependencyUtil.getFormattedOutputDirectory( false, 
true, mojo.outputDirectory, artifact );
-            File file = new File( folder, fileName );
-            assertMarkerFile(artifact);
+            assertUnpacked( artifact );
         }
     }
 
@@ -207,10 +194,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File folder = DependencyUtil.getFormattedOutputDirectory( true, 
true, mojo.outputDirectory, artifact );
-            File file = new File( folder, fileName );
-            assertMarkerFile(artifact);
+            assertUnpacked( artifact );
         }
     }
 
@@ -227,10 +211,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File file = new File( mojo.outputDirectory, fileName );
-
-            assertMarkerFile( saf.include( artifact ), artifact );
+            assertUnpacked( saf.include( artifact ), artifact );
         }
     }
 
@@ -248,10 +229,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File file = new File( mojo.outputDirectory, fileName );
-
-            assertMarkerFile( saf.include( artifact ), artifact );
+            assertUnpacked( saf.include( artifact ), artifact );
         }
     }
 
@@ -268,10 +246,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File file = new File( mojo.outputDirectory, fileName );
-
-            assertMarkerFile( saf.include( artifact ), artifact );
+            assertUnpacked( saf.include( artifact ), artifact );
         }
     }
 
@@ -287,9 +262,7 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File file = new File( mojo.outputDirectory, fileName );
-            assertMarkerFile( Artifact.SCOPE_PROVIDED.equals( 
artifact.getScope() ), artifact );
+            assertUnpacked( Artifact.SCOPE_PROVIDED.equals( 
artifact.getScope() ), artifact );
         }
     }
 
@@ -306,30 +279,20 @@
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            String fileName = DependencyUtil.getFormattedFileName( artifact, 
false );
-            File file = new File( mojo.outputDirectory, fileName );
-
-            assertMarkerFile( Artifact.SCOPE_SYSTEM.equals( 
artifact.getScope() ), artifact );
+            assertUnpacked( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() 
), artifact );
         }
     }
 
-/*    public void testCDMClassifier()
-        throws Exception
-    {
-        dotestUnpackDependenciesMojoClassifierType( "jdk14", null );
-    }
-
-    public void testCDMType()
-        throws Exception
-    {
-        dotestUnpackDependenciesMojoClassifierType( null, "zip" );
-    }
-
-    public void testCDMClassifierType()
-        throws Exception
-    {
-        dotestUnpackDependenciesMojoClassifierType( "jdk14", "war" );
-    }*/
+    /*
+     * public void testCDMClassifier() throws Exception {
+     * dotestUnpackDependenciesMojoClassifierType( "jdk14", null ); }
+     * 
+     * public void testCDMType() throws Exception {
+     * dotestUnpackDependenciesMojoClassifierType( null, "zip" ); }
+     * 
+     * public void testCDMClassifierType() throws Exception {
+     * dotestUnpackDependenciesMojoClassifierType( "jdk14", "war" ); }
+     */
 
     public void dotestUnpackDependenciesMojoClassifierType( String 
testClassifier, String testType )
         throws Exception
@@ -362,7 +325,7 @@
             String fileName = artifact.getArtifactId() + useClassifier + "-" + 
artifact.getVersion() + "." + useType;
             File file = new File( mojo.outputDirectory, fileName );
 
-            assertMarkerFile(artifact);
+            assertUnpacked( artifact );
         }
     }
 
@@ -397,132 +360,115 @@
         {
         }
     }
-/*
-    public void testDontOverWriteRelease()
-        throws MojoExecutionException, InterruptedException, IOException
-    {
-
-        Set artifacts = new HashSet();
-        Artifact release = stubFactory.getReleaseArtifact();
-        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
-
-        artifacts.add( release );
-
-        mojo.project.setArtifacts( artifacts );
-        mojo.project.setDependencyArtifacts( artifacts );
-
-        mojo.overWriteIfNewer = false;
-
-        mojo.execute();
-
-        File copiedFile = new File( mojo.outputDirectory, 
DependencyUtil.getFormattedFileName( release, false ) );
-
-        Thread.sleep( 100 );
-        long time = System.currentTimeMillis();
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertEquals( time, copiedFile.lastModified() );
-    }
-
-    public void testOverWriteRelease()
-        throws MojoExecutionException, InterruptedException, IOException
-    {
-
-        Set artifacts = new HashSet();
-        Artifact release = stubFactory.getReleaseArtifact();
-        release.getFile().setLastModified( System.currentTimeMillis() - 2000 );
-
-        artifacts.add( release );
-
-        mojo.project.setArtifacts( artifacts );
-        mojo.project.setDependencyArtifacts( artifacts );
-
-        mojo.overWriteReleases = true;
-        mojo.overWriteIfNewer = false;
-
-        mojo.execute();
-
-        File copiedFile = new File( mojo.outputDirectory, 
DependencyUtil.getFormattedFileName( release, false ) );
-
-        Thread.sleep( 100 );
-        long time = System.currentTimeMillis();
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertTrue( time < copiedFile.lastModified() );
-    }
-
-    public void testDontOverWriteSnap()
-        throws MojoExecutionException, InterruptedException, IOException
-    {
-
-        Set artifacts = new HashSet();
-        Artifact snap = stubFactory.getSnapshotArtifact();
-        snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
-
-        artifacts.add( snap );
-
-        mojo.project.setArtifacts( artifacts );
-        mojo.project.setDependencyArtifacts( artifacts );
-
-        mojo.overWriteReleases = false;
-        mojo.overWriteSnapshots = false;
-        mojo.overWriteIfNewer = false;
-
-        mojo.execute();
-
-        File copiedFile = new File( mojo.outputDirectory, 
DependencyUtil.getFormattedFileName( snap, false ) );
-
-        Thread.sleep( 100 );
-        long time = System.currentTimeMillis();
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertEquals( time, copiedFile.lastModified() );
-    }
-
-    public void testOverWriteSnap()
-        throws MojoExecutionException, InterruptedException, IOException
-    {
-
-        Set artifacts = new HashSet();
-        Artifact snap = stubFactory.getSnapshotArtifact();
-        snap.getFile().setLastModified( System.currentTimeMillis() - 2000 );
-
-        artifacts.add( snap );
-
-        mojo.project.setArtifacts( artifacts );
-        mojo.project.setDependencyArtifacts( artifacts );
-
-        mojo.overWriteReleases = false;
-        mojo.overWriteSnapshots = true;
-        mojo.overWriteIfNewer = false;
-
-        mojo.execute();
-
-        File copiedFile = new File( mojo.outputDirectory, 
DependencyUtil.getFormattedFileName( snap, false ) );
-
-        Thread.sleep( 100 );
-        long time = System.currentTimeMillis();
-        copiedFile.setLastModified( time );
-        Thread.sleep( 100 );
-
-        mojo.execute();
-
-        assertTrue( time < copiedFile.lastModified() );
-    }
-
-    public void testGetDependencies()
-        throws MojoExecutionException
-    {
-        assertSame( mojo.getDependencies( true ), mojo.getDependencySets( true 
).getResolvedDependencies() );
-    }
-*/
+    /*
+     * public void testDontOverWriteRelease() throws MojoExecutionException,
+     * InterruptedException, IOException {
+     * 
+     * Set artifacts = new HashSet(); Artifact release =
+     * stubFactory.getReleaseArtifact(); release.getFile().setLastModified(
+     * System.currentTimeMillis() - 2000 );
+     * 
+     * artifacts.add( release );
+     * 
+     * mojo.project.setArtifacts( artifacts );
+     * mojo.project.setDependencyArtifacts( artifacts );
+     * 
+     * mojo.overWriteIfNewer = false;
+     * 
+     * mojo.execute();
+     * 
+     * File copiedFile = new File( mojo.outputDirectory,
+     * DependencyUtil.getFormattedFileName( release, false ) );
+     * 
+     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
+     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
+     * 
+     * mojo.execute();
+     * 
+     * assertEquals( time, copiedFile.lastModified() ); }
+     * 
+     * public void testOverWriteRelease() throws MojoExecutionException,
+     * InterruptedException, IOException {
+     * 
+     * Set artifacts = new HashSet(); Artifact release =
+     * stubFactory.getReleaseArtifact(); release.getFile().setLastModified(
+     * System.currentTimeMillis() - 2000 );
+     * 
+     * artifacts.add( release );
+     * 
+     * mojo.project.setArtifacts( artifacts );
+     * mojo.project.setDependencyArtifacts( artifacts );
+     * 
+     * mojo.overWriteReleases = true; mojo.overWriteIfNewer = false;
+     * 
+     * mojo.execute();
+     * 
+     * File copiedFile = new File( mojo.outputDirectory,
+     * DependencyUtil.getFormattedFileName( release, false ) );
+     * 
+     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
+     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
+     * 
+     * mojo.execute();
+     * 
+     * assertTrue( time < copiedFile.lastModified() ); }
+     * 
+     * public void testDontOverWriteSnap() throws MojoExecutionException,
+     * InterruptedException, IOException {
+     * 
+     * Set artifacts = new HashSet(); Artifact snap =
+     * stubFactory.getSnapshotArtifact(); snap.getFile().setLastModified(
+     * System.currentTimeMillis() - 2000 );
+     * 
+     * artifacts.add( snap );
+     * 
+     * mojo.project.setArtifacts( artifacts );
+     * mojo.project.setDependencyArtifacts( artifacts );
+     * 
+     * mojo.overWriteReleases = false; mojo.overWriteSnapshots = false;
+     * mojo.overWriteIfNewer = false;
+     * 
+     * mojo.execute();
+     * 
+     * File copiedFile = new File( mojo.outputDirectory,
+     * DependencyUtil.getFormattedFileName( snap, false ) );
+     * 
+     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
+     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
+     * 
+     * mojo.execute();
+     * 
+     * assertEquals( time, copiedFile.lastModified() ); }
+     * 
+     * public void testOverWriteSnap() throws MojoExecutionException,
+     * InterruptedException, IOException {
+     * 
+     * Set artifacts = new HashSet(); Artifact snap =
+     * stubFactory.getSnapshotArtifact(); snap.getFile().setLastModified(
+     * System.currentTimeMillis() - 2000 );
+     * 
+     * artifacts.add( snap );
+     * 
+     * mojo.project.setArtifacts( artifacts );
+     * mojo.project.setDependencyArtifacts( artifacts );
+     * 
+     * mojo.overWriteReleases = false; mojo.overWriteSnapshots = true;
+     * mojo.overWriteIfNewer = false;
+     * 
+     * mojo.execute();
+     * 
+     * File copiedFile = new File( mojo.outputDirectory,
+     * DependencyUtil.getFormattedFileName( snap, false ) );
+     * 
+     * Thread.sleep( 100 ); long time = System.currentTimeMillis();
+     * copiedFile.setLastModified( time ); Thread.sleep( 100 );
+     * 
+     * mojo.execute();
+     * 
+     * assertTrue( time < copiedFile.lastModified() ); }
+     * 
+     * public void testGetDependencies() throws MojoExecutionException {
+     * assertSame( mojo.getDependencies( true ), mojo.getDependencySets( true
+     * ).getResolvedDependencies() ); }
+     */
 }

Modified: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java?view=diff&rev=464113&r1=464112&r2=464113
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
 (original)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/ArtifactStubFactory.java
 Sat Oct 14 21:43:05 2006
@@ -4,12 +4,18 @@
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
-
+import org.codehaus.plexus.logging.Logger;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 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.AbstractDependencyMojo;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.archiver.war.WarArchiver;
 import org.codehaus.plexus.util.FileUtils;
 
 public class ArtifactStubFactory
@@ -20,12 +26,22 @@
 
     File srcFile;
 
+    boolean createUnpackableFile;
+
+    AbstractDependencyMojo mojo;
+
     public ArtifactStubFactory( File workingDir, boolean createFiles )
     {
         this.workingDir = new File( workingDir, "localTestRepo" );
         this.createFiles = createFiles;
     }
 
+    public void setUnpackableFile( AbstractDependencyMojo mojo )
+    {
+        this.createUnpackableFile = true;
+        this.mojo = mojo;
+    }
+
     public Artifact createArtifact( String groupId, String artifactId, String 
version )
         throws IOException
     {
@@ -72,12 +88,68 @@
         {
             theFile.createNewFile();
         }
+        else if ( createUnpackableFile )
+        {
+            try
+            {
+                createUnpackableFile( artifact, theFile );
+            }
+            catch ( NoSuchArchiverException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            catch ( ArchiverException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            catch ( IOException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
         else
         {
             FileUtils.copyFile( srcFile, theFile );
         }
 
         artifact.setFile( theFile );
+    }
+
+    public String getUnpackableFileName( Artifact artifact )
+    {
+        return "" + artifact.getGroupId() + "-" + artifact.getArtifactId() + 
"-" + artifact.getVersion() + "-"
+            + artifact.getClassifier() + "-" + artifact.getType() + ".txt";
+    }
+
+    public void createUnpackableFile( Artifact artifact, File destFile )
+        throws NoSuchArchiverException, ArchiverException, IOException
+    {
+        ArchiverManager archiverManager = mojo.getArchiverManager();
+        Archiver archiver = archiverManager.getArchiver( destFile );
+
+        archiver.setDestFile( destFile );
+        archiver.addFile( srcFile, getUnpackableFileName( artifact ) );
+
+        try
+        {
+            DependencyTestUtils.setVariableValueToObject( archiver, "logger", 
new SilentLog() );
+        }
+        catch ( IllegalAccessException e )
+        {
+            System.out.println( "Unable to override logger with silent log." );
+            e.printStackTrace();
+        }
+        if ( archiver instanceof WarArchiver )
+        {
+            WarArchiver war = (WarArchiver) archiver;
+            // the use of this is counter-intuitive:
+            // http://jira.codehaus.org/browse/PLX-286
+            war.setIgnoreWebxml( false );
+        }
+        archiver.createArchive();
     }
 
     public Artifact getReleaseArtifact()

Added: 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java?view=auto&rev=464113
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
 (added)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/utils/TestSilentLog.java
 Sat Oct 14 21:43:05 2006
@@ -0,0 +1,62 @@
+package org.apache.maven.plugin.dependency.utils;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.logging.Logger;
+
+public class TestSilentLog
+    extends TestCase
+{
+
+    public void testLog()
+    {
+        Log log = new SilentLog();
+        String text = new String( "Text" );
+        Throwable e = new RuntimeException();
+        log.debug( text );
+        log.debug( text, e );
+        log.debug( e );
+        log.info( text );
+        log.info( text, e );
+        log.info( e );
+        log.warn( text );
+        log.warn( text, e );
+        log.warn( e );
+        log.error( text );
+        log.error( text, e );
+        log.error( e );
+        log.isDebugEnabled();
+        log.isErrorEnabled();
+        log.isWarnEnabled();
+        log.isInfoEnabled();
+    }
+
+    public void testLogger()
+    {
+        Logger log = new SilentLog();
+        String text = new String( "Text" );
+        Throwable e = new RuntimeException();
+
+        log.debug( text );
+        log.debug( text, e );
+        log.error( text );
+        log.error( text, e );
+        log.warn( text );
+        log.warn( text, e );
+        log.info(text);
+        log.info(text,e);
+        
+        log.fatalError(text);
+        log.fatalError(text,e);
+        log.getChildLogger(text);
+        log.getName();
+        log.getThreshold();
+        log.isDebugEnabled();
+        log.isErrorEnabled();
+        log.isFatalErrorEnabled();
+        log.isInfoEnabled();
+        log.isWarnEnabled();
+    }
+
+}

Added: 
maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.txt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.txt?view=auto&rev=464113
==============================================================================
--- 
maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.txt
 (added)
+++ 
maven/plugins/trunk/maven-dependency-plugin/src/test/resources/unit/unpack-dependencies-test/test.txt
 Sat Oct 14 21:43:05 2006
@@ -0,0 +1,13 @@
+<project>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+          <configuration>
+              <project 
implementation="org.apache.maven.plugin.dependency.stubs.DependencyProjectStub"/>
+              <silent>true</silent>
+          </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file


Reply via email to