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 020 import org.apache.maven.plugin.MojoExecutionException; 021 import org.apache.maven.wagon.Wagon; 022 import org.apache.maven.wagon.WagonException; 023 024 /** 025 * Download a single file. 026 * 027 * @goal download-single 028 * @requiresProject false 029 */ 030 public class DownloadSingleMojo 031 extends AbstractSingleWagonMojo 032 { 033 /** 034 * Relative path to the URL. 035 * @parameter expression="${wagon.fromFile}" 036 * @required 037 */ 038 private String fromFile; 039 040 /** 041 * Directory to download the remote file to 042 * @parameter expression="${wagon.toDir}" 043 */ 044 private File toDir; 045 046 /** 047 * File to download the remote file to. Use this option to rename the file after download. 048 * When toDir is present, this argument is ignored 049 * @parameter expression="${wagon.toFile}" 050 */ 051 private File toFile; 052 053 054 protected void execute( Wagon wagon ) 055 throws MojoExecutionException, WagonException 056 { 057 058 if ( this.skip ) 059 { 060 this.getLog().info( "Skip execution." ); 061 return; 062 } 063 064 if ( toDir != null ) 065 { 066 toFile = new File( toDir, new File( fromFile ).getName() ); 067 } 068 069 if ( toFile == null ) 070 { 071 throw new MojoExecutionException( "Either toDir or toFile is required" ); 072 } 073 074 this.getLog().info( "Downloading: " + wagon.getRepository().getUrl() + "/" + fromFile + " to " + toFile ); 075 076 wagon.get( fromFile, toFile ); 077 078 } 079 080 }