You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/10/16 22:47:23 UTC

svn commit: r1398988 - in /maven/plugins/trunk/maven-dependency-plugin: pom.xml src/main/java/org/apache/maven/plugin/dependency/GetMojo.java src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java

Author: rfscholte
Date: Tue Oct 16 20:47:22 2012
New Revision: 1398988

URL: http://svn.apache.org/viewvc?rev=1398988&view=rev
Log:
[MDEP-360] Allow using folder as dependency:get destination parameter 

Modified:
    maven/plugins/trunk/maven-dependency-plugin/pom.xml
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/pom.xml?rev=1398988&r1=1398987&r2=1398988&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-dependency-plugin/pom.xml Tue Oct 16 20:47:22 2012
@@ -54,6 +54,9 @@ under the License.
     <contributor>
       <name>Bakito</name>
     </contributor>
+    <contributor>
+      <name>Kalle Korhonen</name>
+    </contributor>
   </contributors>
 
   <properties>

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java?rev=1398988&r1=1398987&r2=1398988&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java Tue Oct 16 20:47:22 2012
@@ -155,7 +155,7 @@ public class GetMojo
     private String artifact;
 
     /**
-     * The destination file to copy the artifact to, if other than the local repository
+     * The destination file or directory to copy the artifact to, if other than the local repository
      *
      * @since 2.4
      */
@@ -272,7 +272,14 @@ public class GetMojo
             }
             try
             {
-                FileUtils.copyFile( toDownload.getFile(), new File( destination ) );
+                if ( dest.isDirectory() )
+                {
+                    FileUtils.copyFileToDirectory( src, dest );
+                }
+                else
+                {
+                    FileUtils.copyFile( src, dest );
+                } 
             }
             catch ( IOException e )
             {

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java?rev=1398988&r1=1398987&r2=1398988&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugin/dependency/TestGetMojo.java Tue Oct 16 20:47:22 2012
@@ -28,6 +28,7 @@ import org.apache.maven.artifact.reposit
 import org.apache.maven.artifact.repository.layout.LegacyRepositoryLayout;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
+import org.codehaus.plexus.util.FileUtils;
 
 public class TestGetMojo
     extends AbstractDependencyMojoTestCase
@@ -49,7 +50,19 @@ public class TestGetMojo
             @Override
             public String pathOf( Artifact artifact )
             {
-                return super.pathOf( artifact ).replace( ':', '_' );
+                StringBuilder pathOf = new StringBuilder();
+                pathOf.append( artifact.getGroupId() )
+                    .append( '_' )
+                    .append( artifact.getArtifactId() )
+                    .append( '-' )
+                    .append( artifact.getVersion() );
+                if( artifact.getClassifier() != null )
+                {
+                    pathOf.append( '-' )
+                    .append( artifact.getClassifier() );
+                }
+                pathOf.append( '.' ).append( artifact.getArtifactHandler().getExtension() );
+                return pathOf.toString();
             }
         } );
     }
@@ -75,6 +88,39 @@ public class TestGetMojo
         setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
         mojo.execute();
     }
+    
+    /**
+     * Test destination parameter
+     * 
+     * @throws Exception
+     */
+    public void testDestination()
+        throws Exception
+    {
+        // Set properties, transitive = default value = true
+        setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
+        setVariableValueToObject( mojo, "repositoryUrl", "http://repo1.maven.apache.org/maven2" );
+        setVariableValueToObject( mojo, "groupId", "org.apache.maven" );
+        setVariableValueToObject( mojo, "artifactId", "maven-model" );
+        setVariableValueToObject( mojo, "version", "2.0.9" );
+        File output = new File( getBasedir(), "target/unit-tests/get-test/destination-file/maven-model-2.0.9.jar" );
+        output.delete();
+        setVariableValueToObject( mojo, "destination", output.getAbsolutePath() );
+
+        mojo.execute();
+        assertTrue( output.exists() );
+
+        // Test directory
+        output = new File( getBasedir(), "target/unit-tests/get-test/destination-dir" );
+        output.mkdirs();
+        FileUtils.cleanDirectory( output );
+        setVariableValueToObject( mojo, "destination", output.getAbsolutePath() );
+
+        mojo.execute();
+        assertTrue( new File( output, "org.apache.maven_maven-model-2.0.9.jar" ).exists() );
+    }
+    
+    
 
     /**
      * Test remote repositories parameter