View Javadoc
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.util.Iterator;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.MojoFailureException;
26  import org.codehaus.plexus.util.StringUtils;
27  
28  import de.schlichtherle.truezip.file.TFile;
29  
30  /**
31   * Move a single file or multiple files (via FileSet) between archives or directories.
32   * 
33   * @goal move
34   * @phase process-resources
35   * @version $Id: $
36   */
37  public class MoveMojo
38      extends AbstractManipulateArchiveMojo
39  {
40      /**
41       * Path to original file.
42       * 
43       * @parameter
44       * @since 1.0 beta-1
45       */
46      private String from;
47  
48      /**
49       * Path to destination file.
50       * 
51       * @parameter
52       * @since 1.0 beta-1
53       */
54      private String to;
55  
56      public void execute()
57          throws MojoExecutionException, MojoFailureException
58      {
59  
60          if ( skip )
61          {
62              this.getLog().info( "Skip this execution" );
63              return;
64          }
65  
66          super.execute();
67  
68          intitializeArchiveDectector();
69  
70          if ( !StringUtils.isBlank( from ) )
71          {
72              TFile file = new TFile( this.resolveRelativePath( from ) );
73  
74              if ( StringUtils.isBlank( from ) )
75              {
76                  throw new MojoExecutionException(
77                                                    "You have specified 'from' configuration to perform the move, but 'to' configuration is not available. " );
78              }
79  
80              TFile tofile = new TFile( this.resolveRelativePath( to ) );
81  
82              try
83              {
84                  this.truezip.moveFile( file, tofile );
85              }
86              catch ( Exception e )
87              {
88                  throw new MojoExecutionException( "Move file fails", e );
89              }
90          }
91  
92          if ( this.fileset != null )
93          {
94              this.filesets.add( this.fileset );
95              this.fileset = null;
96          }
97  
98          for ( Iterator<Fileset> it = filesets.iterator(); it.hasNext(); )
99          {
100             Fileset oneFileSet = (Fileset) it.next();
101 
102             try
103             {
104                 this.resolveRelativePath( oneFileSet );
105                 this.truezip.move( oneFileSet );
106             }
107             catch ( Exception e )
108             {
109                 throw new MojoExecutionException( "Move fileset fails", e );
110             }
111 
112         }
113 
114         this.tryImmediateUpdate();
115 
116     }
117 }