1 package org.codehaus.mojo.truezip; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.File; 23 import java.io.IOException; 24 25 import org.apache.maven.plugin.MojoExecutionException; 26 import org.apache.maven.plugin.MojoFailureException; 27 28 import de.schlichtherle.truezip.file.TFile; 29 30 /** 31 * Copy an archive/directory to another archive/directory. Mainly used from command line to unpack/pack any known 32 * archive type. 33 * <p> 34 * Example: 35 * <ul> 36 * <li>mvn truezip:cp -Dfrom=a.zip -Dto=b</li> 37 * <li>mvn truezip:cp -Dfrom=b -Dto=b.zip</li> 38 * </ul> 39 * </p> 40 * 41 * @goal cp 42 * @requiresProject false 43 * @version $Id: $ 44 */ 45 public class CliCopyMojo 46 extends AbstractArchiveMojo 47 { 48 /** 49 * Path to an archive to be unpacked. 50 * 51 * @parameter property="from" 52 * @required 53 * @since 1.0 beta-4 54 */ 55 private File from; 56 57 /** 58 * Path to an archive or directory to unpack to. 59 * 60 * @parameter property="to" 61 * @required 62 * @since 1.0 beta-4 63 */ 64 private File to; 65 66 public void execute() 67 throws MojoExecutionException, MojoFailureException 68 { 69 if ( skip ) 70 { 71 this.getLog().info( "Skip this execution" ); 72 return; 73 } 74 75 super.execute(); 76 77 intitializeArchiveDectector(); 78 79 try 80 { 81 truezip.copyFile( new TFile( from ), new TFile( to ) ); 82 } 83 catch ( IOException e ) 84 { 85 throw new MojoExecutionException( "Unable to copy: " + from + " to " + to, e ); 86 } 87 88 this.tryImmediateUpdate(); 89 90 } 91 92 }