You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2023/08/30 11:49:25 UTC
[maven-ear-plugin] branch 39 created (now 0e2c583)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a change to branch 39
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git
at 0e2c583 [MEAR-327] update to parent pom 39
This branch includes the following new commits:
new 0e2c583 [MEAR-327] update to parent pom 39
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-ear-plugin] 01/01: [MEAR-327] update to parent pom 39
Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch 39
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git
commit 0e2c58319c376510a3c8b5981743bac0584e546e
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Wed Aug 30 07:49:19 2023 -0400
[MEAR-327] update to parent pom 39
---
pom.xml | 78 +-
.../maven/plugins/ear/AbstractEarModule.java | 876 +++----
.../apache/maven/plugins/ear/AbstractEarMojo.java | 820 +++---
.../maven/plugins/ear/AbstractXmlWriter.java | 135 +-
.../apache/maven/plugins/ear/AppClientModule.java | 149 +-
.../maven/plugins/ear/ApplicationXmlWriter.java | 581 ++---
.../plugins/ear/ApplicationXmlWriterContext.java | 402 +--
.../maven/plugins/ear/EarExecutionContext.java | 221 +-
.../org/apache/maven/plugins/ear/EarModule.java | 289 ++-
.../apache/maven/plugins/ear/EarModuleFactory.java | 326 ++-
.../java/org/apache/maven/plugins/ear/EarMojo.java | 2030 +++++++--------
.../maven/plugins/ear/EarPluginException.java | 145 +-
.../apache/maven/plugins/ear/EjbClientModule.java | 120 +-
.../org/apache/maven/plugins/ear/EjbModule.java | 153 +-
.../java/org/apache/maven/plugins/ear/EjbRef.java | 93 +-
.../org/apache/maven/plugins/ear/EnvEntry.java | 307 ++-
.../plugins/ear/GenerateApplicationXmlMojo.java | 1013 ++++----
.../org/apache/maven/plugins/ear/HarModule.java | 171 +-
.../org/apache/maven/plugins/ear/JarModule.java | 245 +-
.../maven/plugins/ear/JbossAppXmlWriter.java | 387 ++-
.../maven/plugins/ear/JbossConfiguration.java | 710 +++---
.../apache/maven/plugins/ear/JbossEarModule.java | 93 +-
.../org/apache/maven/plugins/ear/ParModule.java | 118 +-
.../org/apache/maven/plugins/ear/RarModule.java | 161 +-
.../org/apache/maven/plugins/ear/ResourceRef.java | 111 +-
.../org/apache/maven/plugins/ear/SarModule.java | 198 +-
.../org/apache/maven/plugins/ear/SecurityRole.java | 270 +-
.../plugins/ear/UnknownArtifactTypeException.java | 113 +-
.../org/apache/maven/plugins/ear/WebModule.java | 275 +-
.../org/apache/maven/plugins/ear/WsrModule.java | 118 +-
.../maven/plugins/ear/util/ArtifactRepository.java | 294 +--
.../ear/util/ArtifactTypeMappingService.java | 347 ++-
.../maven/plugins/ear/util/EarMavenArchiver.java | 292 +--
.../plugins/ear/util/InvalidJavaEEVersion.java | 130 +-
.../maven/plugins/ear/util/JavaEEVersion.java | 434 ++--
.../maven/plugins/ear/AbstractEarTestBase.java | 163 +-
.../apache/maven/plugins/ear/EarModuleTest.java | 108 +-
.../org/apache/maven/plugins/ear/EnvEntryTest.java | 207 +-
.../maven/plugins/ear/it/AbstractEarPluginIT.java | 1277 +++++-----
.../org/apache/maven/plugins/ear/it/EarMojoIT.java | 2682 ++++++++++----------
.../plugins/ear/stub/ArtifactHandlerTestStub.java | 152 +-
.../plugins/ear/util/ArtifactRepositoryTest.java | 222 +-
.../ear/util/ArtifactTypeMappingServiceTest.java | 462 ++--
.../plugins/ear/util/EarMavenArchiverTest.java | 171 +-
.../maven/plugins/ear/util/JavaEEVersionTest.java | 266 +-
.../plugins/ear/util/ResourceEntityResolver.java | 87 +-
46 files changed, 8978 insertions(+), 9024 deletions(-)
diff --git a/pom.xml b/pom.xml
index dc8d7ba..b2b7232 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -18,14 +17,13 @@
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <artifactId>maven-plugins</artifactId>
<groupId>org.apache.maven.plugins</groupId>
- <version>37</version>
+ <artifactId>maven-plugins</artifactId>
+ <version>39</version>
<relativePath />
</parent>
@@ -36,6 +34,24 @@
<name>Apache Maven EAR Plugin</name>
<description>Generates a J2EE Enterprise Archive (EAR) file.</description>
+ <contributors>
+ <contributor>
+ <name>Guillaume Boucherie</name>
+ </contributor>
+ <contributor>
+ <name>Fred Bricon</name>
+ </contributor>
+ <contributor>
+ <name>Steve Moyer</name>
+ </contributor>
+ <contributor>
+ <name>Seth Rife</name>
+ </contributor>
+ <contributor>
+ <name>Laszlo Varadi</name>
+ </contributor>
+ </contributors>
+
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
@@ -43,8 +59,8 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-ear-plugin.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-ear-plugin.git</developerConnection>
- <url>https://github.com/apache/maven-ear-plugin/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-ear-plugin/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>JIRA</system>
@@ -61,24 +77,6 @@
</site>
</distributionManagement>
- <contributors>
- <contributor>
- <name>Guillaume Boucherie</name>
- </contributor>
- <contributor>
- <name>Fred Bricon</name>
- </contributor>
- <contributor>
- <name>Steve Moyer</name>
- </contributor>
- <contributor>
- <name>Seth Rife</name>
- </contributor>
- <contributor>
- <name>Laszlo Varadi</name>
- </contributor>
- </contributors>
-
<properties>
<mavenArchiverVersion>3.6.0</mavenArchiverVersion>
<mavenFilteringVersion>3.3.1</mavenFilteringVersion>
@@ -195,28 +193,28 @@
<build>
<resources>
<resource>
- <directory>src/main/filtered-resources</directory>
<filtering>true</filtering>
+ <directory>src/main/filtered-resources</directory>
</resource>
</resources>
<testResources>
<testResource>
- <directory>src/test/resources</directory>
<filtering>true</filtering>
+ <directory>src/test/resources</directory>
<includes>
<include>**/pom.xml</include>
</includes>
</testResource>
<testResource>
- <directory>src/test/resources</directory>
<filtering>false</filtering>
+ <directory>src/test/resources</directory>
<excludes>
<exclude>**/pom.xml</exclude>
</excludes>
</testResource>
<testResource>
- <directory>src/test/filtered-resources</directory>
<filtering>true</filtering>
+ <directory>src/test/filtered-resources</directory>
</testResource>
</testResources>
@@ -305,14 +303,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>integration-test</goal>
- <goal>verify</goal>
- </goals>
- </execution>
- </executions>
<configuration>
<systemPropertyVariables>
<maven.home>${maven.home}</maven.home>
@@ -322,6 +312,14 @@
<basedirectory>${basedir}</basedirectory>
</systemPropertyVariables>
</configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
@@ -337,6 +335,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <showDeprecation>true</showDeprecation>
+ <release>${javaVersion}</release>
+ </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
@@ -344,10 +346,6 @@
<version>3.3.2</version>
</dependency>
</dependencies>
- <configuration>
- <showDeprecation>true</showDeprecation>
- <release>${javaVersion}</release>
- </configuration>
</plugin>
</plugins>
</pluginManagement>
diff --git a/src/main/java/org/apache/maven/plugins/ear/AbstractEarModule.java b/src/main/java/org/apache/maven/plugins/ear/AbstractEarModule.java
index 05026b0..6ac03ed 100644
--- a/src/main/java/org/apache/maven/plugins/ear/AbstractEarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/AbstractEarModule.java
@@ -1,455 +1,421 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.ear.util.ArtifactRepository;
-import org.apache.maven.shared.mapping.MappingUtils;
-import org.codehaus.plexus.interpolation.InterpolationException;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * A base implementation of an {@link EarModule}.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public abstract class AbstractEarModule
- implements EarModule
-{
-
- /**
- * The module element.
- */
- protected static final String MODULE_ELEMENT = "module";
-
- /**
- * The java module.
- */
- protected static final String JAVA_MODULE = "java";
-
- /**
- * The alt-dd module.
- */
- protected static final String ALT_DD = "alt-dd";
-
- private Artifact artifact;
-
- // Those are set by the configuration
-
- private String groupId;
-
- private String artifactId;
-
- /**
- * The type of the artifact
- */
- protected String type;
-
- private String classifier;
-
- /**
- * The bundleDir.
- */
- protected String bundleDir;
-
- /**
- * The bundleFileName.
- */
- protected String bundleFileName;
-
- /**
- * excluded by default {@code false}.
- */
- protected Boolean excluded = Boolean.FALSE;
-
- private String uri;
-
- /**
- * unpack
- */
- protected Boolean unpack = null;
-
- /**
- * The alternate deployment descriptor.
- */
- protected String altDeploymentDescriptor;
-
- private String moduleId;
-
- /**
- * Directory of module which contains libraries packaged into module. {@code null} value means that module
- * doesn't contain any library. Each module type can provide default value for this directory and this option
- * can be used to override that default value. If module libraries are located at the root of module then use
- * single slash (/) to configure that in POM. That is, a single slash is treated as an empty string.
- */
- protected String libDirectory;
-
- /**
- * If module is considered for inclusion into the Class-Path entry of MANIFEST.mf of other modules. {@code false}
- * value leads to removal of the module from the Class-Path entry. {@code true} value leads to modification of the
- * reference to the module in the Class-Path entry if such reference exists or leads to adding of the module into
- * the Class-Path entry if such reference doesn't exist. Removal, modification or adding of the reference in the
- * Class-Path entry depends on libDirectory property of another module and on skinnyWars / skinnyModules parameters
- * of EAR Plugin.
- */
- protected boolean classPathItem;
-
- // This is injected once the module has been built.
-
- /**
- * The {@link EarExecutionContext}
- */
- protected EarExecutionContext earExecutionContext;
-
- /**
- * Empty constructor to be used when the module is built based on the configuration.
- */
- public AbstractEarModule()
- {
- }
-
- /**
- * Creates an ear module from the artifact.
- *
- * @param a the artifact
- */
- public AbstractEarModule( Artifact a )
- {
- this.artifact = a;
- this.groupId = a.getGroupId();
- this.artifactId = a.getArtifactId();
- this.type = a.getType();
- this.classifier = a.getClassifier();
- this.bundleDir = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setEarExecutionContext( EarExecutionContext earExecutionContext )
- {
- this.earExecutionContext = earExecutionContext;
- }
-
- /** {@inheritDoc} */
- public void resolveArtifact( Set<Artifact> artifacts )
- throws EarPluginException, MojoFailureException
- {
- // If the artifact is already set no need to resolve it
- if ( artifact == null )
- {
- // Make sure that at least the groupId and the artifactId are specified
- if ( groupId == null || artifactId == null )
- {
- throw new MojoFailureException( "Could not resolve artifact[" + groupId + ":" + artifactId + ":"
- + getType() + "]" );
- }
- final ArtifactRepository ar = earExecutionContext.getArtifactRepository();
- artifact = ar.getUniqueArtifact( groupId, artifactId, getType(), classifier );
- // Artifact has not been found
- if ( artifact == null )
- {
- Set<Artifact> candidates = ar.getArtifacts( groupId, artifactId, getType() );
- if ( candidates.size() > 1 )
- {
- throw new MojoFailureException( "Artifact[" + this + "] has " + candidates.size()
- + " candidates, please provide a classifier." );
- }
- else
- {
- throw new MojoFailureException( "Artifact[" + this + "] is not a dependency of the project." );
- }
- }
- }
- }
-
- /**
- * @return {@link #artifact}
- */
- public Artifact getArtifact()
- {
- return artifact;
- }
-
- /**
- * @return {@link #moduleId}
- */
- public String getModuleId()
- {
- return moduleId;
- }
-
- /**
- * @return Return the URI.
- */
- public String getUri()
- {
- if ( uri == null )
- {
- if ( getBundleDir() == null )
- {
- uri = getBundleFileName();
- }
- else
- {
- uri = getBundleDir() + getBundleFileName();
- }
- }
- return uri;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getType()
- {
- return type;
- }
-
- /**
- * Returns the artifact's groupId.
- *
- * @return {@link #groupId}
- */
- public String getGroupId()
- {
- return groupId;
- }
-
- /**
- * Returns the artifact's Id.
- *
- * @return {@link #artifactId}
- */
- public String getArtifactId()
- {
- return artifactId;
- }
-
- /**
- * Returns the artifact's classifier.
- *
- * @return the artifact classifier
- */
- public String getClassifier()
- {
- return classifier;
- }
-
- /**
- * Returns the bundle directory. If null, the module is bundled in the root of the EAR.
- *
- * @return the custom bundle directory
- */
- public String getBundleDir()
- {
- bundleDir = cleanArchivePath( bundleDir );
- return bundleDir;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getLibDir()
- {
- libDirectory = cleanArchivePath( libDirectory );
- return libDirectory;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isClassPathItem()
- {
- return classPathItem;
- }
-
- /**
- * {@inheritDoc}
- */
- public String getBundleFileName()
- {
- if ( bundleFileName == null )
- {
- try
- {
- String outputFileNameMapping = earExecutionContext.getOutputFileNameMapping();
- bundleFileName = MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact );
- }
- catch ( InterpolationException e )
- {
- // We currently ignore this here, cause assumption is that
- // has already been happened before..
- // FIXME: Should be checked first.
- }
-
- // bundleFileName = earExecutionContext.getFileNameMapping().mapFileName( artifact );
- }
- return bundleFileName;
- }
-
- /**
- * The alt-dd element specifies an optional URI to the post-assembly version of the deployment descriptor file for a
- * particular Java EE module. The URI must specify the full pathname of the deployment descriptor file relative to
- * the application's root directory.
- *
- * @return the alternative deployment descriptor for this module
- */
- public String getAltDeploymentDescriptor()
- {
- return altDeploymentDescriptor;
- }
-
- /**
- * Specify whether this module should be excluded or not.
- *
- * @return true if this module should be skipped, false otherwise
- */
- public boolean isExcluded()
- {
- return excluded;
- }
-
- /**
- * @return {@link #unpack}
- */
- public Boolean shouldUnpack()
- {
- return unpack;
- }
-
- /**
- * Writes the alternative deployment descriptor if necessary.
- *
- * @param writer the writer to use
- * @param version the java EE version in use
- */
- protected void writeAltDeploymentDescriptor( XMLWriter writer, String version )
- {
- if ( getAltDeploymentDescriptor() != null )
- {
- writer.startElement( ALT_DD );
- writer.writeText( getAltDeploymentDescriptor() );
- writer.endElement();
- }
- }
-
- /**
- * Starts a new {@link #MODULE_ELEMENT} on the specified writer, possibly including an id attribute.
- *
- * @param writer the XML writer.
- * @param generateId whether an id should be generated
- */
- protected void startModuleElement( XMLWriter writer, Boolean generateId )
- {
- writer.startElement( MODULE_ELEMENT );
-
- // If a moduleId is specified, always include it
- if ( getModuleId() != null )
- {
- writer.addAttribute( "id", getModuleId() );
- }
- else if ( generateId )
- {
- // No module id was specified but one should be generated.
- // FIXME: Should we use the mapping using outputFileNameMapping instead
- // of doing this on our own?
- Artifact theArtifact = getArtifact();
- String generatedId = theArtifact.getType().toUpperCase() + "_" + theArtifact.getGroupId() + "."
- + theArtifact.getArtifactId();
- if ( null != theArtifact.getClassifier() && theArtifact.getClassifier().trim().length() > 0 )
- {
- generatedId += "-" + theArtifact.getClassifier().trim();
- }
- writer.addAttribute( "id", generatedId );
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- sb.append( getType() ).append( ":" ).append( groupId ).append( ":" ).append( artifactId );
- if ( classifier != null )
- {
- sb.append( ":" ).append( classifier );
- }
- if ( artifact != null )
- {
- sb.append( ":" ).append( artifact.getVersion() );
- }
- return sb.toString();
- }
-
- /**
- * Cleans the path pointing to the resource inside the archive so that it might be used properly.
- *
- * @param path the path to clean, can be {@code null}
- * @return the cleaned path or {@code null} if given {@code path} is {@code null}
- */
- static String cleanArchivePath( String path )
- {
- if ( path == null )
- {
- return null;
- }
-
- // Using slashes
- path = path.replace( '\\', '/' );
-
- // Remove '/' prefix if any so that path is a relative path
- if ( path.startsWith( "/" ) )
- {
- path = path.substring( 1, path.length() );
- }
-
- if ( path.length() > 0 && !path.endsWith( "/" ) )
- {
- // Adding '/' suffix to specify a path structure if it is not empty
- path = path + "/";
- }
-
- return path;
- }
-
- /**
- * Sets the URI of the module explicitly for testing purposes.
- *
- * @param uri the uri
- */
- void setUri( String uri )
- {
- this.uri = uri;
-
- }
-
- /**
- * @return always {@code true}
- */
- public boolean changeManifestClasspath()
- {
- return true;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.ear.util.ArtifactRepository;
+import org.apache.maven.shared.mapping.MappingUtils;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * A base implementation of an {@link EarModule}.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public abstract class AbstractEarModule implements EarModule {
+
+ /**
+ * The module element.
+ */
+ protected static final String MODULE_ELEMENT = "module";
+
+ /**
+ * The java module.
+ */
+ protected static final String JAVA_MODULE = "java";
+
+ /**
+ * The alt-dd module.
+ */
+ protected static final String ALT_DD = "alt-dd";
+
+ private Artifact artifact;
+
+ // Those are set by the configuration
+
+ private String groupId;
+
+ private String artifactId;
+
+ /**
+ * The type of the artifact
+ */
+ protected String type;
+
+ private String classifier;
+
+ /**
+ * The bundleDir.
+ */
+ protected String bundleDir;
+
+ /**
+ * The bundleFileName.
+ */
+ protected String bundleFileName;
+
+ /**
+ * excluded by default {@code false}.
+ */
+ protected Boolean excluded = Boolean.FALSE;
+
+ private String uri;
+
+ /**
+ * unpack
+ */
+ protected Boolean unpack = null;
+
+ /**
+ * The alternate deployment descriptor.
+ */
+ protected String altDeploymentDescriptor;
+
+ private String moduleId;
+
+ /**
+ * Directory of module which contains libraries packaged into module. {@code null} value means that module
+ * doesn't contain any library. Each module type can provide default value for this directory and this option
+ * can be used to override that default value. If module libraries are located at the root of module then use
+ * single slash (/) to configure that in POM. That is, a single slash is treated as an empty string.
+ */
+ protected String libDirectory;
+
+ /**
+ * If module is considered for inclusion into the Class-Path entry of MANIFEST.mf of other modules. {@code false}
+ * value leads to removal of the module from the Class-Path entry. {@code true} value leads to modification of the
+ * reference to the module in the Class-Path entry if such reference exists or leads to adding of the module into
+ * the Class-Path entry if such reference doesn't exist. Removal, modification or adding of the reference in the
+ * Class-Path entry depends on libDirectory property of another module and on skinnyWars / skinnyModules parameters
+ * of EAR Plugin.
+ */
+ protected boolean classPathItem;
+
+ // This is injected once the module has been built.
+
+ /**
+ * The {@link EarExecutionContext}
+ */
+ protected EarExecutionContext earExecutionContext;
+
+ /**
+ * Empty constructor to be used when the module is built based on the configuration.
+ */
+ public AbstractEarModule() {}
+
+ /**
+ * Creates an ear module from the artifact.
+ *
+ * @param a the artifact
+ */
+ public AbstractEarModule(Artifact a) {
+ this.artifact = a;
+ this.groupId = a.getGroupId();
+ this.artifactId = a.getArtifactId();
+ this.type = a.getType();
+ this.classifier = a.getClassifier();
+ this.bundleDir = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setEarExecutionContext(EarExecutionContext earExecutionContext) {
+ this.earExecutionContext = earExecutionContext;
+ }
+
+ /** {@inheritDoc} */
+ public void resolveArtifact(Set<Artifact> artifacts) throws EarPluginException, MojoFailureException {
+ // If the artifact is already set no need to resolve it
+ if (artifact == null) {
+ // Make sure that at least the groupId and the artifactId are specified
+ if (groupId == null || artifactId == null) {
+ throw new MojoFailureException(
+ "Could not resolve artifact[" + groupId + ":" + artifactId + ":" + getType() + "]");
+ }
+ final ArtifactRepository ar = earExecutionContext.getArtifactRepository();
+ artifact = ar.getUniqueArtifact(groupId, artifactId, getType(), classifier);
+ // Artifact has not been found
+ if (artifact == null) {
+ Set<Artifact> candidates = ar.getArtifacts(groupId, artifactId, getType());
+ if (candidates.size() > 1) {
+ throw new MojoFailureException("Artifact[" + this + "] has " + candidates.size()
+ + " candidates, please provide a classifier.");
+ } else {
+ throw new MojoFailureException("Artifact[" + this + "] is not a dependency of the project.");
+ }
+ }
+ }
+ }
+
+ /**
+ * @return {@link #artifact}
+ */
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ /**
+ * @return {@link #moduleId}
+ */
+ public String getModuleId() {
+ return moduleId;
+ }
+
+ /**
+ * @return Return the URI.
+ */
+ public String getUri() {
+ if (uri == null) {
+ if (getBundleDir() == null) {
+ uri = getBundleFileName();
+ } else {
+ uri = getBundleDir() + getBundleFileName();
+ }
+ }
+ return uri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Returns the artifact's groupId.
+ *
+ * @return {@link #groupId}
+ */
+ public String getGroupId() {
+ return groupId;
+ }
+
+ /**
+ * Returns the artifact's Id.
+ *
+ * @return {@link #artifactId}
+ */
+ public String getArtifactId() {
+ return artifactId;
+ }
+
+ /**
+ * Returns the artifact's classifier.
+ *
+ * @return the artifact classifier
+ */
+ public String getClassifier() {
+ return classifier;
+ }
+
+ /**
+ * Returns the bundle directory. If null, the module is bundled in the root of the EAR.
+ *
+ * @return the custom bundle directory
+ */
+ public String getBundleDir() {
+ bundleDir = cleanArchivePath(bundleDir);
+ return bundleDir;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getLibDir() {
+ libDirectory = cleanArchivePath(libDirectory);
+ return libDirectory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isClassPathItem() {
+ return classPathItem;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getBundleFileName() {
+ if (bundleFileName == null) {
+ try {
+ String outputFileNameMapping = earExecutionContext.getOutputFileNameMapping();
+ bundleFileName = MappingUtils.evaluateFileNameMapping(outputFileNameMapping, artifact);
+ } catch (InterpolationException e) {
+ // We currently ignore this here, cause assumption is that
+ // has already been happened before..
+ // FIXME: Should be checked first.
+ }
+
+ // bundleFileName = earExecutionContext.getFileNameMapping().mapFileName( artifact );
+ }
+ return bundleFileName;
+ }
+
+ /**
+ * The alt-dd element specifies an optional URI to the post-assembly version of the deployment descriptor file for a
+ * particular Java EE module. The URI must specify the full pathname of the deployment descriptor file relative to
+ * the application's root directory.
+ *
+ * @return the alternative deployment descriptor for this module
+ */
+ public String getAltDeploymentDescriptor() {
+ return altDeploymentDescriptor;
+ }
+
+ /**
+ * Specify whether this module should be excluded or not.
+ *
+ * @return true if this module should be skipped, false otherwise
+ */
+ public boolean isExcluded() {
+ return excluded;
+ }
+
+ /**
+ * @return {@link #unpack}
+ */
+ public Boolean shouldUnpack() {
+ return unpack;
+ }
+
+ /**
+ * Writes the alternative deployment descriptor if necessary.
+ *
+ * @param writer the writer to use
+ * @param version the java EE version in use
+ */
+ protected void writeAltDeploymentDescriptor(XMLWriter writer, String version) {
+ if (getAltDeploymentDescriptor() != null) {
+ writer.startElement(ALT_DD);
+ writer.writeText(getAltDeploymentDescriptor());
+ writer.endElement();
+ }
+ }
+
+ /**
+ * Starts a new {@link #MODULE_ELEMENT} on the specified writer, possibly including an id attribute.
+ *
+ * @param writer the XML writer.
+ * @param generateId whether an id should be generated
+ */
+ protected void startModuleElement(XMLWriter writer, Boolean generateId) {
+ writer.startElement(MODULE_ELEMENT);
+
+ // If a moduleId is specified, always include it
+ if (getModuleId() != null) {
+ writer.addAttribute("id", getModuleId());
+ } else if (generateId) {
+ // No module id was specified but one should be generated.
+ // FIXME: Should we use the mapping using outputFileNameMapping instead
+ // of doing this on our own?
+ Artifact theArtifact = getArtifact();
+ String generatedId = theArtifact.getType().toUpperCase() + "_" + theArtifact.getGroupId() + "."
+ + theArtifact.getArtifactId();
+ if (null != theArtifact.getClassifier()
+ && theArtifact.getClassifier().trim().length() > 0) {
+ generatedId += "-" + theArtifact.getClassifier().trim();
+ }
+ writer.addAttribute("id", generatedId);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getType()).append(":").append(groupId).append(":").append(artifactId);
+ if (classifier != null) {
+ sb.append(":").append(classifier);
+ }
+ if (artifact != null) {
+ sb.append(":").append(artifact.getVersion());
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Cleans the path pointing to the resource inside the archive so that it might be used properly.
+ *
+ * @param path the path to clean, can be {@code null}
+ * @return the cleaned path or {@code null} if given {@code path} is {@code null}
+ */
+ static String cleanArchivePath(String path) {
+ if (path == null) {
+ return null;
+ }
+
+ // Using slashes
+ path = path.replace('\\', '/');
+
+ // Remove '/' prefix if any so that path is a relative path
+ if (path.startsWith("/")) {
+ path = path.substring(1, path.length());
+ }
+
+ if (path.length() > 0 && !path.endsWith("/")) {
+ // Adding '/' suffix to specify a path structure if it is not empty
+ path = path + "/";
+ }
+
+ return path;
+ }
+
+ /**
+ * Sets the URI of the module explicitly for testing purposes.
+ *
+ * @param uri the uri
+ */
+ void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * @return always {@code true}
+ */
+ public boolean changeManifestClasspath() {
+ return true;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java b/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java
index 704f158..40925fb 100644
--- a/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java
@@ -1,417 +1,403 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
-import org.apache.maven.plugins.ear.util.JavaEEVersion;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.configuration.PlexusConfigurationException;
-
-/**
- * A base class for EAR-processing related tasks.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public abstract class AbstractEarMojo
- extends AbstractMojo
-{
- /**
- * The application XML URI {@code META-INF/application.xml}
- */
- public static final String APPLICATION_XML_URI = "META-INF/application.xml";
-
- /**
- * The {@code META-INF} folder.
- */
- public static final String META_INF = "META-INF";
-
- /**
- * UTF-8 encoding constant.
- */
- public static final String UTF_8 = "UTF-8";
-
- /**
- * The version of the application.xml to generate. Valid values are 1.3, 1.4, 5, 6, 7 and 8.
- */
- @Parameter( defaultValue = "7" )
- protected String version;
-
- /**
- * Character encoding for the auto-generated deployment file(s).
- */
- @Parameter( defaultValue = "UTF-8" )
- protected String encoding;
-
- /**
- * Directory where the deployment descriptor file(s) will be auto-generated.
- */
- @Parameter( defaultValue = "${project.build.directory}" )
- protected String generatedDescriptorLocation;
-
- /**
- * The maven project.
- */
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
- protected MavenProject project;
-
- /**
- * The ear modules configuration.
- */
- @Parameter
- private EarModule[] modules;
-
- /**
- * The artifact type mappings.
- */
- @Parameter
- protected PlexusConfiguration artifactTypeMappings;
-
- /**
- * The default bundle dir for libraries.
- */
- @Parameter
- protected String defaultLibBundleDir;
-
- /**
- * Should libraries be added in application.xml
- */
- @Parameter( defaultValue = "false" )
- private Boolean includeLibInApplicationXml = Boolean.FALSE;
-
- /**
- * Only here to identify migration issues. The usage of this parameter will fail the build. If you need file name
- * mapping please use {@link #outputFileNameMapping} instead.
- *
- * @deprecated
- */
- @Parameter
- private String fileNameMapping;
-
- /**
- * The file name mapping to use for all dependencies included in the EAR file. The mapping between artifacts and the
- * file names which is used within the EAR file.
- * Details see
- * <a href="./examples/customize-file-name-mapping.html">Customizing The File Name Mapping</a>.
- *
- * @since 3.0.0
- */
- @Parameter( defaultValue = "@{groupId}@-@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@",
- required = true )
- private String outputFileNameMapping;
-
- /**
- * Directory that resources are copied to during the build.
- */
- @Parameter( defaultValue = "${project.build.directory}/${project.build.finalName}", required = true )
- private File workDirectory;
-
- /**
- * The JBoss specific configuration.
- *
- * @parameter
- */
- @Parameter
- private PlexusConfiguration jboss;
-
- /**
- * The id to use to define the main artifact (e.g. the artifact without a classifier) when there is multiple
- * candidates.
- *
- * @parameter
- */
- @Parameter
- private String mainArtifactId = "none";
-
- private List<EarModule> earModules;
-
- private List<EarModule> allEarModules;
-
- private List<EarModule> providedEarModules;
-
- private JbossConfiguration jbossConfiguration;
-
- /** {@inheritDoc} */
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( fileNameMapping != null )
- {
- getLog().error( "fileNameMapping has been removed with version 3.0.0. You are still using it." );
- getLog().error( "Use outputFileNameMapping instead." );
- throw new MojoExecutionException( "fileNameMapping has been removed with version 3.0.0 "
- + "but you are still using it." );
- }
-
- final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
- getLog().debug( "Resolving artifact type mappings ..." );
- ArtifactTypeMappingService typeMappingService;
- try
- {
- typeMappingService = new ArtifactTypeMappingService();
- typeMappingService.configure( artifactTypeMappings );
- }
- catch ( EarPluginException e )
- {
- throw new MojoExecutionException( "Failed to initialize artifact type mappings", e );
- }
- catch ( PlexusConfigurationException e )
- {
- throw new MojoExecutionException( "Invalid artifact type mappings configuration", e );
- }
-
- getLog().debug( "Initializing JBoss configuration if necessary ..." );
- try
- {
- initializeJbossConfiguration();
- }
- catch ( EarPluginException e )
- {
- throw new MojoExecutionException( "Failed to initialize JBoss configuration", e );
- }
-
- getLog().debug( "Initializing ear execution context" );
- EarExecutionContext earExecutionContext =
- new EarExecutionContext( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration,
- outputFileNameMapping, typeMappingService );
-
- getLog().debug( "Resolving ear modules ..." );
- List<EarModule> allModules = new ArrayList<>();
- try
- {
- if ( modules != null && modules.length > 0 )
- {
- // Let's validate user-defined modules
- EarModule module;
-
- for ( EarModule module1 : modules )
- {
- module = module1;
- getLog().debug( "Resolving ear module[" + module + "]" );
- module.setEarExecutionContext( earExecutionContext );
- module.resolveArtifact( project.getArtifacts() );
- allModules.add( module );
- }
- }
-
- // Let's add other modules
- Set<Artifact> artifacts = project.getArtifacts();
- for ( Artifact artifact : artifacts )
- {
- // If the artifact's type is POM, ignore and continue
- // since it's used for transitive deps only.
- if ( "pom".equals( artifact.getType() ) )
- {
- continue;
- }
-
- // Artifact is not yet registered and it has not test scope, nor is it optional
- ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE_PLUS_RUNTIME );
- if ( !isArtifactRegistered( artifact, allModules ) && !artifact.isOptional()
- && filter.include( artifact ) )
- {
- EarModule module = EarModuleFactory.newEarModule( artifact, javaEEVersion, defaultLibBundleDir,
- includeLibInApplicationXml, typeMappingService );
- module.setEarExecutionContext( earExecutionContext );
- allModules.add( module );
- }
- }
- }
- catch ( EarPluginException e )
- {
- throw new MojoExecutionException( "Failed to initialize ear modules", e );
- }
-
- // Now we have everything let's built modules which have not been excluded
- ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
- allEarModules = new ArrayList<>();
- providedEarModules = new ArrayList<>();
- earModules = new ArrayList<>();
- for ( EarModule earModule : allModules )
- {
- if ( earModule.isExcluded() )
- {
- getLog().debug( "Skipping ear module[" + earModule + "]" );
- }
- else
- {
- allEarModules.add( earModule );
- if ( filter.include( earModule.getArtifact() ) )
- {
- earModules.add( earModule );
- }
- else
- {
- providedEarModules.add( earModule );
- }
- }
- }
-
- }
-
- /**
- * @return The list of {@link #earModules}. This corresponds to modules needed at runtime.
- */
- protected List<EarModule> getModules()
- {
- if ( earModules == null )
- {
- throw new IllegalStateException( "Ear modules have not been initialized" );
- }
- return earModules;
- }
-
- /**
- * @return The list of {@link #allEarModules}. This corresponds to all modules (provided + compile + runtime).
- */
- protected List<EarModule> getAllEarModules()
- {
- if ( allEarModules == null )
- {
- throw new IllegalStateException( "EAR modules have not been initialized" );
- }
- return allEarModules;
- }
-
- /**
- * @return the list of {@link #providedEarModules}. This corresponds to provided modules.
- */
- protected List<EarModule> getProvidedEarModules()
- {
- if ( providedEarModules == null )
- {
- throw new IllegalStateException( "Jar modules have not been initialized" );
- }
- return providedEarModules;
- }
-
- /**
- * @return {@link MavenProject}
- */
- protected MavenProject getProject()
- {
- return project;
- }
-
- /**
- * @return {@link #workDirectory}
- */
- protected File getWorkDirectory()
- {
- return workDirectory;
- }
-
- /**
- * @return {@link #jbossConfiguration}
- */
- protected JbossConfiguration getJbossConfiguration()
- {
- return jbossConfiguration;
- }
-
- /**
- * @return {@link #outputFileNameMapping}
- */
- public String getOutputFileNameMapping()
- {
- return outputFileNameMapping;
- }
-
- private static boolean isArtifactRegistered( Artifact a, List<EarModule> currentList )
- {
- for ( EarModule em : currentList )
- {
- if ( em.getArtifact().equals( a ) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Initializes the JBoss configuration.
- *
- * @throws EarPluginException if the configuration is invalid
- */
- private void initializeJbossConfiguration()
- throws EarPluginException
- {
- if ( jboss == null )
- {
- jbossConfiguration = null;
- }
- else
- {
- String childVersion = jboss.getChild( JbossConfiguration.VERSION ).getValue();
- if ( childVersion == null )
- {
- getLog().info( "JBoss version not set, using JBoss 4 by default" );
- childVersion = JbossConfiguration.VERSION_4;
- }
- final String securityDomain = jboss.getChild( JbossConfiguration.SECURITY_DOMAIN ).getValue();
- final String unauthenticatedPrincipal =
- jboss.getChild( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL ).getValue();
-
- final PlexusConfiguration loaderRepositoryEl = jboss.getChild( JbossConfiguration.LOADER_REPOSITORY );
- final String loaderRepository = loaderRepositoryEl.getValue();
- final String loaderRepositoryClass =
- loaderRepositoryEl.getAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE );
- final PlexusConfiguration loaderRepositoryConfigEl =
- jboss.getChild( JbossConfiguration.LOADER_REPOSITORY_CONFIG );
- final String loaderRepositoryConfig = loaderRepositoryConfigEl.getValue();
- final String configParserClass =
- loaderRepositoryConfigEl.getAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE );
-
- final String jmxName = jboss.getChild( JbossConfiguration.JMX_NAME ).getValue();
- final String moduleOrder = jboss.getChild( JbossConfiguration.MODULE_ORDER ).getValue();
-
- final List<String> dataSources = new ArrayList<>();
- final PlexusConfiguration dataSourcesEl = jboss.getChild( JbossConfiguration.DATASOURCES );
- if ( dataSourcesEl != null )
- {
-
- final PlexusConfiguration[] dataSourcesConfig =
- dataSourcesEl.getChildren( JbossConfiguration.DATASOURCE );
- for ( PlexusConfiguration dataSourceConfig : dataSourcesConfig )
- {
- dataSources.add( dataSourceConfig.getValue() );
-
- }
- }
- final String libraryDirectory = jboss.getChild( JbossConfiguration.LIBRARY_DIRECTORY ).getValue();
- jbossConfiguration =
- new JbossConfiguration( childVersion, securityDomain, unauthenticatedPrincipal, jmxName,
- loaderRepository, moduleOrder, dataSources, libraryDirectory,
- loaderRepositoryConfig, loaderRepositoryClass, configParserClass );
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
+
+/**
+ * A base class for EAR-processing related tasks.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public abstract class AbstractEarMojo extends AbstractMojo {
+ /**
+ * The application XML URI {@code META-INF/application.xml}
+ */
+ public static final String APPLICATION_XML_URI = "META-INF/application.xml";
+
+ /**
+ * The {@code META-INF} folder.
+ */
+ public static final String META_INF = "META-INF";
+
+ /**
+ * UTF-8 encoding constant.
+ */
+ public static final String UTF_8 = "UTF-8";
+
+ /**
+ * The version of the application.xml to generate. Valid values are 1.3, 1.4, 5, 6, 7 and 8.
+ */
+ @Parameter(defaultValue = "7")
+ protected String version;
+
+ /**
+ * Character encoding for the auto-generated deployment file(s).
+ */
+ @Parameter(defaultValue = "UTF-8")
+ protected String encoding;
+
+ /**
+ * Directory where the deployment descriptor file(s) will be auto-generated.
+ */
+ @Parameter(defaultValue = "${project.build.directory}")
+ protected String generatedDescriptorLocation;
+
+ /**
+ * The maven project.
+ */
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ protected MavenProject project;
+
+ /**
+ * The ear modules configuration.
+ */
+ @Parameter
+ private EarModule[] modules;
+
+ /**
+ * The artifact type mappings.
+ */
+ @Parameter
+ protected PlexusConfiguration artifactTypeMappings;
+
+ /**
+ * The default bundle dir for libraries.
+ */
+ @Parameter
+ protected String defaultLibBundleDir;
+
+ /**
+ * Should libraries be added in application.xml
+ */
+ @Parameter(defaultValue = "false")
+ private Boolean includeLibInApplicationXml = Boolean.FALSE;
+
+ /**
+ * Only here to identify migration issues. The usage of this parameter will fail the build. If you need file name
+ * mapping please use {@link #outputFileNameMapping} instead.
+ *
+ * @deprecated
+ */
+ @Parameter
+ private String fileNameMapping;
+
+ /**
+ * The file name mapping to use for all dependencies included in the EAR file. The mapping between artifacts and the
+ * file names which is used within the EAR file.
+ * Details see
+ * <a href="./examples/customize-file-name-mapping.html">Customizing The File Name Mapping</a>.
+ *
+ * @since 3.0.0
+ */
+ @Parameter(
+ defaultValue = "@{groupId}@-@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@",
+ required = true)
+ private String outputFileNameMapping;
+
+ /**
+ * Directory that resources are copied to during the build.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}", required = true)
+ private File workDirectory;
+
+ /**
+ * The JBoss specific configuration.
+ *
+ * @parameter
+ */
+ @Parameter
+ private PlexusConfiguration jboss;
+
+ /**
+ * The id to use to define the main artifact (e.g. the artifact without a classifier) when there is multiple
+ * candidates.
+ *
+ * @parameter
+ */
+ @Parameter
+ private String mainArtifactId = "none";
+
+ private List<EarModule> earModules;
+
+ private List<EarModule> allEarModules;
+
+ private List<EarModule> providedEarModules;
+
+ private JbossConfiguration jbossConfiguration;
+
+ /** {@inheritDoc} */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (fileNameMapping != null) {
+ getLog().error("fileNameMapping has been removed with version 3.0.0. You are still using it.");
+ getLog().error("Use outputFileNameMapping instead.");
+ throw new MojoExecutionException(
+ "fileNameMapping has been removed with version 3.0.0 " + "but you are still using it.");
+ }
+
+ final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
+ getLog().debug("Resolving artifact type mappings ...");
+ ArtifactTypeMappingService typeMappingService;
+ try {
+ typeMappingService = new ArtifactTypeMappingService();
+ typeMappingService.configure(artifactTypeMappings);
+ } catch (EarPluginException e) {
+ throw new MojoExecutionException("Failed to initialize artifact type mappings", e);
+ } catch (PlexusConfigurationException e) {
+ throw new MojoExecutionException("Invalid artifact type mappings configuration", e);
+ }
+
+ getLog().debug("Initializing JBoss configuration if necessary ...");
+ try {
+ initializeJbossConfiguration();
+ } catch (EarPluginException e) {
+ throw new MojoExecutionException("Failed to initialize JBoss configuration", e);
+ }
+
+ getLog().debug("Initializing ear execution context");
+ EarExecutionContext earExecutionContext = new EarExecutionContext(
+ project,
+ mainArtifactId,
+ defaultLibBundleDir,
+ jbossConfiguration,
+ outputFileNameMapping,
+ typeMappingService);
+
+ getLog().debug("Resolving ear modules ...");
+ List<EarModule> allModules = new ArrayList<>();
+ try {
+ if (modules != null && modules.length > 0) {
+ // Let's validate user-defined modules
+ EarModule module;
+
+ for (EarModule module1 : modules) {
+ module = module1;
+ getLog().debug("Resolving ear module[" + module + "]");
+ module.setEarExecutionContext(earExecutionContext);
+ module.resolveArtifact(project.getArtifacts());
+ allModules.add(module);
+ }
+ }
+
+ // Let's add other modules
+ Set<Artifact> artifacts = project.getArtifacts();
+ for (Artifact artifact : artifacts) {
+ // If the artifact's type is POM, ignore and continue
+ // since it's used for transitive deps only.
+ if ("pom".equals(artifact.getType())) {
+ continue;
+ }
+
+ // Artifact is not yet registered and it has not test scope, nor is it optional
+ ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
+ if (!isArtifactRegistered(artifact, allModules) && !artifact.isOptional() && filter.include(artifact)) {
+ EarModule module = EarModuleFactory.newEarModule(
+ artifact,
+ javaEEVersion,
+ defaultLibBundleDir,
+ includeLibInApplicationXml,
+ typeMappingService);
+ module.setEarExecutionContext(earExecutionContext);
+ allModules.add(module);
+ }
+ }
+ } catch (EarPluginException e) {
+ throw new MojoExecutionException("Failed to initialize ear modules", e);
+ }
+
+ // Now we have everything let's built modules which have not been excluded
+ ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
+ allEarModules = new ArrayList<>();
+ providedEarModules = new ArrayList<>();
+ earModules = new ArrayList<>();
+ for (EarModule earModule : allModules) {
+ if (earModule.isExcluded()) {
+ getLog().debug("Skipping ear module[" + earModule + "]");
+ } else {
+ allEarModules.add(earModule);
+ if (filter.include(earModule.getArtifact())) {
+ earModules.add(earModule);
+ } else {
+ providedEarModules.add(earModule);
+ }
+ }
+ }
+ }
+
+ /**
+ * @return The list of {@link #earModules}. This corresponds to modules needed at runtime.
+ */
+ protected List<EarModule> getModules() {
+ if (earModules == null) {
+ throw new IllegalStateException("Ear modules have not been initialized");
+ }
+ return earModules;
+ }
+
+ /**
+ * @return The list of {@link #allEarModules}. This corresponds to all modules (provided + compile + runtime).
+ */
+ protected List<EarModule> getAllEarModules() {
+ if (allEarModules == null) {
+ throw new IllegalStateException("EAR modules have not been initialized");
+ }
+ return allEarModules;
+ }
+
+ /**
+ * @return the list of {@link #providedEarModules}. This corresponds to provided modules.
+ */
+ protected List<EarModule> getProvidedEarModules() {
+ if (providedEarModules == null) {
+ throw new IllegalStateException("Jar modules have not been initialized");
+ }
+ return providedEarModules;
+ }
+
+ /**
+ * @return {@link MavenProject}
+ */
+ protected MavenProject getProject() {
+ return project;
+ }
+
+ /**
+ * @return {@link #workDirectory}
+ */
+ protected File getWorkDirectory() {
+ return workDirectory;
+ }
+
+ /**
+ * @return {@link #jbossConfiguration}
+ */
+ protected JbossConfiguration getJbossConfiguration() {
+ return jbossConfiguration;
+ }
+
+ /**
+ * @return {@link #outputFileNameMapping}
+ */
+ public String getOutputFileNameMapping() {
+ return outputFileNameMapping;
+ }
+
+ private static boolean isArtifactRegistered(Artifact a, List<EarModule> currentList) {
+ for (EarModule em : currentList) {
+ if (em.getArtifact().equals(a)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Initializes the JBoss configuration.
+ *
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private void initializeJbossConfiguration() throws EarPluginException {
+ if (jboss == null) {
+ jbossConfiguration = null;
+ } else {
+ String childVersion = jboss.getChild(JbossConfiguration.VERSION).getValue();
+ if (childVersion == null) {
+ getLog().info("JBoss version not set, using JBoss 4 by default");
+ childVersion = JbossConfiguration.VERSION_4;
+ }
+ final String securityDomain =
+ jboss.getChild(JbossConfiguration.SECURITY_DOMAIN).getValue();
+ final String unauthenticatedPrincipal =
+ jboss.getChild(JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL).getValue();
+
+ final PlexusConfiguration loaderRepositoryEl = jboss.getChild(JbossConfiguration.LOADER_REPOSITORY);
+ final String loaderRepository = loaderRepositoryEl.getValue();
+ final String loaderRepositoryClass =
+ loaderRepositoryEl.getAttribute(JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE);
+ final PlexusConfiguration loaderRepositoryConfigEl =
+ jboss.getChild(JbossConfiguration.LOADER_REPOSITORY_CONFIG);
+ final String loaderRepositoryConfig = loaderRepositoryConfigEl.getValue();
+ final String configParserClass =
+ loaderRepositoryConfigEl.getAttribute(JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE);
+
+ final String jmxName = jboss.getChild(JbossConfiguration.JMX_NAME).getValue();
+ final String moduleOrder =
+ jboss.getChild(JbossConfiguration.MODULE_ORDER).getValue();
+
+ final List<String> dataSources = new ArrayList<>();
+ final PlexusConfiguration dataSourcesEl = jboss.getChild(JbossConfiguration.DATASOURCES);
+ if (dataSourcesEl != null) {
+
+ final PlexusConfiguration[] dataSourcesConfig =
+ dataSourcesEl.getChildren(JbossConfiguration.DATASOURCE);
+ for (PlexusConfiguration dataSourceConfig : dataSourcesConfig) {
+ dataSources.add(dataSourceConfig.getValue());
+ }
+ }
+ final String libraryDirectory =
+ jboss.getChild(JbossConfiguration.LIBRARY_DIRECTORY).getValue();
+ jbossConfiguration = new JbossConfiguration(
+ childVersion,
+ securityDomain,
+ unauthenticatedPrincipal,
+ jmxName,
+ loaderRepository,
+ moduleOrder,
+ dataSources,
+ libraryDirectory,
+ loaderRepositoryConfig,
+ loaderRepositoryClass,
+ configParserClass);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/AbstractXmlWriter.java b/src/main/java/org/apache/maven/plugins/ear/AbstractXmlWriter.java
index c22bc69..1eb1d08 100644
--- a/src/main/java/org/apache/maven/plugins/ear/AbstractXmlWriter.java
+++ b/src/main/java/org/apache/maven/plugins/ear/AbstractXmlWriter.java
@@ -1,63 +1,72 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.codehaus.plexus.util.WriterFactory;
-import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * A base class for deployment descriptor file generators.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-abstract class AbstractXmlWriter
-{
-
- private final String encoding;
-
- AbstractXmlWriter( String encoding )
- {
- this.encoding = encoding;
- }
-
- Writer initializeWriter( final File destinationFile )
- throws EarPluginException
- {
- try
- {
- return WriterFactory.newXmlWriter( destinationFile );
- }
- catch ( IOException ex )
- {
- throw new EarPluginException(
- "Exception while opening file[" + destinationFile.getAbsolutePath() + "]", ex );
- }
- }
-
- XMLWriter initializeXmlWriter( final Writer writer, final String docType )
- {
- return new PrettyPrintXMLWriter( writer, encoding, docType );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * A base class for deployment descriptor file generators.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+abstract class AbstractXmlWriter {
+
+ private final String encoding;
+
+ AbstractXmlWriter(String encoding) {
+ this.encoding = encoding;
+ }
+
+ Writer initializeWriter(final File destinationFile) throws EarPluginException {
+ try {
+ return WriterFactory.newXmlWriter(destinationFile);
+ } catch (IOException ex) {
+ throw new EarPluginException("Exception while opening file[" + destinationFile.getAbsolutePath() + "]", ex);
+ }
+ }
+
+ XMLWriter initializeXmlWriter(final Writer writer, final String docType) {
+ return new PrettyPrintXMLWriter(writer, encoding, docType);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/AppClientModule.java b/src/main/java/org/apache/maven/plugins/ear/AppClientModule.java
index 6ff9994..2464fe5 100644
--- a/src/main/java/org/apache/maven/plugins/ear/AppClientModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/AppClientModule.java
@@ -1,68 +1,81 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * The {@link EarModule} implementation for an application client module.
- *
- * @author Stephane Nicoll
- */
-public class AppClientModule
- extends AbstractEarModule
-{
- /**
- * Default type of the artifact of an application client module.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "app-client";
-
- /**
- * Create an instance.
- */
- public AppClientModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- }
-
- /**
- * @param a {@link Artifact}
- */
- public AppClientModule( Artifact a )
- {
- super( a );
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendModule( XMLWriter writer, String version, Boolean generateId )
- {
- startModuleElement( writer, generateId );
- writer.startElement( JAVA_MODULE );
- writer.writeText( getUri() );
- writer.endElement();
-
- writeAltDeploymentDescriptor( writer, version );
-
- writer.endElement();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for an application client module.
+ *
+ * @author Stephane Nicoll
+ */
+public class AppClientModule extends AbstractEarModule {
+ /**
+ * Default type of the artifact of an application client module.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "app-client";
+
+ /**
+ * Create an instance.
+ */
+ public AppClientModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ */
+ public AppClientModule(Artifact a) {
+ super(a);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendModule(XMLWriter writer, String version, Boolean generateId) {
+ startModuleElement(writer, generateId);
+ writer.startElement(JAVA_MODULE);
+ writer.writeText(getUri());
+ writer.endElement();
+
+ writeAltDeploymentDescriptor(writer, version);
+
+ writer.endElement();
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
index d9e4bbd..817ec0b 100644
--- a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
+++ b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriter.java
@@ -1,305 +1,276 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.io.Writer;
-
-import org.apache.maven.plugins.ear.util.JavaEEVersion;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * An <code>XmlWriter</code> based implementation used to generate an {@code application.xml} file.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-final class ApplicationXmlWriter
- extends AbstractXmlWriter
-{
- //@formatter:off
- public static final String DOCTYPE_1_3 = "application PUBLIC\n"
- + "\t\"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN\"\n"
- + "\t\"http://java.sun.com/dtd/application_1_3.dtd\"";
- //@formatter:on
-
- private static final String APPLICATION_ELEMENT = "application";
-
- private final JavaEEVersion version;
-
- private final Boolean generateModuleId;
-
- ApplicationXmlWriter( JavaEEVersion version, String encoding, Boolean generateModuleId )
- {
- super( encoding );
- this.version = version;
- this.generateModuleId = generateModuleId;
- }
-
- void write( ApplicationXmlWriterContext context )
- throws EarPluginException
- {
- try ( Writer w = initializeWriter( context.getDestinationFile() ) )
- {
- XMLWriter writer = null;
- if ( JavaEEVersion.ONE_DOT_THREE.eq( version ) )
- {
- writer = initializeRootElementOneDotThree( w );
- }
- else if ( JavaEEVersion.ONE_DOT_FOUR.eq( version ) )
- {
- writer = initializeRootElementOneDotFour( w );
- }
- else if ( JavaEEVersion.FIVE.eq( version ) )
- {
- writer = initializeRootElementFive( w );
- }
- else if ( JavaEEVersion.SIX.eq( version ) )
- {
- writer = initializeRootElementSix( w );
- }
- else if ( JavaEEVersion.SEVEN.eq( version ) )
- {
- writer = initializeRootElementSeven( w );
- }
- else if ( JavaEEVersion.EIGHT.eq( version ) )
- {
- writer = initializeRootElementEight( w );
- }
- else if ( JavaEEVersion.NINE.eq( version ) )
- {
- writer = initializeRootElementNine( w );
- }
- else if ( JavaEEVersion.TEN.eq( version ) )
- {
- writer = initializeRootElementTen( w );
- }
-
- // writer is still on root element, so we can still add this attribute
- if ( context.getApplicationId() != null )
- {
- writer.addAttribute( "id", context.getApplicationId() );
- }
-
- // As from JavaEE6
- if ( version.ge( JavaEEVersion.SIX ) )
- {
- writeApplicationName( context.getApplicationName(), writer );
- }
-
- // IMPORTANT: the order of the description and display-name elements was
- // reversed between J2EE 1.3 and J2EE 1.4.
- if ( version.eq( JavaEEVersion.ONE_DOT_THREE ) )
- {
- writeDisplayName( context.getDisplayName(), writer );
- writeDescription( context.getDescription(), writer );
- }
- else
- {
- writeDescription( context.getDescription(), writer );
- writeDisplayName( context.getDisplayName(), writer );
- }
-
- // As from JavaEE6
- if ( version.ge( JavaEEVersion.SIX ) )
- {
- writeInitializeInOrder( context.getInitializeInOrder(), writer );
- }
-
- // Do not change this unless you really know what you're doing :)
- for ( EarModule module : context.getEarModules() )
- {
- module.appendModule( writer, version.getVersion(), generateModuleId );
- }
-
- for ( SecurityRole securityRole : context.getSecurityRoles() )
- {
- securityRole.appendSecurityRole( writer );
- }
-
- if ( version.ge( JavaEEVersion.FIVE ) )
- {
- writeLibraryDirectory( context.getLibraryDirectory(), writer );
- }
-
- if ( version.ge( JavaEEVersion.SIX ) )
- {
- for ( EnvEntry envEntry : context.getEnvEntries() )
- {
- envEntry.appendEnvEntry( writer );
- }
- for ( EjbRef ejbEntry : context.getEjbEntries() )
- {
- ejbEntry.appendEjbRefEntry( writer );
- }
- for ( ResourceRef resourceEntry : context.getResourceRefs() )
- {
- resourceEntry.appendResourceRefEntry( writer );
- }
- }
-
- writer.endElement();
- }
- catch ( IOException ex )
- {
- // ignore
- }
- }
-
- private void writeApplicationName( String applicationName, XMLWriter writer )
- {
- if ( applicationName != null )
- {
- writer.startElement( "application-name" );
- writer.writeText( applicationName );
- writer.endElement();
- }
- }
-
- private void writeDescription( String description, XMLWriter writer )
- {
- if ( description != null )
- {
- writer.startElement( "description" );
- writer.writeText( description );
- writer.endElement();
- }
- }
-
- private void writeDisplayName( String displayName, XMLWriter writer )
- {
- if ( displayName != null )
- {
- writer.startElement( "display-name" );
- writer.writeText( displayName );
- writer.endElement();
- }
- }
-
- private void writeInitializeInOrder( Boolean initializeInOrder, XMLWriter writer )
- {
- if ( initializeInOrder != null )
- {
- writer.startElement( "initialize-in-order" );
- writer.writeText( initializeInOrder.toString() );
- writer.endElement();
- }
- }
-
- private void writeLibraryDirectory( String libraryDirectory, XMLWriter writer )
- {
- if ( libraryDirectory != null )
- {
- writer.startElement( "library-directory" );
- writer.writeText( libraryDirectory );
- writer.endElement();
- }
- }
-
- private XMLWriter initializeRootElementOneDotThree( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 );
- writer.startElement( APPLICATION_ELEMENT );
- return writer;
- }
-
- private XMLWriter initializeRootElementOneDotFour( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" );
- writer.addAttribute( "version", "1.4" );
- return writer;
- }
-
- private XMLWriter initializeRootElementFive( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" );
- writer.addAttribute( "version", "5" );
- return writer;
- }
-
- private XMLWriter initializeRootElementSix( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" );
- writer.addAttribute( "version", "6" );
- return writer;
- }
-
- private XMLWriter initializeRootElementSeven( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "http://xmlns.jcp.org/xml/ns/javaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" );
- writer.addAttribute( "version", "7" );
- return writer;
- }
-
- private XMLWriter initializeRootElementEight( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "http://xmlns.jcp.org/xml/ns/javaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_8.xsd" );
- writer.addAttribute( "version", "8" );
- return writer;
- }
-
- private XMLWriter initializeRootElementNine( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "https://jakarta.ee/xml/ns/jakartaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_9.xsd" );
- writer.addAttribute( "version", "9" );
- return writer;
- }
-
- private XMLWriter initializeRootElementTen( Writer w )
- {
- XMLWriter writer = initializeXmlWriter( w, null );
- writer.startElement( APPLICATION_ELEMENT );
- writer.addAttribute( "xmlns", "https://jakarta.ee/xml/ns/jakartaee" );
- writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- writer.addAttribute( "xsi:schemaLocation",
- "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_10.xsd" );
- writer.addAttribute( "version", "10" );
- return writer;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * An <code>XmlWriter</code> based implementation used to generate an {@code application.xml} file.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+final class ApplicationXmlWriter extends AbstractXmlWriter {
+ // @formatter:off
+ public static final String DOCTYPE_1_3 = "application PUBLIC\n"
+ + "\t\"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN\"\n"
+ + "\t\"http://java.sun.com/dtd/application_1_3.dtd\"";
+ // @formatter:on
+
+ private static final String APPLICATION_ELEMENT = "application";
+
+ private final JavaEEVersion version;
+
+ private final Boolean generateModuleId;
+
+ ApplicationXmlWriter(JavaEEVersion version, String encoding, Boolean generateModuleId) {
+ super(encoding);
+ this.version = version;
+ this.generateModuleId = generateModuleId;
+ }
+
+ void write(ApplicationXmlWriterContext context) throws EarPluginException {
+ try (Writer w = initializeWriter(context.getDestinationFile())) {
+ XMLWriter writer = null;
+ if (JavaEEVersion.ONE_DOT_THREE.eq(version)) {
+ writer = initializeRootElementOneDotThree(w);
+ } else if (JavaEEVersion.ONE_DOT_FOUR.eq(version)) {
+ writer = initializeRootElementOneDotFour(w);
+ } else if (JavaEEVersion.FIVE.eq(version)) {
+ writer = initializeRootElementFive(w);
+ } else if (JavaEEVersion.SIX.eq(version)) {
+ writer = initializeRootElementSix(w);
+ } else if (JavaEEVersion.SEVEN.eq(version)) {
+ writer = initializeRootElementSeven(w);
+ } else if (JavaEEVersion.EIGHT.eq(version)) {
+ writer = initializeRootElementEight(w);
+ } else if (JavaEEVersion.NINE.eq(version)) {
+ writer = initializeRootElementNine(w);
+ } else if (JavaEEVersion.TEN.eq(version)) {
+ writer = initializeRootElementTen(w);
+ }
+
+ // writer is still on root element, so we can still add this attribute
+ if (context.getApplicationId() != null) {
+ writer.addAttribute("id", context.getApplicationId());
+ }
+
+ // As from JavaEE6
+ if (version.ge(JavaEEVersion.SIX)) {
+ writeApplicationName(context.getApplicationName(), writer);
+ }
+
+ // IMPORTANT: the order of the description and display-name elements was
+ // reversed between J2EE 1.3 and J2EE 1.4.
+ if (version.eq(JavaEEVersion.ONE_DOT_THREE)) {
+ writeDisplayName(context.getDisplayName(), writer);
+ writeDescription(context.getDescription(), writer);
+ } else {
+ writeDescription(context.getDescription(), writer);
+ writeDisplayName(context.getDisplayName(), writer);
+ }
+
+ // As from JavaEE6
+ if (version.ge(JavaEEVersion.SIX)) {
+ writeInitializeInOrder(context.getInitializeInOrder(), writer);
+ }
+
+ // Do not change this unless you really know what you're doing :)
+ for (EarModule module : context.getEarModules()) {
+ module.appendModule(writer, version.getVersion(), generateModuleId);
+ }
+
+ for (SecurityRole securityRole : context.getSecurityRoles()) {
+ securityRole.appendSecurityRole(writer);
+ }
+
+ if (version.ge(JavaEEVersion.FIVE)) {
+ writeLibraryDirectory(context.getLibraryDirectory(), writer);
+ }
+
+ if (version.ge(JavaEEVersion.SIX)) {
+ for (EnvEntry envEntry : context.getEnvEntries()) {
+ envEntry.appendEnvEntry(writer);
+ }
+ for (EjbRef ejbEntry : context.getEjbEntries()) {
+ ejbEntry.appendEjbRefEntry(writer);
+ }
+ for (ResourceRef resourceEntry : context.getResourceRefs()) {
+ resourceEntry.appendResourceRefEntry(writer);
+ }
+ }
+
+ writer.endElement();
+ } catch (IOException ex) {
+ // ignore
+ }
+ }
+
+ private void writeApplicationName(String applicationName, XMLWriter writer) {
+ if (applicationName != null) {
+ writer.startElement("application-name");
+ writer.writeText(applicationName);
+ writer.endElement();
+ }
+ }
+
+ private void writeDescription(String description, XMLWriter writer) {
+ if (description != null) {
+ writer.startElement("description");
+ writer.writeText(description);
+ writer.endElement();
+ }
+ }
+
+ private void writeDisplayName(String displayName, XMLWriter writer) {
+ if (displayName != null) {
+ writer.startElement("display-name");
+ writer.writeText(displayName);
+ writer.endElement();
+ }
+ }
+
+ private void writeInitializeInOrder(Boolean initializeInOrder, XMLWriter writer) {
+ if (initializeInOrder != null) {
+ writer.startElement("initialize-in-order");
+ writer.writeText(initializeInOrder.toString());
+ writer.endElement();
+ }
+ }
+
+ private void writeLibraryDirectory(String libraryDirectory, XMLWriter writer) {
+ if (libraryDirectory != null) {
+ writer.startElement("library-directory");
+ writer.writeText(libraryDirectory);
+ writer.endElement();
+ }
+ }
+
+ private XMLWriter initializeRootElementOneDotThree(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, DOCTYPE_1_3);
+ writer.startElement(APPLICATION_ELEMENT);
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementOneDotFour(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/j2ee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd");
+ writer.addAttribute("version", "1.4");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementFive(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd");
+ writer.addAttribute("version", "5");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementSix(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/javaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd");
+ writer.addAttribute("version", "6");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementSeven(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "http://xmlns.jcp.org/xml/ns/javaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd");
+ writer.addAttribute("version", "7");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementEight(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "http://xmlns.jcp.org/xml/ns/javaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_8.xsd");
+ writer.addAttribute("version", "8");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementNine(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "https://jakarta.ee/xml/ns/jakartaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_9.xsd");
+ writer.addAttribute("version", "9");
+ return writer;
+ }
+
+ private XMLWriter initializeRootElementTen(Writer w) {
+ XMLWriter writer = initializeXmlWriter(w, null);
+ writer.startElement(APPLICATION_ELEMENT);
+ writer.addAttribute("xmlns", "https://jakarta.ee/xml/ns/jakartaee");
+ writer.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ writer.addAttribute(
+ "xsi:schemaLocation",
+ "https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_10.xsd");
+ writer.addAttribute("version", "10");
+ return writer;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriterContext.java b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriterContext.java
index 9730acc..ba49a81 100644
--- a/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriterContext.java
+++ b/src/main/java/org/apache/maven/plugins/ear/ApplicationXmlWriterContext.java
@@ -1,196 +1,206 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.util.List;
-
-/**
- * A context for the {@link ApplicationXmlWriter}.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-class ApplicationXmlWriterContext
-{
-
- private String applicationId;
-
- private final File destinationFile;
-
- private final List<EarModule> earModules;
-
- private final List<SecurityRole> securityRoles;
-
- private final List<EnvEntry> envEntries;
-
- private final List<EjbRef> ejbEntries;
-
- private final List<ResourceRef> resourceRefs;
-
- private final String displayName;
-
- private final String description;
-
- private final String libraryDirectory;
-
- private final String applicationName;
-
- private final Boolean initializeInOrder;
-
- ApplicationXmlWriterContext( File destinationFile, List<EarModule> earModules,
- List<SecurityRole> securityRoles, List<EnvEntry> envEntries,
- List<EjbRef> ejbEntries, List<ResourceRef> resourceRefs, String displayName,
- String description, String libraryDirectory, String applicationName,
- Boolean initializeInOrder )
- {
- this.destinationFile = destinationFile;
- this.earModules = earModules;
- this.securityRoles = securityRoles;
- this.envEntries = envEntries;
- this.ejbEntries = ejbEntries;
- this.resourceRefs = resourceRefs;
- this.displayName = displayName;
- this.description = description;
- this.libraryDirectory = libraryDirectory;
- this.applicationName = applicationName;
- this.initializeInOrder = initializeInOrder;
- }
-
- public final ApplicationXmlWriterContext setApplicationId( String applicationId )
- {
- this.applicationId = applicationId;
- return this;
- }
-
- public final String getApplicationId()
- {
- return applicationId;
- }
-
- /**
- * Returns the name of the file to use to write application.xml to.
- *
- * @return the output file
- */
- public File getDestinationFile()
- {
- return destinationFile;
- }
-
- /**
- * Returns the list of {@link EarModule} instances.
- *
- * @return the ear modules
- */
- public List<EarModule> getEarModules()
- {
- return earModules;
- }
-
- /**
- * Returns the list of {@link SecurityRole} instances.
- *
- * @return the security roles
- */
- public List<SecurityRole> getSecurityRoles()
- {
- return securityRoles;
- }
-
- /**
- * Returns the list of {@link EnvEntry} instances (as per JavaEE 6).
- *
- * @return the env-entry elements
- */
- public List<EnvEntry> getEnvEntries()
- {
- return envEntries;
- }
-
- /**
- * Returns the list of {@link EjbRef}.
- *
- * @return the env-ref elements
- */
- public List<EjbRef> getEjbEntries()
- {
- return ejbEntries;
- }
-
- /**
- * Returns the list of {@link ResourceRef}.
- *
- * @return the resource-ref elements.
- */
- public List<ResourceRef> getResourceRefs()
- {
- return resourceRefs;
- }
-
- /**
- * Returns the display name.
- *
- * @return the display name
- */
- public String getDisplayName()
- {
- return displayName;
- }
-
- /**
- * Returns the description.
- *
- * @return the description
- */
- public String getDescription()
- {
- return description;
- }
-
- /**
- * Returns the library directory (as per JavaEE 5).
- *
- * @return the library directory
- */
- public String getLibraryDirectory()
- {
- return libraryDirectory;
- }
-
- /**
- * Returns the application name (as per JavaEE 6).
- *
- * @return the application name
- */
- public String getApplicationName()
- {
- return applicationName;
- }
-
- /**
- * Returns the value of the initialize in order parameter (as per JavaEE 6).
- *
- * @return the initialize in order value
- */
- public Boolean getInitializeInOrder()
- {
- return initializeInOrder;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * A context for the {@link ApplicationXmlWriter}.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+class ApplicationXmlWriterContext {
+
+ private String applicationId;
+
+ private final File destinationFile;
+
+ private final List<EarModule> earModules;
+
+ private final List<SecurityRole> securityRoles;
+
+ private final List<EnvEntry> envEntries;
+
+ private final List<EjbRef> ejbEntries;
+
+ private final List<ResourceRef> resourceRefs;
+
+ private final String displayName;
+
+ private final String description;
+
+ private final String libraryDirectory;
+
+ private final String applicationName;
+
+ private final Boolean initializeInOrder;
+
+ ApplicationXmlWriterContext(
+ File destinationFile,
+ List<EarModule> earModules,
+ List<SecurityRole> securityRoles,
+ List<EnvEntry> envEntries,
+ List<EjbRef> ejbEntries,
+ List<ResourceRef> resourceRefs,
+ String displayName,
+ String description,
+ String libraryDirectory,
+ String applicationName,
+ Boolean initializeInOrder) {
+ this.destinationFile = destinationFile;
+ this.earModules = earModules;
+ this.securityRoles = securityRoles;
+ this.envEntries = envEntries;
+ this.ejbEntries = ejbEntries;
+ this.resourceRefs = resourceRefs;
+ this.displayName = displayName;
+ this.description = description;
+ this.libraryDirectory = libraryDirectory;
+ this.applicationName = applicationName;
+ this.initializeInOrder = initializeInOrder;
+ }
+
+ public final ApplicationXmlWriterContext setApplicationId(String applicationId) {
+ this.applicationId = applicationId;
+ return this;
+ }
+
+ public final String getApplicationId() {
+ return applicationId;
+ }
+
+ /**
+ * Returns the name of the file to use to write application.xml to.
+ *
+ * @return the output file
+ */
+ public File getDestinationFile() {
+ return destinationFile;
+ }
+
+ /**
+ * Returns the list of {@link EarModule} instances.
+ *
+ * @return the ear modules
+ */
+ public List<EarModule> getEarModules() {
+ return earModules;
+ }
+
+ /**
+ * Returns the list of {@link SecurityRole} instances.
+ *
+ * @return the security roles
+ */
+ public List<SecurityRole> getSecurityRoles() {
+ return securityRoles;
+ }
+
+ /**
+ * Returns the list of {@link EnvEntry} instances (as per JavaEE 6).
+ *
+ * @return the env-entry elements
+ */
+ public List<EnvEntry> getEnvEntries() {
+ return envEntries;
+ }
+
+ /**
+ * Returns the list of {@link EjbRef}.
+ *
+ * @return the env-ref elements
+ */
+ public List<EjbRef> getEjbEntries() {
+ return ejbEntries;
+ }
+
+ /**
+ * Returns the list of {@link ResourceRef}.
+ *
+ * @return the resource-ref elements.
+ */
+ public List<ResourceRef> getResourceRefs() {
+ return resourceRefs;
+ }
+
+ /**
+ * Returns the display name.
+ *
+ * @return the display name
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Returns the library directory (as per JavaEE 5).
+ *
+ * @return the library directory
+ */
+ public String getLibraryDirectory() {
+ return libraryDirectory;
+ }
+
+ /**
+ * Returns the application name (as per JavaEE 6).
+ *
+ * @return the application name
+ */
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ /**
+ * Returns the value of the initialize in order parameter (as per JavaEE 6).
+ *
+ * @return the initialize in order value
+ */
+ public Boolean getInitializeInOrder() {
+ return initializeInOrder;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarExecutionContext.java b/src/main/java/org/apache/maven/plugins/ear/EarExecutionContext.java
index fab4838..576e1cd 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarExecutionContext.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarExecutionContext.java
@@ -1,99 +1,122 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.plugins.ear.util.ArtifactRepository;
-import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
-import org.apache.maven.project.MavenProject;
-
-/**
- * Contains various runtime parameters used to customize the generated EAR file.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class EarExecutionContext
-{
- private String defaultLibBundleDir;
-
- private JbossConfiguration jbossConfiguration;
-
- private String outputFileNameMapping;
-
- private ArtifactRepository artifactRepository;
-
- /**
- * @param project {@link MavenProject}
- * @param mainArtifactId The artifactId.
- * @param defaultLibBundleDir The defaultLibBundleDir.
- * @param jbossConfiguration {@link JbossConfiguration}
- * @param fileNameMappingName file name mapping.
- * @param typeMappingService {@link ArtifactTypeMappingService}
- */
- public EarExecutionContext( MavenProject project, String mainArtifactId, String defaultLibBundleDir,
- JbossConfiguration jbossConfiguration, String fileNameMappingName,
- ArtifactTypeMappingService typeMappingService )
- {
- initialize( project, mainArtifactId, defaultLibBundleDir, jbossConfiguration, fileNameMappingName,
- typeMappingService );
-
- }
-
- /**
- * @return {@link #defaultLibBundleDir}
- */
- public String getDefaultLibBundleDir()
- {
- return defaultLibBundleDir;
- }
-
- /**
- * @return {@link #jbossConfiguration}
- */
- public boolean isJbossConfigured()
- {
- return jbossConfiguration != null;
- }
-
- /**
- * @return {@link #outputFileNameMapping}
- */
- public String getOutputFileNameMapping()
- {
- return outputFileNameMapping;
- }
-
- /**
- * @return {@link #artifactRepository}
- */
- public ArtifactRepository getArtifactRepository()
- {
- return artifactRepository;
- }
-
- private void initialize( MavenProject project, String mainArtifactId, String defaultLibBundleDir,
- JbossConfiguration jbossConfiguration, String outputFileNameMapping,
- ArtifactTypeMappingService typeMappingService )
- {
- this.artifactRepository = new ArtifactRepository( project.getArtifacts(), mainArtifactId, typeMappingService );
- this.defaultLibBundleDir = defaultLibBundleDir;
- this.jbossConfiguration = jbossConfiguration;
- this.outputFileNameMapping = outputFileNameMapping;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugins.ear.util.ArtifactRepository;
+import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Contains various runtime parameters used to customize the generated EAR file.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EarExecutionContext {
+ private String defaultLibBundleDir;
+
+ private JbossConfiguration jbossConfiguration;
+
+ private String outputFileNameMapping;
+
+ private ArtifactRepository artifactRepository;
+
+ /**
+ * @param project {@link MavenProject}
+ * @param mainArtifactId The artifactId.
+ * @param defaultLibBundleDir The defaultLibBundleDir.
+ * @param jbossConfiguration {@link JbossConfiguration}
+ * @param fileNameMappingName file name mapping.
+ * @param typeMappingService {@link ArtifactTypeMappingService}
+ */
+ public EarExecutionContext(
+ MavenProject project,
+ String mainArtifactId,
+ String defaultLibBundleDir,
+ JbossConfiguration jbossConfiguration,
+ String fileNameMappingName,
+ ArtifactTypeMappingService typeMappingService) {
+ initialize(
+ project,
+ mainArtifactId,
+ defaultLibBundleDir,
+ jbossConfiguration,
+ fileNameMappingName,
+ typeMappingService);
+ }
+
+ /**
+ * @return {@link #defaultLibBundleDir}
+ */
+ public String getDefaultLibBundleDir() {
+ return defaultLibBundleDir;
+ }
+
+ /**
+ * @return {@link #jbossConfiguration}
+ */
+ public boolean isJbossConfigured() {
+ return jbossConfiguration != null;
+ }
+
+ /**
+ * @return {@link #outputFileNameMapping}
+ */
+ public String getOutputFileNameMapping() {
+ return outputFileNameMapping;
+ }
+
+ /**
+ * @return {@link #artifactRepository}
+ */
+ public ArtifactRepository getArtifactRepository() {
+ return artifactRepository;
+ }
+
+ private void initialize(
+ MavenProject project,
+ String mainArtifactId,
+ String defaultLibBundleDir,
+ JbossConfiguration jbossConfiguration,
+ String outputFileNameMapping,
+ ArtifactTypeMappingService typeMappingService) {
+ this.artifactRepository = new ArtifactRepository(project.getArtifacts(), mainArtifactId, typeMappingService);
+ this.defaultLibBundleDir = defaultLibBundleDir;
+ this.jbossConfiguration = jbossConfiguration;
+ this.outputFileNameMapping = outputFileNameMapping;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarModule.java b/src/main/java/org/apache/maven/plugins/ear/EarModule.java
index 80b4f56..f5b1a37 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarModule.java
@@ -1,137 +1,152 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-import java.util.Set;
-
-/**
- * The ear module interface.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public interface EarModule
-{
-
- /**
- * Returns the {@link Artifact} representing this module.
- *
- * Note that this might return {@code null} till the module has been resolved.
- *
- * @return the artifact
- * @see #resolveArtifact(java.util.Set)
- */
- Artifact getArtifact();
-
- /**
- * Returns the {@code URI} for this module.
- *
- * @return the {@code URI}
- */
- String getUri();
-
- /**
- * Returns the type associated to the module.
- *
- * @return the artifact's type of the module
- */
- String getType();
-
- /**
- * Specify whether this module should be excluded or not.
- *
- * @return true if this module should be skipped, false otherwise
- */
- boolean isExcluded();
-
- /**
- * Specify whether this module should be unpacked in the EAR archive or not.
- *
- * Returns null if no configuration was specified so that defaulting may apply.
- *
- * @return true if this module should be bundled unpacked, false otherwise
- */
- Boolean shouldUnpack();
-
- /**
- * The alt-dd element specifies an optional URI to the post-assembly version of the deployment descriptor file for a
- * particular Java EE module. The URI must specify the full pathname of the deployment descriptor file relative to
- * the application's root directory.
- *
- * @return the alternative deployment descriptor for this module
- * @since JavaEE 5
- */
- String getAltDeploymentDescriptor();
-
- /**
- * Appends the {@code XML} representation of this module.
- *
- * @param writer the writer to use
- * @param version the version of the {@code application.xml} file
- * @param generateId whether an id should be generated
- */
- void appendModule( XMLWriter writer, String version, Boolean generateId );
-
- /**
- * Resolves the {@link Artifact} represented by the module. Note that the {@link EarExecutionContext} might be used
- * to customize further the resolution.
- *
- * @param artifacts the project's artifacts
- * @throws EarPluginException if the artifact could not be resolved
- * @throws MojoFailureException if an unexpected error occurred
- */
- void resolveArtifact( Set<Artifact> artifacts )
- throws EarPluginException, MojoFailureException;
-
- /**
- * @param earExecutionContext The execution context.
- */
- void setEarExecutionContext( EarExecutionContext earExecutionContext );
-
- /**
- * @return the state if manifest classpath will be changed or not.
- */
- boolean changeManifestClasspath();
-
- /**
- * @return The directory of the module which contains the JAR libraries packaged within the module.
- * Can be {@code null}, which means that module doesn't contain any packaged libraries.
- */
- String getLibDir();
-
- /**
- * Returns the bundle file name. If {@code null}, the artifact's file name is returned.
- *
- * @return the bundle file name
- */
- String getBundleFileName();
-
- /**
- * If module should be included into the Class-Path entry of MANIFEST.mf. Doesn't impact Class-Path entry of
- * MANIFEST.mf of modules which contain all of their dependencies unless skinnyWars / skinnyModules is turned on.
- *
- * @return {@code }True} if module should be included into the Class-Path entry of MANIFEST.mf
- */
- boolean isClassPathItem();
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The ear module interface.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public interface EarModule {
+
+ /**
+ * Returns the {@link Artifact} representing this module.
+ *
+ * Note that this might return {@code null} till the module has been resolved.
+ *
+ * @return the artifact
+ * @see #resolveArtifact(java.util.Set)
+ */
+ Artifact getArtifact();
+
+ /**
+ * Returns the {@code URI} for this module.
+ *
+ * @return the {@code URI}
+ */
+ String getUri();
+
+ /**
+ * Returns the type associated to the module.
+ *
+ * @return the artifact's type of the module
+ */
+ String getType();
+
+ /**
+ * Specify whether this module should be excluded or not.
+ *
+ * @return true if this module should be skipped, false otherwise
+ */
+ boolean isExcluded();
+
+ /**
+ * Specify whether this module should be unpacked in the EAR archive or not.
+ *
+ * Returns null if no configuration was specified so that defaulting may apply.
+ *
+ * @return true if this module should be bundled unpacked, false otherwise
+ */
+ Boolean shouldUnpack();
+
+ /**
+ * The alt-dd element specifies an optional URI to the post-assembly version of the deployment descriptor file for a
+ * particular Java EE module. The URI must specify the full pathname of the deployment descriptor file relative to
+ * the application's root directory.
+ *
+ * @return the alternative deployment descriptor for this module
+ * @since JavaEE 5
+ */
+ String getAltDeploymentDescriptor();
+
+ /**
+ * Appends the {@code XML} representation of this module.
+ *
+ * @param writer the writer to use
+ * @param version the version of the {@code application.xml} file
+ * @param generateId whether an id should be generated
+ */
+ void appendModule(XMLWriter writer, String version, Boolean generateId);
+
+ /**
+ * Resolves the {@link Artifact} represented by the module. Note that the {@link EarExecutionContext} might be used
+ * to customize further the resolution.
+ *
+ * @param artifacts the project's artifacts
+ * @throws EarPluginException if the artifact could not be resolved
+ * @throws MojoFailureException if an unexpected error occurred
+ */
+ void resolveArtifact(Set<Artifact> artifacts) throws EarPluginException, MojoFailureException;
+
+ /**
+ * @param earExecutionContext The execution context.
+ */
+ void setEarExecutionContext(EarExecutionContext earExecutionContext);
+
+ /**
+ * @return the state if manifest classpath will be changed or not.
+ */
+ boolean changeManifestClasspath();
+
+ /**
+ * @return The directory of the module which contains the JAR libraries packaged within the module.
+ * Can be {@code null}, which means that module doesn't contain any packaged libraries.
+ */
+ String getLibDir();
+
+ /**
+ * Returns the bundle file name. If {@code null}, the artifact's file name is returned.
+ *
+ * @return the bundle file name
+ */
+ String getBundleFileName();
+
+ /**
+ * If module should be included into the Class-Path entry of MANIFEST.mf. Doesn't impact Class-Path entry of
+ * MANIFEST.mf of modules which contain all of their dependencies unless skinnyWars / skinnyModules is turned on.
+ *
+ * @return {@code }True} if module should be included into the Class-Path entry of MANIFEST.mf
+ */
+ boolean isClassPathItem();
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarModuleFactory.java b/src/main/java/org/apache/maven/plugins/ear/EarModuleFactory.java
index e52827c..e2a9919 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarModuleFactory.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarModuleFactory.java
@@ -1,169 +1,157 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
-import org.apache.maven.plugins.ear.util.JavaEEVersion;
-
-/**
- * Builds an {@link EarModule} based on an {@code Artifact}.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public final class EarModuleFactory
-{
- private static final String TEST_JAR_ARTIFACT_TYPE = "test-jar";
- private static final String JBOSS_PAR_ARTIFACT_TYPE = "jboss-par";
- private static final String JBOSS_SAR_ARTIFACT_TYPE = "jboss-sar";
- private static final String JBOSS_HAR_ARTIFACT_TYPE = "jboss-har";
-
- /**
- * The list of artifact types.
- */
- private static final List<String> STANDARD_ARTIFACT_TYPES =
- Collections.unmodifiableList( Arrays.asList(
- JarModule.DEFAULT_ARTIFACT_TYPE,
- EjbModule.DEFAULT_ARTIFACT_TYPE,
- ParModule.DEFAULT_ARTIFACT_TYPE,
- EjbClientModule.DEFAULT_ARTIFACT_TYPE,
- AppClientModule.DEFAULT_ARTIFACT_TYPE,
- RarModule.DEFAULT_ARTIFACT_TYPE,
- WebModule.DEFAULT_ARTIFACT_TYPE,
- SarModule.DEFAULT_ARTIFACT_TYPE,
- WsrModule.DEFAULT_ARTIFACT_TYPE,
- HarModule.DEFAULT_ARTIFACT_TYPE,
- TEST_JAR_ARTIFACT_TYPE,
- JBOSS_PAR_ARTIFACT_TYPE,
- JBOSS_SAR_ARTIFACT_TYPE,
- JBOSS_HAR_ARTIFACT_TYPE ) );
-
- /**
- * Creates a new {@link EarModule} based on the specified {@link Artifact} and the specified execution
- * configuration.
- *
- * @param artifact the artifact
- * @param javaEEVersion the javaEE version to use
- * @param defaultLibBundleDir the default bundle dir for {@link org.apache.maven.plugins.ear.JarModule}
- * @param includeInApplicationXml should {@link org.apache.maven.plugins.ear.JarModule} be included in application
- * Xml
- * @param typeMappingService The artifact type mapping service
- * @return an ear module for this artifact
- * @throws UnknownArtifactTypeException if the artifact is not handled
- */
- public static EarModule newEarModule( Artifact artifact, JavaEEVersion javaEEVersion, String defaultLibBundleDir,
- Boolean includeInApplicationXml,
- ArtifactTypeMappingService typeMappingService )
- throws UnknownArtifactTypeException
- {
- // Get the standard artifact type based on default config and user-defined mapping(s)
- final String artifactType;
- try
- {
- artifactType = typeMappingService.getStandardType( artifact.getType() );
- }
- catch ( UnknownArtifactTypeException e )
- {
- throw new UnknownArtifactTypeException( e.getMessage() + " for " + artifact.getArtifactId() );
- }
-
- if ( JarModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) || TEST_JAR_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new JarModule( artifact, defaultLibBundleDir, includeInApplicationXml );
- }
- else if ( EjbModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new EjbModule( artifact );
- }
- else if ( ParModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType )
- || JBOSS_PAR_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new ParModule( artifact );
- }
- else if ( EjbClientModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- // Somewhat weird way to tackle the problem described in MEAR-85
- if ( javaEEVersion.le( JavaEEVersion.ONE_DOT_FOUR ) )
- {
- return new EjbClientModule( artifact, null );
- }
- else
- {
- return new EjbClientModule( artifact, defaultLibBundleDir );
- }
- }
- else if ( AppClientModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new AppClientModule( artifact );
- }
- else if ( RarModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new RarModule( artifact );
- }
- else if ( WebModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new WebModule( artifact );
- }
- else if ( SarModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType )
- || JBOSS_SAR_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new SarModule( artifact );
- }
- else if ( WsrModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new WsrModule( artifact );
- }
- else if ( HarModule.DEFAULT_ARTIFACT_TYPE.equals( artifactType )
- || JBOSS_HAR_ARTIFACT_TYPE.equals( artifactType ) )
- {
- return new HarModule( artifact );
- }
- else
- {
- throw new IllegalStateException( "Could not handle artifact type[" + artifactType + "]" );
- }
- }
-
- /**
- * Returns a list of standard artifact types.
- *
- * @return the standard artifact types
- */
- public static List<String> getStandardArtifactTypes()
- {
- return STANDARD_ARTIFACT_TYPES;
- }
-
- /**
- * Specify whether the specified type is standard artifact type.
- *
- * @param type the type to check
- * @return true if the specified type is a standard artifact type
- */
- public static boolean isStandardArtifactType( final String type )
- {
- return STANDARD_ARTIFACT_TYPES.contains( type );
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService;
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+
+/**
+ * Builds an {@link EarModule} based on an {@code Artifact}.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public final class EarModuleFactory {
+ private static final String TEST_JAR_ARTIFACT_TYPE = "test-jar";
+ private static final String JBOSS_PAR_ARTIFACT_TYPE = "jboss-par";
+ private static final String JBOSS_SAR_ARTIFACT_TYPE = "jboss-sar";
+ private static final String JBOSS_HAR_ARTIFACT_TYPE = "jboss-har";
+
+ /**
+ * The list of artifact types.
+ */
+ private static final List<String> STANDARD_ARTIFACT_TYPES = Collections.unmodifiableList(Arrays.asList(
+ JarModule.DEFAULT_ARTIFACT_TYPE,
+ EjbModule.DEFAULT_ARTIFACT_TYPE,
+ ParModule.DEFAULT_ARTIFACT_TYPE,
+ EjbClientModule.DEFAULT_ARTIFACT_TYPE,
+ AppClientModule.DEFAULT_ARTIFACT_TYPE,
+ RarModule.DEFAULT_ARTIFACT_TYPE,
+ WebModule.DEFAULT_ARTIFACT_TYPE,
+ SarModule.DEFAULT_ARTIFACT_TYPE,
+ WsrModule.DEFAULT_ARTIFACT_TYPE,
+ HarModule.DEFAULT_ARTIFACT_TYPE,
+ TEST_JAR_ARTIFACT_TYPE,
+ JBOSS_PAR_ARTIFACT_TYPE,
+ JBOSS_SAR_ARTIFACT_TYPE,
+ JBOSS_HAR_ARTIFACT_TYPE));
+
+ /**
+ * Creates a new {@link EarModule} based on the specified {@link Artifact} and the specified execution
+ * configuration.
+ *
+ * @param artifact the artifact
+ * @param javaEEVersion the javaEE version to use
+ * @param defaultLibBundleDir the default bundle dir for {@link org.apache.maven.plugins.ear.JarModule}
+ * @param includeInApplicationXml should {@link org.apache.maven.plugins.ear.JarModule} be included in application
+ * Xml
+ * @param typeMappingService The artifact type mapping service
+ * @return an ear module for this artifact
+ * @throws UnknownArtifactTypeException if the artifact is not handled
+ */
+ public static EarModule newEarModule(
+ Artifact artifact,
+ JavaEEVersion javaEEVersion,
+ String defaultLibBundleDir,
+ Boolean includeInApplicationXml,
+ ArtifactTypeMappingService typeMappingService)
+ throws UnknownArtifactTypeException {
+ // Get the standard artifact type based on default config and user-defined mapping(s)
+ final String artifactType;
+ try {
+ artifactType = typeMappingService.getStandardType(artifact.getType());
+ } catch (UnknownArtifactTypeException e) {
+ throw new UnknownArtifactTypeException(e.getMessage() + " for " + artifact.getArtifactId());
+ }
+
+ if (JarModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType) || TEST_JAR_ARTIFACT_TYPE.equals(artifactType)) {
+ return new JarModule(artifact, defaultLibBundleDir, includeInApplicationXml);
+ } else if (EjbModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ return new EjbModule(artifact);
+ } else if (ParModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)
+ || JBOSS_PAR_ARTIFACT_TYPE.equals(artifactType)) {
+ return new ParModule(artifact);
+ } else if (EjbClientModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ // Somewhat weird way to tackle the problem described in MEAR-85
+ if (javaEEVersion.le(JavaEEVersion.ONE_DOT_FOUR)) {
+ return new EjbClientModule(artifact, null);
+ } else {
+ return new EjbClientModule(artifact, defaultLibBundleDir);
+ }
+ } else if (AppClientModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ return new AppClientModule(artifact);
+ } else if (RarModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ return new RarModule(artifact);
+ } else if (WebModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ return new WebModule(artifact);
+ } else if (SarModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)
+ || JBOSS_SAR_ARTIFACT_TYPE.equals(artifactType)) {
+ return new SarModule(artifact);
+ } else if (WsrModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)) {
+ return new WsrModule(artifact);
+ } else if (HarModule.DEFAULT_ARTIFACT_TYPE.equals(artifactType)
+ || JBOSS_HAR_ARTIFACT_TYPE.equals(artifactType)) {
+ return new HarModule(artifact);
+ } else {
+ throw new IllegalStateException("Could not handle artifact type[" + artifactType + "]");
+ }
+ }
+
+ /**
+ * Returns a list of standard artifact types.
+ *
+ * @return the standard artifact types
+ */
+ public static List<String> getStandardArtifactTypes() {
+ return STANDARD_ARTIFACT_TYPES;
+ }
+
+ /**
+ * Specify whether the specified type is standard artifact type.
+ *
+ * @param type the type to check
+ * @return true if the specified type is a standard artifact type
+ */
+ public static boolean isStandardArtifactType(final String type) {
+ return STANDARD_ARTIFACT_TYPES.contains(type);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
index 3f11163..53d6423 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarMojo.java
@@ -1,1083 +1,947 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.ProviderMismatchException;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.StandardOpenOption;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileTime;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-
-import org.apache.maven.archiver.MavenArchiveConfiguration;
-import org.apache.maven.archiver.MavenArchiver;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.plugins.ear.util.EarMavenArchiver;
-import org.apache.maven.plugins.ear.util.JavaEEVersion;
-import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.shared.filtering.FilterWrapper;
-import org.apache.maven.shared.filtering.MavenFileFilter;
-import org.apache.maven.shared.filtering.MavenFilteringException;
-import org.apache.maven.shared.filtering.MavenResourcesExecution;
-import org.apache.maven.shared.filtering.MavenResourcesFiltering;
-import org.apache.maven.shared.mapping.MappingUtils;
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.codehaus.plexus.archiver.Archiver;
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.archiver.UnArchiver;
-import org.codehaus.plexus.archiver.ear.EarArchiver;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
-import org.codehaus.plexus.archiver.jar.Manifest;
-import org.codehaus.plexus.archiver.jar.Manifest.Attribute;
-import org.codehaus.plexus.archiver.jar.ManifestException;
-import org.codehaus.plexus.archiver.manager.ArchiverManager;
-import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.components.io.filemappers.FileMapper;
-import org.codehaus.plexus.interpolation.InterpolationException;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.StringUtils;
-
-/**
- * Builds J2EE Enterprise Archive (EAR) files.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-@Mojo( name = "ear",
- defaultPhase = LifecyclePhase.PACKAGE,
- threadSafe = true,
- requiresDependencyResolution = ResolutionScope.TEST )
-public class EarMojo
- extends AbstractEarMojo
-{
- /**
- * Default file name mapping used by artifacts located in local repository.
- */
- private static final String ARTIFACT_DEFAULT_FILE_NAME_MAPPING =
- "@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@";
-
- /**
- * Single directory for extra files to include in the EAR.
- */
- @Parameter( defaultValue = "${basedir}/src/main/application", required = true )
- private File earSourceDirectory;
-
- /**
- * The comma separated list of tokens to include in the EAR.
- */
- @Parameter( alias = "includes", defaultValue = "**" )
- private String earSourceIncludes;
-
- /**
- * The comma separated list of tokens to exclude from the EAR.
- */
- @Parameter( alias = "excludes" )
- private String earSourceExcludes;
-
- /**
- * Specify that the EAR sources should be filtered.
- *
- * @since 2.3.2
- */
- @Parameter( defaultValue = "false" )
- private boolean filtering;
-
- /**
- * Filters (property files) to include during the interpolation of the pom.xml.
- *
- * @since 2.3.2
- */
- @Parameter
- private List<String> filters;
-
- /**
- * A list of file extensions that should not be filtered if filtering is enabled.
- *
- * @since 2.3.2
- */
- @Parameter
- private List<String> nonFilteredFileExtensions;
-
- /**
- * To escape interpolated value with Windows path c:\foo\bar will be replaced with c:\\foo\\bar.
- *
- * @since 2.3.2
- */
- @Parameter( defaultValue = "false" )
- private boolean escapedBackslashesInFilePath;
-
- /**
- * Expression preceded with this String won't be interpolated \${foo} will be replaced with ${foo}.
- *
- * @since 2.3.2
- */
- @Parameter
- protected String escapeString;
-
- /**
- * In case of using the {@link #skinnyWars} and {@link #defaultLibBundleDir} usually the classpath will be modified.
- * By settings this option {@code true} you can change this and keep the classpath untouched. This option has been
- * introduced to keep the backward compatibility with earlier versions of the plugin.
- *
- * @since 2.10
- */
- @Parameter( defaultValue = "false" )
- private boolean skipClassPathModification;
-
- /**
- * The location of a custom application.xml file to be used within the EAR file.
- */
- @Parameter
- private File applicationXml;
-
- /**
- * The directory for the generated EAR.
- */
- @Parameter( defaultValue = "${project.build.directory}", required = true )
- private String outputDirectory;
-
- /**
- * The name of the EAR file to generate.
- */
- @Parameter( defaultValue = "${project.build.finalName}", required = true, readonly = true )
- private String finalName;
-
- /**
- * The comma separated list of artifact's type(s) to unpack by default.
- */
- @Parameter
- private String unpackTypes;
-
- /**
- * Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.
- */
- @Parameter
- private String classifier;
-
- /**
- * A comma separated list of tokens to exclude when packaging the EAR. By default nothing is excluded. Note that you
- * can use the Java Regular Expressions engine to include and exclude specific pattern using the expression
- * %regex[]. Hint: read the about (?!Pattern).
- *
- * @since 2.7
- */
- @Parameter
- private String packagingExcludes;
-
- /**
- * A comma separated list of tokens to include when packaging the EAR. By default everything is included. Note that
- * you can use the Java Regular Expressions engine to include and exclude specific pattern using the expression
- * %regex[].
- *
- * @since 2.7
- */
- @Parameter
- private String packagingIncludes;
-
- /**
- * Whether to create skinny WARs or not. A skinny WAR is a WAR that does not have all of its dependencies in
- * WEB-INF/lib. Instead those dependencies are shared between the WARs through the EAR.
- *
- * @since 2.7
- */
- @Parameter( defaultValue = "false" )
- private boolean skinnyWars;
-
- /**
- * Whether to create skinny EAR modules or not. A skinny EAR module is a WAR, SAR, HAR, RAR or WSR module that
- * does not contain all of its dependencies in it. Instead those dependencies are shared between the WARs, SARs,
- * HARs, RARs and WSRs through the EAR. This option takes precedence over {@link #skinnyWars} option. That is if
- * skinnyModules is {@code true} but {@link #skinnyWars} is {@code false} (explicitly or by default) then all
- * modules including WARs are skinny.
- *
- * @since 3.2.0
- */
- @Parameter( defaultValue = "false" )
- private boolean skinnyModules;
-
- /**
- * The Plexus EAR archiver to create the output archive.
- */
- @Component( role = Archiver.class, hint = "ear" )
- private EarArchiver earArchiver;
-
- /**
- * The Plexus JAR archiver to create the output archive if not EAR application descriptor is provided (JavaEE 5+).
- */
- @Component( role = Archiver.class, hint = "jar" )
- private JarArchiver jarArchiver;
-
- /**
- * The archive configuration to use. See <a href="https://maven.apache.org/shared/maven-archiver/">Maven Archiver
- * Reference</a>.
- */
- @Parameter
- private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
-
- /**
- * Timestamp for reproducible output archive entries, either formatted as ISO 8601
- * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
- * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
- *
- * @since 3.1.0
- */
- @Parameter( defaultValue = "${project.build.outputTimestamp}" )
- private String outputTimestamp;
-
- /**
- */
- @Component
- private MavenProjectHelper projectHelper;
-
- /**
- * The archive manager.
- */
- @Component
- private ArchiverManager archiverManager;
-
- /**
- */
- @Component( role = MavenFileFilter.class, hint = "default" )
- private MavenFileFilter mavenFileFilter;
-
- /**
- */
- @Component( role = MavenResourcesFiltering.class, hint = "default" )
- private MavenResourcesFiltering mavenResourcesFiltering;
-
- /**
- * @since 2.3.2
- */
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
-
- private List<FilterWrapper> filterWrappers;
-
- /** {@inheritDoc} */
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- // Initializes ear modules
- super.execute();
-
- File earFile = getEarFile( outputDirectory, finalName, classifier );
- MavenArchiver archiver = new EarMavenArchiver( getModules() );
- File ddFile = new File( getWorkDirectory(), APPLICATION_XML_URI );
-
- JarArchiver theArchiver;
- if ( ddFile.exists() )
- {
- earArchiver.setAppxml( ddFile );
- theArchiver = earArchiver;
- }
- else
- {
- // current Plexus EarArchiver does not support application.xml-less JavaEE 5+ case
- // => fallback to Plexus Jar archiver
- theArchiver = jarArchiver;
- }
- getLog().debug( "Ear archiver implementation [" + theArchiver.getClass().getName() + "]" );
- archiver.setArchiver( theArchiver );
- archiver.setOutputFile( earFile );
- archiver.setCreatedBy( "Maven EAR Plugin", "org.apache.maven.plugins", "maven-ear-plugin" );
-
- // configure for Reproducible Builds based on outputTimestamp value
- archiver.configureReproducibleBuild( outputTimestamp );
-
- final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
-
- final Collection<String> outdatedResources = initOutdatedResources();
-
- // Initializes unpack types
- List<String> unpackTypesList = createUnpackList();
-
- // Copy modules
- copyModules( javaEEVersion, unpackTypesList, outdatedResources );
-
- // Copy source files
- try
- {
- File earSourceDir = earSourceDirectory;
-
- if ( earSourceDir.exists() )
- {
- getLog().info( "Copy ear sources to " + getWorkDirectory().getAbsolutePath() );
- String[] fileNames = getEarFiles( earSourceDir );
- for ( String fileName : fileNames )
- {
- copyFile( new File( earSourceDir, fileName ), new File( getWorkDirectory(), fileName ) );
- outdatedResources.remove( Paths.get( fileName ).toString() );
- }
- }
-
- if ( applicationXml != null )
- {
- // rename to application.xml
- getLog().info( "Including custom application.xml[" + applicationXml + "]" );
- File metaInfDir = new File( getWorkDirectory(), META_INF );
- copyFile( applicationXml, new File( metaInfDir, "/application.xml" ) );
- outdatedResources.remove( Paths.get( "META-INF/application.xml" ).toString() );
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error copying EAR sources", e );
- }
- catch ( MavenFilteringException e )
- {
- throw new MojoExecutionException( "Error filtering EAR sources", e );
- }
-
- // Check if deployment descriptor is there
- if ( !ddFile.exists() && ( javaEEVersion.lt( JavaEEVersion.FIVE ) ) )
- {
- throw new MojoExecutionException( "Deployment descriptor: " + ddFile.getAbsolutePath()
- + " does not exist." );
- }
- // no need to check timestamp for descriptors: removing if outdated does not really make sense
- outdatedResources.remove( Paths.get( APPLICATION_XML_URI ).toString() );
- if ( getJbossConfiguration() != null )
- {
- outdatedResources.remove( Paths.get( "META-INF/jboss-app.xml" ).toString() );
- }
-
- deleteOutdatedResources( outdatedResources );
-
- try
- {
- getLog().debug( "Excluding " + Arrays.asList( getPackagingExcludes() ) + " from the generated EAR." );
- getLog().debug( "Including " + Arrays.asList( getPackagingIncludes() ) + " in the generated EAR." );
-
- archiver.getArchiver().addDirectory( getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes() );
-
- archiver.createArchive( session, getProject(), archive );
- }
- catch ( ManifestException | IOException | DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( "Error assembling EAR", e );
- }
-
- if ( classifier != null )
- {
- projectHelper.attachArtifact( getProject(), "ear", classifier, earFile );
- }
- else
- {
- getProject().getArtifact().setFile( earFile );
- }
- }
-
- private void copyModules( final JavaEEVersion javaEEVersion,
- List<String> unpackTypesList,
- Collection<String> outdatedResources )
- throws MojoExecutionException, MojoFailureException
- {
- try
- {
- for ( EarModule module : getModules() )
- {
- final File sourceFile = module.getArtifact().getFile();
- final File destinationFile = buildDestinationFile( getWorkDirectory(), module.getUri() );
- if ( !sourceFile.isFile() )
- {
- throw new MojoExecutionException( "Cannot copy a directory: " + sourceFile.getAbsolutePath()
- + "; Did you package/install " + module.getArtifact() + "?" );
- }
-
- if ( destinationFile.getCanonicalPath().equals( sourceFile.getCanonicalPath() ) )
- {
- getLog().info( "Skipping artifact [" + module + "], as it already exists at [" + module.getUri()
- + "]" );
- // FIXME: Shouldn't that result in a build failure!?
- continue;
- }
-
- // If the module is within the unpack list, make sure that no unpack wasn't forced (null or true)
- // If the module is not in the unpack list, it should be true
- if ( ( unpackTypesList.contains( module.getType() )
- && ( module.shouldUnpack() == null || module.shouldUnpack() ) )
- || ( module.shouldUnpack() != null && module.shouldUnpack() ) )
- {
- getLog().info( "Copying artifact [" + module + "] to [" + module.getUri() + "] (unpacked)" );
- // Make sure that the destination is a directory to avoid plexus nasty stuff :)
- if ( !destinationFile.isDirectory() && !destinationFile.mkdirs() )
- {
- throw new MojoExecutionException( "Error creating " + destinationFile );
- }
- unpack( sourceFile, destinationFile, outdatedResources );
-
- if ( module.changeManifestClasspath() )
- {
- changeManifestClasspath( module, destinationFile, javaEEVersion, outdatedResources );
- }
- }
- else
- {
- if ( sourceFile.lastModified() > destinationFile.lastModified() )
- {
- getLog().info( "Copying artifact [" + module + "] to [" + module.getUri() + "]" );
- createParentIfNecessary( destinationFile );
- Files.copy( sourceFile.toPath(), destinationFile.toPath(),
- LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING );
- if ( module.changeManifestClasspath() )
- {
- changeManifestClasspath( module, destinationFile, javaEEVersion, outdatedResources );
- }
- }
- else
- {
- getLog().debug( "Skipping artifact [" + module + "], as it is already up to date at ["
- + module.getUri() + "]" );
- }
- removeFromOutdatedResources( destinationFile.toPath(), outdatedResources );
- }
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error copying EAR modules", e );
- }
- catch ( ArchiverException e )
- {
- throw new MojoExecutionException( "Error unpacking EAR modules", e );
- }
- catch ( NoSuchArchiverException e )
- {
- throw new MojoExecutionException( "No Archiver found for EAR modules", e );
- }
- }
-
- private List<String> createUnpackList()
- throws MojoExecutionException
- {
- List<String> unpackTypesList = new ArrayList<>();
- if ( unpackTypes != null )
- {
- unpackTypesList = Arrays.asList( unpackTypes.split( "," ) );
- for ( String type : unpackTypesList )
- {
- if ( !EarModuleFactory.isStandardArtifactType( type ) )
- {
- throw new MojoExecutionException( "Invalid type [" + type + "] supported types are "
- + EarModuleFactory.getStandardArtifactTypes() );
- }
- }
- getLog().debug( "Initialized unpack types " + unpackTypesList );
- }
- return unpackTypesList;
- }
-
- /**
- * @return {@link #applicationXml}
- */
- public File getApplicationXml()
- {
- return applicationXml;
- }
-
- /**
- * @param applicationXml {@link #applicationXml}
- */
- public void setApplicationXml( File applicationXml )
- {
- this.applicationXml = applicationXml;
- }
-
- /**
- * Returns a string array of the excludes to be used when assembling/copying the ear.
- *
- * @return an array of tokens to exclude
- */
- protected String[] getExcludes()
- {
- List<String> excludeList = new ArrayList<>( FileUtils.getDefaultExcludesAsList() );
- if ( earSourceExcludes != null && !"".equals( earSourceExcludes ) )
- {
- excludeList.addAll( Arrays.asList( StringUtils.split( earSourceExcludes, "," ) ) );
- }
-
- // if applicationXml is specified, omit the one in the source directory
- if ( getApplicationXml() != null && !"".equals( getApplicationXml() ) )
- {
- excludeList.add( "**/" + META_INF + "/application.xml" );
- }
-
- return excludeList.toArray( new String[excludeList.size()] );
- }
-
- /**
- * Returns a string array of the includes to be used when assembling/copying the ear.
- *
- * @return an array of tokens to include
- */
- protected String[] getIncludes()
- {
- return StringUtils.split( Objects.toString( earSourceIncludes, "" ), "," );
- }
-
- /**
- * @return The array with the packaging excludes.
- */
- public String[] getPackagingExcludes()
- {
- if ( packagingExcludes == null || packagingExcludes.isEmpty() )
- {
- return new String[0];
- }
- else
- {
- return StringUtils.split( packagingExcludes, "," );
- }
- }
-
- /**
- * @param packagingExcludes {@link #packagingExcludes}
- */
- public void setPackagingExcludes( String packagingExcludes )
- {
- this.packagingExcludes = packagingExcludes;
- }
-
- /**
- * @return the arrays with the includes
- */
- public String[] getPackagingIncludes()
- {
- if ( packagingIncludes == null || packagingIncludes.isEmpty() )
- {
- return new String[] { "**" };
- }
- else
- {
- return StringUtils.split( packagingIncludes, "," );
- }
- }
-
- /**
- * @param packagingIncludes {@link #packagingIncludes}
- */
- public void setPackagingIncludes( String packagingIncludes )
- {
- this.packagingIncludes = packagingIncludes;
- }
-
- private static File buildDestinationFile( File buildDir, String uri )
- {
- return new File( buildDir, uri );
- }
-
- /**
- * Returns the EAR file to generate, based on an optional classifier.
- *
- * @param basedir the output directory
- * @param finalName the name of the ear file
- * @param classifier an optional classifier
- * @return the EAR file to generate
- */
- private static File getEarFile( String basedir, String finalName, String classifier )
- {
- if ( classifier == null )
- {
- classifier = "";
- }
- else if ( classifier.trim().length() > 0 && !classifier.startsWith( "-" ) )
- {
- classifier = "-" + classifier;
- }
-
- return new File( basedir, finalName + classifier + ".ear" );
- }
-
- /**
- * Returns a list of filenames that should be copied over to the destination directory.
- *
- * @param sourceDir the directory to be scanned
- * @return the array of filenames, relative to the sourceDir
- */
- private String[] getEarFiles( File sourceDir )
- {
- DirectoryScanner scanner = new DirectoryScanner();
- scanner.setBasedir( sourceDir );
- scanner.setExcludes( getExcludes() );
- scanner.addDefaultExcludes();
-
- scanner.setIncludes( getIncludes() );
-
- scanner.scan();
-
- return scanner.getIncludedFiles();
- }
-
- /**
- * Unpacks the module into the EAR structure.
- *
- * @param source file to be unpacked
- * @param destDir where to put the unpacked files
- * @param outdatedResources currently outdated resources
- * @throws ArchiverException a corrupt archive
- * @throws NoSuchArchiverException if we don't have an appropriate archiver
- * @throws IOException in case of a general IOException
- */
- public void unpack( File source, final File destDir, final Collection<String> outdatedResources )
- throws ArchiverException, NoSuchArchiverException, IOException
- {
- Path destPath = destDir.toPath();
-
- UnArchiver unArchiver = archiverManager.getUnArchiver( "zip" );
- unArchiver.setSourceFile( source );
- unArchiver.setDestDirectory( destDir );
- unArchiver.setFileMappers( new FileMapper[] {
- pName ->
- {
- removeFromOutdatedResources( destPath.resolve( pName ), outdatedResources );
- return pName;
- }
- } );
-
- // Extract the module
- unArchiver.extract();
- }
-
- private void copyFile( File source, File target )
- throws MavenFilteringException, IOException, MojoExecutionException
- {
- createParentIfNecessary( target );
- if ( filtering && !isNonFilteredExtension( source.getName() ) )
- {
- mavenFileFilter.copyFile( source, target, true, getFilterWrappers(), encoding );
- }
- else
- {
- Files.copy( source.toPath(), target.toPath(), LinkOption.NOFOLLOW_LINKS,
- StandardCopyOption.REPLACE_EXISTING );
- }
- }
-
- private void createParentIfNecessary( File target )
- throws IOException
- {
- // Silly that we have to do this ourselves
- File parentDirectory = target.getParentFile();
- if ( parentDirectory != null && !parentDirectory.exists() )
- {
- Files.createDirectories( parentDirectory.toPath() );
- }
- }
-
- /**
- * @param fileName the name of the file which should be checked
- * @return {@code true} if the name is part of the non filtered extensions; {@code false} otherwise
- */
- public boolean isNonFilteredExtension( String fileName )
- {
- return !mavenResourcesFiltering.filteredFileExtension( fileName, nonFilteredFileExtensions );
- }
-
- private List<FilterWrapper> getFilterWrappers()
- throws MojoExecutionException
- {
- if ( filterWrappers == null )
- {
- try
- {
- MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
- mavenResourcesExecution.setMavenProject( getProject() );
- mavenResourcesExecution.setEscapedBackslashesInFilePath( escapedBackslashesInFilePath );
- mavenResourcesExecution.setFilters( filters );
- mavenResourcesExecution.setEscapeString( escapeString );
-
- filterWrappers = mavenFileFilter.getDefaultFilterWrappers( mavenResourcesExecution );
- }
- catch ( MavenFilteringException e )
- {
- getLog().error( "Fail to build filtering wrappers " + e.getMessage() );
- throw new MojoExecutionException( e.getMessage(), e );
- }
- }
- return filterWrappers;
- }
-
- private void changeManifestClasspath( EarModule module, File original, JavaEEVersion javaEEVersion,
- Collection<String> outdatedResources )
- throws MojoFailureException
- {
- final String moduleLibDir = module.getLibDir();
- if ( !( ( moduleLibDir == null ) || skinnyModules || ( skinnyWars && module instanceof WebModule ) ) )
- {
- return;
- }
-
- // for new created items
- FileTime outputFileTime = MavenArchiver.parseBuildOutputTimestamp( outputTimestamp )
- .map( FileTime::from )
- .orElse( null );
-
- FileSystem fileSystem = null;
-
- try
- {
- Path workDirectory;
-
- // Handle the case that the destination might be a directory (project-038)
- // We can get FileSystems only for files
- if ( original.isFile() )
- {
- fileSystem = FileSystems.newFileSystem(
- original.toPath(), Thread.currentThread().getContextClassLoader() );
- workDirectory = fileSystem.getRootDirectories().iterator().next();
- }
- else
- {
- workDirectory = original.toPath();
- }
-
- // Create a META-INF/MANIFEST.MF file if it doesn't exist (project-038)
- Path metaInfDirectory = workDirectory.resolve( "META-INF" );
- if ( !Files.exists( metaInfDirectory ) )
- {
- Files.createDirectory( metaInfDirectory );
- if ( outputFileTime != null )
- {
- Files.setLastModifiedTime( metaInfDirectory, outputFileTime );
- }
- getLog().debug(
- "This project did not have a META-INF directory before, so a new directory was created." );
- }
- Path manifestFile = metaInfDirectory.resolve( "MANIFEST.MF" );
- if ( !Files.exists( manifestFile ) )
- {
- Files.createFile( manifestFile );
- if ( outputFileTime != null )
- {
- Files.setLastModifiedTime( manifestFile, outputFileTime );
- }
- getLog().debug(
- "This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." );
- }
-
- Manifest mf = readManifest( manifestFile );
- Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" );
- List<String> classPathElements = new ArrayList<>();
-
- boolean classPathExists;
- if ( classPath != null )
- {
- classPathExists = true;
- classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) );
- }
- else
- {
- classPathExists = false;
- classPath = new Attribute( "Class-Path", "" );
- }
-
- if ( ( moduleLibDir != null ) && ( skinnyModules || ( skinnyWars && module instanceof WebModule ) ) )
- {
- // Remove modules
- for ( EarModule otherModule : getAllEarModules() )
- {
- if ( module.equals( otherModule ) )
- {
- continue;
- }
- // MEAR-189:
- // We use the original name, cause in case of outputFileNameMapping
- // we could not not delete it and it will end up in the resulting EAR and the WAR
- // will not be cleaned up.
- final Path workLibDir = workDirectory.resolve( moduleLibDir );
- Path artifact = workLibDir.resolve( module.getArtifact().getFile().getName() );
-
- // MEAR-217
- // If WAR contains files with timestamps, but EAR strips them away (useBaseVersion=true)
- // the artifact is not found. Therefore, respect the current fileNameMapping additionally.
-
- if ( !Files.exists( artifact ) )
- {
- getLog().debug( "module does not exist with original file name." );
- artifact = workLibDir.resolve( otherModule.getBundleFileName() );
- getLog().debug( "Artifact with mapping: " + artifact.toAbsolutePath() );
- }
-
- if ( !Files.exists( artifact ) )
- {
- getLog().debug( "Artifact with mapping does not exist." );
- artifact = workLibDir.resolve( otherModule.getArtifact().getFile().getName() );
- getLog().debug( "Artifact with original file name: " + artifact.toAbsolutePath() );
- }
-
- if ( !Files.exists( artifact ) )
- {
- getLog().debug( "Artifact with original file name does not exist." );
- final Artifact otherModuleArtifact = otherModule.getArtifact();
- if ( otherModuleArtifact.isSnapshot() )
- {
- try
- {
- artifact = workLibDir.resolve( MappingUtils.evaluateFileNameMapping(
- ARTIFACT_DEFAULT_FILE_NAME_MAPPING, otherModuleArtifact ) );
- getLog()
- .debug( "Artifact with default mapping file name: " + artifact.toAbsolutePath() );
- }
- catch ( InterpolationException e )
- {
- getLog().warn(
- "Failed to evaluate file name for [" + otherModule + "] module using mapping: "
- + ARTIFACT_DEFAULT_FILE_NAME_MAPPING );
- }
- }
- }
-
- if ( Files.exists( artifact ) )
- {
- getLog().debug( " -> Artifact to delete: " + artifact );
- Files.delete( artifact );
- }
- }
- }
-
- // Modify the classpath entries in the manifest
- final boolean forceClassPathModification =
- javaEEVersion.lt( JavaEEVersion.FIVE ) || defaultLibBundleDir == null;
- final boolean classPathExtension = !skipClassPathModification || forceClassPathModification;
- for ( EarModule otherModule : getModules() )
- {
- if ( module.equals( otherModule ) )
- {
- continue;
- }
- final int moduleClassPathIndex = findModuleInClassPathElements( classPathElements, otherModule );
- if ( moduleClassPathIndex != -1 )
- {
- if ( otherModule.isClassPathItem() )
- {
- classPathElements.set( moduleClassPathIndex, otherModule.getUri() );
- }
- else
- {
- classPathElements.remove( moduleClassPathIndex );
- }
- }
- else if ( otherModule.isClassPathItem() && classPathExtension )
- {
- classPathElements.add( otherModule.getUri() );
- }
- }
-
- // Remove provided modules from classpath
- for ( EarModule otherModule : getProvidedEarModules() )
- {
- final int moduleClassPathIndex = findModuleInClassPathElements( classPathElements, otherModule );
- if ( moduleClassPathIndex != -1 )
- {
- classPathElements.remove( moduleClassPathIndex );
- }
- }
-
- if ( !skipClassPathModification || !classPathElements.isEmpty() || classPathExists )
- {
- classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );
- mf.getMainSection().addConfiguredAttribute( classPath );
-
- // Write the manifest to disk, preserve timestamp
- FileTime lastModifiedTime = Files.getLastModifiedTime( manifestFile );
- try ( BufferedWriter writer = Files.newBufferedWriter( manifestFile, StandardCharsets.UTF_8,
- StandardOpenOption.WRITE,
- StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING ) )
- {
- mf.write( writer );
- }
- Files.setLastModifiedTime( manifestFile, lastModifiedTime );
- removeFromOutdatedResources( manifestFile, outdatedResources );
- }
-
- if ( fileSystem != null )
- {
- fileSystem.close();
- fileSystem = null;
- }
- }
- catch ( ManifestException | IOException | ArchiverException e )
- {
- throw new MojoFailureException( e.getMessage(), e );
- }
- finally
- {
- if ( fileSystem != null )
- {
- try
- {
- fileSystem.close();
- }
- catch ( IOException e )
- {
- // ignore here
- }
- }
- }
- }
-
- private static Manifest readManifest( Path manifestFile )
- throws IOException
- {
- // Read the manifest from disk
- try ( InputStream in = Files.newInputStream( manifestFile ) )
- {
- return new Manifest( in );
- }
- }
-
- private Collection<String> initOutdatedResources()
- {
- final Collection<String> outdatedResources = new ArrayList<>();
-
- if ( getWorkDirectory().exists() )
- {
- try
- {
- Files.walkFileTree( getWorkDirectory().toPath(), new SimpleFileVisitor<Path>()
- {
- @Override
- public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
- throws IOException
- {
- outdatedResources.add( getWorkDirectory().toPath().relativize( file ).toString() );
- return super.visitFile( file, attrs );
- }
- } );
- }
- catch ( IOException e )
- {
- getLog().warn( "Can't detect outdated resources", e );
- }
- }
-
- getLog().debug( "initOutdatedResources: " + outdatedResources );
- return outdatedResources;
- }
-
- private void deleteOutdatedResources( final Collection<String> outdatedResources )
- {
- getLog().debug( "deleteOutdatedResources: " + outdatedResources );
- final long startTime = session.getStartTime().getTime();
-
- getLog().debug( "deleteOutdatedResources session startTime: " + startTime );
-
- for ( String outdatedResource : outdatedResources )
- {
- File resourceFile = new File( getWorkDirectory(), outdatedResource );
- if ( resourceFile.lastModified() < startTime )
- {
- getLog().info( "deleting outdated resource " + outdatedResource );
- getLog().debug( outdatedResource + " last modified: " + resourceFile.lastModified() );
- resourceFile.delete();
- }
- }
- }
-
- private void removeFromOutdatedResources( Path destination, Collection<String> outdatedResources )
- {
- Path relativeDestFile;
- try
- {
- relativeDestFile = getWorkDirectory().toPath().relativize( destination.normalize() );
- }
- catch ( ProviderMismatchException e )
- {
- relativeDestFile = destination.normalize();
- }
-
- if ( outdatedResources.remove( relativeDestFile.toString() ) )
- {
- getLog().debug( "Remove from outdatedResources: " + relativeDestFile );
- }
- }
-
- /**
- * Searches for the given JAR module in the list of classpath elements. If JAR module is found among specified
- * classpath elements then returns index of first matching element. Returns -1 otherwise.
- *
- * @param classPathElements classpath elements to search among
- * @param module module to find among classpath elements defined by {@code classPathElements}
- * @return -1 if {@code module} was not found in {@code classPathElements} or index of item of
- * {@code classPathElements} which matches {@code module}
- */
- private int findModuleInClassPathElements( final List<String> classPathElements, final EarModule module )
- {
- if ( classPathElements.isEmpty() )
- {
- return -1;
- }
- int moduleClassPathIndex = classPathElements.indexOf( module.getBundleFileName() );
- if ( moduleClassPathIndex != -1 )
- {
- return moduleClassPathIndex;
- }
- final Artifact artifact = module.getArtifact();
- moduleClassPathIndex = classPathElements.indexOf( artifact.getFile().getName() );
- if ( moduleClassPathIndex != -1 )
- {
- return moduleClassPathIndex;
- }
- if ( artifact.isSnapshot() )
- {
- try
- {
- moduleClassPathIndex = classPathElements
- .indexOf( MappingUtils.evaluateFileNameMapping( ARTIFACT_DEFAULT_FILE_NAME_MAPPING, artifact ) );
- if ( moduleClassPathIndex != -1 )
- {
- return moduleClassPathIndex;
- }
- }
- catch ( InterpolationException e )
- {
- getLog().warn( "Failed to evaluate file name for [" + module + "] module using mapping: "
- + ARTIFACT_DEFAULT_FILE_NAME_MAPPING );
- }
- }
- return classPathElements.indexOf( module.getUri() );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.ProviderMismatchException;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.ear.util.EarMavenArchiver;
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.shared.filtering.FilterWrapper;
+import org.apache.maven.shared.filtering.MavenFileFilter;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.MavenResourcesExecution;
+import org.apache.maven.shared.filtering.MavenResourcesFiltering;
+import org.apache.maven.shared.mapping.MappingUtils;
+import org.apache.maven.shared.utils.io.FileUtils;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.ear.EarArchiver;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.Manifest.Attribute;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.components.io.filemappers.FileMapper;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Builds J2EE Enterprise Archive (EAR) files.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+@Mojo(
+ name = "ear",
+ defaultPhase = LifecyclePhase.PACKAGE,
+ threadSafe = true,
+ requiresDependencyResolution = ResolutionScope.TEST)
+public class EarMojo extends AbstractEarMojo {
+ /**
+ * Default file name mapping used by artifacts located in local repository.
+ */
+ private static final String ARTIFACT_DEFAULT_FILE_NAME_MAPPING =
+ "@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@";
+
+ /**
+ * Single directory for extra files to include in the EAR.
+ */
+ @Parameter(defaultValue = "${basedir}/src/main/application", required = true)
+ private File earSourceDirectory;
+
+ /**
+ * The comma separated list of tokens to include in the EAR.
+ */
+ @Parameter(alias = "includes", defaultValue = "**")
+ private String earSourceIncludes;
+
+ /**
+ * The comma separated list of tokens to exclude from the EAR.
+ */
+ @Parameter(alias = "excludes")
+ private String earSourceExcludes;
+
+ /**
+ * Specify that the EAR sources should be filtered.
+ *
+ * @since 2.3.2
+ */
+ @Parameter(defaultValue = "false")
+ private boolean filtering;
+
+ /**
+ * Filters (property files) to include during the interpolation of the pom.xml.
+ *
+ * @since 2.3.2
+ */
+ @Parameter
+ private List<String> filters;
+
+ /**
+ * A list of file extensions that should not be filtered if filtering is enabled.
+ *
+ * @since 2.3.2
+ */
+ @Parameter
+ private List<String> nonFilteredFileExtensions;
+
+ /**
+ * To escape interpolated value with Windows path c:\foo\bar will be replaced with c:\\foo\\bar.
+ *
+ * @since 2.3.2
+ */
+ @Parameter(defaultValue = "false")
+ private boolean escapedBackslashesInFilePath;
+
+ /**
+ * Expression preceded with this String won't be interpolated \${foo} will be replaced with ${foo}.
+ *
+ * @since 2.3.2
+ */
+ @Parameter
+ protected String escapeString;
+
+ /**
+ * In case of using the {@link #skinnyWars} and {@link #defaultLibBundleDir} usually the classpath will be modified.
+ * By settings this option {@code true} you can change this and keep the classpath untouched. This option has been
+ * introduced to keep the backward compatibility with earlier versions of the plugin.
+ *
+ * @since 2.10
+ */
+ @Parameter(defaultValue = "false")
+ private boolean skipClassPathModification;
+
+ /**
+ * The location of a custom application.xml file to be used within the EAR file.
+ */
+ @Parameter
+ private File applicationXml;
+
+ /**
+ * The directory for the generated EAR.
+ */
+ @Parameter(defaultValue = "${project.build.directory}", required = true)
+ private String outputDirectory;
+
+ /**
+ * The name of the EAR file to generate.
+ */
+ @Parameter(defaultValue = "${project.build.finalName}", required = true, readonly = true)
+ private String finalName;
+
+ /**
+ * The comma separated list of artifact's type(s) to unpack by default.
+ */
+ @Parameter
+ private String unpackTypes;
+
+ /**
+ * Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.
+ */
+ @Parameter
+ private String classifier;
+
+ /**
+ * A comma separated list of tokens to exclude when packaging the EAR. By default nothing is excluded. Note that you
+ * can use the Java Regular Expressions engine to include and exclude specific pattern using the expression
+ * %regex[]. Hint: read the about (?!Pattern).
+ *
+ * @since 2.7
+ */
+ @Parameter
+ private String packagingExcludes;
+
+ /**
+ * A comma separated list of tokens to include when packaging the EAR. By default everything is included. Note that
+ * you can use the Java Regular Expressions engine to include and exclude specific pattern using the expression
+ * %regex[].
+ *
+ * @since 2.7
+ */
+ @Parameter
+ private String packagingIncludes;
+
+ /**
+ * Whether to create skinny WARs or not. A skinny WAR is a WAR that does not have all of its dependencies in
+ * WEB-INF/lib. Instead those dependencies are shared between the WARs through the EAR.
+ *
+ * @since 2.7
+ */
+ @Parameter(defaultValue = "false")
+ private boolean skinnyWars;
+
+ /**
+ * Whether to create skinny EAR modules or not. A skinny EAR module is a WAR, SAR, HAR, RAR or WSR module that
+ * does not contain all of its dependencies in it. Instead those dependencies are shared between the WARs, SARs,
+ * HARs, RARs and WSRs through the EAR. This option takes precedence over {@link #skinnyWars} option. That is if
+ * skinnyModules is {@code true} but {@link #skinnyWars} is {@code false} (explicitly or by default) then all
+ * modules including WARs are skinny.
+ *
+ * @since 3.2.0
+ */
+ @Parameter(defaultValue = "false")
+ private boolean skinnyModules;
+
+ /**
+ * The Plexus EAR archiver to create the output archive.
+ */
+ @Component(role = Archiver.class, hint = "ear")
+ private EarArchiver earArchiver;
+
+ /**
+ * The Plexus JAR archiver to create the output archive if not EAR application descriptor is provided (JavaEE 5+).
+ */
+ @Component(role = Archiver.class, hint = "jar")
+ private JarArchiver jarArchiver;
+
+ /**
+ * The archive configuration to use. See <a href="https://maven.apache.org/shared/maven-archiver/">Maven Archiver
+ * Reference</a>.
+ */
+ @Parameter
+ private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+ /**
+ * Timestamp for reproducible output archive entries, either formatted as ISO 8601
+ * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
+ * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
+ *
+ * @since 3.1.0
+ */
+ @Parameter(defaultValue = "${project.build.outputTimestamp}")
+ private String outputTimestamp;
+
+ /**
+ */
+ @Component
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * The archive manager.
+ */
+ @Component
+ private ArchiverManager archiverManager;
+
+ /**
+ */
+ @Component(role = MavenFileFilter.class, hint = "default")
+ private MavenFileFilter mavenFileFilter;
+
+ /**
+ */
+ @Component(role = MavenResourcesFiltering.class, hint = "default")
+ private MavenResourcesFiltering mavenResourcesFiltering;
+
+ /**
+ * @since 2.3.2
+ */
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
+ private MavenSession session;
+
+ private List<FilterWrapper> filterWrappers;
+
+ /** {@inheritDoc} */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ // Initializes ear modules
+ super.execute();
+
+ File earFile = getEarFile(outputDirectory, finalName, classifier);
+ MavenArchiver archiver = new EarMavenArchiver(getModules());
+ File ddFile = new File(getWorkDirectory(), APPLICATION_XML_URI);
+
+ JarArchiver theArchiver;
+ if (ddFile.exists()) {
+ earArchiver.setAppxml(ddFile);
+ theArchiver = earArchiver;
+ } else {
+ // current Plexus EarArchiver does not support application.xml-less JavaEE 5+ case
+ // => fallback to Plexus Jar archiver
+ theArchiver = jarArchiver;
+ }
+ getLog().debug("Ear archiver implementation [" + theArchiver.getClass().getName() + "]");
+ archiver.setArchiver(theArchiver);
+ archiver.setOutputFile(earFile);
+ archiver.setCreatedBy("Maven EAR Plugin", "org.apache.maven.plugins", "maven-ear-plugin");
+
+ // configure for Reproducible Builds based on outputTimestamp value
+ archiver.configureReproducibleBuild(outputTimestamp);
+
+ final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
+
+ final Collection<String> outdatedResources = initOutdatedResources();
+
+ // Initializes unpack types
+ List<String> unpackTypesList = createUnpackList();
+
+ // Copy modules
+ copyModules(javaEEVersion, unpackTypesList, outdatedResources);
+
+ // Copy source files
+ try {
+ File earSourceDir = earSourceDirectory;
+
+ if (earSourceDir.exists()) {
+ getLog().info("Copy ear sources to " + getWorkDirectory().getAbsolutePath());
+ String[] fileNames = getEarFiles(earSourceDir);
+ for (String fileName : fileNames) {
+ copyFile(new File(earSourceDir, fileName), new File(getWorkDirectory(), fileName));
+ outdatedResources.remove(Paths.get(fileName).toString());
+ }
+ }
+
+ if (applicationXml != null) {
+ // rename to application.xml
+ getLog().info("Including custom application.xml[" + applicationXml + "]");
+ File metaInfDir = new File(getWorkDirectory(), META_INF);
+ copyFile(applicationXml, new File(metaInfDir, "/application.xml"));
+ outdatedResources.remove(Paths.get("META-INF/application.xml").toString());
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error copying EAR sources", e);
+ } catch (MavenFilteringException e) {
+ throw new MojoExecutionException("Error filtering EAR sources", e);
+ }
+
+ // Check if deployment descriptor is there
+ if (!ddFile.exists() && (javaEEVersion.lt(JavaEEVersion.FIVE))) {
+ throw new MojoExecutionException("Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
+ }
+ // no need to check timestamp for descriptors: removing if outdated does not really make sense
+ outdatedResources.remove(Paths.get(APPLICATION_XML_URI).toString());
+ if (getJbossConfiguration() != null) {
+ outdatedResources.remove(Paths.get("META-INF/jboss-app.xml").toString());
+ }
+
+ deleteOutdatedResources(outdatedResources);
+
+ try {
+ getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated EAR.");
+ getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated EAR.");
+
+ archiver.getArchiver().addDirectory(getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes());
+
+ archiver.createArchive(session, getProject(), archive);
+ } catch (ManifestException | IOException | DependencyResolutionRequiredException e) {
+ throw new MojoExecutionException("Error assembling EAR", e);
+ }
+
+ if (classifier != null) {
+ projectHelper.attachArtifact(getProject(), "ear", classifier, earFile);
+ } else {
+ getProject().getArtifact().setFile(earFile);
+ }
+ }
+
+ private void copyModules(
+ final JavaEEVersion javaEEVersion, List<String> unpackTypesList, Collection<String> outdatedResources)
+ throws MojoExecutionException, MojoFailureException {
+ try {
+ for (EarModule module : getModules()) {
+ final File sourceFile = module.getArtifact().getFile();
+ final File destinationFile = buildDestinationFile(getWorkDirectory(), module.getUri());
+ if (!sourceFile.isFile()) {
+ throw new MojoExecutionException("Cannot copy a directory: " + sourceFile.getAbsolutePath()
+ + "; Did you package/install " + module.getArtifact() + "?");
+ }
+
+ if (destinationFile.getCanonicalPath().equals(sourceFile.getCanonicalPath())) {
+ getLog().info("Skipping artifact [" + module + "], as it already exists at [" + module.getUri()
+ + "]");
+ // FIXME: Shouldn't that result in a build failure!?
+ continue;
+ }
+
+ // If the module is within the unpack list, make sure that no unpack wasn't forced (null or true)
+ // If the module is not in the unpack list, it should be true
+ if ((unpackTypesList.contains(module.getType())
+ && (module.shouldUnpack() == null || module.shouldUnpack()))
+ || (module.shouldUnpack() != null && module.shouldUnpack())) {
+ getLog().info("Copying artifact [" + module + "] to [" + module.getUri() + "] (unpacked)");
+ // Make sure that the destination is a directory to avoid plexus nasty stuff :)
+ if (!destinationFile.isDirectory() && !destinationFile.mkdirs()) {
+ throw new MojoExecutionException("Error creating " + destinationFile);
+ }
+ unpack(sourceFile, destinationFile, outdatedResources);
+
+ if (module.changeManifestClasspath()) {
+ changeManifestClasspath(module, destinationFile, javaEEVersion, outdatedResources);
+ }
+ } else {
+ if (sourceFile.lastModified() > destinationFile.lastModified()) {
+ getLog().info("Copying artifact [" + module + "] to [" + module.getUri() + "]");
+ createParentIfNecessary(destinationFile);
+ Files.copy(
+ sourceFile.toPath(),
+ destinationFile.toPath(),
+ LinkOption.NOFOLLOW_LINKS,
+ StandardCopyOption.REPLACE_EXISTING);
+ if (module.changeManifestClasspath()) {
+ changeManifestClasspath(module, destinationFile, javaEEVersion, outdatedResources);
+ }
+ } else {
+ getLog().debug("Skipping artifact [" + module + "], as it is already up to date at ["
+ + module.getUri() + "]");
+ }
+ removeFromOutdatedResources(destinationFile.toPath(), outdatedResources);
+ }
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error copying EAR modules", e);
+ } catch (ArchiverException e) {
+ throw new MojoExecutionException("Error unpacking EAR modules", e);
+ } catch (NoSuchArchiverException e) {
+ throw new MojoExecutionException("No Archiver found for EAR modules", e);
+ }
+ }
+
+ private List<String> createUnpackList() throws MojoExecutionException {
+ List<String> unpackTypesList = new ArrayList<>();
+ if (unpackTypes != null) {
+ unpackTypesList = Arrays.asList(unpackTypes.split(","));
+ for (String type : unpackTypesList) {
+ if (!EarModuleFactory.isStandardArtifactType(type)) {
+ throw new MojoExecutionException("Invalid type [" + type + "] supported types are "
+ + EarModuleFactory.getStandardArtifactTypes());
+ }
+ }
+ getLog().debug("Initialized unpack types " + unpackTypesList);
+ }
+ return unpackTypesList;
+ }
+
+ /**
+ * @return {@link #applicationXml}
+ */
+ public File getApplicationXml() {
+ return applicationXml;
+ }
+
+ /**
+ * @param applicationXml {@link #applicationXml}
+ */
+ public void setApplicationXml(File applicationXml) {
+ this.applicationXml = applicationXml;
+ }
+
+ /**
+ * Returns a string array of the excludes to be used when assembling/copying the ear.
+ *
+ * @return an array of tokens to exclude
+ */
+ protected String[] getExcludes() {
+ List<String> excludeList = new ArrayList<>(FileUtils.getDefaultExcludesAsList());
+ if (earSourceExcludes != null && !"".equals(earSourceExcludes)) {
+ excludeList.addAll(Arrays.asList(StringUtils.split(earSourceExcludes, ",")));
+ }
+
+ // if applicationXml is specified, omit the one in the source directory
+ if (getApplicationXml() != null && !"".equals(getApplicationXml())) {
+ excludeList.add("**/" + META_INF + "/application.xml");
+ }
+
+ return excludeList.toArray(new String[excludeList.size()]);
+ }
+
+ /**
+ * Returns a string array of the includes to be used when assembling/copying the ear.
+ *
+ * @return an array of tokens to include
+ */
+ protected String[] getIncludes() {
+ return StringUtils.split(Objects.toString(earSourceIncludes, ""), ",");
+ }
+
+ /**
+ * @return The array with the packaging excludes.
+ */
+ public String[] getPackagingExcludes() {
+ if (packagingExcludes == null || packagingExcludes.isEmpty()) {
+ return new String[0];
+ } else {
+ return StringUtils.split(packagingExcludes, ",");
+ }
+ }
+
+ /**
+ * @param packagingExcludes {@link #packagingExcludes}
+ */
+ public void setPackagingExcludes(String packagingExcludes) {
+ this.packagingExcludes = packagingExcludes;
+ }
+
+ /**
+ * @return the arrays with the includes
+ */
+ public String[] getPackagingIncludes() {
+ if (packagingIncludes == null || packagingIncludes.isEmpty()) {
+ return new String[] {"**"};
+ } else {
+ return StringUtils.split(packagingIncludes, ",");
+ }
+ }
+
+ /**
+ * @param packagingIncludes {@link #packagingIncludes}
+ */
+ public void setPackagingIncludes(String packagingIncludes) {
+ this.packagingIncludes = packagingIncludes;
+ }
+
+ private static File buildDestinationFile(File buildDir, String uri) {
+ return new File(buildDir, uri);
+ }
+
+ /**
+ * Returns the EAR file to generate, based on an optional classifier.
+ *
+ * @param basedir the output directory
+ * @param finalName the name of the ear file
+ * @param classifier an optional classifier
+ * @return the EAR file to generate
+ */
+ private static File getEarFile(String basedir, String finalName, String classifier) {
+ if (classifier == null) {
+ classifier = "";
+ } else if (classifier.trim().length() > 0 && !classifier.startsWith("-")) {
+ classifier = "-" + classifier;
+ }
+
+ return new File(basedir, finalName + classifier + ".ear");
+ }
+
+ /**
+ * Returns a list of filenames that should be copied over to the destination directory.
+ *
+ * @param sourceDir the directory to be scanned
+ * @return the array of filenames, relative to the sourceDir
+ */
+ private String[] getEarFiles(File sourceDir) {
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir(sourceDir);
+ scanner.setExcludes(getExcludes());
+ scanner.addDefaultExcludes();
+
+ scanner.setIncludes(getIncludes());
+
+ scanner.scan();
+
+ return scanner.getIncludedFiles();
+ }
+
+ /**
+ * Unpacks the module into the EAR structure.
+ *
+ * @param source file to be unpacked
+ * @param destDir where to put the unpacked files
+ * @param outdatedResources currently outdated resources
+ * @throws ArchiverException a corrupt archive
+ * @throws NoSuchArchiverException if we don't have an appropriate archiver
+ * @throws IOException in case of a general IOException
+ */
+ public void unpack(File source, final File destDir, final Collection<String> outdatedResources)
+ throws ArchiverException, NoSuchArchiverException, IOException {
+ Path destPath = destDir.toPath();
+
+ UnArchiver unArchiver = archiverManager.getUnArchiver("zip");
+ unArchiver.setSourceFile(source);
+ unArchiver.setDestDirectory(destDir);
+ unArchiver.setFileMappers(new FileMapper[] {
+ pName -> {
+ removeFromOutdatedResources(destPath.resolve(pName), outdatedResources);
+ return pName;
+ }
+ });
+
+ // Extract the module
+ unArchiver.extract();
+ }
+
+ private void copyFile(File source, File target)
+ throws MavenFilteringException, IOException, MojoExecutionException {
+ createParentIfNecessary(target);
+ if (filtering && !isNonFilteredExtension(source.getName())) {
+ mavenFileFilter.copyFile(source, target, true, getFilterWrappers(), encoding);
+ } else {
+ Files.copy(
+ source.toPath(), target.toPath(), LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING);
+ }
+ }
+
+ private void createParentIfNecessary(File target) throws IOException {
+ // Silly that we have to do this ourselves
+ File parentDirectory = target.getParentFile();
+ if (parentDirectory != null && !parentDirectory.exists()) {
+ Files.createDirectories(parentDirectory.toPath());
+ }
+ }
+
+ /**
+ * @param fileName the name of the file which should be checked
+ * @return {@code true} if the name is part of the non filtered extensions; {@code false} otherwise
+ */
+ public boolean isNonFilteredExtension(String fileName) {
+ return !mavenResourcesFiltering.filteredFileExtension(fileName, nonFilteredFileExtensions);
+ }
+
+ private List<FilterWrapper> getFilterWrappers() throws MojoExecutionException {
+ if (filterWrappers == null) {
+ try {
+ MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution();
+ mavenResourcesExecution.setMavenProject(getProject());
+ mavenResourcesExecution.setEscapedBackslashesInFilePath(escapedBackslashesInFilePath);
+ mavenResourcesExecution.setFilters(filters);
+ mavenResourcesExecution.setEscapeString(escapeString);
+
+ filterWrappers = mavenFileFilter.getDefaultFilterWrappers(mavenResourcesExecution);
+ } catch (MavenFilteringException e) {
+ getLog().error("Fail to build filtering wrappers " + e.getMessage());
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+ return filterWrappers;
+ }
+
+ private void changeManifestClasspath(
+ EarModule module, File original, JavaEEVersion javaEEVersion, Collection<String> outdatedResources)
+ throws MojoFailureException {
+ final String moduleLibDir = module.getLibDir();
+ if (!((moduleLibDir == null) || skinnyModules || (skinnyWars && module instanceof WebModule))) {
+ return;
+ }
+
+ // for new created items
+ FileTime outputFileTime = MavenArchiver.parseBuildOutputTimestamp(outputTimestamp)
+ .map(FileTime::from)
+ .orElse(null);
+
+ FileSystem fileSystem = null;
+
+ try {
+ Path workDirectory;
+
+ // Handle the case that the destination might be a directory (project-038)
+ // We can get FileSystems only for files
+ if (original.isFile()) {
+ fileSystem = FileSystems.newFileSystem(
+ original.toPath(), Thread.currentThread().getContextClassLoader());
+ workDirectory = fileSystem.getRootDirectories().iterator().next();
+ } else {
+ workDirectory = original.toPath();
+ }
+
+ // Create a META-INF/MANIFEST.MF file if it doesn't exist (project-038)
+ Path metaInfDirectory = workDirectory.resolve("META-INF");
+ if (!Files.exists(metaInfDirectory)) {
+ Files.createDirectory(metaInfDirectory);
+ if (outputFileTime != null) {
+ Files.setLastModifiedTime(metaInfDirectory, outputFileTime);
+ }
+ getLog().debug(
+ "This project did not have a META-INF directory before, so a new directory was created.");
+ }
+ Path manifestFile = metaInfDirectory.resolve("MANIFEST.MF");
+ if (!Files.exists(manifestFile)) {
+ Files.createFile(manifestFile);
+ if (outputFileTime != null) {
+ Files.setLastModifiedTime(manifestFile, outputFileTime);
+ }
+ getLog().debug(
+ "This project did not have a META-INF/MANIFEST.MF file before, so a new file was created.");
+ }
+
+ Manifest mf = readManifest(manifestFile);
+ Attribute classPath = mf.getMainSection().getAttribute("Class-Path");
+ List<String> classPathElements = new ArrayList<>();
+
+ boolean classPathExists;
+ if (classPath != null) {
+ classPathExists = true;
+ classPathElements.addAll(Arrays.asList(classPath.getValue().split(" ")));
+ } else {
+ classPathExists = false;
+ classPath = new Attribute("Class-Path", "");
+ }
+
+ if ((moduleLibDir != null) && (skinnyModules || (skinnyWars && module instanceof WebModule))) {
+ // Remove modules
+ for (EarModule otherModule : getAllEarModules()) {
+ if (module.equals(otherModule)) {
+ continue;
+ }
+ // MEAR-189:
+ // We use the original name, cause in case of outputFileNameMapping
+ // we could not not delete it and it will end up in the resulting EAR and the WAR
+ // will not be cleaned up.
+ final Path workLibDir = workDirectory.resolve(moduleLibDir);
+ Path artifact =
+ workLibDir.resolve(module.getArtifact().getFile().getName());
+
+ // MEAR-217
+ // If WAR contains files with timestamps, but EAR strips them away (useBaseVersion=true)
+ // the artifact is not found. Therefore, respect the current fileNameMapping additionally.
+
+ if (!Files.exists(artifact)) {
+ getLog().debug("module does not exist with original file name.");
+ artifact = workLibDir.resolve(otherModule.getBundleFileName());
+ getLog().debug("Artifact with mapping: " + artifact.toAbsolutePath());
+ }
+
+ if (!Files.exists(artifact)) {
+ getLog().debug("Artifact with mapping does not exist.");
+ artifact = workLibDir.resolve(
+ otherModule.getArtifact().getFile().getName());
+ getLog().debug("Artifact with original file name: " + artifact.toAbsolutePath());
+ }
+
+ if (!Files.exists(artifact)) {
+ getLog().debug("Artifact with original file name does not exist.");
+ final Artifact otherModuleArtifact = otherModule.getArtifact();
+ if (otherModuleArtifact.isSnapshot()) {
+ try {
+ artifact = workLibDir.resolve(MappingUtils.evaluateFileNameMapping(
+ ARTIFACT_DEFAULT_FILE_NAME_MAPPING, otherModuleArtifact));
+ getLog().debug("Artifact with default mapping file name: " + artifact.toAbsolutePath());
+ } catch (InterpolationException e) {
+ getLog().warn("Failed to evaluate file name for [" + otherModule
+ + "] module using mapping: " + ARTIFACT_DEFAULT_FILE_NAME_MAPPING);
+ }
+ }
+ }
+
+ if (Files.exists(artifact)) {
+ getLog().debug(" -> Artifact to delete: " + artifact);
+ Files.delete(artifact);
+ }
+ }
+ }
+
+ // Modify the classpath entries in the manifest
+ final boolean forceClassPathModification =
+ javaEEVersion.lt(JavaEEVersion.FIVE) || defaultLibBundleDir == null;
+ final boolean classPathExtension = !skipClassPathModification || forceClassPathModification;
+ for (EarModule otherModule : getModules()) {
+ if (module.equals(otherModule)) {
+ continue;
+ }
+ final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule);
+ if (moduleClassPathIndex != -1) {
+ if (otherModule.isClassPathItem()) {
+ classPathElements.set(moduleClassPathIndex, otherModule.getUri());
+ } else {
+ classPathElements.remove(moduleClassPathIndex);
+ }
+ } else if (otherModule.isClassPathItem() && classPathExtension) {
+ classPathElements.add(otherModule.getUri());
+ }
+ }
+
+ // Remove provided modules from classpath
+ for (EarModule otherModule : getProvidedEarModules()) {
+ final int moduleClassPathIndex = findModuleInClassPathElements(classPathElements, otherModule);
+ if (moduleClassPathIndex != -1) {
+ classPathElements.remove(moduleClassPathIndex);
+ }
+ }
+
+ if (!skipClassPathModification || !classPathElements.isEmpty() || classPathExists) {
+ classPath.setValue(StringUtils.join(classPathElements.iterator(), " "));
+ mf.getMainSection().addConfiguredAttribute(classPath);
+
+ // Write the manifest to disk, preserve timestamp
+ FileTime lastModifiedTime = Files.getLastModifiedTime(manifestFile);
+ try (BufferedWriter writer = Files.newBufferedWriter(
+ manifestFile,
+ StandardCharsets.UTF_8,
+ StandardOpenOption.WRITE,
+ StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING)) {
+ mf.write(writer);
+ }
+ Files.setLastModifiedTime(manifestFile, lastModifiedTime);
+ removeFromOutdatedResources(manifestFile, outdatedResources);
+ }
+
+ if (fileSystem != null) {
+ fileSystem.close();
+ fileSystem = null;
+ }
+ } catch (ManifestException | IOException | ArchiverException e) {
+ throw new MojoFailureException(e.getMessage(), e);
+ } finally {
+ if (fileSystem != null) {
+ try {
+ fileSystem.close();
+ } catch (IOException e) {
+ // ignore here
+ }
+ }
+ }
+ }
+
+ private static Manifest readManifest(Path manifestFile) throws IOException {
+ // Read the manifest from disk
+ try (InputStream in = Files.newInputStream(manifestFile)) {
+ return new Manifest(in);
+ }
+ }
+
+ private Collection<String> initOutdatedResources() {
+ final Collection<String> outdatedResources = new ArrayList<>();
+
+ if (getWorkDirectory().exists()) {
+ try {
+ Files.walkFileTree(getWorkDirectory().toPath(), new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ outdatedResources.add(
+ getWorkDirectory().toPath().relativize(file).toString());
+ return super.visitFile(file, attrs);
+ }
+ });
+ } catch (IOException e) {
+ getLog().warn("Can't detect outdated resources", e);
+ }
+ }
+
+ getLog().debug("initOutdatedResources: " + outdatedResources);
+ return outdatedResources;
+ }
+
+ private void deleteOutdatedResources(final Collection<String> outdatedResources) {
+ getLog().debug("deleteOutdatedResources: " + outdatedResources);
+ final long startTime = session.getStartTime().getTime();
+
+ getLog().debug("deleteOutdatedResources session startTime: " + startTime);
+
+ for (String outdatedResource : outdatedResources) {
+ File resourceFile = new File(getWorkDirectory(), outdatedResource);
+ if (resourceFile.lastModified() < startTime) {
+ getLog().info("deleting outdated resource " + outdatedResource);
+ getLog().debug(outdatedResource + " last modified: " + resourceFile.lastModified());
+ resourceFile.delete();
+ }
+ }
+ }
+
+ private void removeFromOutdatedResources(Path destination, Collection<String> outdatedResources) {
+ Path relativeDestFile;
+ try {
+ relativeDestFile = getWorkDirectory().toPath().relativize(destination.normalize());
+ } catch (ProviderMismatchException e) {
+ relativeDestFile = destination.normalize();
+ }
+
+ if (outdatedResources.remove(relativeDestFile.toString())) {
+ getLog().debug("Remove from outdatedResources: " + relativeDestFile);
+ }
+ }
+
+ /**
+ * Searches for the given JAR module in the list of classpath elements. If JAR module is found among specified
+ * classpath elements then returns index of first matching element. Returns -1 otherwise.
+ *
+ * @param classPathElements classpath elements to search among
+ * @param module module to find among classpath elements defined by {@code classPathElements}
+ * @return -1 if {@code module} was not found in {@code classPathElements} or index of item of
+ * {@code classPathElements} which matches {@code module}
+ */
+ private int findModuleInClassPathElements(final List<String> classPathElements, final EarModule module) {
+ if (classPathElements.isEmpty()) {
+ return -1;
+ }
+ int moduleClassPathIndex = classPathElements.indexOf(module.getBundleFileName());
+ if (moduleClassPathIndex != -1) {
+ return moduleClassPathIndex;
+ }
+ final Artifact artifact = module.getArtifact();
+ moduleClassPathIndex = classPathElements.indexOf(artifact.getFile().getName());
+ if (moduleClassPathIndex != -1) {
+ return moduleClassPathIndex;
+ }
+ if (artifact.isSnapshot()) {
+ try {
+ moduleClassPathIndex = classPathElements.indexOf(
+ MappingUtils.evaluateFileNameMapping(ARTIFACT_DEFAULT_FILE_NAME_MAPPING, artifact));
+ if (moduleClassPathIndex != -1) {
+ return moduleClassPathIndex;
+ }
+ } catch (InterpolationException e) {
+ getLog().warn("Failed to evaluate file name for [" + module + "] module using mapping: "
+ + ARTIFACT_DEFAULT_FILE_NAME_MAPPING);
+ }
+ }
+ return classPathElements.indexOf(module.getUri());
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EarPluginException.java b/src/main/java/org/apache/maven/plugins/ear/EarPluginException.java
index 9243b9b..0741f95 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EarPluginException.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EarPluginException.java
@@ -1,67 +1,78 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * The base exception of the EAR plugin.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class EarPluginException
- extends Exception
-{
-
- /**
- *
- */
- private static final long serialVersionUID = -5540929953103327928L;
-
- /**
- * Create an instance.
- */
- public EarPluginException()
- {
- }
-
- /**
- * @param message The message for the exception.
- */
- public EarPluginException( String message )
- {
- super( message );
- }
-
- /**
- * @param cause {@link Throwable}
- */
- public EarPluginException( Throwable cause )
- {
- super( cause );
- }
-
- /**
- * @param message The message to emit.
- * @param cause {@link Throwable}
- */
- public EarPluginException( String message, Throwable cause )
- {
- super( message, cause );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * The base exception of the EAR plugin.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EarPluginException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5540929953103327928L;
+
+ /**
+ * Create an instance.
+ */
+ public EarPluginException() {}
+
+ /**
+ * @param message The message for the exception.
+ */
+ public EarPluginException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause {@link Throwable}
+ */
+ public EarPluginException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param message The message to emit.
+ * @param cause {@link Throwable}
+ */
+ public EarPluginException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EjbClientModule.java b/src/main/java/org/apache/maven/plugins/ear/EjbClientModule.java
index bd16ebc..73256eb 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EjbClientModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EjbClientModule.java
@@ -1,53 +1,67 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-
-/**
- * The {@link EarModule} implementation for an ejb client module.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class EjbClientModule
- extends JarModule
-{
- /**
- * Default type of the artifact of an ejb client module.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "ejb-client";
-
- /**
- * Create an instance.
- */
- public EjbClientModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- }
-
- /**
- * @param a {@link Artifact}
- * @param defaultLibBundleDir The default lib bundle directory.
- */
- public EjbClientModule( Artifact a, String defaultLibBundleDir )
- {
- super( a, defaultLibBundleDir, Boolean.FALSE );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for an ejb client module.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EjbClientModule extends JarModule {
+ /**
+ * Default type of the artifact of an ejb client module.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "ejb-client";
+
+ /**
+ * Create an instance.
+ */
+ public EjbClientModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ * @param defaultLibBundleDir The default lib bundle directory.
+ */
+ public EjbClientModule(Artifact a, String defaultLibBundleDir) {
+ super(a, defaultLibBundleDir, Boolean.FALSE);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EjbModule.java b/src/main/java/org/apache/maven/plugins/ear/EjbModule.java
index f9adb3c..cd94997 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EjbModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EjbModule.java
@@ -1,70 +1,83 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * The {@link EarModule} implementation for an EJB module.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class EjbModule
- extends AbstractEarModule
-{
- /**
- * Default type of the artifact of an EJB module.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "ejb";
-
- private static final String EJB_MODULE = "ejb";
-
- /**
- * Create an instance.
- */
- public EjbModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- }
-
- /**
- * @param a {@link Artifact}
- */
- public EjbModule( Artifact a )
- {
- super( a );
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendModule( XMLWriter writer, String version, Boolean generateId )
- {
- startModuleElement( writer, generateId );
- writer.startElement( EJB_MODULE );
- writer.writeText( getUri() );
- writer.endElement();
-
- writeAltDeploymentDescriptor( writer, version );
-
- writer.endElement();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for an EJB module.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EjbModule extends AbstractEarModule {
+ /**
+ * Default type of the artifact of an EJB module.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "ejb";
+
+ private static final String EJB_MODULE = "ejb";
+
+ /**
+ * Create an instance.
+ */
+ public EjbModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ */
+ public EjbModule(Artifact a) {
+ super(a);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendModule(XMLWriter writer, String version, Boolean generateId) {
+ startModuleElement(writer, generateId);
+ writer.startElement(EJB_MODULE);
+ writer.writeText(getUri());
+ writer.endElement();
+
+ writeAltDeploymentDescriptor(writer, version);
+
+ writer.endElement();
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EjbRef.java b/src/main/java/org/apache/maven/plugins/ear/EjbRef.java
index e57b6c1..80675c4 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EjbRef.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EjbRef.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.plugins.ear;
/*
@@ -23,12 +41,11 @@ import org.codehaus.plexus.util.xml.XMLWriter;
/**
* Representation of {@code ejb-ref} element in {@code application.xml} file.
- *
+ *
* @author Karl Heinz Marbaise
* @since 2.10
*/
-public class EjbRef
-{
+public class EjbRef {
static final String DESCRIPTION = "description";
static final String EJB_REF = "ejb-ref";
@@ -53,120 +70,102 @@ public class EjbRef
* @param type The ejb-ref-type
* @param lookupName The lookupname.
*/
- public EjbRef( String description, String name, String type, String lookupName )
- {
- if ( name == null || name.isEmpty() )
- {
- throw new IllegalArgumentException( EJB_NAME + " in " + EJB_REF + " element cannot be null." );
- }
- else if ( ( type == null || type.isEmpty() ) && ( lookupName == null || lookupName.isEmpty() ) )
- {
- throw new IllegalArgumentException( EJB_TYPE + " in " + EJB_REF + " element cannot be null if no "
- + EJB_LOOKUP_NAME + " was specified." );
-
+ public EjbRef(String description, String name, String type, String lookupName) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException(EJB_NAME + " in " + EJB_REF + " element cannot be null.");
+ } else if ((type == null || type.isEmpty()) && (lookupName == null || lookupName.isEmpty())) {
+ throw new IllegalArgumentException(EJB_TYPE + " in " + EJB_REF + " element cannot be null if no "
+ + EJB_LOOKUP_NAME + " was specified.");
}
this.description = description;
this.name = name;
this.type = type;
this.lookupName = lookupName;
-
}
/**
* Appends the {@code XML} representation of this env-entry.
- *
+ *
* @param writer the writer to use
*/
- public void appendEjbRefEntry( XMLWriter writer )
- {
- writer.startElement( EJB_REF );
+ public void appendEjbRefEntry(XMLWriter writer) {
+ writer.startElement(EJB_REF);
// description
- if ( getDescription() != null )
- {
- doWriteElement( writer, DESCRIPTION, getDescription() );
+ if (getDescription() != null) {
+ doWriteElement(writer, DESCRIPTION, getDescription());
}
// ejb name
- doWriteElement( writer, EJB_NAME, getName() );
+ doWriteElement(writer, EJB_NAME, getName());
// ejb-type
- if ( getType() != null )
- {
- doWriteElement( writer, EJB_TYPE, getType() );
+ if (getType() != null) {
+ doWriteElement(writer, EJB_TYPE, getType());
}
// lookup-name
- if ( getLookupName() != null )
- {
- doWriteElement( writer, EJB_LOOKUP_NAME, getLookupName() );
+ if (getLookupName() != null) {
+ doWriteElement(writer, EJB_LOOKUP_NAME, getLookupName());
}
// end of ejb-ref
writer.endElement();
}
- private void doWriteElement( XMLWriter writer, String element, String text )
- {
- writer.startElement( element );
- writer.writeText( text );
+ private void doWriteElement(XMLWriter writer, String element, String text) {
+ writer.startElement(element);
+ writer.writeText(text);
writer.endElement();
}
/**
* @return {@link #name}
*/
- public String getName()
- {
+ public String getName() {
return name;
}
/**
* @param name {@link #name}
*/
- public void setName( String name )
- {
+ public void setName(String name) {
this.name = name;
}
/**
* @return {@link #type}
*/
- public String getType()
- {
+ public String getType() {
return type;
}
/**
* @param type {@link #type}
*/
- public void setType( String type )
- {
+ public void setType(String type) {
this.type = type;
}
/**
* @return {@link #lookupName}
*/
- public String getLookupName()
- {
+ public String getLookupName() {
return lookupName;
}
/**
* @param lookupName {@link #lookupName}
*/
- public void setLookupName( String lookupName )
- {
+ public void setLookupName(String lookupName) {
this.lookupName = lookupName;
}
/**
* @return {@link #description}
*/
- public String getDescription()
- {
+ public String getDescription() {
return description;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/ear/EnvEntry.java b/src/main/java/org/apache/maven/plugins/ear/EnvEntry.java
index e3fb775..9a4a95a 100644
--- a/src/main/java/org/apache/maven/plugins/ear/EnvEntry.java
+++ b/src/main/java/org/apache/maven/plugins/ear/EnvEntry.java
@@ -1,154 +1,153 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * The representation of a env-entry entry within an application.xml file.
- *
- * @author Jim Brownfield based on code by <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-class EnvEntry
-{
-
- static final String ENV_ENTRY = "env-entry";
-
- static final String DESCRIPTION = "description";
-
- static final String ENV_ENTRY_NAME = "env-entry-name";
-
- static final String ENV_ENTRY_TYPE = "env-entry-type";
-
- static final String ENV_ENTRY_VALUE = "env-entry-value";
-
- static final String ENV_LOOKUP_NAME = "lookup-name";
-
- private final String description;
-
- private final String name;
-
- private final String type;
-
- private final String value;
-
- private final String lookupName;
-
- EnvEntry( String description, String name, String type, String value, String lookupName )
- {
- if ( name == null || name.isEmpty() )
- {
- throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." );
- }
- else if ( ( type == null || type.isEmpty() ) && ( value == null || value.isEmpty() ) )
-
- {
- throw new IllegalArgumentException( ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no "
- + ENV_ENTRY_VALUE + " was specified." );
-
- }
-
- this.description = description;
- this.name = name;
- this.type = type;
- this.value = value;
- this.lookupName = lookupName;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getType()
- {
- return type;
- }
-
- public String getValue()
- {
- return value;
- }
-
- public String getLookupName()
- {
- return lookupName;
- }
-
- /**
- * Appends the {@code XML} representation of this env-entry.
- *
- * @param writer the writer to use
- */
- public void appendEnvEntry( XMLWriter writer )
- {
- System.out.println( "appendEnvEntry()" );
- writer.startElement( ENV_ENTRY );
-
- // description
- if ( getDescription() != null )
- {
- doWriteElement( writer, DESCRIPTION, getDescription() );
- }
-
- // env entry name
- doWriteElement( writer, ENV_ENTRY_NAME, getName() );
-
- // env entry type
- if ( getType() != null )
- {
- doWriteElement( writer, ENV_ENTRY_TYPE, getType() );
- }
-
- // env entry value
- if ( getValue() != null )
- {
- doWriteElement( writer, ENV_ENTRY_VALUE, getValue() );
- }
-
- // lookup-name
- if ( getLookupName() != null )
- {
- doWriteElement( writer, ENV_LOOKUP_NAME, getLookupName() );
- }
-
- // end of env-entry
- writer.endElement();
- }
-
- private void doWriteElement( XMLWriter writer, String element, String text )
- {
- writer.startElement( element );
- writer.writeText( text );
- writer.endElement();
- }
-
- public String toString()
- {
- return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + ", lookup-name="
- + getLookupName() + "]";
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The representation of a env-entry entry within an application.xml file.
+ *
+ * @author Jim Brownfield based on code by <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+class EnvEntry {
+
+ static final String ENV_ENTRY = "env-entry";
+
+ static final String DESCRIPTION = "description";
+
+ static final String ENV_ENTRY_NAME = "env-entry-name";
+
+ static final String ENV_ENTRY_TYPE = "env-entry-type";
+
+ static final String ENV_ENTRY_VALUE = "env-entry-value";
+
+ static final String ENV_LOOKUP_NAME = "lookup-name";
+
+ private final String description;
+
+ private final String name;
+
+ private final String type;
+
+ private final String value;
+
+ private final String lookupName;
+
+ EnvEntry(String description, String name, String type, String value, String lookupName) {
+ if (name == null || name.isEmpty()) {
+ throw new IllegalArgumentException(ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null.");
+ } else if ((type == null || type.isEmpty()) && (value == null || value.isEmpty())) {
+
+ throw new IllegalArgumentException(ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no "
+ + ENV_ENTRY_VALUE + " was specified.");
+ }
+
+ this.description = description;
+ this.name = name;
+ this.type = type;
+ this.value = value;
+ this.lookupName = lookupName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public String getLookupName() {
+ return lookupName;
+ }
+
+ /**
+ * Appends the {@code XML} representation of this env-entry.
+ *
+ * @param writer the writer to use
+ */
+ public void appendEnvEntry(XMLWriter writer) {
+ System.out.println("appendEnvEntry()");
+ writer.startElement(ENV_ENTRY);
+
+ // description
+ if (getDescription() != null) {
+ doWriteElement(writer, DESCRIPTION, getDescription());
+ }
+
+ // env entry name
+ doWriteElement(writer, ENV_ENTRY_NAME, getName());
+
+ // env entry type
+ if (getType() != null) {
+ doWriteElement(writer, ENV_ENTRY_TYPE, getType());
+ }
+
+ // env entry value
+ if (getValue() != null) {
+ doWriteElement(writer, ENV_ENTRY_VALUE, getValue());
+ }
+
+ // lookup-name
+ if (getLookupName() != null) {
+ doWriteElement(writer, ENV_LOOKUP_NAME, getLookupName());
+ }
+
+ // end of env-entry
+ writer.endElement();
+ }
+
+ private void doWriteElement(XMLWriter writer, String element, String text) {
+ writer.startElement(element);
+ writer.writeText(text);
+ writer.endElement();
+ }
+
+ public String toString() {
+ return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + ", lookup-name="
+ + getLookupName() + "]";
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/GenerateApplicationXmlMojo.java b/src/main/java/org/apache/maven/plugins/ear/GenerateApplicationXmlMojo.java
index d792f61..1e8a207 100644
--- a/src/main/java/org/apache/maven/plugins/ear/GenerateApplicationXmlMojo.java
+++ b/src/main/java/org/apache/maven/plugins/ear/GenerateApplicationXmlMojo.java
@@ -1,531 +1,482 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-import org.apache.maven.plugins.ear.util.JavaEEVersion;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-import org.codehaus.plexus.interpolation.InterpolationException;
-import org.codehaus.plexus.interpolation.Interpolator;
-import org.codehaus.plexus.interpolation.MapBasedValueSource;
-import org.codehaus.plexus.interpolation.StringSearchInterpolator;
-import org.codehaus.plexus.interpolation.ValueSource;
-import org.codehaus.plexus.util.FileUtils;
-
-/**
- * Generates the EAR deployment descriptor file(s).
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-@Mojo( name = "generate-application-xml",
- defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
- threadSafe = true,
- requiresDependencyResolution = ResolutionScope.TEST )
-public class GenerateApplicationXmlMojo
- extends AbstractEarMojo
-{
-
- /**
- * The DEFAULT library folder.
- */
- public static final String DEFAULT = "DEFAULT";
-
- /**
- * The empty folder.
- */
- public static final String EMPTY = "EMPTY";
-
- /**
- * The NONE not existent folder.
- */
- public static final String NONE = "NONE";
-
- /**
- * Whether the application.xml should be generated or not.
- */
- @Parameter( defaultValue = "true" )
- private Boolean generateApplicationXml = Boolean.TRUE;
-
- /**
- * Whether a module ID should be generated if none is specified.
- */
- @Parameter( defaultValue = "false" )
- private Boolean generateModuleId = Boolean.FALSE;
-
- /**
- * Application name of the application to be used when the application.xml file is auto-generated. Since JavaEE6.
- */
- @Parameter
- private String applicationName;
-
- /**
- * Display name of the application to be used when the application.xml file is auto-generated.
- */
- @Parameter( defaultValue = "${project.artifactId}" )
- private String displayName;
-
- /**
- * Description of the application to be used when the application.xml file is auto-generated.
- */
- @Parameter( defaultValue = "${project.description}" )
- private String description;
-
- /**
- * Defines how the {@code library-directory} element should be written in the application.xml file.
- * <p/>
- * Three special values can be set:
- * <ul>
- * <li><code>DEFAULT</code> (default) generates a {@code library-directory} element with the value of the
- * {@code defaultLibBundleDir} parameter</li>
- * <li><code>EMPTY</code> generates an empty {@code library-directory} element. Per spec, this disables the
- * scanning of jar files in the {@code lib} directory of the ear file</li>
- * <li><code>NONE</code> does not write the library-directory element at all. A corner case that can be used in
- * Oracle Weblogic to delegate the classloading to the container</li>
- * </ul>
- * <p/>
- * Since JavaEE5.
- */
- @Parameter( defaultValue = DEFAULT )
- private String libraryDirectoryMode;
-
- /**
- * Defines the value of the initialize in order element to be used when the application.xml file is auto-generated.
- * When set to true, modules must be initialized in the order they're listed in this deployment descriptor, with the
- * exception of application client modules, which can be initialized in any order. If initialize-in-order is not set
- * or set to false, the order of initialization is unspecified and may be product-dependent. Since JavaEE6.
- */
- @Parameter
- private Boolean initializeInOrder;
-
- /**
- * Defines the application id used when generating the deployment descriptor.
- *
- * @since 2.9
- */
- @Parameter
- private String applicationId;
-
- /**
- * The security-roles to be added to the auto-generated application.xml file.
- */
- @Parameter
- private PlexusConfiguration security;
-
- /**
- * The env-entries to be added to the auto-generated application.xml file. Since JavaEE6.
- */
- @Parameter( alias = "env-entries" )
- private PlexusConfiguration envEntries;
-
- /**
- * The {@code ejb-ref} entries.
- */
- @Parameter( alias = "ejb-refs" )
- private PlexusConfiguration ejbRefs;
-
- /**
- * The {@code resource-ref} entries.
- */
- @Parameter
- private PlexusConfiguration resourceRefs;
-
- /**
- * {@inheritDoc}
- */
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- // Initializes ear modules
- super.execute();
-
- // Handle application.xml
- if ( !generateApplicationXml )
- {
- getLog().debug( "Generation of application.xml is disabled" );
- }
- else
- {
- final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion( version );
-
- // Generate deployment descriptor and copy it to the build directory
- getLog().info( "Generating application.xml" );
- try
- {
- generateStandardDeploymentDescriptor( javaEEVersion );
- }
- catch ( EarPluginException e )
- {
- throw new MojoExecutionException( "Failed to generate application.xml", e );
- }
-
- try
- {
- FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "application.xml" ),
- new File( getWorkDirectory(), "META-INF" ) );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to copy application.xml to final destination", e );
- }
- }
-
- // Handle jboss-app.xml
- if ( getJbossConfiguration() == null )
- {
- getLog().debug( "Generation of jboss-app.xml is disabled" );
- }
- else
- {
- // Generate deployment descriptor and copy it to the build directory
- getLog().info( "Generating jboss-app.xml" );
- try
- {
- generateJbossDeploymentDescriptor();
- }
- catch ( EarPluginException e )
- {
- throw new MojoExecutionException( "Failed to generate jboss-app.xml", e );
- }
-
- try
- {
- FileUtils.copyFileToDirectory( new File( generatedDescriptorLocation, "jboss-app.xml" ),
- new File( getWorkDirectory(), "META-INF" ) );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to copy jboss-app.xml to final destination", e );
- }
- }
- }
-
- /**
- * Generates the deployment descriptor.
- *
- * @param javaEEVersion {@link JavaEEVersion}
- * @throws EarPluginException if the configuration is invalid
- */
- protected void generateStandardDeploymentDescriptor( JavaEEVersion javaEEVersion )
- throws EarPluginException
- {
- File outputDir = new File( generatedDescriptorLocation );
- if ( !outputDir.exists() )
- {
- if ( !outputDir.mkdirs() )
- {
- throw new EarPluginException( "Error creating " + outputDir );
- }
- }
-
- File descriptor = new File( outputDir, "application.xml" );
-
- final ApplicationXmlWriter writer = new ApplicationXmlWriter( javaEEVersion, encoding, generateModuleId );
- final ApplicationXmlWriterContext context =
- new ApplicationXmlWriterContext( descriptor, getModules(), buildSecurityRoles(), buildEnvEntries(),
- buildEjbEntries(), buildResourceRefs(), displayName, description,
- getActualLibraryDirectory(), applicationName,
- initializeInOrder ).setApplicationId( applicationId );
- writer.write( context );
- }
-
- /**
- * Generates the JBoss deployment descriptor.
- *
- * @throws EarPluginException if the configuration is invalid
- */
- protected void generateJbossDeploymentDescriptor()
- throws EarPluginException
- {
- File outputDir = new File( generatedDescriptorLocation );
- if ( !outputDir.exists() )
- {
- if ( !outputDir.mkdirs() )
- {
- throw new EarPluginException( "Error creating " + outputDir );
- }
- }
-
- File descriptor = new File( outputDir, "jboss-app.xml" );
-
- JbossAppXmlWriter writer = new JbossAppXmlWriter( encoding );
- writer.write( descriptor, getJbossConfiguration(), getModules() );
- }
-
- /**
- * Builds the security roles based on the configuration.
- *
- * @return a list of SecurityRole object(s)
- * @throws EarPluginException if the configuration is invalid
- */
- private List<SecurityRole> buildSecurityRoles()
- throws EarPluginException
- {
- final List<SecurityRole> result = new ArrayList<>();
- if ( security == null )
- {
- return result;
- }
- final PlexusConfiguration[] securityRoles = security.getChildren( SecurityRole.SECURITY_ROLE );
-
- for ( PlexusConfiguration securityRole : securityRoles )
- {
- final String id = securityRole.getAttribute( SecurityRole.ID_ATTRIBUTE );
- final String childRoleName = securityRole.getChild( SecurityRole.ROLE_NAME ).getValue();
- final String childRoleNameId =
- securityRole.getChild( SecurityRole.ROLE_NAME ).getAttribute( SecurityRole.ID_ATTRIBUTE );
- final String childDescription = securityRole.getChild( SecurityRole.DESCRIPTION ).getValue();
- final String childDescriptionId =
- securityRole.getChild( SecurityRole.DESCRIPTION ).getAttribute( SecurityRole.ID_ATTRIBUTE );
-
- if ( childRoleName == null )
- {
- throw new EarPluginException( "Invalid security-role configuration, role-name could not be null." );
- }
- else
- {
- result.add( new SecurityRole( childRoleName, childRoleNameId, id, childDescription,
- childDescriptionId ) );
- }
- }
- return result;
- }
-
- /**
- * This help method was needed otherwise the interpolate method of interpolator will make an empty string of a
- * {@code null} element which results in supplemental elements for env-entry.
- *
- * @param interpolator The interpolator
- * @param element The element
- * @return The interpolated elements.
- * @throws InterpolationException in case of an error.
- */
- private String interpolate( Interpolator interpolator, String element )
- throws InterpolationException
- {
- if ( element == null )
- {
- return element;
- }
- else
- {
- return interpolator.interpolate( element );
- }
- }
-
- /**
- * Builds the env-entries based on the configuration.
- *
- * @return a list of EnvEntry object(s)
- * @throws EarPluginException if the configuration is invalid
- */
- private List<EnvEntry> buildEnvEntries()
- throws EarPluginException
- {
- final List<EnvEntry> result = new ArrayList<>();
- if ( envEntries == null )
- {
- return result;
- }
- try
- {
- StringSearchInterpolator ssi = new StringSearchInterpolator();
- ValueSource vs = new MapBasedValueSource( project.getProperties() );
- ssi.addValueSource( vs );
-
- final PlexusConfiguration[] allEnvEntries = envEntries.getChildren( EnvEntry.ENV_ENTRY );
-
- getLog().debug( "buildEnvEntries: allEnvEntries size:" + allEnvEntries.length );
- for ( PlexusConfiguration envEntry : allEnvEntries )
- {
- final String childDescription =
- interpolate( ssi, envEntry.getChild( EnvEntry.DESCRIPTION ).getValue() );
- final String childEnvEntryName =
- interpolate( ssi, envEntry.getChild( EnvEntry.ENV_ENTRY_NAME ).getValue() );
- final String childEnvEntryType =
- interpolate( ssi, envEntry.getChild( EnvEntry.ENV_ENTRY_TYPE ).getValue() );
- final String childEnvEntryValue =
- interpolate( ssi, envEntry.getChild( EnvEntry.ENV_ENTRY_VALUE ).getValue() );
- final String childEnvLookupNameValue =
- interpolate( ssi, envEntry.getChild( EnvEntry.ENV_LOOKUP_NAME ).getValue() );
-
- try
- {
- result.add( new EnvEntry( childDescription, childEnvEntryName, childEnvEntryType,
- childEnvEntryValue, childEnvLookupNameValue ) );
- }
- catch ( IllegalArgumentException e )
- {
- throw new EarPluginException( "Invalid env-entry [" + envEntry + "]", e );
- }
- }
- return result;
- }
- catch ( InterpolationException e )
- {
- throw new EarPluginException( "Interpolation exception:", e );
- }
-
- }
-
- /**
- * Builds the ejb-ref based on the configuration.
- *
- * @return a list of EjbRef object(s)
- * @throws EarPluginException if the configuration is invalid
- */
- private List<EjbRef> buildEjbEntries()
- throws EarPluginException
- {
- final List<EjbRef> result = new ArrayList<>();
- if ( ejbRefs == null )
- {
- return result;
- }
- try
- {
- StringSearchInterpolator ssi = new StringSearchInterpolator();
- ValueSource vs = new MapBasedValueSource( project.getProperties() );
- ssi.addValueSource( vs );
-
- final PlexusConfiguration[] allEjbEntries = ejbRefs.getChildren( EjbRef.EJB_REF );
-
- for ( PlexusConfiguration ejbEntry : allEjbEntries )
- {
- final String childDescription =
- interpolate( ssi, ejbEntry.getChild( EnvEntry.DESCRIPTION ).getValue() );
- final String childEjbEntryName = interpolate( ssi, ejbEntry.getChild( EjbRef.EJB_NAME ).getValue() );
- final String childEjbEntryType = interpolate( ssi, ejbEntry.getChild( EjbRef.EJB_TYPE ).getValue() );
- final String childEjbLookupNameValue =
- interpolate( ssi, ejbEntry.getChild( EjbRef.EJB_LOOKUP_NAME ).getValue() );
-
- try
- {
- result.add( new EjbRef( childDescription, childEjbEntryName, childEjbEntryType,
- childEjbLookupNameValue ) );
- }
- catch ( IllegalArgumentException e )
- {
- throw new EarPluginException( "Invalid ejb-ref [" + ejbEntry + "]", e );
- }
- }
- return result;
- }
- catch ( InterpolationException e )
- {
- throw new EarPluginException( "Interpolation exception:", e );
- }
-
- }
-
- /**
- * Builds the <code>resource-ref</code> based on the configuration.
- *
- * @return a list of ResourceRef object(s)
- * @throws EarPluginException if the configuration is invalid
- */
- private List<ResourceRef> buildResourceRefs()
- throws EarPluginException
- {
- final List<ResourceRef> result = new ArrayList<>();
- if ( resourceRefs == null )
- {
- return result;
- }
- try
- {
- getLog().debug( "Resources found" );
- StringSearchInterpolator ssi = new StringSearchInterpolator();
- ValueSource vs = new MapBasedValueSource( project.getProperties() );
- ssi.addValueSource( vs );
-
- // TODO: Check if this is a good idea hard code that here? Better idea?
- final PlexusConfiguration[] allResourceRefEntries = resourceRefs.getChildren( "resourceRef" );
-
- getLog().debug( "allResourceRefEntries length: " + allResourceRefEntries.length );
- for ( PlexusConfiguration resEntry : allResourceRefEntries )
- {
- getLog().debug( "Resources resEntry:" + resEntry.getName() );
-
- final String childResRefName =
- interpolate( ssi, resEntry.getChild( ResourceRef.RESOURCE_REF_NAME ).getValue() );
- final String childResType =
- interpolate( ssi, resEntry.getChild( ResourceRef.RESOURCE_TYPE ).getValue() );
- final String childResRefAuth =
- interpolate( ssi, resEntry.getChild( ResourceRef.RESOURCE_AUTH ).getValue() );
- final String childResRefLookupName =
- interpolate( ssi, resEntry.getChild( ResourceRef.LOOKUP_NAME ).getValue() );
-
- try
- {
- result.add(
- new ResourceRef( childResRefName, childResType, childResRefAuth, childResRefLookupName ) );
- }
- catch ( IllegalArgumentException e )
- {
- throw new EarPluginException( "Invalid resource-ref [" + resEntry + "]", e );
- }
- }
- return result;
- }
- catch ( InterpolationException e )
- {
- throw new EarPluginException( "Interpolation exception:", e );
- }
-
- }
-
- /**
- * Returns the value to use for the {@code library-directory} element, based on the library directory mode.
- */
- private String getActualLibraryDirectory()
- throws EarPluginException
- {
- final String mode = libraryDirectoryMode == null ? DEFAULT : libraryDirectoryMode.toUpperCase();
-
- if ( DEFAULT.equals( mode ) )
- {
- return defaultLibBundleDir;
- }
- else if ( EMPTY.equals( mode ) )
- {
- return "";
- }
- else if ( NONE.equals( mode ) )
- {
- return null;
- }
- else
- {
- throw new EarPluginException( "Unsupported library directory mode [" + libraryDirectoryMode
- + "] Supported modes " + ( Arrays.asList( DEFAULT, EMPTY, NONE ) ) );
- }
- }
-}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.plugins.ear.util.JavaEEVersion;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.interpolation.InterpolationException;
+import org.codehaus.plexus.interpolation.Interpolator;
+import org.codehaus.plexus.interpolation.MapBasedValueSource;
+import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.interpolation.ValueSource;
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Generates the EAR deployment descriptor file(s).
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+@Mojo(
+ name = "generate-application-xml",
+ defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
+ threadSafe = true,
+ requiresDependencyResolution = ResolutionScope.TEST)
+public class GenerateApplicationXmlMojo extends AbstractEarMojo {
+
+ /**
+ * The DEFAULT library folder.
+ */
+ public static final String DEFAULT = "DEFAULT";
+
+ /**
+ * The empty folder.
+ */
+ public static final String EMPTY = "EMPTY";
+
+ /**
+ * The NONE not existent folder.
+ */
+ public static final String NONE = "NONE";
+
+ /**
+ * Whether the application.xml should be generated or not.
+ */
+ @Parameter(defaultValue = "true")
+ private Boolean generateApplicationXml = Boolean.TRUE;
+
+ /**
+ * Whether a module ID should be generated if none is specified.
+ */
+ @Parameter(defaultValue = "false")
+ private Boolean generateModuleId = Boolean.FALSE;
+
+ /**
+ * Application name of the application to be used when the application.xml file is auto-generated. Since JavaEE6.
+ */
+ @Parameter
+ private String applicationName;
+
+ /**
+ * Display name of the application to be used when the application.xml file is auto-generated.
+ */
+ @Parameter(defaultValue = "${project.artifactId}")
+ private String displayName;
+
+ /**
+ * Description of the application to be used when the application.xml file is auto-generated.
+ */
+ @Parameter(defaultValue = "${project.description}")
+ private String description;
+
+ /**
+ * Defines how the {@code library-directory} element should be written in the application.xml file.
+ * <p/>
+ * Three special values can be set:
+ * <ul>
+ * <li><code>DEFAULT</code> (default) generates a {@code library-directory} element with the value of the
+ * {@code defaultLibBundleDir} parameter</li>
+ * <li><code>EMPTY</code> generates an empty {@code library-directory} element. Per spec, this disables the
+ * scanning of jar files in the {@code lib} directory of the ear file</li>
+ * <li><code>NONE</code> does not write the library-directory element at all. A corner case that can be used in
+ * Oracle Weblogic to delegate the classloading to the container</li>
+ * </ul>
+ * <p/>
+ * Since JavaEE5.
+ */
+ @Parameter(defaultValue = DEFAULT)
+ private String libraryDirectoryMode;
+
+ /**
+ * Defines the value of the initialize in order element to be used when the application.xml file is auto-generated.
+ * When set to true, modules must be initialized in the order they're listed in this deployment descriptor, with the
+ * exception of application client modules, which can be initialized in any order. If initialize-in-order is not set
+ * or set to false, the order of initialization is unspecified and may be product-dependent. Since JavaEE6.
+ */
+ @Parameter
+ private Boolean initializeInOrder;
+
+ /**
+ * Defines the application id used when generating the deployment descriptor.
+ *
+ * @since 2.9
+ */
+ @Parameter
+ private String applicationId;
+
+ /**
+ * The security-roles to be added to the auto-generated application.xml file.
+ */
+ @Parameter
+ private PlexusConfiguration security;
+
+ /**
+ * The env-entries to be added to the auto-generated application.xml file. Since JavaEE6.
+ */
+ @Parameter(alias = "env-entries")
+ private PlexusConfiguration envEntries;
+
+ /**
+ * The {@code ejb-ref} entries.
+ */
+ @Parameter(alias = "ejb-refs")
+ private PlexusConfiguration ejbRefs;
+
+ /**
+ * The {@code resource-ref} entries.
+ */
+ @Parameter
+ private PlexusConfiguration resourceRefs;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ // Initializes ear modules
+ super.execute();
+
+ // Handle application.xml
+ if (!generateApplicationXml) {
+ getLog().debug("Generation of application.xml is disabled");
+ } else {
+ final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
+
+ // Generate deployment descriptor and copy it to the build directory
+ getLog().info("Generating application.xml");
+ try {
+ generateStandardDeploymentDescriptor(javaEEVersion);
+ } catch (EarPluginException e) {
+ throw new MojoExecutionException("Failed to generate application.xml", e);
+ }
+
+ try {
+ FileUtils.copyFileToDirectory(
+ new File(generatedDescriptorLocation, "application.xml"),
+ new File(getWorkDirectory(), "META-INF"));
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to copy application.xml to final destination", e);
+ }
+ }
+
+ // Handle jboss-app.xml
+ if (getJbossConfiguration() == null) {
+ getLog().debug("Generation of jboss-app.xml is disabled");
+ } else {
+ // Generate deployment descriptor and copy it to the build directory
+ getLog().info("Generating jboss-app.xml");
+ try {
+ generateJbossDeploymentDescriptor();
+ } catch (EarPluginException e) {
+ throw new MojoExecutionException("Failed to generate jboss-app.xml", e);
+ }
+
+ try {
+ FileUtils.copyFileToDirectory(
+ new File(generatedDescriptorLocation, "jboss-app.xml"),
+ new File(getWorkDirectory(), "META-INF"));
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to copy jboss-app.xml to final destination", e);
+ }
+ }
+ }
+
+ /**
+ * Generates the deployment descriptor.
+ *
+ * @param javaEEVersion {@link JavaEEVersion}
+ * @throws EarPluginException if the configuration is invalid
+ */
+ protected void generateStandardDeploymentDescriptor(JavaEEVersion javaEEVersion) throws EarPluginException {
+ File outputDir = new File(generatedDescriptorLocation);
+ if (!outputDir.exists()) {
+ if (!outputDir.mkdirs()) {
+ throw new EarPluginException("Error creating " + outputDir);
+ }
+ }
+
+ File descriptor = new File(outputDir, "application.xml");
+
+ final ApplicationXmlWriter writer = new ApplicationXmlWriter(javaEEVersion, encoding, generateModuleId);
+ final ApplicationXmlWriterContext context = new ApplicationXmlWriterContext(
+ descriptor,
+ getModules(),
+ buildSecurityRoles(),
+ buildEnvEntries(),
+ buildEjbEntries(),
+ buildResourceRefs(),
+ displayName,
+ description,
+ getActualLibraryDirectory(),
+ applicationName,
+ initializeInOrder)
+ .setApplicationId(applicationId);
+ writer.write(context);
+ }
+
+ /**
+ * Generates the JBoss deployment descriptor.
+ *
+ * @throws EarPluginException if the configuration is invalid
+ */
+ protected void generateJbossDeploymentDescriptor() throws EarPluginException {
+ File outputDir = new File(generatedDescriptorLocation);
+ if (!outputDir.exists()) {
+ if (!outputDir.mkdirs()) {
+ throw new EarPluginException("Error creating " + outputDir);
+ }
+ }
+
+ File descriptor = new File(outputDir, "jboss-app.xml");
+
+ JbossAppXmlWriter writer = new JbossAppXmlWriter(encoding);
+ writer.write(descriptor, getJbossConfiguration(), getModules());
+ }
+
+ /**
+ * Builds the security roles based on the configuration.
+ *
+ * @return a list of SecurityRole object(s)
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private List<SecurityRole> buildSecurityRoles() throws EarPluginException {
+ final List<SecurityRole> result = new ArrayList<>();
+ if (security == null) {
+ return result;
+ }
+ final PlexusConfiguration[] securityRoles = security.getChildren(SecurityRole.SECURITY_ROLE);
+
+ for (PlexusConfiguration securityRole : securityRoles) {
+ final String id = securityRole.getAttribute(SecurityRole.ID_ATTRIBUTE);
+ final String childRoleName =
+ securityRole.getChild(SecurityRole.ROLE_NAME).getValue();
+ final String childRoleNameId =
+ securityRole.getChild(SecurityRole.ROLE_NAME).getAttribute(SecurityRole.ID_ATTRIBUTE);
+ final String childDescription =
+ securityRole.getChild(SecurityRole.DESCRIPTION).getValue();
+ final String childDescriptionId =
+ securityRole.getChild(SecurityRole.DESCRIPTION).getAttribute(SecurityRole.ID_ATTRIBUTE);
+
+ if (childRoleName == null) {
+ throw new EarPluginException("Invalid security-role configuration, role-name could not be null.");
+ } else {
+ result.add(new SecurityRole(childRoleName, childRoleNameId, id, childDescription, childDescriptionId));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * This help method was needed otherwise the interpolate method of interpolator will make an empty string of a
+ * {@code null} element which results in supplemental elements for env-entry.
+ *
+ * @param interpolator The interpolator
+ * @param element The element
+ * @return The interpolated elements.
+ * @throws InterpolationException in case of an error.
+ */
+ private String interpolate(Interpolator interpolator, String element) throws InterpolationException {
+ if (element == null) {
+ return element;
+ } else {
+ return interpolator.interpolate(element);
+ }
+ }
+
+ /**
+ * Builds the env-entries based on the configuration.
+ *
+ * @return a list of EnvEntry object(s)
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private List<EnvEntry> buildEnvEntries() throws EarPluginException {
+ final List<EnvEntry> result = new ArrayList<>();
+ if (envEntries == null) {
+ return result;
+ }
+ try {
+ StringSearchInterpolator ssi = new StringSearchInterpolator();
+ ValueSource vs = new MapBasedValueSource(project.getProperties());
+ ssi.addValueSource(vs);
+
+ final PlexusConfiguration[] allEnvEntries = envEntries.getChildren(EnvEntry.ENV_ENTRY);
+
+ getLog().debug("buildEnvEntries: allEnvEntries size:" + allEnvEntries.length);
+ for (PlexusConfiguration envEntry : allEnvEntries) {
+ final String childDescription =
+ interpolate(ssi, envEntry.getChild(EnvEntry.DESCRIPTION).getValue());
+ final String childEnvEntryName = interpolate(
+ ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_NAME).getValue());
+ final String childEnvEntryType = interpolate(
+ ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_TYPE).getValue());
+ final String childEnvEntryValue = interpolate(
+ ssi, envEntry.getChild(EnvEntry.ENV_ENTRY_VALUE).getValue());
+ final String childEnvLookupNameValue = interpolate(
+ ssi, envEntry.getChild(EnvEntry.ENV_LOOKUP_NAME).getValue());
+
+ try {
+ result.add(new EnvEntry(
+ childDescription,
+ childEnvEntryName,
+ childEnvEntryType,
+ childEnvEntryValue,
+ childEnvLookupNameValue));
+ } catch (IllegalArgumentException e) {
+ throw new EarPluginException("Invalid env-entry [" + envEntry + "]", e);
+ }
+ }
+ return result;
+ } catch (InterpolationException e) {
+ throw new EarPluginException("Interpolation exception:", e);
+ }
+ }
+
+ /**
+ * Builds the ejb-ref based on the configuration.
+ *
+ * @return a list of EjbRef object(s)
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private List<EjbRef> buildEjbEntries() throws EarPluginException {
+ final List<EjbRef> result = new ArrayList<>();
+ if (ejbRefs == null) {
+ return result;
+ }
+ try {
+ StringSearchInterpolator ssi = new StringSearchInterpolator();
+ ValueSource vs = new MapBasedValueSource(project.getProperties());
+ ssi.addValueSource(vs);
+
+ final PlexusConfiguration[] allEjbEntries = ejbRefs.getChildren(EjbRef.EJB_REF);
+
+ for (PlexusConfiguration ejbEntry : allEjbEntries) {
+ final String childDescription =
+ interpolate(ssi, ejbEntry.getChild(EnvEntry.DESCRIPTION).getValue());
+ final String childEjbEntryName =
+ interpolate(ssi, ejbEntry.getChild(EjbRef.EJB_NAME).getValue());
+ final String childEjbEntryType =
+ interpolate(ssi, ejbEntry.getChild(EjbRef.EJB_TYPE).getValue());
+ final String childEjbLookupNameValue = interpolate(
+ ssi, ejbEntry.getChild(EjbRef.EJB_LOOKUP_NAME).getValue());
+
+ try {
+ result.add(new EjbRef(
+ childDescription, childEjbEntryName, childEjbEntryType, childEjbLookupNameValue));
+ } catch (IllegalArgumentException e) {
+ throw new EarPluginException("Invalid ejb-ref [" + ejbEntry + "]", e);
+ }
+ }
+ return result;
+ } catch (InterpolationException e) {
+ throw new EarPluginException("Interpolation exception:", e);
+ }
+ }
+
+ /**
+ * Builds the <code>resource-ref</code> based on the configuration.
+ *
+ * @return a list of ResourceRef object(s)
+ * @throws EarPluginException if the configuration is invalid
+ */
+ private List<ResourceRef> buildResourceRefs() throws EarPluginException {
+ final List<ResourceRef> result = new ArrayList<>();
+ if (resourceRefs == null) {
+ return result;
+ }
+ try {
+ getLog().debug("Resources found");
+ StringSearchInterpolator ssi = new StringSearchInterpolator();
+ ValueSource vs = new MapBasedValueSource(project.getProperties());
+ ssi.addValueSource(vs);
+
+ // TODO: Check if this is a good idea hard code that here? Better idea?
+ final PlexusConfiguration[] allResourceRefEntries = resourceRefs.getChildren("resourceRef");
+
+ getLog().debug("allResourceRefEntries length: " + allResourceRefEntries.length);
+ for (PlexusConfiguration resEntry : allResourceRefEntries) {
+ getLog().debug("Resources resEntry:" + resEntry.getName());
+
+ final String childResRefName = interpolate(
+ ssi, resEntry.getChild(ResourceRef.RESOURCE_REF_NAME).getValue());
+ final String childResType = interpolate(
+ ssi, resEntry.getChild(ResourceRef.RESOURCE_TYPE).getValue());
+ final String childResRefAuth = interpolate(
+ ssi, resEntry.getChild(ResourceRef.RESOURCE_AUTH).getValue());
+ final String childResRefLookupName = interpolate(
+ ssi, resEntry.getChild(ResourceRef.LOOKUP_NAME).getValue());
+
+ try {
+ result.add(new ResourceRef(childResRefName, childResType, childResRefAuth, childResRefLookupName));
+ } catch (IllegalArgumentException e) {
+ throw new EarPluginException("Invalid resource-ref [" + resEntry + "]", e);
+ }
+ }
+ return result;
+ } catch (InterpolationException e) {
+ throw new EarPluginException("Interpolation exception:", e);
+ }
+ }
+
+ /**
+ * Returns the value to use for the {@code library-directory} element, based on the library directory mode.
+ */
+ private String getActualLibraryDirectory() throws EarPluginException {
+ final String mode = libraryDirectoryMode == null ? DEFAULT : libraryDirectoryMode.toUpperCase();
+
+ if (DEFAULT.equals(mode)) {
+ return defaultLibBundleDir;
+ } else if (EMPTY.equals(mode)) {
+ return "";
+ } else if (NONE.equals(mode)) {
+ return null;
+ } else {
+ throw new EarPluginException("Unsupported library directory mode [" + libraryDirectoryMode
+ + "] Supported modes " + (Arrays.asList(DEFAULT, EMPTY, NONE)));
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/HarModule.java b/src/main/java/org/apache/maven/plugins/ear/HarModule.java
index 1d2198d..c5438bc 100644
--- a/src/main/java/org/apache/maven/plugins/ear/HarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/HarModule.java
@@ -1,80 +1,91 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * The {@link EarModule} implementation for a JBoss Hibernate archive.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class HarModule
- extends AbstractEarModule
- implements JbossEarModule
-{
- /**
- * Default type of the artifact of a JBoss Hibernate archive.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "har";
-
- private static final String DEFAULT_LIB_DIRECTORY = "lib";
-
- /**
- * Create an instance.
- */
- public HarModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- this.libDirectory = DEFAULT_LIB_DIRECTORY;
- }
-
- /**
- * @param a {@link Artifact}
- */
- public HarModule( Artifact a )
- {
- super( a );
- this.libDirectory = DEFAULT_LIB_DIRECTORY;
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendModule( XMLWriter writer, String version, Boolean generateId )
- {
- // No entry is generated by this artifact ; it should be
- // defined in the jboss-app.xml.
- // See http://docs.jboss.org/jbossas/getting_started/v4/html/hibernate.html
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendJbossModule( XMLWriter writer, String version )
- {
- writer.startElement( MODULE_ELEMENT );
- writer.startElement( "har" );
- writer.writeText( getUri() );
- writer.endElement();
- writer.endElement();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for a JBoss Hibernate archive.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class HarModule extends AbstractEarModule implements JbossEarModule {
+ /**
+ * Default type of the artifact of a JBoss Hibernate archive.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "har";
+
+ private static final String DEFAULT_LIB_DIRECTORY = "lib";
+
+ /**
+ * Create an instance.
+ */
+ public HarModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ this.libDirectory = DEFAULT_LIB_DIRECTORY;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ */
+ public HarModule(Artifact a) {
+ super(a);
+ this.libDirectory = DEFAULT_LIB_DIRECTORY;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendModule(XMLWriter writer, String version, Boolean generateId) {
+ // No entry is generated by this artifact ; it should be
+ // defined in the jboss-app.xml.
+ // See http://docs.jboss.org/jbossas/getting_started/v4/html/hibernate.html
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendJbossModule(XMLWriter writer, String version) {
+ writer.startElement(MODULE_ELEMENT);
+ writer.startElement("har");
+ writer.writeText(getUri());
+ writer.endElement();
+ writer.endElement();
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/JarModule.java b/src/main/java/org/apache/maven/plugins/ear/JarModule.java
index 0a925c8..fc38f7e 100644
--- a/src/main/java/org/apache/maven/plugins/ear/JarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/JarModule.java
@@ -1,119 +1,126 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoFailureException;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-import java.util.Set;
-
-/**
- * The {@link EarModule} implementation for a non J2EE module such as third party libraries.
- *
- * <p>Such module is not incorporated in the generated {@code application.xml}
- * but some application servers support it. To include it in the generated
- * deployment descriptor anyway, set the {@code includeInApplicationXml} boolean flag.
- * </p>
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class JarModule
- extends AbstractEarModule
-{
- /**
- * Default type of the artifact of a non Java EE module such as third party library.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "jar";
-
- private Boolean includeInApplicationXml = Boolean.FALSE;
-
- /**
- * Create an instance.
- */
- public JarModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- this.classPathItem = true;
- }
-
- /**
- * @param a {@link Artifact}
- * @param defaultLibBundleDir The default library bundle directory.
- * @param includeInApplicationXml Include the application xml or not.
- */
- public JarModule( Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml )
- {
- super( a );
- setLibBundleDir( defaultLibBundleDir );
- this.includeInApplicationXml = includeInApplicationXml;
- this.classPathItem = true;
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendModule( XMLWriter writer, String version, Boolean generateId )
- {
- // Generates an entry in the application.xml only if
- // includeInApplicationXml is set
- if ( includeInApplicationXml )
- {
- startModuleElement( writer, generateId );
- writer.startElement( JAVA_MODULE );
- writer.writeText( getUri() );
- writer.endElement();
-
- writeAltDeploymentDescriptor( writer, version );
-
- writer.endElement();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void resolveArtifact( Set<Artifact> artifacts )
- throws EarPluginException, MojoFailureException
- {
- // Let's resolve the artifact
- super.resolveArtifact( artifacts );
-
- // If the defaultLibBundleDir is set and no bundle dir is
- // set, set the default as bundle dir
- setLibBundleDir( earExecutionContext.getDefaultLibBundleDir() );
- }
-
- private void setLibBundleDir( String defaultLibBundleDir )
- {
- if ( defaultLibBundleDir != null && bundleDir == null )
- {
- this.bundleDir = defaultLibBundleDir;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean changeManifestClasspath()
- {
- return false;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for a non J2EE module such as third party libraries.
+ *
+ * <p>Such module is not incorporated in the generated {@code application.xml}
+ * but some application servers support it. To include it in the generated
+ * deployment descriptor anyway, set the {@code includeInApplicationXml} boolean flag.
+ * </p>
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class JarModule extends AbstractEarModule {
+ /**
+ * Default type of the artifact of a non Java EE module such as third party library.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "jar";
+
+ private Boolean includeInApplicationXml = Boolean.FALSE;
+
+ /**
+ * Create an instance.
+ */
+ public JarModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ this.classPathItem = true;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ * @param defaultLibBundleDir The default library bundle directory.
+ * @param includeInApplicationXml Include the application xml or not.
+ */
+ public JarModule(Artifact a, String defaultLibBundleDir, Boolean includeInApplicationXml) {
+ super(a);
+ setLibBundleDir(defaultLibBundleDir);
+ this.includeInApplicationXml = includeInApplicationXml;
+ this.classPathItem = true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendModule(XMLWriter writer, String version, Boolean generateId) {
+ // Generates an entry in the application.xml only if
+ // includeInApplicationXml is set
+ if (includeInApplicationXml) {
+ startModuleElement(writer, generateId);
+ writer.startElement(JAVA_MODULE);
+ writer.writeText(getUri());
+ writer.endElement();
+
+ writeAltDeploymentDescriptor(writer, version);
+
+ writer.endElement();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void resolveArtifact(Set<Artifact> artifacts) throws EarPluginException, MojoFailureException {
+ // Let's resolve the artifact
+ super.resolveArtifact(artifacts);
+
+ // If the defaultLibBundleDir is set and no bundle dir is
+ // set, set the default as bundle dir
+ setLibBundleDir(earExecutionContext.getDefaultLibBundleDir());
+ }
+
+ private void setLibBundleDir(String defaultLibBundleDir) {
+ if (defaultLibBundleDir != null && bundleDir == null) {
+ this.bundleDir = defaultLibBundleDir;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean changeManifestClasspath() {
+ return false;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/JbossAppXmlWriter.java b/src/main/java/org/apache/maven/plugins/ear/JbossAppXmlWriter.java
index 666acbc..259914b 100644
--- a/src/main/java/org/apache/maven/plugins/ear/JbossAppXmlWriter.java
+++ b/src/main/java/org/apache/maven/plugins/ear/JbossAppXmlWriter.java
@@ -1,198 +1,189 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * An {@code XmlWriter} based implementation used to generate a {@code jboss-app.xml} file
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-final class JbossAppXmlWriter
- extends AbstractXmlWriter
-{
-
- public static final String DOCTYPE_3_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.3//EN\"\n"
- + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd\"";
-
- public static final String DOCTYPE_4 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.4//EN\"\n"
- + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd\"";
-
- public static final String DOCTYPE_4_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 4.2//EN\"\n"
- + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd\"";
-
- public static final String DOCTYPE_5 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD Java EE Application 5.0//EN\"\n"
- + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd\"";
-
- private static final String JBOSS_APP_ELEMENT = "jboss-app";
-
- private static final String MODULE_ELEMENT = "module";
-
- private static final String SERVICE_ELEMENT = "service";
-
- JbossAppXmlWriter( String encoding )
- {
- super( encoding );
- }
-
- public void write( File destinationFile, JbossConfiguration jbossConfiguration, List<EarModule> earModules )
- throws EarPluginException
- {
- try ( Writer w = initializeWriter( destinationFile ) )
- {
- XMLWriter writer;
- if ( jbossConfiguration.isJbossThreeDotTwo() )
- {
- writer = initializeXmlWriter( w, DOCTYPE_3_2 );
- }
- else if ( jbossConfiguration.isJbossFour() )
- {
- writer = initializeXmlWriter( w, DOCTYPE_4 );
- }
- else if ( jbossConfiguration.isJbossFourDotTwo() )
- {
- writer = initializeXmlWriter( w, DOCTYPE_4_2 );
- }
- else
- {
- writer = initializeXmlWriter( w, DOCTYPE_5 );
- }
- writer.startElement( JBOSS_APP_ELEMENT );
-
- // Make sure to write the things in the right order so that the DTD validates
-
- // module-order (only available as from 4.2)
- if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null )
- {
- writer.startElement( JbossConfiguration.MODULE_ORDER );
- writer.writeText( jbossConfiguration.getModuleOrder() );
- writer.endElement();
- }
-
- // If JBoss 4, write the jboss4 specific stuff
- if ( jbossConfiguration.isJbossFourOrHigher() )
- {
- if ( jbossConfiguration.getSecurityDomain() != null )
- {
- writer.startElement( JbossConfiguration.SECURITY_DOMAIN );
- writer.writeText( jbossConfiguration.getSecurityDomain() );
- writer.endElement();
- }
- if ( jbossConfiguration.getUnauthenticatedPrincipal() != null )
- {
- writer.startElement( JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL );
- writer.writeText( jbossConfiguration.getUnauthenticatedPrincipal() );
- writer.endElement();
- }
- }
-
- // classloader repository
- if ( jbossConfiguration.getLoaderRepository() != null
- || jbossConfiguration.getLoaderRepositoryConfig() != null )
- {
- writer.startElement( JbossConfiguration.LOADER_REPOSITORY );
-
- // classloader repository class
- if ( jbossConfiguration.getLoaderRepositoryClass() != null )
- {
- writer.addAttribute( JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE,
- jbossConfiguration.getLoaderRepositoryClass() );
- }
-
- // we don't need to write any text if only the loader repo configuration is changed
- if ( jbossConfiguration.getLoaderRepository() != null )
- {
- writer.writeText( jbossConfiguration.getLoaderRepository() );
- }
-
- // classloader configuration
- if ( jbossConfiguration.getLoaderRepositoryConfig() != null )
- {
- writer.startElement( JbossConfiguration.LOADER_REPOSITORY_CONFIG );
-
- // classloader configuration parser
- if ( jbossConfiguration.getConfigParserClass() != null )
- {
- writer.addAttribute( JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE,
- jbossConfiguration.getConfigParserClass() );
- }
- writer.writeText( jbossConfiguration.getLoaderRepositoryConfig() );
- writer.endElement();
- }
-
- writer.endElement();
- }
-
- // jmx name
- if ( jbossConfiguration.getJmxName() != null )
- {
- writer.startElement( JbossConfiguration.JMX_NAME );
- writer.writeText( jbossConfiguration.getJmxName() );
- writer.endElement();
- }
-
- // library-directory (only available as from 4.2)
- if ( jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null )
- {
- writer.startElement( JbossConfiguration.LIBRARY_DIRECTORY );
- writer.writeText( jbossConfiguration.getLibraryDirectory() );
- writer.endElement();
- }
-
- // Modules
-
- List<String> dataSources = jbossConfiguration.getDataSources();
- // Write out data source modules first
- if ( dataSources != null )
- {
- for ( String dsPath : dataSources )
- {
- writer.startElement( MODULE_ELEMENT );
- writer.startElement( SERVICE_ELEMENT );
- writer.writeText( dsPath );
- writer.endElement();
- writer.endElement();
- }
- }
-
- // Write the JBoss specific modules
- for ( EarModule earModule : earModules )
- {
- if ( JbossEarModule.class.isInstance( earModule ) )
- {
- JbossEarModule jbossEarModule = (JbossEarModule) earModule;
- jbossEarModule.appendJbossModule( writer, jbossConfiguration.getVersion() );
- }
- }
- writer.endElement();
-
- }
- catch ( IOException ex )
- {
- throw new EarPluginException( ex );
- }
- }
-}
\ No newline at end of file
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * An {@code XmlWriter} based implementation used to generate a {@code jboss-app.xml} file
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+final class JbossAppXmlWriter extends AbstractXmlWriter {
+
+ public static final String DOCTYPE_3_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.3//EN\"\n"
+ + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd\"";
+
+ public static final String DOCTYPE_4 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 1.4//EN\"\n"
+ + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_0.dtd\"";
+
+ public static final String DOCTYPE_4_2 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD J2EE Application 4.2//EN\"\n"
+ + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd\"";
+
+ public static final String DOCTYPE_5 = "jboss-app PUBLIC\n" + "\t\"-//JBoss//DTD Java EE Application 5.0//EN\"\n"
+ + "\t\"http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd\"";
+
+ private static final String JBOSS_APP_ELEMENT = "jboss-app";
+
+ private static final String MODULE_ELEMENT = "module";
+
+ private static final String SERVICE_ELEMENT = "service";
+
+ JbossAppXmlWriter(String encoding) {
+ super(encoding);
+ }
+
+ public void write(File destinationFile, JbossConfiguration jbossConfiguration, List<EarModule> earModules)
+ throws EarPluginException {
+ try (Writer w = initializeWriter(destinationFile)) {
+ XMLWriter writer;
+ if (jbossConfiguration.isJbossThreeDotTwo()) {
+ writer = initializeXmlWriter(w, DOCTYPE_3_2);
+ } else if (jbossConfiguration.isJbossFour()) {
+ writer = initializeXmlWriter(w, DOCTYPE_4);
+ } else if (jbossConfiguration.isJbossFourDotTwo()) {
+ writer = initializeXmlWriter(w, DOCTYPE_4_2);
+ } else {
+ writer = initializeXmlWriter(w, DOCTYPE_5);
+ }
+ writer.startElement(JBOSS_APP_ELEMENT);
+
+ // Make sure to write the things in the right order so that the DTD validates
+
+ // module-order (only available as from 4.2)
+ if (jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getModuleOrder() != null) {
+ writer.startElement(JbossConfiguration.MODULE_ORDER);
+ writer.writeText(jbossConfiguration.getModuleOrder());
+ writer.endElement();
+ }
+
+ // If JBoss 4, write the jboss4 specific stuff
+ if (jbossConfiguration.isJbossFourOrHigher()) {
+ if (jbossConfiguration.getSecurityDomain() != null) {
+ writer.startElement(JbossConfiguration.SECURITY_DOMAIN);
+ writer.writeText(jbossConfiguration.getSecurityDomain());
+ writer.endElement();
+ }
+ if (jbossConfiguration.getUnauthenticatedPrincipal() != null) {
+ writer.startElement(JbossConfiguration.UNAUHTHENTICTED_PRINCIPAL);
+ writer.writeText(jbossConfiguration.getUnauthenticatedPrincipal());
+ writer.endElement();
+ }
+ }
+
+ // classloader repository
+ if (jbossConfiguration.getLoaderRepository() != null
+ || jbossConfiguration.getLoaderRepositoryConfig() != null) {
+ writer.startElement(JbossConfiguration.LOADER_REPOSITORY);
+
+ // classloader repository class
+ if (jbossConfiguration.getLoaderRepositoryClass() != null) {
+ writer.addAttribute(
+ JbossConfiguration.LOADER_REPOSITORY_CLASS_ATTRIBUTE,
+ jbossConfiguration.getLoaderRepositoryClass());
+ }
+
+ // we don't need to write any text if only the loader repo configuration is changed
+ if (jbossConfiguration.getLoaderRepository() != null) {
+ writer.writeText(jbossConfiguration.getLoaderRepository());
+ }
+
+ // classloader configuration
+ if (jbossConfiguration.getLoaderRepositoryConfig() != null) {
+ writer.startElement(JbossConfiguration.LOADER_REPOSITORY_CONFIG);
+
+ // classloader configuration parser
+ if (jbossConfiguration.getConfigParserClass() != null) {
+ writer.addAttribute(
+ JbossConfiguration.CONFIG_PARSER_CLASS_ATTRIBUTE,
+ jbossConfiguration.getConfigParserClass());
+ }
+ writer.writeText(jbossConfiguration.getLoaderRepositoryConfig());
+ writer.endElement();
+ }
+
+ writer.endElement();
+ }
+
+ // jmx name
+ if (jbossConfiguration.getJmxName() != null) {
+ writer.startElement(JbossConfiguration.JMX_NAME);
+ writer.writeText(jbossConfiguration.getJmxName());
+ writer.endElement();
+ }
+
+ // library-directory (only available as from 4.2)
+ if (jbossConfiguration.isJbossFourDotTwoOrHigher() && jbossConfiguration.getLibraryDirectory() != null) {
+ writer.startElement(JbossConfiguration.LIBRARY_DIRECTORY);
+ writer.writeText(jbossConfiguration.getLibraryDirectory());
+ writer.endElement();
+ }
+
+ // Modules
+
+ List<String> dataSources = jbossConfiguration.getDataSources();
+ // Write out data source modules first
+ if (dataSources != null) {
+ for (String dsPath : dataSources) {
+ writer.startElement(MODULE_ELEMENT);
+ writer.startElement(SERVICE_ELEMENT);
+ writer.writeText(dsPath);
+ writer.endElement();
+ writer.endElement();
+ }
+ }
+
+ // Write the JBoss specific modules
+ for (EarModule earModule : earModules) {
+ if (JbossEarModule.class.isInstance(earModule)) {
+ JbossEarModule jbossEarModule = (JbossEarModule) earModule;
+ jbossEarModule.appendJbossModule(writer, jbossConfiguration.getVersion());
+ }
+ }
+ writer.endElement();
+
+ } catch (IOException ex) {
+ throw new EarPluginException(ex);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/JbossConfiguration.java b/src/main/java/org/apache/maven/plugins/ear/JbossConfiguration.java
index 3f712f5..5cec988 100644
--- a/src/main/java/org/apache/maven/plugins/ear/JbossConfiguration.java
+++ b/src/main/java/org/apache/maven/plugins/ear/JbossConfiguration.java
@@ -1,358 +1,352 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.List;
-
-/**
- * The JBoss specific configuration, used to generate the jboss-app.xml deployment descriptor file
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-class JbossConfiguration
-{
- static final String VERSION_3_2 = "3.2";
-
- static final String VERSION_4 = "4";
-
- static final String VERSION_4_2 = "4.2";
-
- static final String VERSION_5 = "5";
-
- static final String VERSION = "version";
-
- static final String SECURITY_DOMAIN = "security-domain";
-
- static final String UNAUHTHENTICTED_PRINCIPAL = "unauthenticated-principal";
-
- static final String JMX_NAME = "jmx-name";
-
- static final String LOADER_REPOSITORY = "loader-repository";
-
- static final String LOADER_REPOSITORY_CLASS_ATTRIBUTE = "loaderRepositoryClass";
-
- static final String LOADER_REPOSITORY_CONFIG = "loader-repository-config";
-
- static final String CONFIG_PARSER_CLASS_ATTRIBUTE = "configParserClass";
-
- static final String MODULE_ORDER = "module-order";
-
- static final String DATASOURCES = "data-sources";
-
- static final String DATASOURCE = "data-source";
-
- static final String LIBRARY_DIRECTORY = "library-directory";
-
- private final String version;
-
- private boolean jbossThreeDotTwo;
-
- private boolean jbossFour;
-
- private boolean jbossFourDotTwo;
-
- private boolean jbossFive;
-
- private final String securityDomain;
-
- private final String unauthenticatedPrincipal;
-
- private final String jmxName;
-
- private final String loaderRepository;
-
- private final String loaderRepositoryConfig;
-
- private final String loaderRepositoryClass;
-
- private final String configParserClass;
-
- private final String moduleOrder;
-
- private final List<String> dataSources;
-
- private final String libraryDirectory;
-
- JbossConfiguration( String version, String securityDomain, String unauthenticatedPrincipal, String jmxName,
- String loaderRepository, String moduleOrder, List<String> dataSources,
- String libraryDirectory, String loaderRepositoryConfig, String loaderRepositoryClass,
- String configParserClass )
- throws EarPluginException
- {
- if ( version == null )
- {
- throw new EarPluginException( "jboss version could not be null." );
- }
- else
- {
- this.version = version;
- if ( version.equals( JbossConfiguration.VERSION_3_2 ) )
- {
- this.jbossThreeDotTwo = true;
- }
- else if ( version.equals( JbossConfiguration.VERSION_4 ) )
- {
- this.jbossFour = true;
- }
- else if ( version.equals( JbossConfiguration.VERSION_4_2 ) )
- {
- this.jbossFourDotTwo = true;
- }
- else if ( version.equals( JbossConfiguration.VERSION_5 ) )
- {
- this.jbossFive = true;
- }
- else
- {
- throw new EarPluginException(
- "Invalid JBoss configuration, version[" + version + "] is not supported." );
- }
- this.securityDomain = securityDomain;
- this.unauthenticatedPrincipal = unauthenticatedPrincipal;
- this.jmxName = jmxName;
- this.loaderRepository = loaderRepository;
- this.moduleOrder = moduleOrder;
- this.dataSources = dataSources;
- this.libraryDirectory = libraryDirectory;
- this.loaderRepositoryConfig = loaderRepositoryConfig;
- this.loaderRepositoryClass = loaderRepositoryClass;
- this.configParserClass = configParserClass;
- }
- }
-
- /**
- * Returns the targeted version of JBoss.
- *
- * @return the jboss version
- */
- public String getVersion()
- {
- return version;
- }
-
- /**
- * Returns true if the targeted JBoss version is 3.2.
- *
- * @return if the targeted version is 3.2
- */
- public boolean isJbossThreeDotTwo()
- {
- return jbossThreeDotTwo;
- }
-
- /**
- * Returns true if the targeted JBoss version is 4.
- *
- * @return if the targeted version is 4
- */
- public boolean isJbossFour()
- {
- return jbossFour;
- }
-
- /**
- * Returns true if the targeted JBoss version if 4 or higher (that is 4, 4.2 or 5).
- *
- * @return true if the targeted version is 4+
- */
- public boolean isJbossFourOrHigher()
- {
- return jbossFour || jbossFourDotTwo || jbossFive;
- }
-
- /**
- * Returns true if the targeted JBoss version is 4.2.
- *
- * @return if the targeted version is 4.2
- */
- public boolean isJbossFourDotTwo()
- {
- return jbossFourDotTwo;
- }
-
- /**
- * Returns true if the targeted JBoss version if 4.2 or higher (that is 4.2 or 5).
- *
- * @return true if the targeted version is 4.2+
- */
- public boolean isJbossFourDotTwoOrHigher()
- {
- return jbossFourDotTwo || jbossFive;
- }
-
- /**
- * Returns true if the targeted JBoss version is 5.
- *
- * @return if the targeted version is 5
- */
- public boolean isJbossFive()
- {
- return jbossFive;
- }
-
- /**
- * The security-domain element specifies the JNDI name of the security manager that implements the
- * EJBSecurityManager and RealmMapping for the domain. When specified at the jboss level it specifies the security
- * domain for all j2ee components in the deployment unit.
- * <p/>
- * One can override the global security-domain at the container level using the security-domain element at the
- * container-configuration level.
- * <p/>
- * Only available as from JBoss 4.
- *
- * @return the JNDI name of the security manager
- */
- public String getSecurityDomain()
- {
- return securityDomain;
- }
-
- /**
- * The unauthenticated-principal element specifies the name of the principal that will be returned by the
- * EJBContext.getCallerPrincipal() method if there is no authenticated user. This Principal has no roles or
- * privileges to call any other beans.
- * <p/>
- * Only available as from JBoss 4.
- *
- * @return the unauthenticated principal
- */
- public String getUnauthenticatedPrincipal()
- {
- return unauthenticatedPrincipal;
- }
-
- /**
- * The jmx-name element allows one to specify the JMX ObjectName to use for the MBean associated with the ear
- * module. This must be a unique name and valid JMX ObjectName string.
- *
- * @return the object name of the ear mbean
- */
- public String getJmxName()
- {
- return jmxName;
- }
-
- /**
- * The loader-repository specifies the name of the UnifiedLoaderRepository MBean to use for the ear to provide ear
- * level scoping of classes deployed in the ear. It is a unique JMX ObjectName string.
- * <p/>
- * <P>
- * Example:
- * </P>
- * <loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear</loader-repository>
- *
- * @return the object name of the ear mbean
- */
- public String getLoaderRepository()
- {
- return loaderRepository;
- }
-
- /**
- * The module-order specifies the order in which the modules specified in the application.xml file gets loaded.
- * Allowed values are:
- * <p/>
- * <module-order>strict</module-order> The strict value indicates that the deployments of the modules will be done
- * in the order that would be specified in the application.xml and jboss-app.xml file.
- * <p/>
- * <module-order>implicit</module-order> The implicit value indicates the deployment would follow the order which
- * would be specified in the DeploymentSorter.
- * <p/>
- * Returns {@code null} if no module order is set.
- * <p/>
- * Only available in JBoss 4.2 and 4.3. Has no effect in JBoss 5 and is not added when mentioned version is used.
- *
- * @return the module order
- */
- public String getModuleOrder()
- {
- return moduleOrder;
- }
-
- /**
- * Returns the list of datasources to include in the {@code jboss-app.xml} file as services. Each element of the
- * list is the relative path to the datasource file contained in the EAR archive.
- *
- * @return the list of datasources paths
- */
- public List<String> getDataSources()
- {
- return dataSources;
- }
-
- /**
- * Returns the library directory to include in the {@code jboss-app.xml} file. It tells JBoss where to find
- * non-Java EE libraries included in the EAR.
- *
- * @return the library directory
- */
- public String getLibraryDirectory()
- {
- return libraryDirectory;
- }
-
- /**
- * Returns the class loader repository configuration to include in the {@code jboss-app.xml} file. The content of
- * this element is handed to the class loader, thereby altering it's default behaviour.
- * <p/>
- * This element is added as a child to the {@code loader-repository} element. If the element is not present in the
- * configuration, it will be added.
- * <p/>
- * Example: <loader-repository-config>java2ParentDelegaton=true</loader-repository-config>
- *
- * @return the class loader repository configuration
- */
- public String getLoaderRepositoryConfig()
- {
- return loaderRepositoryConfig;
- }
-
- /**
- * Returns the class loader repository class to include in the {@code jboss-app.xml} file. It tells JBoss which
- * loader repository implementation to use.
- * <p/>
- * This element is added as an attribute to the {@code loader-repository} element, therefore it is not added if no
- * such element configuration is present.
- * <p/>
- * Example: <loader-repository-class>org.mindbug.jboss.AlternateLoaderRepository</loader-repository-class>
- *
- * @return the class loader repository class
- */
- public String getLoaderRepositoryClass()
- {
- return loaderRepositoryClass;
- }
-
- /**
- * Returns the class loader's configuration parser class to include in the {@code jboss-app.xml} file. It tells
- * JBoss how to parse the configuration given in the {@code loader-repository-config} element.
- * <p/>
- * This element is added as an attribute to the {@code loader-repository-config} element, therefore it is not added
- * if no such element configuration is present.
- * <p/>
- * Example: <config-parser-class>org.mindbug.jboss.AlternateLoaderRepositoryConfigParser</config-parser-class>
- *
- * @return the class loader's configuration parser class
- */
- public String getConfigParserClass()
- {
- return configParserClass;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+/**
+ * The JBoss specific configuration, used to generate the jboss-app.xml deployment descriptor file
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+class JbossConfiguration {
+ static final String VERSION_3_2 = "3.2";
+
+ static final String VERSION_4 = "4";
+
+ static final String VERSION_4_2 = "4.2";
+
+ static final String VERSION_5 = "5";
+
+ static final String VERSION = "version";
+
+ static final String SECURITY_DOMAIN = "security-domain";
+
+ static final String UNAUHTHENTICTED_PRINCIPAL = "unauthenticated-principal";
+
+ static final String JMX_NAME = "jmx-name";
+
+ static final String LOADER_REPOSITORY = "loader-repository";
+
+ static final String LOADER_REPOSITORY_CLASS_ATTRIBUTE = "loaderRepositoryClass";
+
+ static final String LOADER_REPOSITORY_CONFIG = "loader-repository-config";
+
+ static final String CONFIG_PARSER_CLASS_ATTRIBUTE = "configParserClass";
+
+ static final String MODULE_ORDER = "module-order";
+
+ static final String DATASOURCES = "data-sources";
+
+ static final String DATASOURCE = "data-source";
+
+ static final String LIBRARY_DIRECTORY = "library-directory";
+
+ private final String version;
+
+ private boolean jbossThreeDotTwo;
+
+ private boolean jbossFour;
+
+ private boolean jbossFourDotTwo;
+
+ private boolean jbossFive;
+
+ private final String securityDomain;
+
+ private final String unauthenticatedPrincipal;
+
+ private final String jmxName;
+
+ private final String loaderRepository;
+
+ private final String loaderRepositoryConfig;
+
+ private final String loaderRepositoryClass;
+
+ private final String configParserClass;
+
+ private final String moduleOrder;
+
+ private final List<String> dataSources;
+
+ private final String libraryDirectory;
+
+ JbossConfiguration(
+ String version,
+ String securityDomain,
+ String unauthenticatedPrincipal,
+ String jmxName,
+ String loaderRepository,
+ String moduleOrder,
+ List<String> dataSources,
+ String libraryDirectory,
+ String loaderRepositoryConfig,
+ String loaderRepositoryClass,
+ String configParserClass)
+ throws EarPluginException {
+ if (version == null) {
+ throw new EarPluginException("jboss version could not be null.");
+ } else {
+ this.version = version;
+ if (version.equals(JbossConfiguration.VERSION_3_2)) {
+ this.jbossThreeDotTwo = true;
+ } else if (version.equals(JbossConfiguration.VERSION_4)) {
+ this.jbossFour = true;
+ } else if (version.equals(JbossConfiguration.VERSION_4_2)) {
+ this.jbossFourDotTwo = true;
+ } else if (version.equals(JbossConfiguration.VERSION_5)) {
+ this.jbossFive = true;
+ } else {
+ throw new EarPluginException("Invalid JBoss configuration, version[" + version + "] is not supported.");
+ }
+ this.securityDomain = securityDomain;
+ this.unauthenticatedPrincipal = unauthenticatedPrincipal;
+ this.jmxName = jmxName;
+ this.loaderRepository = loaderRepository;
+ this.moduleOrder = moduleOrder;
+ this.dataSources = dataSources;
+ this.libraryDirectory = libraryDirectory;
+ this.loaderRepositoryConfig = loaderRepositoryConfig;
+ this.loaderRepositoryClass = loaderRepositoryClass;
+ this.configParserClass = configParserClass;
+ }
+ }
+
+ /**
+ * Returns the targeted version of JBoss.
+ *
+ * @return the jboss version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version is 3.2.
+ *
+ * @return if the targeted version is 3.2
+ */
+ public boolean isJbossThreeDotTwo() {
+ return jbossThreeDotTwo;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version is 4.
+ *
+ * @return if the targeted version is 4
+ */
+ public boolean isJbossFour() {
+ return jbossFour;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version if 4 or higher (that is 4, 4.2 or 5).
+ *
+ * @return true if the targeted version is 4+
+ */
+ public boolean isJbossFourOrHigher() {
+ return jbossFour || jbossFourDotTwo || jbossFive;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version is 4.2.
+ *
+ * @return if the targeted version is 4.2
+ */
+ public boolean isJbossFourDotTwo() {
+ return jbossFourDotTwo;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version if 4.2 or higher (that is 4.2 or 5).
+ *
+ * @return true if the targeted version is 4.2+
+ */
+ public boolean isJbossFourDotTwoOrHigher() {
+ return jbossFourDotTwo || jbossFive;
+ }
+
+ /**
+ * Returns true if the targeted JBoss version is 5.
+ *
+ * @return if the targeted version is 5
+ */
+ public boolean isJbossFive() {
+ return jbossFive;
+ }
+
+ /**
+ * The security-domain element specifies the JNDI name of the security manager that implements the
+ * EJBSecurityManager and RealmMapping for the domain. When specified at the jboss level it specifies the security
+ * domain for all j2ee components in the deployment unit.
+ * <p/>
+ * One can override the global security-domain at the container level using the security-domain element at the
+ * container-configuration level.
+ * <p/>
+ * Only available as from JBoss 4.
+ *
+ * @return the JNDI name of the security manager
+ */
+ public String getSecurityDomain() {
+ return securityDomain;
+ }
+
+ /**
+ * The unauthenticated-principal element specifies the name of the principal that will be returned by the
+ * EJBContext.getCallerPrincipal() method if there is no authenticated user. This Principal has no roles or
+ * privileges to call any other beans.
+ * <p/>
+ * Only available as from JBoss 4.
+ *
+ * @return the unauthenticated principal
+ */
+ public String getUnauthenticatedPrincipal() {
+ return unauthenticatedPrincipal;
+ }
+
+ /**
+ * The jmx-name element allows one to specify the JMX ObjectName to use for the MBean associated with the ear
+ * module. This must be a unique name and valid JMX ObjectName string.
+ *
+ * @return the object name of the ear mbean
+ */
+ public String getJmxName() {
+ return jmxName;
+ }
+
+ /**
+ * The loader-repository specifies the name of the UnifiedLoaderRepository MBean to use for the ear to provide ear
+ * level scoping of classes deployed in the ear. It is a unique JMX ObjectName string.
+ * <p/>
+ * <P>
+ * Example:
+ * </P>
+ * <loader-repository>jboss.test:loader=cts-cmp2v1-sar.ear</loader-repository>
+ *
+ * @return the object name of the ear mbean
+ */
+ public String getLoaderRepository() {
+ return loaderRepository;
+ }
+
+ /**
+ * The module-order specifies the order in which the modules specified in the application.xml file gets loaded.
+ * Allowed values are:
+ * <p/>
+ * <module-order>strict</module-order> The strict value indicates that the deployments of the modules will be done
+ * in the order that would be specified in the application.xml and jboss-app.xml file.
+ * <p/>
+ * <module-order>implicit</module-order> The implicit value indicates the deployment would follow the order which
+ * would be specified in the DeploymentSorter.
+ * <p/>
+ * Returns {@code null} if no module order is set.
+ * <p/>
+ * Only available in JBoss 4.2 and 4.3. Has no effect in JBoss 5 and is not added when mentioned version is used.
+ *
+ * @return the module order
+ */
+ public String getModuleOrder() {
+ return moduleOrder;
+ }
+
+ /**
+ * Returns the list of datasources to include in the {@code jboss-app.xml} file as services. Each element of the
+ * list is the relative path to the datasource file contained in the EAR archive.
+ *
+ * @return the list of datasources paths
+ */
+ public List<String> getDataSources() {
+ return dataSources;
+ }
+
+ /**
+ * Returns the library directory to include in the {@code jboss-app.xml} file. It tells JBoss where to find
+ * non-Java EE libraries included in the EAR.
+ *
+ * @return the library directory
+ */
+ public String getLibraryDirectory() {
+ return libraryDirectory;
+ }
+
+ /**
+ * Returns the class loader repository configuration to include in the {@code jboss-app.xml} file. The content of
+ * this element is handed to the class loader, thereby altering it's default behaviour.
+ * <p/>
+ * This element is added as a child to the {@code loader-repository} element. If the element is not present in the
+ * configuration, it will be added.
+ * <p/>
+ * Example: <loader-repository-config>java2ParentDelegaton=true</loader-repository-config>
+ *
+ * @return the class loader repository configuration
+ */
+ public String getLoaderRepositoryConfig() {
+ return loaderRepositoryConfig;
+ }
+
+ /**
+ * Returns the class loader repository class to include in the {@code jboss-app.xml} file. It tells JBoss which
+ * loader repository implementation to use.
+ * <p/>
+ * This element is added as an attribute to the {@code loader-repository} element, therefore it is not added if no
+ * such element configuration is present.
+ * <p/>
+ * Example: <loader-repository-class>org.mindbug.jboss.AlternateLoaderRepository</loader-repository-class>
+ *
+ * @return the class loader repository class
+ */
+ public String getLoaderRepositoryClass() {
+ return loaderRepositoryClass;
+ }
+
+ /**
+ * Returns the class loader's configuration parser class to include in the {@code jboss-app.xml} file. It tells
+ * JBoss how to parse the configuration given in the {@code loader-repository-config} element.
+ * <p/>
+ * This element is added as an attribute to the {@code loader-repository-config} element, therefore it is not added
+ * if no such element configuration is present.
+ * <p/>
+ * Example: <config-parser-class>org.mindbug.jboss.AlternateLoaderRepositoryConfigParser</config-parser-class>
+ *
+ * @return the class loader's configuration parser class
+ */
+ public String getConfigParserClass() {
+ return configParserClass;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/JbossEarModule.java b/src/main/java/org/apache/maven/plugins/ear/JbossEarModule.java
index 4dedb4a..8e806b5 100644
--- a/src/main/java/org/apache/maven/plugins/ear/JbossEarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/JbossEarModule.java
@@ -1,38 +1,55 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * Represents a JBoss specific ear module.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public interface JbossEarModule
-{
- /**
- * Appends the {@code XML} representation of this module for the jboss-app.xml file.
- *
- * @param writer the writer to use
- * @param version the version of the {@code jboss-app.xml} file
- */
- void appendJbossModule( XMLWriter writer, String version );
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Represents a JBoss specific ear module.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public interface JbossEarModule {
+ /**
+ * Appends the {@code XML} representation of this module for the jboss-app.xml file.
+ *
+ * @param writer the writer to use
+ * @param version the version of the {@code jboss-app.xml} file
+ */
+ void appendJbossModule(XMLWriter writer, String version);
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/ParModule.java b/src/main/java/org/apache/maven/plugins/ear/ParModule.java
index 53fbcc9..50f05ee 100644
--- a/src/main/java/org/apache/maven/plugins/ear/ParModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/ParModule.java
@@ -1,52 +1,66 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-
-/**
- * The {@link EarModule} implementation for a Par module.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class ParModule
- extends EjbModule
-{
- /**
- * Default type of the artifact of a Par module.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "par";
-
- /**
- * Create an instance.
- */
- public ParModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- }
-
- /**
- * @param a {@link Artifact}
- */
- public ParModule( Artifact a )
- {
- super( a );
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * The {@link EarModule} implementation for a Par module.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class ParModule extends EjbModule {
+ /**
+ * Default type of the artifact of a Par module.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "par";
+
+ /**
+ * Create an instance.
+ */
+ public ParModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ */
+ public ParModule(Artifact a) {
+ super(a);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/RarModule.java b/src/main/java/org/apache/maven/plugins/ear/RarModule.java
index 0b3ec8b..297427b 100644
--- a/src/main/java/org/apache/maven/plugins/ear/RarModule.java
+++ b/src/main/java/org/apache/maven/plugins/ear/RarModule.java
@@ -1,74 +1,87 @@
-package org.apache.maven.plugins.ear;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.codehaus.plexus.util.xml.XMLWriter;
-
-/**
- * The {@link EarModule} implementation for an J2EE connector module.
- *
- * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- */
-public class RarModule
- extends AbstractEarModule
-{
- /**
- * Default type of the artifact of an Java EE connector module.
- */
- public static final String DEFAULT_ARTIFACT_TYPE = "rar";
-
- private static final String RAR_MODULE = "connector";
-
- private static final String DEFAULT_LIB_DIRECTORY = "/";
-
- /**
- * Create an instance.
- */
- public RarModule()
- {
- this.type = DEFAULT_ARTIFACT_TYPE;
- this.libDirectory = DEFAULT_LIB_DIRECTORY;
- }
-
- /**
- * @param a {@link Artifact}
- */
- public RarModule( Artifact a )
- {
- super( a );
- this.libDirectory = DEFAULT_LIB_DIRECTORY;
- }
-
- /**
- * {@inheritDoc}
- */
- public void appendModule( XMLWriter writer, String version, Boolean generateId )
- {
- startModuleElement( writer, generateId );
- writer.startElement( RAR_MODULE );
- writer.writeText( getUri() );
- writer.endElement();
-
- writeAltDeploymentDescriptor( writer, version );
-
- writer.endElement();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.ear;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * The {@link EarModule} implementation for an J2EE connector module.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class RarModule extends AbstractEarModule {
+ /**
+ * Default type of the artifact of an Java EE connector module.
+ */
+ public static final String DEFAULT_ARTIFACT_TYPE = "rar";
+
+ private static final String RAR_MODULE = "connector";
+
+ private static final String DEFAULT_LIB_DIRECTORY = "/";
+
+ /**
+ * Create an instance.
+ */
+ public RarModule() {
+ this.type = DEFAULT_ARTIFACT_TYPE;
+ this.libDirectory = DEFAULT_LIB_DIRECTORY;
+ }
+
+ /**
+ * @param a {@link Artifact}
+ */
+ public RarModule(Artifact a) {
+ super(a);
+ this.libDirectory = DEFAULT_LIB_DIRECTORY;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void appendModule(XMLWriter writer, String version, Boolean generateId) {
+ startModuleElement(writer, generateId);
+ writer.startElement(RAR_MODULE);
+ writer.writeText(getUri());
+ writer.endElement();
+
+ writeAltDeploymentDescriptor(writer, version);
+
+ writer.endElement();
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/ear/ResourceRef.java b/src/main/java/org/apache/maven/plugins/ear/ResourceRef.java
index 339dfb2..5964064 100644
--- a/src/main/java/org/apache/maven/plugins/ear/ResourceRef.java
+++ b/src/main/java/org/apache/maven/plugins/ear/ResourceRef.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
... 8586 lines suppressed ...