1 package org.codehaus.mojo.natives.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import java.io.File;
25
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugins.annotations.Component;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.project.MavenProjectHelper;
32 import org.codehaus.mojo.natives.NativeSources;
33 import org.codehaus.plexus.archiver.util.DefaultFileSet;
34 import org.codehaus.plexus.archiver.zip.ZipArchiver;
35
36
37
38
39
40 @Mojo(name = "inczip", defaultPhase = LifecyclePhase.PACKAGE)
41 public class NativeBundleIncludeFilesMojo
42 extends AbstractNativeMojo
43 {
44
45
46
47
48
49 @Parameter
50 private NativeSources[] sources = new NativeSources[0];
51
52
53
54
55
56 @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.inczip", required = true)
57 private File incZipFile;
58
59
60
61
62
63 @Parameter(defaultValue = "false")
64 private boolean skipIncludeDeployment;
65
66
67
68
69
70 @Component
71 private MavenProjectHelper projectHelper;
72
73 public void execute()
74 throws MojoExecutionException
75 {
76 if ( skipIncludeDeployment )
77 {
78 return;
79 }
80
81 if ( this.sources.length != 0 )
82 {
83 try
84 {
85 ZipArchiver archiver = new ZipArchiver();
86
87 boolean zipIt = false;
88 for ( int i = 0; i < sources.length; ++i )
89 {
90 if ( sources[i].isDeployable() )
91 {
92 DefaultFileSet fileSet = new DefaultFileSet();
93 fileSet.setUsingDefaultExcludes( true );
94 fileSet.setDirectory( sources[i].getDirectory() );
95 fileSet.setIncludes( sources[i].getIncludes() );
96 fileSet.setExcludes( sources[i].getExcludes() );
97 archiver.addFileSet( fileSet );
98 zipIt = true;
99 }
100 }
101
102 if ( zipIt )
103 {
104 archiver.setDestFile( this.incZipFile );
105 archiver.createArchive();
106 projectHelper.attachArtifact( this.project, INCZIP_TYPE, null, this.incZipFile );
107 }
108 }
109 catch ( Exception e )
110 {
111 throw new MojoExecutionException( e.getMessage(), e );
112 }
113 }
114 }
115
116 }