View Javadoc

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