You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2017/12/20 09:34:11 UTC
[maven-ear-plugin] 08/16: MNG-1488: added global scope
defaultJavaBundleDir property. If set,
all Java modules without a custom bundleDir are placed in the default bundle
directory. See howto for an example.
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to annotated tag maven-ear-plugin-2.1
in repository https://gitbox.apache.org/repos/asf/maven-ear-plugin.git
commit 4206b5028e4ac05b036239c3e33e5d064d13aebc
Author: Stephane Nicoll <sn...@apache.org>
AuthorDate: Sun Nov 13 12:42:44 2005 +0000
MNG-1488: added global scope defaultJavaBundleDir property. If set, all Java modules without a custom bundleDir are placed in the default bundle directory. See howto for an example.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk/maven-plugins/maven-ear-plugin@332974 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/maven/plugin/ear/AbstractEarModule.java | 18 ++++++-------
.../apache/maven/plugin/ear/AbstractEarMojo.java | 11 ++++++--
.../org/apache/maven/plugin/ear/EarModule.java | 12 +++++----
.../apache/maven/plugin/ear/EarModuleFactory.java | 10 +++++---
.../apache/maven/plugin/ear/EjbClientModule.java | 2 +-
.../org/apache/maven/plugin/ear/JavaModule.java | 27 ++++++++++++++++++-
.../org/apache/maven/plugin/ear/WebModule.java | 4 +--
src/site/apt/howto.apt | 30 ++++++++++++++++++++++
.../apache/maven/plugin/ear/EarModuleTest.java} | 27 ++++++++-----------
9 files changed, 99 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java b/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
index f07b3e1..1aefba2 100644
--- a/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
+++ b/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
@@ -44,11 +44,11 @@ public abstract class AbstractEarModule
private String artifactId;
- private String bundleDir;
+ protected String bundleDir;
- private String bundleFileName;
+ protected String bundleFileName;
- private Boolean excluded = Boolean.FALSE;
+ protected Boolean excluded = Boolean.FALSE;
/**
* Empty constructor to be used when the module
@@ -71,7 +71,7 @@ public abstract class AbstractEarModule
this.bundleDir = null;
}
- public void resolveArtifact( Set artifacts )
+ public void resolveArtifact( Set artifacts, String defaultJavaBundleDir )
throws MojoFailureException
{
if ( artifact == null )
@@ -210,7 +210,7 @@ public abstract class AbstractEarModule
* @param bundleDir the bundle directory to clean
* @return the cleaned bundle directory
*/
- private static String cleanBundleDir( String bundleDir )
+ static String cleanBundleDir( String bundleDir )
{
if ( bundleDir == null )
{
@@ -221,19 +221,17 @@ public abstract class AbstractEarModule
bundleDir = bundleDir.replace( '\\', '/' );
// Remove '/' prefix if any so that directory is a relative path
- if ( bundleDir.startsWith( " / " ) )
+ if ( bundleDir.startsWith( "/" ) )
{
bundleDir = bundleDir.substring( 1, bundleDir.length() );
}
- // Adding '/' suffix to specify a directory structure
- if ( !bundleDir.endsWith( "/" ) )
+ if ( bundleDir.length() > 0 && !bundleDir.endsWith( "/" ) )
{
+ // Adding '/' suffix to specify a directory structure if it is not empty
bundleDir = bundleDir + "/";
}
- System.out.println( "Bundle dir[" + bundleDir + "]" );
-
return bundleDir;
}
}
diff --git a/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
index 4b6f8f1..4df21ff 100644
--- a/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
+++ b/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
@@ -60,6 +60,13 @@ public abstract class AbstractEarMojo
private EarModule[] modules;
/**
+ * The default bundle dir for Java modules.
+ *
+ * @parameter
+ */
+ private String defaultJavaBundleDir;
+
+ /**
* Directory that resources are copied to during the build.
*
* @parameter expression="${project.build.directory}/${project.build.finalName}"
@@ -88,7 +95,7 @@ public abstract class AbstractEarMojo
{
module = (EarModule) modules[i];
getLog().debug( "Resolving ear module[" + module + "]" );
- module.resolveArtifact( project.getArtifacts() );
+ module.resolveArtifact( project.getArtifacts(), defaultJavaBundleDir );
allModules.add( module );
}
}
@@ -109,7 +116,7 @@ public abstract class AbstractEarMojo
ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
if ( !isArtifactRegistered( artifact, allModules ) && !artifact.isOptional() && filter.include( artifact ) )
{
- EarModule module = EarModuleFactory.newEarModule( artifact );
+ EarModule module = EarModuleFactory.newEarModule( artifact, defaultJavaBundleDir );
allModules.add( module );
}
}
diff --git a/src/main/java/org/apache/maven/plugin/ear/EarModule.java b/src/main/java/org/apache/maven/plugin/ear/EarModule.java
index 0eb642f..98d7636 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EarModule.java
+++ b/src/main/java/org/apache/maven/plugin/ear/EarModule.java
@@ -38,7 +38,7 @@ public interface EarModule
* module has been resolved.
*
* @return the artifact
- * @see #resolveArtifact(java.util.Set)
+ * @see #resolveArtifact(java.util.Set, String)
*/
public Artifact getArtifact();
@@ -59,18 +59,20 @@ public interface EarModule
/**
* Appends the <tt>XML</tt> representation of this module.
*
- * @param writer the writer to use
+ * @param writer the writer to use
* @param version the version of the <tt>application.xml</tt> file
*/
public void appendModule( XMLWriter writer, String version );
/**
- * Resolves the {@link Artifact} represented by the module.
+ * Resolves the {@link Artifact} represented by the module with
+ * the specified execution configuration.
*
- * @param artifacts the project's artifacts
+ * @param artifacts the project's artifacts
+ * @param defaultJavaBundleDir the default bundle dir for {@link JavaModule}
* @throws EarPluginException if the artifact could not be resolved
*/
- public void resolveArtifact( Set artifacts )
+ public void resolveArtifact( Set artifacts, String defaultJavaBundleDir )
throws EarPluginException, MojoFailureException;
}
diff --git a/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java b/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
index 7553ec9..a8825ea 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
+++ b/src/main/java/org/apache/maven/plugin/ear/EarModuleFactory.java
@@ -29,16 +29,18 @@ public final class EarModuleFactory
/**
* Creates a new {@link EarModule} based on the
- * specified {@link Artifact}.
+ * specified {@link Artifact} and the specified
+ * execution configuration.
*
- * @param artifact the artifact
+ * @param artifact the artifact
+ * @param defaultJavaBundleDir the default bundle dir for {@link JavaModule}
* @return an ear module for this artifact
*/
- public static final EarModule newEarModule( Artifact artifact )
+ public static final EarModule newEarModule( Artifact artifact, String defaultJavaBundleDir )
{
if ( "jar".equals( artifact.getType() ) )
{
- return new JavaModule( artifact );
+ return new JavaModule( artifact, defaultJavaBundleDir );
}
else if ( "ejb".equals( artifact.getType() ) )
{
diff --git a/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java b/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
index 5849df0..e72cf9d 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
+++ b/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
@@ -34,7 +34,7 @@ public class EjbClientModule
public EjbClientModule( Artifact a )
{
- super( a );
+ super( a, null );
}
protected String getType()
diff --git a/src/main/java/org/apache/maven/plugin/ear/JavaModule.java b/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
index 94a90ef..cf24b79 100644
--- a/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
+++ b/src/main/java/org/apache/maven/plugin/ear/JavaModule.java
@@ -17,8 +17,11 @@ package org.apache.maven.plugin.ear;
*/
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 J2EE client module.
*
@@ -34,11 +37,14 @@ public class JavaModule
public JavaModule()
{
+
}
- public JavaModule( Artifact a )
+ public JavaModule( Artifact a, String defaultJavaBundleDir )
{
super( a );
+ setJavaBundleDir( defaultJavaBundleDir );
+
}
public void appendModule( XMLWriter writer, String version )
@@ -55,8 +61,27 @@ public class JavaModule
}
}
+ public void resolveArtifact( Set artifacts, String defaultJavaBundleDir )
+ throws MojoFailureException
+ {
+ // Let's resolve the artifact
+ super.resolveArtifact( artifacts, defaultJavaBundleDir );
+
+ // If the defaultJavaBundleDir is set and no bundle dir is
+ // set, set the default as bundle dir
+ setJavaBundleDir( defaultJavaBundleDir );
+ }
+
protected String getType()
{
return "jar";
}
+
+ private void setJavaBundleDir( String defaultJavaBundleDir )
+ {
+ if ( defaultJavaBundleDir != null && bundleDir == null )
+ {
+ this.bundleDir = defaultJavaBundleDir;
+ }
+ }
}
diff --git a/src/main/java/org/apache/maven/plugin/ear/WebModule.java b/src/main/java/org/apache/maven/plugin/ear/WebModule.java
index 5e06235..098f4de 100644
--- a/src/main/java/org/apache/maven/plugin/ear/WebModule.java
+++ b/src/main/java/org/apache/maven/plugin/ear/WebModule.java
@@ -63,11 +63,11 @@ public class WebModule
writer.endElement(); // module
}
- public void resolveArtifact( Set artifacts )
+ public void resolveArtifact( Set artifacts, String defaultJavaBundleDir )
throws MojoFailureException
{
// Let's resolve the artifact
- super.resolveArtifact( artifacts );
+ super.resolveArtifact( artifacts, defaultJavaBundleDir );
// Context root has not been customized - using default
if ( contextRoot == null )
diff --git a/src/site/apt/howto.apt b/src/site/apt/howto.apt
index 4e10bdc..883da74 100644
--- a/src/site/apt/howto.apt
+++ b/src/site/apt/howto.apt
@@ -30,6 +30,8 @@ Introduction
jar dependency could be included in the generated application.xml by specifying the
includeInApplicationXml flag.
+ It is also possible to specify a default bundle directory for all third party libraries
+
Customizing the context root
The sample below shows how to customize the context root of an artifact to be placed
@@ -81,6 +83,34 @@ Customizing a module location
</build>
+---------
+ Note that it is possible to specify a default bundle directory for all Java modules. If a Java module
+ has not the bundleDir property above, the default one is used. Here is an example of such configuration:
+
++--------
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <defaultBundleDir>APP-INF/lib
+ <configuration>
+ [...]
+ <modules>
+ <javaModule>
+ <groupId>artifactGroupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <bundleDir>/</bundleDir>
+ </javaModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
++---------
+
+ In this case, all Java modules will be placed in the APP-INF/lib directory except the specified artifact
+ which will be placed at the root of the EAR structure.
+
Customizing a module file name
The sample below shows how to rename a module being placed in the EAR file:
diff --git a/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java b/src/test/java/org/apache/maven/plugin/ear/EarModuleTest.java
similarity index 52%
copy from src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
copy to src/test/java/org/apache/maven/plugin/ear/EarModuleTest.java
index 5849df0..003cc75 100644
--- a/src/main/java/org/apache/maven/plugin/ear/EjbClientModule.java
+++ b/src/test/java/org/apache/maven/plugin/ear/EarModuleTest.java
@@ -16,29 +16,22 @@ package org.apache.maven.plugin.ear;
* limitations under the License.
*/
-import org.apache.maven.artifact.Artifact;
+import junit.framework.TestCase;
/**
- * The {@link EarModule} implementation for an Ejb-client module.
+ * Ear module test case.
*
* @author <a href="snicoll@apache.org">Stephane Nicoll</a>
- * @version $Id$
+ * @version $Id: AbstractEarModule.java 314956 2005-10-12 18:27:15 +0200 (Wed, 12 Oct 2005) brett $
*/
-public class EjbClientModule
- extends JavaModule
+public class EarModuleTest extends TestCase
{
- public EjbClientModule()
- {
- }
-
- public EjbClientModule( Artifact a )
- {
- super( a );
- }
-
- protected String getType()
- {
- return "ejb-client";
+ public void testCleanBuildDir() {
+ assertEquals("APP-INF/lib/", AbstractEarModule.cleanBundleDir( "APP-INF/lib"));
+ assertEquals("APP-INF/lib/", AbstractEarModule.cleanBundleDir( "APP-INF/lib/"));
+ assertEquals("APP-INF/lib/", AbstractEarModule.cleanBundleDir( "/APP-INF/lib"));
+ assertEquals("APP-INF/lib/", AbstractEarModule.cleanBundleDir( "/APP-INF/lib/"));
+ assertEquals("", AbstractEarModule.cleanBundleDir( "/"));
}
}
--
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <co...@maven.apache.org>.