1 package org.apache.maven.plugin.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
34 public class WebModule
35 extends AbstractEarModule
36 {
37 protected static final String WEB_MODULE = "web";
38
39 protected static final String WEB_URI_FIELD = "web-uri";
40
41 protected static final String CONTEXT_ROOT_FIELD = "context-root";
42
43 private String contextRoot;
44
45 public WebModule()
46 {
47 }
48
49 public WebModule( Artifact a )
50 {
51 super( a );
52 this.contextRoot = getDefaultContextRoot( a );
53 }
54
55 public void appendModule( XMLWriter writer, String version )
56 {
57 writer.startElement( MODULE_ELEMENT );
58 writer.startElement( WEB_MODULE );
59 writer.startElement( WEB_URI_FIELD );
60 writer.writeText( getUri() );
61 writer.endElement();
62
63 writer.startElement( CONTEXT_ROOT_FIELD );
64 writer.writeText( getContextRoot() );
65 writer.endElement();
66
67 writer.endElement();
68
69 writeAltDeploymentDescriptor( writer, version);
70
71 writer.endElement();
72 }
73
74 public void resolveArtifact( Set artifacts )
75 throws EarPluginException, MojoFailureException
76 {
77
78 super.resolveArtifact( artifacts );
79
80
81 if ( contextRoot == null )
82 {
83 contextRoot = getDefaultContextRoot( getArtifact() );
84 }
85 }
86
87
88
89
90
91
92
93
94
95 public String getContextRoot()
96 {
97 return contextRoot;
98 }
99
100 public String getType()
101 {
102 return "war";
103 }
104
105
106
107
108
109
110
111
112 private static String getDefaultContextRoot( Artifact a )
113 {
114 if ( a == null )
115 {
116 throw new NullPointerException( "Artifact could not be null." );
117 }
118 return "/" + a.getArtifactId();
119 }
120 }