You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2009/08/21 01:36:52 UTC

svn commit: r806398 - in /maven/plugins/trunk/maven-resources-plugin: ./ src/it/MRESOURCES-77/ src/it/custom-delimiter/ src/it/custom-delimiter/src/ src/it/custom-delimiter/src/main/ src/it/custom-delimiter/src/main/filters/ src/it/custom-delimiter/src...

Author: jdcasey
Date: Thu Aug 20 23:36:51 2009
New Revision: 806398

URL: http://svn.apache.org/viewvc?rev=806398&view=rev
Log:
[MRESOURCES-60] Support custom delimiters.

Added:
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml   (with props)
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties   (with props)
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/my.filter
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt   (with props)
    maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh   (with props)
Modified:
    maven/plugins/trunk/maven-resources-plugin/pom.xml
    maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-77/pom.xml
    maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java

Modified: maven/plugins/trunk/maven-resources-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/pom.xml?rev=806398&r1=806397&r2=806398&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-resources-plugin/pom.xml Thu Aug 20 23:36:51 2009
@@ -71,7 +71,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.5.8</version>
+      <version>1.5.15</version>
     </dependency>
 
     <dependency>
@@ -83,7 +83,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-interpolation</artifactId>
-      <version>1.7</version>
+      <version>1.12-SNAPSHOT</version>
     </dependency>
 
     <dependency>

