Author: snicoll Date: Sun Sep 5 18:16:55 2010 New Revision: 992847 URL: http://svn.apache.org/viewvc?rev=992847&view=rev Log: MEAR-98: Added a file name mapping implementation that omits the version. Based on a patch by Benjamin LERMAN.
Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMappingTest.java maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/application.xml - copied, changed from r992819, maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-067/expected-META-INF/application.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/pom.xml Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/customize-file-name-mapping.apt.vm maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt maven/plugins/trunk/maven-ear-plugin/src/site/apt/usage.apt.vm maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java Sun Sep 5 18:16:55 2010 @@ -36,17 +36,24 @@ public abstract class AbstractFileNameMa /** * Generates a standard file name for the specified {...@link Artifact}. * <p/> - * Returns something like <tt>artifactId-version[-classifier].extension</tt>. + * Returns something like <tt>artifactId-version[-classifier].extension</tt> + * if <tt>addVersion</tt> is true. Otherwise it generates something + * like <tt>artifactId[-classifier].extension</tt> * - * @param a the artifact to generate a filename from + * @param a the artifact to generate a filename from + * @param addVersion whether the version should be added * @return the filename, with a standard format */ - protected String generateFileName( final Artifact a ) + protected String generateFileName( final Artifact a, boolean addVersion ) { final String extension = a.getArtifactHandler().getExtension(); final StringBuilder buffer = new StringBuilder( 128 ); - buffer.append( a.getArtifactId() ).append( '-' ).append( a.getBaseVersion() ); + buffer.append( a.getArtifactId() ); + if ( addVersion ) + { + buffer.append( '-' ).append( a.getBaseVersion() ); + } if ( a.hasClassifier() ) { buffer.append( '-' ).append( a.getClassifier() ); Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FileNameMappingFactory.java Sun Sep 5 18:16:55 2010 @@ -37,6 +37,9 @@ public class FileNameMappingFactory static final String FULL_FILE_NAME_MAPPING = "full"; + static final String NO_VERSION_FILE_NAME_MAPPING = "no-version"; + + private FileNameMappingFactory() { } @@ -65,6 +68,10 @@ public class FileNameMappingFactory { return new FullFileNameMapping(); } + if ( NO_VERSION_FILE_NAME_MAPPING.equals( nameOrClass ) ) + { + return new NoVersionFileNameMapping(); + } try { final Class c = Class.forName( nameOrClass ); @@ -77,7 +84,7 @@ public class FileNameMappingFactory } catch ( InstantiationException e ) { - throw new IllegalStateException( "Could not instanciate file name mapping implementation[" + nameOrClass + + throw new IllegalStateException( "Could not instantiate file name mapping implementation[" + nameOrClass + "] make sure it has a default public constructor" ); } catch ( IllegalAccessException e ) Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java Sun Sep 5 18:16:55 2010 @@ -35,6 +35,6 @@ public class FullFileNameMapping public String mapFileName( final Artifact a ) { final String dashedGroupId = a.getGroupId().replace( '.', '-' ); - return dashedGroupId + "-" + generateFileName( a ); + return dashedGroupId + "-" + generateFileName( a, true ); } } Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMapping.java?rev=992847&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMapping.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMapping.java Sun Sep 5 18:16:55 2010 @@ -0,0 +1,39 @@ +package org.apache.maven.plugin.ear.output; + +/* + * 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; + +/** + * A simplified version of the standard file name mapping which does not + * retain the version in the generated file name. + * + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public class NoVersionFileNameMapping + extends AbstractFileNameMapping +{ + + public String mapFileName( Artifact a ) + { + return generateFileName( a, false ); + } + +} Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java Sun Sep 5 18:16:55 2010 @@ -34,7 +34,7 @@ public class StandardFileNameMapping public String mapFileName( final Artifact a ) { - return generateFileName( a ); + return generateFileName( a, true ); } } Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/customize-file-name-mapping.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/customize-file-name-mapping.apt.vm?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/customize-file-name-mapping.apt.vm (original) +++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/customize-file-name-mapping.apt.vm Sun Sep 5 18:16:55 2010 @@ -45,4 +45,5 @@ Customizing The File Name Mapping </build> +--------- - As a result, each artifact file name will be prefixed by the groupId to avoid clashes. + As a result, each artifact file name will be prefixed by the groupId to avoid clashes. There is also a + <<<no-version>>> file name mapping if you do not want to get the version in the file names. Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt (original) +++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt Sun Sep 5 18:16:55 2010 @@ -164,5 +164,7 @@ EAR Plugin Tests * project-067: builds an EAR with generateModuleId enabled and a custom module + * project-068: builds an EAR with the no-version file name mapping + \ No newline at end of file Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/usage.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/usage.apt.vm?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/apt/usage.apt.vm (original) +++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/usage.apt.vm Sun Sep 5 18:16:55 2010 @@ -110,9 +110,11 @@ mvn package The file name mapping to use for artifacts stored in the EAR can be specified using the <<<fileNameMapping>>> parameter. Valid values for this parameter - are <<<standard>>> (default) and <<<full>>>. By specifying <<<full>>> as file - name mapping, artifacts are prefixed by the <<<groupId>>> where dots have been - replaced by dashes. + are <<<standard>>> (default), <<<full>>> and <<<no-version>>>. By specifying + <<<full>>> as file name mapping, artifacts are prefixed by the <<<groupId>>> + where dots have been replaced by dashes. <<<no-version>>> can be used as a + replacement of the default mapping; the only difference is that the version + is omitted. For more information on EAR modules, please see the {{{modules.html}modules configuration}} page. Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java Sun Sep 5 18:16:55 2010 @@ -708,7 +708,6 @@ public class EarMojoIT doTestProject( "project-066", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); } - /** * Builds an EAR with generateModuleId enabled and a custom module. */ @@ -718,4 +717,13 @@ public class EarMojoIT doTestProject( "project-067", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); } + /** + * Builds an EAR with the no-version file name mapping. + */ + public void testProject068() + throws Exception + { + doTestProject( "project-068", new String[]{ "ejb-sample-one.jar", "ejb-sample-two.jar" } ); + } + } Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java?rev=992847&r1=992846&r2=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FileNameMappingFactoryTest.java Sun Sep 5 18:16:55 2010 @@ -68,6 +68,14 @@ public class FileNameMappingFactoryTest assertEquals( FullFileNameMapping.class, actual.getClass() ); } + public void testGetFileNameMappingByName3() + { + final FileNameMapping actual = + FileNameMappingFactory.getFileNameMapping( FileNameMappingFactory.NO_VERSION_FILE_NAME_MAPPING ); + assertNotNull( actual ); + assertEquals( NoVersionFileNameMapping.class, actual.getClass() ); + } + public void testGetFileNameMappingByClass() { final FileNameMapping actual = Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMappingTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMappingTest.java?rev=992847&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMappingTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/NoVersionFileNameMappingTest.java Sun Sep 5 18:16:55 2010 @@ -0,0 +1,41 @@ +package org.apache.maven.plugin.ear.output; + +/* + * 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. + */ + +/** + * @author Stephane Nicoll + */ +public class NoVersionFileNameMappingTest + extends AbstractFileNameMappingTest +{ + private final NoVersionFileNameMapping instance = new NoVersionFileNameMapping(); + + public void testSimpleArtifact() + { + assertEquals( "foo.jar", instance.mapFileName( createArtifact( "foo", "1.0-SNAPSHOT", "jar" ) ) ); + } + + public void testArtifactWithClassifier() + { + assertEquals( "foo-sources.jar", + instance.mapFileName( createArtifact( "foo", "1.0-SNAPSHOT", "jar", "sources" ) ) ); + } + +} Copied: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/application.xml (from r992819, maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-067/expected-META-INF/application.xml) URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/application.xml?p2=maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/application.xml&p1=maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-067/expected-META-INF/application.xml&r1=992819&r2=992847&rev=992847&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-067/expected-META-INF/application.xml (original) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/expected-META-INF/application.xml Sun Sep 5 18:16:55 2010 @@ -22,11 +22,11 @@ under the License. "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd"> <application> - <display-name>maven-ear-plugin-test-project-067</display-name> - <module id="sample-one-id"> - <ejb>ejb-sample-one-1.0.jar</ejb> + <display-name>maven-ear-plugin-test-project-068</display-name> + <module> + <ejb>ejb-sample-one.jar</ejb> </module> - <module id="EJB_eartest.ejb-sample-two"> - <ejb>ejb-sample-two-1.0.jar</ejb> + <module> + <ejb>ejb-sample-two.jar</ejb> </module> </application> \ No newline at end of file Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/pom.xml?rev=992847&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-068/pom.xml Sun Sep 5 18:16:55 2010 @@ -0,0 +1,55 @@ +<?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 +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. +--> + +<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/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>ear</groupId> + <artifactId>maven-ear-plugin-test-project-068</artifactId> + <version>99.0</version> + <name>Maven</name> + <packaging>ear</packaging> + <dependencies> + <dependency> + <groupId>eartest</groupId> + <artifactId>ejb-sample-one</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + <dependency> + <groupId>eartest</groupId> + <artifactId>ejb-sample-two</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <fileNameMapping>no-version</fileNameMapping> + </configuration> + </plugin> + </plugins> + </build> +</project>