mirror of https://github.com/apache/maven.git
PR: MNG-788
add filtering to the build element git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@290877 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4248472d6
commit
cbcf2d48e1
|
@ -150,6 +150,8 @@ it0053: Test that attached artifacts have the same buildnumber and timestamp
|
|||
as the main artifact. This will not correctly verify until we have
|
||||
some way to pattern-match the buildnumber/timestamp...
|
||||
|
||||
it0054: Test resource filtering.
|
||||
|
||||
it0055: Test that source includes/excludes with in the compiler plugin config.
|
||||
This will test excludes and testExcludes...
|
||||
|
||||
|
@ -191,7 +193,6 @@ it0067: Test activation of a profile from the command line.
|
|||
- generated sources
|
||||
- generated resources from sources
|
||||
- generated resources from generated sources
|
||||
- filtered resources
|
||||
- build that requires a plugin download
|
||||
- transitive dependencies
|
||||
- goal attainment not requiring depedency resolution
|
||||
|
|
|
@ -11,6 +11,7 @@ it0058
|
|||
it0057
|
||||
it0056
|
||||
it0055
|
||||
it0054
|
||||
it0053
|
||||
it0052
|
||||
it0051
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
target/classes/org/apache/maven/it0054/Person.class
|
||||
target/test-classes/org/apache/maven/it0054/PersonTest.class
|
||||
target/maven-core-it0054-1.0.jar
|
||||
target/maven-core-it0054-1.0.jar!/it0054.properties
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,27 @@
|
|||
<model>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core-it0054</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<filters>
|
||||
<filter>src/main/filters/filters.properties</filter>
|
||||
</filters>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</model>
|
|
@ -0,0 +1,2 @@
|
|||
surname = van zyl
|
||||
country = Canada
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0054;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
name = jason
|
||||
surname = ${surname}
|
||||
country = @country@
|
|
@ -0,0 +1,24 @@
|
|||
package org.apache.maven.it0054;
|
||||
|
||||
import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
throws Exception
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
|
||||
Properties p = new Properties();
|
||||
p.load( getClass().getResourceAsStream( "/it0054.properties" ) );
|
||||
assertEquals( "check name", "jason", p.getProperty( "name" ) );
|
||||
assertEquals( "check surname", "van zyl", p.getProperty( "surname" ) );
|
||||
assertEquals( "check country", "Canada", p.getProperty( "country" ) );
|
||||
}
|
||||
}
|
|
@ -856,6 +856,17 @@
|
|||
]]></description>
|
||||
<type>String</type>
|
||||
</field>
|
||||
<field>
|
||||
<name>filters</name>
|
||||
<version>4.0.0</version>
|
||||
<description><![CDATA[
|
||||
The list of filter properties files that are used when filtering is enabled.
|
||||
]]></description>
|
||||
<association>
|
||||
<type>String</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
<class>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<artifactId>maven-plugin-parent</artifactId>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<version>2.0-beta-1</version>
|
||||
<version>2.0-beta-2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
<packaging>maven-plugin</packaging>
|
||||
<name>Maven Resources Plugin</name>
|
||||
<version>2.0-beta-2-SNAPSHOT</version>
|
||||
<prerequisites>
|
||||
<maven>2.0-beta-2-SNAPSHOT</maven>
|
||||
</prerequisites>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
|
@ -22,7 +25,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
<version>2.0-beta-1</version>
|
||||
<version>2.0-beta-2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -69,13 +69,15 @@ public class ResourcesMojo
|
|||
* Wheter to apply filters during transfer.
|
||||
*
|
||||
* @parameter
|
||||
* @deprecated
|
||||
*/
|
||||
private boolean filtering = false;
|
||||
private boolean filtering = true;
|
||||
|
||||
/**
|
||||
* The name of the filter property file to use.
|
||||
*
|
||||
* @parameter expression="${basedir}/filter.properties"
|
||||
* @deprecated use the filters section of the POM.
|
||||
*/
|
||||
private File filterPropertiesFile;
|
||||
|
||||
|
@ -92,6 +94,11 @@ public class ResourcesMojo
|
|||
|
||||
private static final String[] DEFAULT_INCLUDES = {"**/**"};
|
||||
|
||||
/**
|
||||
* @parameter expression="${project.build.filters}"
|
||||
*/
|
||||
private List filters;
|
||||
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
|
@ -173,13 +180,34 @@ public class ResourcesMojo
|
|||
{
|
||||
if ( filtering )
|
||||
{
|
||||
try
|
||||
if ( filters == null || filters.isEmpty() && filterPropertiesFile.exists() )
|
||||
{
|
||||
filterProperties = PropertyUtils.loadPropertyFile( filterPropertiesFile, true, true );
|
||||
// Deprecated - remove
|
||||
try
|
||||
{
|
||||
filterProperties = PropertyUtils.loadPropertyFile( filterPropertiesFile, true, true );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error loading property file '" + filterPropertiesFile + "'", e );
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
else
|
||||
{
|
||||
throw new MojoExecutionException( "Error loading property file '" + filterPropertiesFile + "'", e );
|
||||
filterProperties = new Properties();
|
||||
for ( Iterator i = filters.iterator(); i.hasNext(); )
|
||||
{
|
||||
String filtersfile = (String) i.next();
|
||||
try
|
||||
{
|
||||
Properties properties = PropertyUtils.loadPropertyFile( new File( filtersfile ), true, true );
|
||||
filterProperties.putAll( properties );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error loading property file '" + filtersfile + "'", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1440,4 +1440,8 @@ public class MavenProject
|
|||
return getModel().getProperties();
|
||||
}
|
||||
|
||||
public List getFilters()
|
||||
{
|
||||
return getBuild().getFilters();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,18 @@ public class DefaultProfileInjector
|
|||
modelBuild.setTestResources( profileTestResources );
|
||||
}
|
||||
|
||||
if ( profileBuild.getFilters() != null )
|
||||
{
|
||||
if ( modelBuild.getFilters() == null )
|
||||
{
|
||||
modelBuild.setFilters( profileBuild.getFilters() );
|
||||
}
|
||||
else
|
||||
{
|
||||
modelBuild.getFilters().addAll( profileBuild.getFilters() );
|
||||
}
|
||||
}
|
||||
|
||||
injectPlugins( profileBuild, modelBuild );
|
||||
|
||||
// Plugin management :: aggregate
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
package org.apache.maven.project.overlay;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.model.Build;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -10,6 +26,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @todo why delegate? this is asking for trouble when there are additions.
|
||||
*/
|
||||
public class BuildOverlay
|
||||
extends Build
|
||||
{
|
||||
|
@ -234,4 +253,23 @@ public class BuildOverlay
|
|||
return build.toString();
|
||||
}
|
||||
|
||||
public void addFilter( String string )
|
||||
{
|
||||
build.addFilter( string );
|
||||
} //-- void addFilter(String)
|
||||
|
||||
public List getFilters()
|
||||
{
|
||||
return build.getFilters();
|
||||
} //-- java.util.List getFilters()
|
||||
|
||||
public void removeFilter( String string )
|
||||
{
|
||||
build.removeFilter( string );
|
||||
} //-- void removeFilter(String)
|
||||
|
||||
public void setFilters( List filters )
|
||||
{
|
||||
build.setFilters( filters );
|
||||
} //-- void setFilters(java.util.List)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ import org.apache.maven.model.Resource;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DefaultPathTranslator
|
||||
implements PathTranslator
|
||||
|
@ -56,6 +58,18 @@ public class DefaultPathTranslator
|
|||
resource.setDirectory( alignToBaseDirectory( resource.getDirectory(), basedir ) );
|
||||
}
|
||||
|
||||
if ( build.getFilters() != null )
|
||||
{
|
||||
List filters = new ArrayList();
|
||||
for ( Iterator i = build.getFilters().iterator(); i.hasNext(); )
|
||||
{
|
||||
String filter = (String) i.next();
|
||||
|
||||
filters.add( alignToBaseDirectory( filter, basedir ) );
|
||||
}
|
||||
build.setFilters( filters );
|
||||
}
|
||||
|
||||
build.setOutputDirectory( alignToBaseDirectory( build.getOutputDirectory(), basedir ) );
|
||||
|
||||
build.setTestOutputDirectory( alignToBaseDirectory( build.getTestOutputDirectory(), basedir ) );
|
||||
|
|
Loading…
Reference in New Issue