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