View Javadoc
1   package org.codehaus.mojo.wagon;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.wagon.ConnectionException;
26  import org.apache.maven.wagon.Wagon;
27  import org.apache.maven.wagon.WagonException;
28  
29  public abstract class AbstractCopyMojo
30      extends AbstractDoubleWagonMojo
31  {
32  
33      protected abstract void copy( Wagon src, Wagon target )
34          throws IOException, WagonException;
35  
36      @Override
37      public void execute()
38          throws MojoExecutionException
39      {
40  
41          if ( this.skip )
42          {
43              this.getLog().info( "Skip execution." );
44              return;
45          }
46  
47          Wagon srcWagon = null;
48          Wagon targetWagon = null;
49  
50          try
51          {
52              srcWagon = createWagon( sourceId, source );
53              targetWagon = createWagon( targetId, target );
54              copy( srcWagon, targetWagon );
55          }
56          catch ( Exception e )
57          {
58              throw new MojoExecutionException( "Error during performing repository copy", e );
59          }
60          finally
61          {
62              disconnectWagon( srcWagon );
63              disconnectWagon( targetWagon );
64          }
65  
66      }
67  
68      private void disconnectWagon( Wagon wagon )
69      {
70          try
71          {
72              if ( wagon != null )
73              {
74                  wagon.disconnect();
75              }
76          }
77          catch ( ConnectionException e )
78          {
79              getLog().debug( "Error disconnecting wagon - ignored", e );
80          }
81      }
82  
83  }