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 org.apache.maven.artifact.manager.WagonManager;
019    import org.apache.maven.plugin.AbstractMojo;
020    import org.apache.maven.plugin.MojoExecutionException;
021    import org.apache.maven.project.MavenProject;
022    import org.apache.maven.settings.Settings;
023    import org.apache.maven.wagon.Wagon;
024    import org.codehaus.mojo.wagon.shared.WagonFileSet;
025    import org.codehaus.mojo.wagon.shared.WagonUtils;
026    
027    /**
028     * Provides base functionality for dealing with I/O using wagon.
029     *
030     */
031    public abstract class AbstractWagonMojo extends AbstractMojo {
032    
033        /**
034         * @component
035         */
036        protected WagonManager wagonManager;
037    
038        /**
039         * The current user system settings for use in Maven.
040         *
041         * @parameter expression="${settings}"
042         * @readonly
043         */
044        protected Settings settings;
045    
046        /**
047         * Internal Maven's project
048         *
049         * @parameter expression="${project}"
050         * @readonly
051         */
052        protected MavenProject project;
053    
054        /**
055         * When <code>true</code>, skip the execution.
056         *
057         * @parameter expression="${wagon.skip}" default-value="false"
058         */
059        protected boolean skip = false;
060    
061        /**
062         * Convenient method to create a wagon
063         *
064         * @param id
065         * @param url
066         * @param wagonManager
067         * @param settings
068         * @param logger
069         * @return
070         * @throws MojoExecutionException
071         */
072        protected Wagon createWagon(String id, String url) throws MojoExecutionException {
073            try {
074                return WagonUtils.createWagon(id, url, wagonManager, settings, this.getLog());
075            } catch (Exception e) {
076                throw new MojoExecutionException("Unable to create a Wagon instance for " + url, e);
077            }
078    
079        }
080    
081        protected WagonFileSet getWagonFileSet(String fromDir, String includes, String excludes, boolean caseSensitive,
082                String toDir) {
083            return WagonUtils.getWagonFileSet(fromDir, includes, excludes, caseSensitive, toDir);
084        }
085    
086    }