1 package org.codehaus.mojo.truezip;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStream;
26 import java.io.PrintStream;
27 import java.util.List;
28
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugin.MojoFailureException;
31 import org.codehaus.plexus.util.IOUtil;
32 import org.codehaus.plexus.util.StringUtils;
33
34 import de.schlichtherle.truezip.file.TFile;
35
36
37
38
39
40
41
42
43 public class ListMojo
44 extends AbstractManipulateArchiveMojo
45 {
46
47
48
49
50
51
52
53 private File outputFile;
54
55
56
57
58
59
60
61 private boolean printFullPath = true;
62
63 public void execute()
64 throws MojoExecutionException, MojoFailureException
65 {
66
67 if ( skip )
68 {
69 this.getLog().info( "Skip this execution" );
70 return;
71 }
72
73 super.execute();
74
75 intitializeArchiveDectector();
76
77 PrintStream ps = System.out;
78
79 OutputStream os = null;
80
81 if ( this.outputFile != null )
82 {
83 try
84 {
85 outputFile.getParentFile().mkdirs();
86 os = new FileOutputStream( outputFile );
87 ps = new PrintStream( os );
88 }
89 catch ( IOException e )
90 {
91 throw new MojoFailureException( e.getMessage() );
92 }
93 }
94
95 try
96 {
97 this.processFileSets( ps );
98 }
99 finally
100 {
101 IOUtil.close( os );
102 }
103
104 this.tryImmediateUpdate();
105
106 }
107
108 private void processFileSets( PrintStream ps )
109 throws MojoExecutionException, MojoFailureException
110 {
111 if ( this.fileset != null )
112 {
113 this.filesets.add( this.fileset );
114 this.fileset = null;
115 }
116
117 for ( int i = 0; i < filesets.size(); ++i )
118 {
119 Fileset fileSet = (Fileset) this.filesets.get( i );
120
121 if ( StringUtils.isBlank( fileSet.getDirectory() ) )
122 {
123 fileSet.setDirectory( this.project.getBasedir().getAbsolutePath() );
124 }
125
126 this.resolveRelativePath( fileSet );
127
128 List<TFile> fileList = this.truezip.list( this.filesets.get( i ) );
129
130 for ( int j = 0; j < fileList.size(); ++j )
131 {
132 TFile file = fileList.get( j );
133 if ( printFullPath )
134 {
135 ps.println( ( file.getPath() ) );
136 }
137 else
138 {
139 int startPos = fileSet.getDirectory().length() + 1;
140 ps.println( ( file.getPath().substring( startPos ) ) );
141 }
142
143 }
144 }
145 }
146 }