001    package org.codehaus.mojo.wagon;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005     * agreements. See the NOTICE file distributed with this work for additional information regarding
006     * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance with the License. You may obtain a
008     * copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software distributed under the License
013     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014     * or implied. See the License for the specific language governing permissions and limitations under
015     * the License.
016     */
017    
018    import java.io.File;
019    import java.io.IOException;
020    import java.util.Arrays;
021    
022    import org.apache.maven.shared.model.fileset.FileSet;
023    import org.apache.maven.wagon.Wagon;
024    import org.apache.maven.wagon.WagonException;
025    import org.codehaus.mojo.wagon.shared.WagonUpload;
026    import org.codehaus.plexus.util.StringUtils;
027    
028    /**
029     * Upload multiple sets of files.
030     *
031     * @goal upload
032     * @requiresProject true
033     */
034    public class UploadMojo extends AbstractSingleWagonMojo {
035        /**
036         * Local directory to upload to wagon's "url/toDir"
037         *
038         * @parameter expression="${wagon.fromDir}" default-value="${project.basedir}"
039         */
040        private File fromDir;
041    
042        /**
043         * Comma separate list of Ant's excludes to scan for local files
044         *
045         * @parameter expression="${wagon.excludes}"
046         *
047         */
048        private String excludes;
049    
050        /**
051         * Comma separate list of Ant's includes to scan for local files
052         *
053         * @parameter expression="${wagon.includes}" localDirectory's Ant includes
054         */
055        private String includes;
056    
057        /**
058         * Follow local symbolic link if possible
059         *
060         * @parameter expression="${wagon.followSymLink}" default-value="false"
061         */
062        private boolean followSymLink = false;
063    
064        /**
065         * Use default exclude sets
066         *
067         * @parameter expression="${wagon.useDefaultExcludes}" default-value="true"
068         */
069        private boolean useDefaultExcludes = true;
070    
071        /**
072         * Remote path relative to Wagon's url to upload local files to.
073         *
074         * @parameter expression="${wagon.toDir}" default-value="";
075         */
076        private String toDir = "";
077    
078        /**
079         * Optimize the upload by locally compressed all files in one bundle, upload the bundle, and finally remote
080         * uncompress the bundle.
081         *
082         * @parameter expression="${wagon.optimize}" default-value="false";
083         */
084    
085        private boolean optimize = false;
086    
087        /**
088         * @component
089         */
090        protected WagonUpload wagonUpload;
091    
092        @Override
093        protected void execute(Wagon wagon) throws WagonException, IOException {
094            FileSet fileSet = new FileSet();
095    
096            fileSet.setDirectory(this.fromDir.getAbsolutePath());
097    
098            if (!StringUtils.isBlank(includes)) {
099                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    }