1 | |
package org.apache.maven.plugins.site; |
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.IOException; |
24 | |
|
25 | |
import org.apache.maven.archiver.MavenArchiveConfiguration; |
26 | |
import org.apache.maven.archiver.MavenArchiver; |
27 | |
import org.apache.maven.artifact.DependencyResolutionRequiredException; |
28 | |
import org.apache.maven.plugin.MojoExecutionException; |
29 | |
import org.apache.maven.plugin.MojoFailureException; |
30 | |
import org.apache.maven.project.MavenProjectHelper; |
31 | |
|
32 | |
import org.codehaus.plexus.archiver.ArchiverException; |
33 | |
import org.codehaus.plexus.archiver.jar.JarArchiver; |
34 | |
import org.codehaus.plexus.archiver.jar.ManifestException; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public class SiteJarMojo |
46 | |
extends SiteMojo |
47 | |
{ |
48 | 0 | private static final String[] DEFAULT_ARCHIVE_EXCLUDES = new String[]{}; |
49 | |
|
50 | 0 | private static final String[] DEFAULT_ARCHIVE_INCLUDES = new String[]{"**/**"}; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
private String jarOutputDirectory; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
private String finalName; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
private MavenProjectHelper projectHelper; |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
private boolean attach; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
private JarArchiver jarArchiver; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | 0 | private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private String[] archiveIncludes; |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
private String[] archiveExcludes; |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
public void execute() |
122 | |
throws MojoExecutionException, MojoFailureException |
123 | |
{ |
124 | 0 | if ( !outputDirectory.exists() ) |
125 | |
{ |
126 | 0 | super.execute(); |
127 | |
} |
128 | |
|
129 | |
try |
130 | |
{ |
131 | 0 | File outputFile = createArchive( outputDirectory, |
132 | |
finalName + "-" + getClassifier() + "." + getArtifactType() ); |
133 | |
|
134 | 0 | if ( attach ) |
135 | |
{ |
136 | 0 | projectHelper.attachArtifact( project, getArtifactType(), getClassifier(), outputFile ); |
137 | |
} |
138 | |
else |
139 | |
{ |
140 | 0 | getLog().info( "NOT adding site jar to the list of attached artifacts." ); |
141 | |
} |
142 | |
} |
143 | 0 | catch ( ArchiverException e ) |
144 | |
{ |
145 | 0 | throw new MojoExecutionException( "Error while creating archive.", e ); |
146 | |
} |
147 | 0 | catch ( IOException e ) |
148 | |
{ |
149 | 0 | throw new MojoExecutionException( "Error while creating archive.", e ); |
150 | |
} |
151 | 0 | catch ( ManifestException e ) |
152 | |
{ |
153 | 0 | throw new MojoExecutionException( "Error while creating archive.", e ); |
154 | |
} |
155 | 0 | catch ( DependencyResolutionRequiredException e ) |
156 | |
{ |
157 | 0 | throw new MojoExecutionException( "Error while creating archive.", e ); |
158 | 0 | } |
159 | 0 | } |
160 | |
|
161 | |
protected String getArtifactType() |
162 | |
{ |
163 | 0 | return "jar"; |
164 | |
} |
165 | |
|
166 | |
protected String getClassifier() |
167 | |
{ |
168 | 0 | return "site"; |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
private File createArchive( File siteDirectory, String jarFilename ) |
183 | |
throws ArchiverException, IOException, ManifestException, DependencyResolutionRequiredException |
184 | |
{ |
185 | 0 | File siteJar = new File( jarOutputDirectory, jarFilename ); |
186 | |
|
187 | 0 | MavenArchiver archiver = new MavenArchiver(); |
188 | |
|
189 | 0 | archiver.setArchiver( this.jarArchiver ); |
190 | |
|
191 | 0 | archiver.setOutputFile( siteJar ); |
192 | |
|
193 | 0 | if ( !siteDirectory.isDirectory() ) |
194 | |
{ |
195 | 0 | getLog().warn( "JAR will be empty - no content was marked for inclusion !" ); |
196 | |
} |
197 | |
else |
198 | |
{ |
199 | 0 | archiver.getArchiver().addDirectory( siteDirectory, getArchiveIncludes(), getArchiveExcludes() ); |
200 | |
} |
201 | |
|
202 | 0 | archiver.createArchive( project, archive ); |
203 | |
|
204 | 0 | return siteJar; |
205 | |
} |
206 | |
|
207 | |
private String[] getArchiveIncludes() |
208 | |
{ |
209 | 0 | if ( this.archiveIncludes != null && this.archiveIncludes.length > 0 ) |
210 | |
{ |
211 | 0 | return this.archiveIncludes; |
212 | |
} |
213 | |
|
214 | 0 | return DEFAULT_ARCHIVE_INCLUDES; |
215 | |
} |
216 | |
|
217 | |
private String[] getArchiveExcludes() |
218 | |
{ |
219 | 0 | if ( this.archiveExcludes != null && this.archiveExcludes.length > 0 ) |
220 | |
{ |
221 | 0 | return this.archiveExcludes; |
222 | |
} |
223 | 0 | return DEFAULT_ARCHIVE_EXCLUDES; |
224 | |
} |
225 | |
} |