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 /** 41 * Provides base functionality for dealing with I/O using single wagon. 42 * 43 */ 44 public abstract class AbstractSingleWagonMojo extends AbstractWagonMojo { 45 46 /** 47 * URL to upload to or download from or list. Must exist and point to a directory. 48 * 49 * @parameter expression="${wagon.url}" 50 * @required 51 */ 52 private String url; 53 54 /** 55 * settings.xml's server id for the URL. This is used when wagon needs extra authentication information. 56 * 57 * @parameter expression="${wagon.serverId}" default-value="serverId"; 58 */ 59 private String serverId; 60 61 @Override 62 public void execute() throws MojoExecutionException { 63 if (this.skip) { 64 this.getLog().info("Skip execution."); 65 return; 66 } 67 68 Wagon wagon = null; 69 try { 70 wagon = createWagon(serverId, url); 71 execute(wagon); 72 } catch (WagonException e) { 73 throw new MojoExecutionException("Error handling resource", e); 74 } catch (IOException e) { 75 throw new MojoExecutionException("Error handling resource", e); 76 } finally { 77 disconnectQuietly(wagon); 78 } 79 } 80 81 protected void disconnectQuietly(Wagon wagon) { 82 if (wagon == null) { 83 return; 84 } 85 try { 86 wagon.disconnect(); 87 } catch (ConnectionException e) { 88 getLog().debug("Error disconnecting wagon - ignored", e); 89 } 90 } 91 92 /** 93 * Perform the necessary action. To be implemented in the child mojo. 94 * 95 * @param wagon 96 * @throws MojoExecutionException 97 * @throws WagonException 98 */ 99 protected abstract void execute(Wagon wagon) throws MojoExecutionException, WagonException, IOException; 100 101 }