Modified: maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-77/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-77/pom.xml?rev=806398&r1=806397&r2=806398&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-77/pom.xml (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-77/pom.xml Thu Aug 20 23:36:51 2009
@@ -41,8 +41,7 @@
     <plugins>
       <plugin>
         <artifactId>maven-resources-plugin</artifactId>
-        <!-- <version>@pom.version@</version> -->
-        <version>2.4-SNAPSHOT</version>
+        <version>@pom.version@</version>
         <executions>
           <execution>
             <id>custom-resources</id>

Added: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml?rev=806398&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml Thu Aug 20 23:36:51 2009
@@ -0,0 +1,78 @@
+<?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>org.apache.maven.plugins</groupId>
+  <artifactId>maven-resources-plugin-it-filter</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
+    <filters>
+      <filter>src/main/filters/my.filter</filter>
+      <filter>src/main/filters/filter2.properties</filter>
+    </filters>
+    <plugins>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <!-- <version>@pom.version@</version> -->
+        <version>2.4-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <id>default-resources</id>
+            <configuration>
+              <delimiters>
+                <delimiter><![CDATA[>*<]]></delimiter>
+              </delimiters>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!--
+    Look at SomeResource.txt after being processed with filtering.
+    Note the tokens for ${projectProperty} and ${profileProperty} for the "filter resolution" case should be resolved and evaluated
+    using the POM property values of the filter tokens
+  -->
+  <properties>
+    <projectProperty>foo-projectProperty-bar</projectProperty>
+  </properties>
+
+  <profiles>
+    <profile>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <properties>
+        <profileProperty>foo-profileProperty-bar</profileProperty>
+      </properties>
+    </profile>
+  </profiles>
+</project>

Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties?rev=806398&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties Thu Aug 20 23:36:51 2009
@@ -0,0 +1,3 @@
+var1=Foo
+var2=${var1}-Bar
+var3=${var2}/Thing
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/filter2.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/my.filter
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/my.filter?rev=806398&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/my.filter (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/filters/my.filter Thu Aug 20 23:36:51 2009
@@ -0,0 +1,6 @@
+
+filter.token.project.version=${project.version}
+filter.token.projectProperty=${projectProperty}
+filter.token.profileProperty=${profileProperty}
+execProps=fromFilter
+value=foo
\ No newline at end of file

Added: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt?rev=806398&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt Thu Aug 20 23:36:51 2009
@@ -0,0 +1,15 @@
+
+test:direct resolution project.version=${project.version}
+test:filter resolution project.version=${filter.token.project.version}
+
+test:filter direct projectProperty=${projectProperty}
+test:filter resolution projectProperty=${filter.token.projectProperty}
+
+test:filter direct profileProperty=${profileProperty}
+test:filter resolution profileProperty=${filter.token.profileProperty}
+
+test:filter syspropsExecutionPropsWins=${execProps}
+
+newToken=@value@
+
+var3=>var3<

Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/src/main/resources/SomeResource.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh?rev=806398&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh Thu Aug 20 23:36:51 2009
@@ -0,0 +1,125 @@
+
+/*
+ * 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.*;
+
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    File target = new File( basedir, "target" );
+    if ( !target.exists() || !target.isDirectory() )
+    {
+        System.err.println( "target file is missing or a directory." );
+        return false;
+    }
+    
+    File someResource = new File( target, "/classes/SomeResource.txt" );
+    if ( !someResource.exists() || someResource.isDirectory() )
+    {
+        System.err.println( "SomeResource.txt is missing or not a file." );
+        return false;
+    }    
+    
+    FileInputStream fis = new FileInputStream ( someResource );
+    String paramContent = IOUtil.toString ( fis );
+    
+    //test:direct resolution project.version=1.0-SNAPSHOT
+    int indexOf = paramContent.indexOf( "test:direct resolution project.version=1.0-SNAPSHOT" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:direct resolution project.version=1.0-SNAPSHOT" );
+      return false;
+    }    
+    
+
+    //test:filter resolution project.version=1.0-SNAPSHOT
+    indexOf = paramContent.indexOf( "test:filter resolution project.version=1.0-SNAPSHOT" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter resolution project.version=1.0-SNAPSHOT" );
+      return false;
+    } 
+    
+    //test:filter direct projectProperty=foo-projectProperty-bar
+    indexOf = paramContent.indexOf( "test:filter direct projectProperty=foo-projectProperty-bar" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter direct projectProperty=foo-projectProperty-bar" );
+      return false;
+    }    
+    
+    //test:filter resolution projectProperty=foo-projectProperty-bar
+    indexOf = paramContent.indexOf( "test:filter resolution projectProperty=foo-projectProperty-bar" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter resolution projectProperty=foo-projectProperty-bar" );
+      return false;
+    }         
+    
+    //test:filter direct profileProperty=foo-profileProperty-bar    
+    indexOf = paramContent.indexOf( "test:filter direct profileProperty=foo-profileProperty-bar" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter direct profileProperty=foo-profileProperty-bar" );
+      return false;
+    }     
+    
+    //test:filter resolution profileProperty=foo-profileProperty-bar    
+    indexOf = paramContent.indexOf( "test:filter resolution profileProperty=foo-profileProperty-bar" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter resolution profileProperty=foo-profileProperty-bar" );
+      return false;
+    }
+    
+    //test:filter syspropsExecutionPropsWins=fromExecProps
+    indexOf = paramContent.indexOf( "test:filter syspropsExecutionPropsWins=fromExecProps" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains test:filter syspropsExecutionPropsWins=fromExecProps" );
+      return false;
+    }   
+    
+    //newToken=foo     
+    indexOf = paramContent.indexOf( "newToken=foo" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains newToken=foo" );
+      return false;
+    }
+    
+    //var3=Foo-Bar/Thing     
+    indexOf = paramContent.indexOf( "var3=Foo-Bar/Thing" );
+    if ( indexOf < 0)
+    {
+      System.err.println( "SomeResource.txt not contains var3=Foo-Bar/Thing" );
+      return false;
+    }             
+}
+catch( IOException e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;

Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/custom-delimiter/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java?rev=806398&r1=806397&r2=806398&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/main/java/org/apache/maven/plugin/resources/ResourcesMojo.java Thu Aug 20 23:36:51 2009
@@ -19,14 +19,6 @@
  * under the License.
  */
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
@@ -38,6 +30,14 @@
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+
 /**
  * Copy resources for the main source code to the main output directory.
  *
@@ -188,9 +188,16 @@
      * <p>
      * Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can).
      * </p>
+     * @parameter
      * @since 2.4
      */
-    protected Set delimiters;
+    protected List delimiters;
+    
+    /**
+     * @parameter default-value="true"
+     * @since 2.4
+     */
+    protected boolean useDefaultDelimiters;
     
     public void execute()
         throws MojoExecutionException
@@ -226,7 +233,14 @@
             // if these are NOT set, just use the defaults, which are '${*}' and '@'.
             if ( delimiters != null && !delimiters.isEmpty() )
             {
-                mavenResourcesExecution.setDelimiters( delimiters );
+                LinkedHashSet delims = new LinkedHashSet();
+                if ( useDefaultDelimiters )
+                {
+                    delims.addAll( mavenResourcesExecution.getDelimiters() );
+                }
+                delims.addAll( delimiters );
+                
+                mavenResourcesExecution.setDelimiters( delims );
             }
             
             if ( nonFilteredFileExtensions != null )
@@ -334,14 +348,24 @@
         this.filters = filters;
     }
 
-    public Set getDelimiters()
+    public List getDelimiters()
     {
         return delimiters;
     }
 
-    public void setDelimiters( Set delimiters )
+    public void setDelimiters( List delimiters )
     {
         this.delimiters = delimiters;
     }
 
+    public boolean isUseDefaultDelimiters()
+    {
+        return useDefaultDelimiters;
+    }
+
+    public void setUseDefaultDelimiters( boolean useDefaultDelimiters )
+    {
+        this.useDefaultDelimiters = useDefaultDelimiters;
+    }
+
 }