You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/02/13 22:11:28 UTC
[maven-filtering] 18/44: update documentation merge duplicate code
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to annotated tag maven-filtering-1.0-alpha-1
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git
commit 9447d00a721cae20e62abed5fbd8bfd91dd8e39a
Author: Oliver Lamy <ol...@apache.org>
AuthorDate: Mon Feb 18 22:19:43 2008 +0000
update documentation
merge duplicate code
git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@628894 13f79535-47bb-0310-9956-ffa450edef68
---
.../shared/filtering/DefaultMavenFileFilter.java | 83 ++++++++--------------
.../maven/shared/filtering/MavenFileFilter.java | 1 -
.../shared/filtering/MavenResourcesFiltering.java | 14 ++--
.../maven/shared/filtering/PropertyUtils.java | 4 ++
src/site/apt/index.apt | 24 +++++--
5 files changed, 61 insertions(+), 65 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index bf7709b..a089ab9 100755
--- a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -87,69 +87,20 @@ public class DefaultMavenFileFilter
filterProperties.putAll( System.getProperties() );
// Project properties
- filterProperties.putAll( mavenProject.getProperties() == null ? Collections.EMPTY_MAP : mavenProject.getProperties() );
+ filterProperties.putAll( mavenProject.getProperties() == null ? Collections.EMPTY_MAP : mavenProject
+ .getProperties() );
// Take a copy of filterProperties to ensure that evaluated filterTokens are not propagated
// to subsequent filter files. NB this replicates current behaviour and seems to make sense.
final Properties baseProps = new Properties();
baseProps.putAll( filterProperties );
- if ( filters != null )
- {
- for ( Iterator i = filters.iterator(); i.hasNext(); )
- {
- String filterfile = (String) i.next();
- try
- {
- Properties properties = PropertyUtils.loadPropertyFile( new File( filterfile ), baseProps );
- filterProperties.putAll( properties );
- }
- catch ( IOException e )
- {
- throw new MavenFilteringException( "Error loading property file '" + filterfile + "'", e );
- }
- }
- }
-
- List buildFilters = mavenProject.getFilters();
- if ( buildFilters != null )
- {
- for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
- {
- String filterFile = (String) iterator.next();
- try
- {
+ loadProperties( filterProperties, filters, baseProps );
- Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
- filterProperties.putAll( properties );
- }
- catch ( IOException e )
- {
- throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
- }
- }
- }
+ loadProperties( filterProperties, mavenProject.getFilters(), baseProps );
- buildFilters = mavenProject.getBuild().getFilters();
- if ( buildFilters != null )
- {
- for ( Iterator iterator = buildFilters.iterator(); iterator.hasNext(); )
- {
- String filterFile = (String) iterator.next();
- try
- {
+ loadProperties( filterProperties, mavenProject.getBuild().getFilters(), baseProps );
- Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
- filterProperties.putAll( properties );
- }
- catch ( IOException e )
- {
- throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
- }
- }
- }
-
-
List defaultFilterWrappers = new ArrayList( 3 );
// support ${token}
@@ -181,10 +132,32 @@ public class DefaultMavenFileFilter
return new InterpolationFilterReader( reader, reflectionProperties, "${", "}" );
}
};
-
+
defaultFilterWrappers.add( third );
return defaultFilterWrappers;
}
+ private void loadProperties( Properties filterProperties, List /*String*/propertiesFilePaths, Properties baseProps )
+ throws MavenFilteringException
+ {
+ if ( propertiesFilePaths != null )
+ {
+ for ( Iterator iterator = propertiesFilePaths.iterator(); iterator.hasNext(); )
+ {
+ String filterFile = (String) iterator.next();
+ try
+ {
+ // TODO new File should be new File(mavenProject.getBasedir(), filterfile ) ?
+ Properties properties = PropertyUtils.loadPropertyFile( new File( filterFile ), baseProps );
+ filterProperties.putAll( properties );
+ }
+ catch ( IOException e )
+ {
+ throw new MavenFilteringException( "Error loading property file '" + filterFile + "'", e );
+ }
+ }
+ }
+ }
+
}
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index a1f8c81..8c17c08 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -20,7 +20,6 @@ package org.apache.maven.shared.filtering;
*/
import java.io.File;
-import java.io.IOException;
import java.util.List;
import org.apache.maven.project.MavenProject;
diff --git a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
index 843ed86..498b936 100755
--- a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java
@@ -35,8 +35,8 @@ public interface MavenResourcesFiltering
/**
* @param resources {@link List} of {@link org.apache.maven.model.Resource}
* @param outputDirectory parent destination directory
- * @param mavenProject
- * @param encoding
+ * @param mavenProject the maven project
+ * @param encoding encoding to use for writing files
* @param fileFilters {@link List} of String which are path to a Property file
* @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
* @throws MavenFilteringException
@@ -48,7 +48,7 @@ public interface MavenResourcesFiltering
/**
* @param resources {@link List} of {@link org.apache.maven.model.Resource}
* @param outputDirectory parent destination directory
- * @param encoding
+ * @param encoding encoding to use for writing files
* @param filterWrappers {@link List} of FileUtils.FilterWrapper
* @param resourcesBaseDirectory baseDirectory of resources
* @param nonFilteredFileExtensions {@link List} of String for non filtered file extensions
@@ -62,7 +62,13 @@ public interface MavenResourcesFiltering
* return the List of the non filtered extensions (jpg,jpeg,gif,bmp,png)
* @return {@link List} of {@link String}
*/
- public List getDefaultNonFilteredFileExtensions();
+ List getDefaultNonFilteredFileExtensions();
+ /**
+ * @param fileName the file name
+ * @param userNonFilteredFileExtensions an extra list of file extensions
+ * @return true if filtering can be apply to the file (means extensions.lowerCase is in the
+ * default List or in the user defined extension List)
+ */
boolean filteredFileExtension( String fileName, List userNonFilteredFileExtensions );
}
diff --git a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
index 8e7ada0..8dff312 100755
--- a/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java
@@ -106,6 +106,7 @@ public final class PropertyUtils
* @param fail wheter to throw an exception when the file cannot be loaded or to return null
* @param useSystemProps wheter to incorporate System.getProperties settings into the returned Properties object.
* @return the loaded and fully resolved Properties object
+ * @throws IOException if profile does not exist, or cannot be read.
*/
public static Properties loadPropertyFile( File propfile, boolean fail, boolean useSystemProps )
throws IOException
@@ -149,6 +150,9 @@ public final class PropertyUtils
* the value of a property contains a key), and will
* not loop endlessly on a pair like
* test = ${test}.
+ * @param k
+ * @param p
+ * @return
*/
private static String getPropertyValue( String k, Properties p )
{
diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt
index 5a1354c..709d13d 100755
--- a/src/site/apt/index.apt
+++ b/src/site/apt/index.apt
@@ -25,14 +25,17 @@
Maven Filtering Component
- This Plexus components has been build with the filtering process coming from the maven-resources-plugin.
+ This Plexus components has been build with the filtering process/code coming from the maven-resources-plugin.
The goal is to provide a common way for all plugins which needs to filtering resources.
* Component MavenResourcesFiltering
This component will apply filtering on a List of org.apache.maven.model.Resource.
- The method without the filterWrappers parameter will interpolate the files using the default FileUtils.FilterWrapper.
+
+ The method without the filterWrappers parameter will interpolate the files using the default List of FileUtils.FilterWrapper (see above).
+
+ The component will not filtering some predefined file extensions (jpg,jpeg,gif,bmp,png). Note : you can easily add extra file extensions.
* Component MavenFileFilter
@@ -47,6 +50,17 @@ Maven Filtering Component
[]
- <<NOTE>> : The sentence "values from SystemProps, project.properties, filters, project.filters and project.build.filters"
- means pairs of key/value will be loaded/overriding with this order. The value for key java.version can be overriding
- with a property in the maven project (yes crazy but possible).
\ No newline at end of file
+ The values (Properties object) used for interpolation are loaded with the following order :
+
+ * System Properties
+
+ * List of properties ( the method has a parameter which accept a List of String -> path properties files )
+
+ * pom.filters
+
+ * pom.build.filters
+
+ []
+
+ <<NOTE>> : As it's a Properties object, last defined key/value pair wins .
+ The value for key java.version can be overriding with a property in the maven project (yes crazy but possible).
\ No newline at end of file