1 package org.apache.maven.plugins.ear;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 * The {@link EarModule} implementation for an Acr Module.
30 *
31 * @author <a href="mailto:khmarbaise@apache.org">Karl Heinz Marbaise</a>
32 * @since 3.0.0
33 */
34 public class AcrModule
35 extends AbstractEarModule
36 {
37 private Boolean includeInApplicationXml = Boolean.FALSE;
38
39 private static final String APP_CLIENT = "app-client";
40
41 /**
42 * Create an instance.
43 */
44 public AcrModule()
45 {
46 super();
47 }
48
49 /**
50 * @param a {@link Artifact}
51 * @param defaultLibBundleDir The default library bundle directory.
52 * @param includeInApplicationXml Include the application xml or not.
53 */
54 public AcrModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
55 {
56 super( a );
57 setLibBundleDir( defaultLibBundleDir );
58 this.includeInApplicationXml = includeInApplicationXml;
59
60 }
61
62 /**
63 * {@inheritDoc}
64 */
65 public void appendModule( XMLWriter writer, String version, Boolean generateId )
66 {
67 // Generates an entry in the application.xml only if
68 // includeInApplicationXml is set
69 if ( includeInApplicationXml )
70 {
71 startModuleElement( writer, generateId );
72 writer.startElement( APP_CLIENT );
73 writer.writeText( getUri() );
74 writer.endElement();
75
76 writeAltDeploymentDescriptor( writer, version );
77
78 writer.endElement();
79 }
80 }
81
82 /**
83 * {@inheritDoc}
84 */
85 public void resolveArtifact( Set<Artifact> artifacts )
86 throws EarPluginException, MojoFailureException
87 {
88 // Let's resolve the artifact
89 super.resolveArtifact( artifacts );
90
91 // If the defaultLibBundleDir is set and no bundle dir is
92 // set, set the default as bundle dir
93 setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
94 }
95
96 /**
97 * {@inheritDoc}
98 */
99 public String getType()
100 {
101 return APP_CLIENT;
102 }
103
104 private void setLibBundleDir( String defaultLibBundleDir )
105 {
106 if ( defaultLibBundleDir != null && bundleDir == null )
107 {
108 this.bundleDir = defaultLibBundleDir;
109 }
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 public boolean changeManifestClasspath()
116 {
117 return false;
118 }
119 }