Author: dennisl
Date: Mon May 24 10:17:47 2010
New Revision: 947587

URL: http://svn.apache.org/viewvc?rev=947587&view=rev
Log:
[MWAR-212] Allow optional @classifier@ in <outputFileNameMapping>

Implemented using the same syntax (and code) as the Assembly Plugin

Modified:
    
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/util/MappingUtils.java
    
maven/plugins/trunk/maven-war-plugin/src/site/apt/examples/file-name-mapping.apt
    
maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/util/MappingUtilsTest.java

Modified: 
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/util/MappingUtils.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/util/MappingUtils.java?rev=947587&r1=947586&r2=947587&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/util/MappingUtils.java
 (original)
+++ 
maven/plugins/trunk/maven-war-plugin/src/main/java/org/apache/maven/plugin/war/util/MappingUtils.java
 Mon May 24 10:17:47 2010
@@ -38,6 +38,7 @@ import org.codehaus.plexus.interpolation
  * The expression might use any field of the {...@link Artifact} interface. 
Some
  * examples might be:
  * <ul>
+ * <li>@{artifact...@-@{version}@@{dashclassifie...@.@{extension}@</li>
  * <li>@{artifact...@-@{versi...@.@{extension}@</li>
  * <li>@{artifact...@.@{extension}@</li>
  * </ul>
@@ -70,6 +71,19 @@ public class MappingUtils
         Properties classifierMask = new Properties();
         classifierMask.setProperty( "classifier", "" );
 
+        // Support for special expressions, like @{dashClassifier?}@, see 
MWAR-212
+        String classifier = artifact.getClassifier();
+        if ( classifier != null )
+        {
+            classifierMask.setProperty( "dashClassifier?", "-" + classifier );
+            classifierMask.setProperty( "dashClassifier", "-" + classifier );
+        }
+        else
+        {
+            classifierMask.setProperty( "dashClassifier?", "" );
+            classifierMask.setProperty( "dashClassifier", "" );
+        }
+
         interpolator.addValueSource( new PropertiesBasedValueSource ( 
classifierMask ) );
 
         value = interpolator.interpolate( value, "__artifact" );

Modified: 
maven/plugins/trunk/maven-war-plugin/src/site/apt/examples/file-name-mapping.apt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/site/apt/examples/file-name-mapping.apt?rev=947587&r1=947586&r2=947587&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-war-plugin/src/site/apt/examples/file-name-mapping.apt
 (original)
+++ 
maven/plugins/trunk/maven-war-plugin/src/site/apt/examples/file-name-mapping.apt
 Mon May 24 10:17:47 2010
@@ -2,8 +2,9 @@
  Using File Name Mapping
  ------
  Stephane Nicoll
+ Dennis Lundberg
  ------
- 2008-08-03
+ 2010-05-24
 
 ~~ Licensed to the Apache Software Foundation (ASF) under one
 ~~ or more contributor license agreements.  See the NOTICE file
@@ -34,18 +35,26 @@ Using File Name Mapping
 @{artifact...@-@{versi...@.@{extension}@
 +-----
 
- If the artifact has a classifier it is of course:
+ If the artifact has a classifier the default pattern is of course:
 
 +-----
 @{artifact...@-@{versi...@-@{classifi...@.@{extension}@
 +-----
 
  The <<<outputFileNameMapping>>> parameter allows you to give a custom 
pattern. Each token defined in the
- pattern will be replaced with the value for the current artifact. You can use 
any property of Artifact and
- ArtifactHandler as a token.
+ pattern will be replaced with a value from the current artifact. You can use 
any property of Artifact and
+ ArtifactHandler as a token. There is also a special token named 
<<<dashClassifier?>>> that can be used.
+ It will add the string "-yourclassifier" if and only if the artifact has a 
classifier.
 
- For instance, to store the libraries and TLDs without version numbers, use 
the following pattern:
+ For instance, to store the libraries and TLDs without version numbers or 
classifiers, use the following pattern:
 
 +-----
 @{artifact...@.@{extension}@
 +-----
+
+ To store the libraries and TLDs without version numbers but with classifiers
+ (if they exist), use the following pattern:
+
++-----
+...@{artifactid}@@{dashclassifie...@.@{extension}@
++-----

Modified: 
maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/util/MappingUtilsTest.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/util/MappingUtilsTest.java?rev=947587&r1=947586&r2=947587&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/util/MappingUtilsTest.java
 (original)
+++ 
maven/plugins/trunk/maven-war-plugin/src/test/java/org/apache/maven/plugin/war/util/MappingUtilsTest.java
 Mon May 24 10:17:47 2010
@@ -82,6 +82,34 @@ public class MappingUtilsTest
                       MappingUtils.evaluateFileNameMapping( 
AbstractWarMojo.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER, jar ) );
     }
 
+    /**
+     * Test for MWAR-212.
+     */
+    public void testMappingWithOptionalClassifier()
+        throws MojoExecutionException, InterpolationException
+    {
+        final String MAPPING_WITH_OPTIONAL_CLASSIFIER_1 = 
"@{artifact...@-@{version}@@{dashclassifi...@.@{extension}@";
+        final String MAPPING_WITH_OPTIONAL_CLASSIFIER_2 = 
"@{artifact...@-@{version}@@{dashclassifie...@.@{extension}@";
+
+        TestArtifactStub jar = new TestArtifactStub();
+        jar.setGroupId( "org.apache.sample" );
+        jar.setArtifactId( "maven-test-lib" );
+        jar.setVersion( "1.0" );
+        assertEquals( "maven-test-lib-1.0.jar",
+                      MappingUtils.evaluateFileNameMapping( 
MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar ) );
+        assertEquals( "maven-test-lib-1.0.jar",
+                      MappingUtils.evaluateFileNameMapping( 
MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar ) );
+
+        jar = new TestArtifactStub();
+        jar.setGroupId( "org.apache.sample" );
+        jar.setArtifactId( "maven-test-lib" );
+        jar.setVersion( "1.0" );
+        jar.setClassifier( "classifier" );
+        assertEquals( "maven-test-lib-1.0-classifier.jar",
+                      MappingUtils.evaluateFileNameMapping( 
MAPPING_WITH_OPTIONAL_CLASSIFIER_1, jar ) );
+        assertEquals( "maven-test-lib-1.0-classifier.jar",
+                      MappingUtils.evaluateFileNameMapping( 
MAPPING_WITH_OPTIONAL_CLASSIFIER_2, jar ) );
+    }
 
     // A very dumb stub used to test the mappings
     class TestArtifactStub


Reply via email to