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 import java.util.Arrays;
21
22 import org.apache.maven.shared.model.fileset.FileSet;
23 import org.apache.maven.wagon.Wagon;
24 import org.apache.maven.wagon.WagonException;
25 import org.codehaus.mojo.wagon.shared.WagonUpload;
26 import org.codehaus.plexus.util.StringUtils;
27
28 /**
29 * Upload multiple sets of files.
30 *
31 * @goal upload
32 * @requiresProject true
33 */
34 public class UploadMojo extends AbstractSingleWagonMojo {
35 /**
36 * Local directory to upload to wagon's "url/toDir"
37 *
38 * @parameter expression="${wagon.fromDir}" default-value="${project.basedir}"
39 */
40 private File fromDir;
41
42 /**
43 * Comma separate list of Ant's excludes to scan for local files
44 *
45 * @parameter expression="${wagon.excludes}"
46 *
47 */
48 private String excludes;
49
50 /**
51 * Comma separate list of Ant's includes to scan for local files
52 *
53 * @parameter expression="${wagon.includes}" localDirectory's Ant includes
54 */
55 private String includes;
56
57 /**
58 * Follow local symbolic link if possible
59 *
60 * @parameter expression="${wagon.followSymLink}" default-value="false"
61 */
62 private boolean followSymLink = false;
63
64 /**
65 * Use default exclude sets
66 *
67 * @parameter expression="${wagon.useDefaultExcludes}" default-value="true"
68 */
69 private boolean useDefaultExcludes = true;
70
71 /**
72 * Remote path relative to Wagon's url to upload local files to.
73 *
74 * @parameter expression="${wagon.toDir}" default-value="";
75 */
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 expression="${wagon.optimize}" default-value="false";
83 */
84
85 private boolean optimize = false;
86
87 /**
88 * @component
89 */
90 protected WagonUpload wagonUpload;
91
92 @Override
93 protected void execute(Wagon wagon) throws WagonException, IOException {
94 FileSet fileSet = new FileSet();
95
96 fileSet.setDirectory(this.fromDir.getAbsolutePath());
97
98 if (!StringUtils.isBlank(includes)) {
99 fileSet.setIncludes(Arrays.asList(StringUtils.split(this.includes, ",")));
100 }
101
102 if (!StringUtils.isBlank(excludes)) {
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 }