1 package org.codehaus.mojo.wagon;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.apache.maven.wagon.Wagon;
26 import org.apache.maven.wagon.WagonException;
27 import org.codehaus.plexus.util.StringUtils;
28
29 import java.io.File;
30
31
32
33
34 @Mojo( name = "download-single", requiresProject = false)
35 public class DownloadSingleMojo
36 extends AbstractSingleWagonMojo
37 {
38
39
40
41 @Parameter( property = "wagon.fromFile")
42 private String fromFile;
43
44
45
46
47 @Parameter( property = "wagon.toDir")
48 private File toDir;
49
50
51
52
53
54 @Parameter( property = "wagon.toFile")
55 private File toFile;
56
57
58
59
60 @Parameter( property = "wagon.skipIfExists")
61 private boolean skipIfExists;
62
63 @Override
64 protected void execute( Wagon wagon )
65 throws MojoExecutionException, WagonException
66 {
67
68 if ( this.skip )
69 {
70 this.getLog().info( "Skip execution." );
71 return;
72 }
73
74 if ( toDir != null )
75 {
76 toFile = new File( toDir, new File( fromFile ).getName() );
77 }
78
79 if ( toFile == null )
80 {
81 throw new MojoExecutionException( "Either toDir or toFile is required" );
82 }
83
84 if ( skipIfExists && toFile.exists() )
85 {
86 getLog().info("Skip execution - file " + toFile + " already exists." );
87 return;
88 }
89 this.getLog().info( "Downloading: " + wagon.getRepository().getUrl() + "/" + fromFile + " to " + toFile );
90
91 wagon.get( fromFile, toFile );
92
93 }
94
95 @Override
96 public void execute()
97 throws MojoExecutionException
98 {
99 if ( StringUtils.isBlank( this.fromFile ) ) {
100
101
102 String [] tokens = StringUtils.split( this.url, "/\\" );
103 this.fromFile = tokens[tokens.length - 1];
104 this.url = url.substring( 0, url.length() - this.fromFile.length() - 1 );
105 }
106
107 super.execute();
108 }
109 }