View Javadoc

1   package org.codehaus.mojo.wagon;
2   
3   /**
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    * 
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.io.File;
19  
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.wagon.Wagon;
22  import org.apache.maven.wagon.WagonException;
23  
24  /**
25   * Download a single file.
26   * 
27   * @goal download-single
28   * @requiresProject false
29   */
30  public class DownloadSingleMojo
31      extends AbstractSingleWagonMojo
32  {
33      /**
34       * Relative path to the URL.
35       * @parameter expression="${wagon.fromFile}"
36       * @required 
37       */
38      private String fromFile;
39      
40      /**
41       * Directory to download the remote file to
42       * @parameter expression="${wagon.toDir}" 
43       */
44      private File toDir;
45  
46      /**
47       * File to download the remote file to.  Use this option to rename the file after download.
48       * When toDir is present, this argument is ignored
49       * @parameter expression="${wagon.toFile}" 
50       */
51      private File toFile;
52      
53  
54      protected void execute( Wagon wagon )
55          throws MojoExecutionException, WagonException
56      {
57          
58          if ( this.skip )
59          {
60              this.getLog().info( "Skip execution." );
61              return;
62          }
63          
64          if ( toDir != null )
65          {
66              toFile = new File( toDir, new File( fromFile ).getName() );
67          }
68          
69          if ( toFile == null )
70          {
71              throw new MojoExecutionException( "Either toDir or toFile is required" );
72          }
73          
74          this.getLog().info( "Downloading: " + wagon.getRepository().getUrl() + "/" + fromFile + " to " + toFile );
75  
76          wagon.get( fromFile, toFile );
77  
78      }
79  
80  }