Author: carlos
Date: Wed Oct 26 17:17:12 2011
New Revision: 1189325

URL: http://svn.apache.org/viewvc?rev=1189325&view=rev
Log:
[MDEP-334] Add a destination parameter to the get mojo

Modified:
    
maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/GetMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/site/apt/usage.apt.vm

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=1189325&r1=1189324&r2=1189325&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
 Wed Oct 26 17:17:12 2011
@@ -19,12 +19,15 @@ package org.apache.maven.plugin.dependen
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -150,6 +153,13 @@ public class GetMojo
     private String artifact;
 
     /**
+     * The destination file to copy the artifact to, if other than the local 
repository
+     * @parameter expression="${dest}"
+     * @since 2.4
+     */
+    private String destination;
+
+    /**
      *
      * @parameter expression="${project.remoteArtifactRepositories}"
      * @required
@@ -271,6 +281,25 @@ public class GetMojo
         {
             throw new MojoExecutionException( "Couldn't download artifact: " + 
e.getMessage(), e );
         }
+
+        if ( destination != null )
+        {
+            File src = toDownload.getFile();
+            File dest = new File( destination );
+            if ( getLog().isInfoEnabled() )
+            {
+                getLog().info( "Copying " + src.getAbsolutePath() + " to " + 
dest.getAbsolutePath() );
+            }
+            try
+            {
+                FileUtils.copyFile( toDownload.getFile(), new File( 
destination ) );
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Couldn't copy downloaded 
artifact from " + src.getAbsolutePath()
+                    + " to " + dest.getAbsolutePath() + " : " + 
e.getMessage(), e );
+            }
+        }
     }
 
     private ArtifactRepositoryLayout getLayout( String id )

Modified: maven/plugins/trunk/maven-dependency-plugin/src/site/apt/usage.apt.vm
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/site/apt/usage.apt.vm?rev=1189325&r1=1189324&r2=1189325&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/site/apt/usage.apt.vm 
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/site/apt/usage.apt.vm Wed 
Oct 26 17:17:12 2011
@@ -673,6 +673,6 @@ mvn dependency:tree -Doutput=/path/to/fi
 +-----+
 mvn dependency:get -DgroupId=org.apache.maven -DartifactId=maven-core 
-Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources 
-DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,myrepo::::http://myrepo.com/maven2
 mvn dependency:get -DartifactId=org.apache.maven -DartifactId=maven-core 
-Dversion=2.2.1 -Dpackaging=jar -Dclassifier=sources 
-DremoteRepositories=http://repo1.maven.apache.org/maven2 
-mvn dependency:get -Dartifact=org.apache.maven:maven-core:2.2.1:jar:sources 
-DremoteRepositories=http://repo1.maven.apache.org/maven2 
+mvn dependency:get -Dartifact=org.apache.maven:maven-core:2.2.1:jar:sources 
-DremoteRepositories=http://repo1.maven.apache.org/maven2 -Ddest=/tmp/myfile.jar
 +-----+
 


Reply via email to