1 | |
package org.apache.maven.plugin.war; |
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.archiver.MavenArchiver; |
23 | |
import org.apache.maven.artifact.DependencyResolutionRequiredException; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.codehaus.plexus.archiver.jar.Manifest; |
26 | |
import org.codehaus.plexus.archiver.jar.ManifestException; |
27 | |
import org.codehaus.plexus.archiver.war.WarArchiver; |
28 | |
import org.codehaus.plexus.util.IOUtil; |
29 | |
import org.codehaus.plexus.util.WriterFactory; |
30 | |
|
31 | |
import java.io.File; |
32 | |
import java.io.IOException; |
33 | |
import java.io.PrintWriter; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 6 | public class WarManifestMojo |
47 | |
extends AbstractWarMojo |
48 | |
{ |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
private WarArchiver warArchiver; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void execute() |
63 | |
throws MojoExecutionException |
64 | |
{ |
65 | 5 | File manifestDir = new File( getWarSourceDirectory(), "META-INF" ); |
66 | 5 | if ( !manifestDir.exists() ) |
67 | |
{ |
68 | 0 | manifestDir.mkdirs(); |
69 | |
} |
70 | 5 | File manifestFile = new File( manifestDir, "MANIFEST.MF" ); |
71 | 5 | MavenArchiver ma = new MavenArchiver(); |
72 | 5 | ma.setArchiver( warArchiver ); |
73 | 5 | ma.setOutputFile( manifestFile ); |
74 | |
|
75 | 5 | PrintWriter printWriter = null; |
76 | |
try |
77 | |
{ |
78 | 5 | Manifest mf = ma.getManifest( getProject(), getArchive() ); |
79 | 5 | printWriter = new PrintWriter( WriterFactory.newWriter( manifestFile, WriterFactory.UTF_8 ) ); |
80 | 5 | mf.write( printWriter ); |
81 | |
} |
82 | 0 | catch ( ManifestException e ) |
83 | |
{ |
84 | 0 | throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e ); |
85 | |
} |
86 | 0 | catch ( DependencyResolutionRequiredException e ) |
87 | |
{ |
88 | 0 | throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e ); |
89 | |
} |
90 | 0 | catch ( IOException e ) |
91 | |
{ |
92 | 0 | throw new MojoExecutionException( "Error preparing the manifest: " + e.getMessage(), e ); |
93 | |
} |
94 | |
finally |
95 | |
{ |
96 | 5 | IOUtil.close( printWriter ); |
97 | 5 | } |
98 | 5 | } |
99 | |
} |