Author: dennisl Date: Thu Feb 26 00:13:18 2009 New Revision: 747974 URL: http://svn.apache.org/viewvc?rev=747974&view=rev Log: [MEJB-13] Add support for configuring exclusion filter for main ejb jar Submitted by: Fredrik Vraalsen Reviewed by: Dennis Lundberg
o The patch was old and couldn't be applied to trunk, so I made the changes manually o Add a test case Modified: maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java Modified: maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java?rev=747974&r1=747973&r2=747974&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugin/ejb/EjbMojo.java Thu Feb 26 00:13:18 2009 @@ -45,16 +45,18 @@ public class EjbMojo extends AbstractMojo { + private static final String EJB_JAR_XML = "META-INF/ejb-jar.xml"; + // TODO: will null work instead? private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"}; - private static final String[] DEFAULT_EXCLUDES = + private static final String[] DEFAULT_EXCLUDES = new String[]{EJB_JAR_XML, "**/package.html"}; + + private static final String[] DEFAULT_CLIENT_EXCLUDES = new String[]{"**/*Bean.class", "**/*CMP.class", "**/*Session.class", "**/package.html"}; private static final String[] EMPTY_STRING_ARRAY = new String[0]; - private static final String EJB_JAR_XML = "META-INF/ejb-jar.xml"; - /** * The directory for the generated EJB. * @@ -128,6 +130,20 @@ private List clientIncludes; /** + * The files and directories to exclude from the main EJB jar. Usage: + * + * <pre> + * <excludes> + * <exclude>**/*Ejb.class</exclude> + * <exclude>**/*Bean.class</exclude> + * </excludes> + * </pre> + * <br/>Default exclusions: META-INF/ejb-jar.xml, **/package.html + * @parameter + */ + private List excludes; + + /** * The Maven project. * * @parameter expression="${project}" @@ -220,8 +236,13 @@ try { - archiver.getArchiver().addDirectory( new File( outputDirectory ), DEFAULT_INCLUDES, - new String[]{EJB_JAR_XML, "**/package.html"} ); + String[] mainJarExcludes = DEFAULT_EXCLUDES; + + if ( excludes != null && !excludes.isEmpty() ) { + mainJarExcludes = (String[]) excludes.toArray( EMPTY_STRING_ARRAY ); + } + + archiver.getArchiver().addDirectory( new File( outputDirectory ), DEFAULT_INCLUDES, mainJarExcludes ); if ( deploymentDescriptor.exists() ) { @@ -268,7 +289,7 @@ getLog().info( "Building EJB client " + clientJarName + "-client" ); - String[] excludes = DEFAULT_EXCLUDES; + String[] excludes = DEFAULT_CLIENT_EXCLUDES; String[] includes = DEFAULT_INCLUDES; if ( clientIncludes != null && !clientIncludes.isEmpty() ) Modified: maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java?rev=747974&r1=747973&r2=747974&view=diff ============================================================================== --- maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java (original) +++ maven/plugins/trunk/maven-ejb-plugin/src/test/java/org/apache/maven/plugin/ejb/EjbMojoTest.java Thu Feb 26 00:13:18 2009 @@ -239,7 +239,7 @@ inclusions.add( "**/*Include.class" ); final MavenProjectResourcesStub project = createTestProject( "client-includes" ); - final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList() ); + final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList(), null ); // put this on the target output dir project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); @@ -277,7 +277,7 @@ exclusions.add( "**/*Exclude.class" ); final MavenProjectResourcesStub project = createTestProject( "client-excludes" ); - final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList(), exclusions ); + final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList(), exclusions, null ); // put this on the target output dir project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); @@ -305,6 +305,45 @@ /** + * Main jar exclusions test. + * + * @throws Exception if any exception occurs + */ + public void testMainJarExclusions() + throws Exception + { + final LinkedList exclusions = new LinkedList(); + exclusions.add( "**/*Exclude.class" ); + + final MavenProjectResourcesStub project = createTestProject( "main-excludes" ); + final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList(), new LinkedList(), exclusions ); + + // put this on the target output dir + project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile( "org/sample/ejb/AppInclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); + project.addFile( "org/sample/ejb/AppExclude.class", MavenProjectResourcesStub.OUTPUT_FILE ); + + // put this on the root dir + project.addFile( "pom.xml", MavenProjectResourcesStub.ROOT_FILE ); + + // start creating the environment + project.setupBuildEnvironment(); + + setVariableValueToObject( mojo, "generateClient", Boolean.TRUE ); + setVariableValueToObject( mojo, "ejbVersion", "2.1" ); + + mojo.execute(); + + assertJarCreation( project, true, true ); + assertJarContent( project, new String[]{"META-INF/MANIFEST.MF", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.xml", + "META-INF/maven/org.apache.maven.test/maven-test-plugin/pom.properties", "org/sample/ejb/AppInclude.class"}, + new String[]{"META-INF/ejb-jar.xml", "org/sample/ejb/AppExclude.class"} ); + + } + + + /** * Client jar inclusion test with a sub-package. * * @throws Exception if any exception occurs @@ -316,7 +355,7 @@ inclusions.add( "org/sample/ejb/*.class" ); final MavenProjectResourcesStub project = createTestProject( "client-includes-subpackage" ); - final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList() ); + final EjbMojo mojo = lookupMojoWithSettings( project, inclusions, new LinkedList(), null ); // put this on the target output dir project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); @@ -356,7 +395,7 @@ exclusions.add( "org/sample/ejb/**" ); final MavenProjectResourcesStub project = createTestProject( "client-excludes-emptypackage" ); - final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList(), exclusions ); + final EjbMojo mojo = lookupMojoWithSettings( project, new LinkedList(), exclusions, null ); // put this on the target output dir project.addFile( "META-INF/ejb-jar.xml", MavenProjectResourcesStub.OUTPUT_FILE ); @@ -508,7 +547,7 @@ } protected EjbMojo lookupMojoWithSettings( final MavenProject project, LinkedList clientIncludes, - LinkedList clientExcludes ) + LinkedList clientExcludes, LinkedList excludes ) throws Exception { final EjbMojo mojo = lookupMojo(); @@ -518,6 +557,7 @@ setVariableValueToObject( mojo, "jarName", DEFAULT_JAR_NAME ); setVariableValueToObject( mojo, "clientExcludes", clientExcludes ); setVariableValueToObject( mojo, "clientIncludes", clientIncludes ); + setVariableValueToObject( mojo, "excludes", excludes ); return mojo; } @@ -525,7 +565,7 @@ protected EjbMojo lookupMojoWithDefaultSettings( final MavenProject project ) throws Exception { - return lookupMojoWithSettings( project, new LinkedList(), new LinkedList() ); + return lookupMojoWithSettings( project, new LinkedList(), new LinkedList(), null ); }