1 package org.apache.maven.plugins.ear;
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.artifact.Artifact;
23 import org.apache.maven.plugin.MojoFailureException;
24 import org.codehaus.plexus.util.xml.XMLWriter;
25
26 import java.util.Set;
27
28
29
30
31
32
33 public class WebModule
34 extends AbstractEarModule
35 {
36 private static final String WEB_MODULE = "web";
37
38 private static final String WEB_URI_FIELD = "web-uri";
39
40 private static final String CONTEXT_ROOT_FIELD = "context-root";
41
42 private String contextRoot;
43
44
45
46
47 public WebModule()
48 {
49 }
50
51
52
53
54 public WebModule( Artifact a )
55 {
56 super( a );
57 this.contextRoot = getDefaultContextRoot( a );
58 }
59
60
61
62
63 public void appendModule( XMLWriter writer, String version, Boolean generateId )
64 {
65 startModuleElement( writer, generateId );
66 writer.startElement( WEB_MODULE );
67 writer.startElement( WEB_URI_FIELD );
68 writer.writeText( getUri() );
69 writer.endElement();
70
71 writer.startElement( CONTEXT_ROOT_FIELD );
72 writer.writeText( getContextRoot() );
73 writer.endElement();
74
75 writer.endElement();
76
77 writeAltDeploymentDescriptor( writer, version );
78
79 writer.endElement();
80 }
81
82
83
84
85 public void resolveArtifact( Set<Artifact> artifacts )
86 throws EarPluginException, MojoFailureException
87 {
88
89 super.resolveArtifact( artifacts );
90
91
92 if ( contextRoot == null )
93 {
94 contextRoot = getDefaultContextRoot( getArtifact() );
95 }
96 }
97
98
99
100
101
102
103
104
105 public String getContextRoot()
106 {
107 return contextRoot;
108 }
109
110
111
112
113 public String getType()
114 {
115 return "war";
116 }
117
118
119
120
121
122
123
124 private static String getDefaultContextRoot( Artifact a )
125 {
126 if ( a == null )
127 {
128 throw new NullPointerException( "Artifact could not be null." );
129 }
130 return "/" + a.getArtifactId();
131 }
132
133
134
135
136 public String getLibDir()
137 {
138 return "WEB-INF/lib";
139 }
140 }