I have an enhancement I offer to contribute, if this mail is going to
the wrong place i apologize and ask "Where should I send it?".
I have been looking for a good way to download an artifact from the
command line. dependency:get can put the file to my local repo or
optionally in a named file, but I want to get the file and retain
whatever name that file has.
I added code in the GetMojo to support a parameter to specify a
destination directory and one to optionally strip the version tag from
the file name. I didn't find any prior art for a test on the existing
destination parameter to copy paste so there is no test case =(
Attached is a svn diff of my change. It includes a version name change
to exclude my magic build from being overwritten if a real version 2.5.2
is released.
Cheers!
/ Andreas
Index: src/main/java/org/apache/maven/plugin/dependency/GetMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/dependency/GetMojo.java (revision 1381468)
+++ src/main/java/org/apache/maven/plugin/dependency/GetMojo.java (working copy)
@@ -32,6 +32,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.dependency.utils.DependencyUtil;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -163,8 +164,25 @@
private String destination;
/**
+ * The destination directory to copy the artifact to, if other than the local repository.
+ * Ignored if destination property specifying destination file is set.
*
+ * @since 2.5.2-dreas
*/
+ @Parameter( property = "destDir" )
+ private String destinationDirectory;
+
+ /**
+ * When used in combination with destinationDirectory ans set to true the version tag is stripped from the file name.
+ *
+ * @since 2.5.2-dreas
+ */
+ @Parameter( property = "stripVersion", defaultValue = "false" )
+ private boolean stripVersion = false;
+
+ /**
+ *
+ */
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true )
private List<ArtifactRepository> pomRemoteRepositories;
@@ -281,6 +299,35 @@
+ " : " + e.getMessage(), e );
}
}
+
+ else if ( destinationDirectory != null )
+ {
+ File src = toDownload.getFile();
+ String destFileName = toDownload.getFile().getName();
+
+ if (stripVersion) {
+ destFileName = DependencyUtil.getFormattedFileName(toDownload, true);
+ }
+
+ File destDir = new File( destinationDirectory );
+ File destFile = new File ( destDir, destFileName );
+
+ if ( getLog().isInfoEnabled() )
+ {
+ getLog().info( "Copying " + src.getAbsolutePath() + " to " + destFile.getAbsolutePath() );
+ }
+ try
+ {
+ destDir.mkdirs();
+ FileUtils.copyFile( toDownload.getFile(), destFile );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException(
+ "Couldn't copy downloaded artifact from " + src.getAbsolutePath() + " to " + destFile.getAbsolutePath()
+ + " : " + e.getMessage(), e );
+ }
+ }
}
ArtifactRepository parseRepository( String repo, ArtifactRepositoryPolicy policy )
Index: pom.xml
===================================================================
--- pom.xml (revision 1381468)
+++ pom.xml (working copy)
@@ -30,7 +30,7 @@
</parent>
<artifactId>maven-dependency-plugin</artifactId>
- <version>2.5.1</version>
+ <version>2.5.2-dreas</version>
<packaging>maven-plugin</packaging>
<name>Maven Dependency Plugin</name>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]