001 /** 002 * Copyright 2008-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.codehaus.mojo.wagon; 017 018 /** 019 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 020 * agreements. See the NOTICE file distributed with this work for additional information regarding 021 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 022 * "License"); you may not use this file except in compliance with the License. You may obtain a 023 * copy of the License at 024 * 025 * http://www.apache.org/licenses/LICENSE-2.0 026 * 027 * Unless required by applicable law or agreed to in writing, software distributed under the License 028 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 029 * or implied. See the License for the specific language governing permissions and limitations under 030 * the License. 031 */ 032 033 import java.io.File; 034 import java.io.IOException; 035 036 import org.apache.maven.plugin.MojoExecutionException; 037 import org.apache.maven.wagon.Wagon; 038 import org.apache.maven.wagon.WagonException; 039 import org.codehaus.plexus.util.StringUtils; 040 041 /** 042 * Upload a single file with option to change name 043 * 044 * @goal upload-single 045 * @requiresProject false 046 */ 047 public class UploadSingleMojo extends AbstractSingleWagonMojo { 048 /** 049 * Path to a local file to be uploaded 050 * 051 * @parameter expression="${wagon.fromFile}" 052 * @required 053 */ 054 private File fromFile; 055 056 /** 057 * Relative path to the URL. When blank, default to fromFile's file name. 058 * 059 * @parameter expression="${wagon.toFile}" 060 */ 061 private String toFile; 062 063 @Override 064 protected void execute(Wagon wagon) throws MojoExecutionException, WagonException, IOException { 065 if (this.skip) { 066 this.getLog().info("Skip execution."); 067 return; 068 } 069 070 if (StringUtils.isBlank(toFile)) { 071 toFile = fromFile.getName(); 072 } 073 074 this.getLog().info("Uploading: " + fromFile + " " + wagon.getRepository().getUrl() + "/" + toFile); 075 076 wagon.put(fromFile, toFile); 077 078 } 079 080 }