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.io.File;
23  import java.util.Date;
24  import java.util.Iterator;
25  import java.util.List;
26  
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  
30  import de.schlichtherle.truezip.file.TFile;
31  
32  /**
33   * Display an archive's list to console. Note: inner archive file length always show 0 byte long. See TrueZip javadoc
34   * for details.
35   * <p>
36   * Example:
37   * <ul>
38   * <li>mvn truezip:ls -Dfrom=a.zip</li>
39   * </ul>
40   * </p>
41   * 
42   * @goal ls
43   * @requiresProject false
44   * @version $Id: $
45   */
46  public class CliListMojo
47      extends AbstractArchiveMojo
48  {
49      /**
50       * Path to an archive file to display.
51       * 
52       * @parameter property="from"
53       * @required
54       * @since 1.0 beta-4
55       */
56      private File from;
57  
58      /**
59       * Drill beyond sub archive.
60       * 
61       * @parameter property="followSubArchive" default-value="false"
62       * @required
63       * @since 1.0 beta-4
64       */
65      private boolean followSubArchive;
66  
67      public void execute()
68          throws MojoExecutionException, MojoFailureException
69      {
70  
71          if ( skip )
72          {
73              this.getLog().info( "Skip this execution" );
74              return;
75          }
76  
77          super.execute();
78  
79          intitializeArchiveDectector();
80  
81          Fileset fileset = new Fileset();
82          fileset.setDirectory( from.getAbsolutePath() );
83          fileset.setFollowArchive( followSubArchive );
84  
85          List<TFile> fileList = truezip.list( fileset );
86  
87          Iterator<TFile> iter = fileList.iterator();
88  
89          while ( iter.hasNext() )
90          {
91              TFile archiveFile = new TFile( iter.next().toString() );
92  
93              String relativePath = archiveFile.getPath();
94              if ( relativePath.startsWith( from.getPath() ) )
95              {
96                  relativePath = relativePath.substring( from.getPath().length() + 1 );
97              }
98  
99              long fileLen = archiveFile.length();
100 
101             System.out.println( fileLen + "\t" + new Date( archiveFile.lastModified() ) + "\t" + relativePath );
102         }
103 
104         this.tryImmediateUpdate();
105 
106     }
107 
108 }