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.IOException;
019    
020    import org.apache.maven.plugin.MojoExecutionException;
021    import org.apache.maven.wagon.ConnectionException;
022    import org.apache.maven.wagon.Wagon;
023    import org.apache.maven.wagon.WagonException;
024    
025    public abstract class AbstractCopyMojo
026        extends AbstractDoubleWagonMojo
027    {
028    
029        protected abstract void copy(  Wagon src, Wagon target ) 
030            throws IOException, WagonException;
031        
032        public void execute()
033            throws MojoExecutionException
034        {
035            
036            if ( this.skip )
037            {
038                this.getLog().info( "Skip execution." );
039                return;
040            }
041            
042            Wagon srcWagon = null;
043            Wagon targetWagon = null;
044    
045            try
046            {
047                srcWagon = createWagon( sourceId, source );
048                targetWagon = createWagon( targetId, target );
049                copy( srcWagon, targetWagon );
050            }
051            catch ( Exception e )
052            {
053                throw new MojoExecutionException( "Error during performing repository copy", e );
054            }
055            finally
056            {
057                disconnectWagon( srcWagon );
058                disconnectWagon( targetWagon );
059            }
060    
061        }
062        
063        private void disconnectWagon( Wagon wagon )
064        {
065            try
066            {
067                if ( wagon != null )
068                {
069                    wagon.disconnect();
070                }
071            }
072            catch ( ConnectionException e )
073            {
074                getLog().debug( "Error disconnecting wagon - ignored", e );
075            }        
076        }
077    
078    }