You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2010/09/23 23:50:37 UTC
svn commit: r1000643 - in /maven/plugins/trunk/maven-resources-plugin: ./
src/it/user-filters/ src/main/java/org/apache/maven/plugin/resources/
src/test/java/org/apache/maven/plugin/resources/filters/
Author: olamy
Date: Thu Sep 23 21:50:36 2010
New Revision: 1000643
URL: http://svn.apache.org/viewvc?rev=1000643&view=rev
Log:
[MRESOURCES-128] Custom resource filters
Added:
maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/
- copied from r979417, maven/plugins/trunk/maven-resources-plugin/src/it/MRESOURCES-78/
maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties (with props)
maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties (with props)
maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/
maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java (with props)
Modified:
maven/plugins/trunk/maven-resources-plugin/pom.xml
maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/pom.xml
maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/verify.groovy
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=1000643&r1=1000642&r2=1000643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-resources-plugin/pom.xml Thu Sep 23 21:50:36 2010
@@ -128,6 +128,12 @@ under the License.
<version>1.0-beta-1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
@@ -137,6 +143,29 @@ under the License.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <version>1.3.4</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.5</version>
<configuration>
Added: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties?rev=1000643&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties Thu Sep 23 21:50:36 2010
@@ -0,0 +1 @@
+invoker.systemPropertiesFile = test.properties
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/pom.xml?rev=1000643&r1=979417&r2=1000643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/pom.xml (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/pom.xml Thu Sep 23 21:50:36 2010
@@ -17,38 +17,54 @@
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.opennms</groupId>
- <artifactId>resources-test</artifactId>
- <name>OpenNMS Resources Test</name>
- <version>1.0</version>
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- </resource>
- <resource>
- <filtering>true</filtering>
- <directory>src/main/filtered</directory>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>@pom.version@</version>
- <configuration>
- <encoding>UTF-8</encoding>
- <escapeString>\</escapeString>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <properties>
- <escaped>this is escaped</escaped>
- <escaped.at>this is escaped.at</escaped.at>
- <foo>this is foo</foo>
- <bar>this is bar</bar>
- </properties>
+<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.plugins.resources.its</groupId>
+ <artifactId>user-filters</artifactId>
+ <name>User Filter Resources Test</name>
+ <version>1.0.16-SNAPSHOT</version>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ <resource>
+ <filtering>true</filtering>
+ <directory>src/main/filtered</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <mavenFilteringHints>
+ <mavenFilteringHint>itFilter</mavenFilteringHint>
+ </mavenFilteringHints>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>@pom.version@</version>
+ <classifier>tests</classifier>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <escaped>this is escaped</escaped>
+ <escaped.at>this is escaped.at</escaped.at>
+ <foo>this is foo</foo>
+ <bar>this is bar</bar>
+ </properties>
</project>
Added: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties?rev=1000643&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties Thu Sep 23 21:50:36 2010
@@ -0,0 +1 @@
+toto=titi
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/test.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/verify.groovy?rev=1000643&r1=979417&r2=1000643&view=diff
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/verify.groovy (original)
+++ maven/plugins/trunk/maven-resources-plugin/src/it/user-filters/verify.groovy Thu Sep 23 21:50:36 2010
@@ -16,12 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
-assert new File(basedir, 'target/classes/filtered.properties').exists();
-assert new File(basedir, 'target/classes/unfiltered.properties').exists();
+assert new File(basedir, 'target/classes/foo.txt').exists();
-filteredContent = new File(basedir, 'target/classes/filtered.properties').text;
-assert filteredContent.contains( 'bar=this is bar');
-assert filteredContent.contains( 'escaped=${escaped}');
-assert filteredContent.contains( 'escaped.at=@escaped.at@');
+content = new File(basedir, 'target/classes/foo.txt').text;
+assert content.contains( 'foo');
+assert content.contains( 'version=1.0.16-SNAPSHOT');
+assert content.contains( 'toto=titi');
return true;
\ No newline at end of file
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=1000643&r1=1000642&r2=1000643&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 Sep 23 21:50:36 2010
@@ -27,6 +27,12 @@ import org.apache.maven.project.MavenPro
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.apache.maven.shared.filtering.MavenResourcesExecution;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
@@ -52,7 +58,8 @@ import java.util.List;
*
*/
public class ResourcesMojo
- extends AbstractMojo
+ extends AbstractMojo
+ implements Contextualizable
{
/**
@@ -201,6 +208,30 @@ public class ResourcesMojo
*/
protected boolean useDefaultDelimiters;
+ /**
+ * List of plexus components hint which implements {@link MavenResourcesFiltering#filterResources(MavenResourcesExecution)}
+ * @parameter
+ * @since 2.4
+ */
+ private List mavenFilteringHints;
+
+ /**
+ * @since 2.4
+ */
+ private PlexusContainer plexusContainer;
+
+ /**
+ * @since 2.4
+ */
+ private List mavenFilteringComponents = new ArrayList();
+
+ public void contextualize( Context context )
+ throws ContextException
+ {
+ getLog().debug( "execute contextualize" );
+ plexusContainer = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+ }
+
public void execute()
throws MojoExecutionException
{
@@ -263,6 +294,8 @@ public class ResourcesMojo
mavenResourcesExecution.setNonFilteredFileExtensions( nonFilteredFileExtensions );
}
mavenResourcesFiltering.filterResources( mavenResourcesExecution );
+
+ executeUserFilterComponents( mavenResourcesExecution );
}
catch ( MavenFilteringException e )
{
@@ -270,6 +303,44 @@ public class ResourcesMojo
}
}
+ /**
+ * @since 2.5
+ */
+ protected void executeUserFilterComponents(MavenResourcesExecution mavenResourcesExecution)
+ throws MojoExecutionException, MavenFilteringException
+ {
+
+ if (mavenFilteringHints != null)
+ {
+ for (Iterator ite = mavenFilteringHints.iterator();ite.hasNext();)
+ {
+ String hint = (String) ite.next();
+ try
+ {
+ mavenFilteringComponents.add( plexusContainer.lookup( MavenResourcesFiltering.class.getName(), hint ) );
+ }
+ catch ( ComponentLookupException e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ }
+ }
+ else
+ {
+ getLog().debug( "no use filter components" );
+ }
+
+ if (mavenFilteringComponents != null && !mavenFilteringComponents.isEmpty())
+ {
+ getLog().debug( "execute user filters" );
+ for(Iterator ite = mavenFilteringComponents.iterator();ite.hasNext();)
+ {
+ MavenResourcesFiltering filter = (MavenResourcesFiltering)ite.next();
+ filter.filterResources( mavenResourcesExecution );
+ }
+ }
+ }
+
protected List getCombinedFiltersList()
{
if ( filters == null || filters.isEmpty() )
Added: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java?rev=1000643&view=auto
==============================================================================
--- maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java (added)
+++ maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java Thu Sep 23 21:50:36 2010
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.resources.filters;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.filtering.MavenFilteringException;
+import org.apache.maven.shared.filtering.MavenResourcesExecution;
+import org.apache.maven.shared.filtering.MavenResourcesFiltering;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 2.5
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.shared.filtering.MavenResourcesFiltering"
+ * role-hint="itFilter"
+ */
+public class ItFilter
+ implements MavenResourcesFiltering
+{
+
+ /**
+ * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(java.util.List, java.io.File, org.apache.maven.project.MavenProject, java.lang.String, java.util.List, java.util.List, org.apache.maven.execution.MavenSession)
+ */
+ public void filterResources( List resources, File outputDirectory, MavenProject mavenProject, String encoding,
+ List fileFilters, List nonFilteredFileExtensions, MavenSession mavenSession )
+ throws MavenFilteringException
+ {
+ //no op
+ }
+
+ /**
+ * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(java.util.List, java.io.File, java.lang.String, java.util.List, java.io.File, java.util.List)
+ */
+ public void filterResources( List resources, File outputDirectory, String encoding, List filterWrappers,
+ File resourcesBaseDirectory, List nonFilteredFileExtensions )
+ throws MavenFilteringException
+ {
+ // no op
+ }
+
+ /**
+ * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#getDefaultNonFilteredFileExtensions()
+ */
+ public List getDefaultNonFilteredFileExtensions()
+ {
+ // no op
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filteredFileExtension(java.lang.String, java.util.List)
+ */
+ public boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions )
+ {
+ return false;
+ }
+
+ /**
+ * @see org.apache.maven.shared.filtering.MavenResourcesFiltering#filterResources(org.apache.maven.shared.filtering.MavenResourcesExecution)
+ */
+ public void filterResources( MavenResourcesExecution mavenResourcesExecution )
+ throws MavenFilteringException
+ {
+ System.out.println("ItFilter filterResources");
+ try
+ {
+ File f = new File( mavenResourcesExecution.getOutputDirectory(), "foo.txt" );
+ List lines = new ArrayList();
+
+ lines.add( "foo" );
+ lines.add( "version="+mavenResourcesExecution.getMavenProject().getVersion() );
+ lines.add( "toto=" + mavenResourcesExecution.getMavenSession().getExecutionProperties().getProperty( "toto" ) );
+ FileUtils.writeLines( f, lines );
+ }
+ catch ( IOException e )
+ {
+ throw new MavenFilteringException( e.getMessage(), e );
+ }
+
+ }
+
+}
Propchange: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-resources-plugin/src/test/java/org/apache/maven/plugin/resources/filters/ItFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision