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 org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.codehaus.plexus.util.StringUtils;
25
26 import de.schlichtherle.truezip.file.TFile;
27
28
29
30
31
32
33
34
35 public class CopyMojo
36 extends AbstractManipulateArchiveMojo
37 {
38
39
40
41
42
43
44
45
46 private FileItem[] files;
47
48 public void execute()
49 throws MojoExecutionException, MojoFailureException
50 {
51
52 if ( skip )
53 {
54 this.getLog().info( "Skip this execution" );
55 return;
56 }
57
58 super.execute();
59
60 intitializeArchiveDectector();
61
62 this.processFileItems();
63
64 this.processFileSets();
65
66 this.tryImmediateUpdate();
67 }
68
69 private void processFileSets()
70 throws MojoExecutionException, MojoFailureException
71 {
72 if ( this.fileset != null )
73 {
74 this.filesets.add( this.fileset );
75 this.fileset = null;
76 }
77
78 for ( int i = 0; i < filesets.size(); ++i )
79 {
80 Fileset fileSet = (Fileset) this.filesets.get( i );
81
82 if ( StringUtils.isBlank( fileSet.getDirectory() ) )
83 {
84 fileSet.setDirectory( this.project.getBasedir().getAbsolutePath() );
85 }
86
87 try
88 {
89 this.resolveRelativePath( fileSet );
90 this.truezip.copy( fileSet );
91 }
92 catch ( Exception e )
93 {
94 throw new MojoExecutionException( "Copy fileset fails", e );
95 }
96 }
97 }
98
99 private void processFileItems()
100 throws MojoExecutionException, MojoFailureException
101 {
102 for ( int i = 0; files != null && i < files.length; ++i )
103 {
104 FileItem copyInfo = files[i];
105
106 this.resolveRelativePath( copyInfo );
107
108 TFile source = new TFile( copyInfo.getSource() );
109
110 TFile dest = new TFile( copyInfo.getDestinationPath() );
111
112 try
113 {
114 this.truezip.copyFile( source, dest );
115 }
116 catch ( Exception e )
117 {
118 throw new MojoExecutionException( "Copy fileset fails", e );
119 }
120 }
121
122 }
123
124 }