maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r450663 - in /maven/plugins/trunk/maven-dependency-plugin/src: main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java
Date Thu, 28 Sep 2006 02:01:42 GMT
Author: brianf
Date: Wed Sep 27 19:01:42 2006
New Revision: 450663

URL: http://svn.apache.org/viewvc?view=rev&rev=450663
Log:
More mojo integration tests

Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestCopyDependenciesMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java?view=diff&rev=450663&r1=450662&r2=450663
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
Wed Sep 27 19:01:42 2006
@@ -43,7 +43,7 @@
      * @parameter expression="${stripVersion}" default-value="false" 
      * @parameter
      */
-    private boolean stripVersion = false;
+    protected boolean stripVersion = false;
 
     /**
      * Main entry into mojo. Gets the list of dependencies and iterates through calling copyArtifact.

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=450663&r1=450662&r2=450663
==============================================================================
--- 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
Wed Sep 27 19:01:42 2006
@@ -1,10 +1,12 @@
 package org.apache.maven.plugin.dependency;
 
 import java.io.File;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugin.dependency.utils.ArtifactStubFactory;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
 import org.apache.maven.project.MavenProject;
@@ -12,6 +14,7 @@
 public class TestCopyDependenciesMojo
     extends AbstractDependencyMojoTestCase
 {
+
     protected void setUp()
         throws Exception
     {
@@ -19,17 +22,12 @@
         super.setUp( "copy-dependencies", true );
     }
 
-    /**
-     * tests the proper discovery and configuration of the mojo
-     * 
-     * @throws Exception
-     */
-    public void testcompileTestEnvironment()
+    private CopyDependenciesMojo getNewMojo()
         throws Exception
     {
         File testPom = new File( getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml"
);
         CopyDependenciesMojo mojo = (CopyDependenciesMojo) lookupMojo( "copy-dependencies",
testPom );
-
+        mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
         assertNotNull( mojo );
         assertNotNull( mojo.project );
         MavenProject project = mojo.project;
@@ -41,18 +39,288 @@
         project.setArtifacts( artifacts );
         project.setDependencyArtifacts( directArtifacts );
 
-        mojo.outputDirectory = new File( this.testDir, "outputDirectory" );
+        return mojo;
+
+    }
+
+    /**
+     * tests the proper discovery and configuration of the mojo
+     * 
+     * @throws Exception
+     */
+    public void testCopyDependenciesMojo()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.execute();
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+            assertTrue( file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoStripVersion()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.stripVersion = true;
+        mojo.execute();
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, true );
+            File file = new File( mojo.outputDirectory, fileName );
+            assertTrue( file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoNoTransitive()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.excludeTransitive = true;
+        mojo.execute();
+        Iterator iter = mojo.project.getDependencyArtifacts().iterator();
+
+        // test - get all direct dependencies and verify that they exist
+        // then delete the file and at the end, verify the folder is empty.
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+            assertTrue( file.exists() );
+            file.delete();
+            assertFalse( file.exists() );
+        }
+        // assumes you can't delete a folder that has files.
+        assertTrue( mojo.outputDirectory.delete() );
+    }
+
+    public void testCopyDependenciesMojoExcludeType()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.excludeTypes = "jar";
+        mojo.execute();
+
+        // test - get all direct dependencies and verify that they exist if they
+        // are not a jar
+        // then delete the file and at the end, verify the folder is empty.
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+            assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), !file.exists() );
+            file.delete();
+            assertFalse( file.exists() );
+        }
+        // assumes you can't delete a folder that has files.
+        assertTrue( mojo.outputDirectory.delete() );
+    }
+
+    public void testCopyDependenciesMojoIncludeType()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+
+        mojo.includeTypes = "jar";
+        // if include is used, exclude should be ignored.
+        mojo.excludeTypes = "jar";
+
         mojo.execute();
 
-        Iterator iter = artifacts.iterator();
+        // test - get all direct dependencies and verify that they exist only if
+        // they are a jar
+        // then delete the file and at the end, verify the folder is empty.
+        Iterator iter = mojo.project.getArtifacts().iterator();
         while ( iter.hasNext() )
         {
             Artifact artifact = (Artifact) iter.next();
-            // TODO: verify there is a test for this method.
-            // TODO: create test for striping versions too
             String fileName = DependencyUtil.getFormattedFileName( artifact, false );
             File file = new File( mojo.outputDirectory, fileName );
+            assertEquals( artifact.getType().equalsIgnoreCase( "jar" ), file.exists() );
+            file.delete();
+            assertFalse( file.exists() );
+        }
+        // assumes you can't delete a folder that has files.
+        assertTrue( mojo.outputDirectory.delete() );
+    }
+
+    public void testCopyDependenciesMojoSubPerType()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.useSubDirectoryPerType = true;
+        mojo.execute();
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        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 );
             assertTrue( file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoSubPerArtifact()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.useSubDirectoryPerArtifact = true;
+        mojo.execute();
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        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 );
+            assertTrue( file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoSubPerArtifactAndType()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getTypedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.useSubDirectoryPerArtifact = true;
+        mojo.useSubDirectoryPerType = true;
+        mojo.execute();
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        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 );
+            assertTrue( file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoIncludeCompileScope()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.includeScope = "compile";
+        mojo.execute();
+        ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope );
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+
+            assertEquals( saf.include( artifact ), file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoIncludeTestScope()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.includeScope = "test";
+        mojo.execute();
+        ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope );
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+
+            assertEquals( saf.include( artifact ), file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoIncludeRuntimeScope()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.includeScope = "runtime";
+        mojo.execute();
+        ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope );
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+
+            assertEquals( saf.include( artifact ), file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoIncludeprovidedScope()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.includeScope = "provided";
+        mojo.execute();
+        ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope );
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+
+            assertEquals( saf.include( artifact ), file.exists() );
+        }
+    }
+
+    public void testCopyDependenciesMojoIncludesystemScope()
+        throws Exception
+    {
+        CopyDependenciesMojo mojo = getNewMojo();
+        mojo.project.setArtifacts( stubFactory.getScopedArtifacts() );
+        mojo.project.setDependencyArtifacts( new HashSet() );
+        mojo.includeScope = "system";
+        mojo.execute();
+        ScopeArtifactFilter saf = new ScopeArtifactFilter( mojo.includeScope );
+
+        Iterator iter = mojo.project.getArtifacts().iterator();
+        while ( iter.hasNext() )
+        {
+            Artifact artifact = (Artifact) iter.next();
+            String fileName = DependencyUtil.getFormattedFileName( artifact, false );
+            File file = new File( mojo.outputDirectory, fileName );
+
+            assertEquals( saf.include( artifact ), file.exists() );
         }
     }
 }



Mime
View raw message