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  import java.io.IOException;
20  
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.wagon.Wagon;
23  import org.apache.maven.wagon.WagonException;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  /**
27   * Upload a single file with option to change name
28   *
29   * @goal upload-single
30   * @requiresProject false
31   */
32  public class UploadSingleMojo extends AbstractSingleWagonMojo {
33      /**
34       * Path to a local file to be uploaded
35       *
36       * @parameter expression="${wagon.fromFile}"
37       * @required
38       */
39      private File fromFile;
40  
41      /**
42       * Relative path to the URL. When blank, default to fromFile's file name.
43       *
44       * @parameter expression="${wagon.toFile}"
45       */
46      private String toFile;
47  
48      @Override
49      protected void execute(Wagon wagon) throws MojoExecutionException, WagonException, IOException {
50          if (this.skip) {
51              this.getLog().info("Skip execution.");
52              return;
53          }
54  
55          if (StringUtils.isBlank(toFile)) {
56              toFile = fromFile.getName();
57          }
58  
59          this.getLog().info("Uploading: " + fromFile + " " + wagon.getRepository().getUrl() + "/" + toFile);
60  
61          wagon.put(fromFile, toFile);
62  
63      }
64  
65  }