View Javadoc

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.IOException;
19  
20  import org.apache.maven.plugin.MojoExecutionException;
21  import org.apache.maven.wagon.ConnectionException;
22  import org.apache.maven.wagon.Wagon;
23  import org.apache.maven.wagon.WagonException;
24  
25  public abstract class AbstractCopyMojo
26      extends AbstractDoubleWagonMojo
27  {
28  
29      protected abstract void copy(  Wagon src, Wagon target ) 
30          throws IOException, WagonException;
31      
32      public void execute()
33          throws MojoExecutionException
34      {
35          
36          if ( this.skip )
37          {
38              this.getLog().info( "Skip execution." );
39              return;
40          }
41          
42          Wagon srcWagon = null;
43          Wagon targetWagon = null;
44  
45          try
46          {
47              srcWagon = createWagon( sourceId, source );
48              targetWagon = createWagon( targetId, target );
49              copy( srcWagon, targetWagon );
50          }
51          catch ( Exception e )
52          {
53              throw new MojoExecutionException( "Error during performing repository copy", e );
54          }
55          finally
56          {
57              disconnectWagon( srcWagon );
58              disconnectWagon( targetWagon );
59          }
60  
61      }
62      
63      private void disconnectWagon( Wagon wagon )
64      {
65          try
66          {
67              if ( wagon != null )
68              {
69                  wagon.disconnect();
70              }
71          }
72          catch ( ConnectionException e )
73          {
74              getLog().debug( "Error disconnecting wagon - ignored", e );
75          }        
76      }
77  
78  }