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