View Javadoc
1   package org.codehaus.mojo.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.IOException;
24  import java.util.Arrays;
25  
26  import org.apache.maven.plugins.annotations.Component;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.shared.model.fileset.FileSet;
30  import org.apache.maven.wagon.Wagon;
31  import org.apache.maven.wagon.WagonException;
32  import org.codehaus.mojo.wagon.shared.WagonUpload;
33  import org.codehaus.plexus.util.StringUtils;
34  
35  /**
36   * Upload multiple sets of files.
37   */
38  @Mojo( name = "upload" )
39  public class UploadMojo
40      extends AbstractSingleWagonMojo
41  {
42      /**
43       * Local directory to upload to wagon's "url/toDir".
44       */
45      @Parameter( property = "wagon.fromDir", defaultValue = "${project.basedir}")
46      private File fromDir;
47  
48      /**
49       * Comma separate list of Ant's excludes to scan for local files.
50       */
51      @Parameter( property = "wagon.excludes")
52      private String excludes;
53  
54      /**
55       * Comma separate list of Ant's includes to scan for local files.
56       */
57      @Parameter( property = "wagon.includes")
58      private String includes;
59  
60      /**
61       * Follow local symbolic link if possible.
62       */
63      @Parameter( property = "wagon.followSymLink", defaultValue = "false")
64      private boolean followSymLink = false;
65  
66      /**
67       * Use default exclude sets.
68       */
69      @Parameter( property = "wagon.useDefaultExcludes", defaultValue = "true")
70      private boolean useDefaultExcludes = true;
71  
72      /**
73       * Remote path relative to Wagon's url to upload local files to.
74       */
75      @Parameter( property = "wagon.toDir")
76      private String toDir = "";
77  
78      /**
79       * Optimize the upload by locally compressed all files in one bundle, upload the bundle, and finally remote
80       * uncompress the bundle.
81       */
82      @Parameter( property = "wagon.optimize", defaultValue = "false")
83      private boolean optimize = false;
84  
85      @Component
86      protected WagonUpload wagonUpload;
87  
88      @Override
89      protected void execute( Wagon wagon )
90          throws WagonException, IOException
91      {
92          FileSet fileSet = new FileSet();
93  
94          fileSet.setDirectory( this.fromDir.getAbsolutePath() );
95  
96          if ( !StringUtils.isBlank( includes ) )
97          {
98              fileSet.setIncludes( Arrays.asList( StringUtils.split( this.includes, "," ) ) );
99          }
100 
101         if ( !StringUtils.isBlank( excludes ) )
102         {
103             fileSet.setExcludes( Arrays.asList( StringUtils.split( this.excludes, "," ) ) );
104         }
105 
106         fileSet.setFollowSymlinks( this.followSymLink );
107 
108         fileSet.setUseDefaultExcludes( this.useDefaultExcludes );
109 
110         fileSet.setOutputDirectory( toDir );
111 
112         this.wagonUpload.upload( wagon, fileSet, optimize, this.getLog() );
113     }
114 
115 }