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