This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git
The following commit(s) were added to refs/heads/master by this push:
new 455d96c [MSHARED-1124] Add new version of methods filterFile and
newDefaultFilterMap
455d96c is described below
commit 455d96c190fc984b95f91fd3d15351575602a219
Author: Slawomir Jaranowski <[email protected]>
AuthorDate: Thu Sep 1 20:45:47 2022 +0200
[MSHARED-1124] Add new version of methods filterFile and newDefaultFilterMap
in order to easier migrate
---
.../org/apache/maven/shared/verifier/Verifier.java | 55 ++++++++++++++++++----
.../apache/maven/shared/verifier/VerifierTest.java | 12 +++++
2 files changed, 59 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/verifier/Verifier.java
b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
index 2229bd1..a478eec 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Verifier.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
@@ -950,6 +950,11 @@ public class Verifier
/**
* Filters a text file by replacing some user-defined tokens.
+ * This method is equivalent to:
+ *
+ * <pre>
+ * filterFile( srcPath, dstPath, fileEncoding,
verifier.newDefaultFilterMap() )
+ * </pre>
*
* @param srcPath The path to the input file, relative to the
base directory, must not be
* <code>null</code>.
@@ -957,21 +962,39 @@ public class Verifier
* input file, must not be <code>null</code>.
* @param fileEncoding The file encoding to use, may be
<code>null</code> or empty to use the platform's default
* encoding.
- * @param filterProperties The mapping from tokens to replacement values,
must not be <code>null</code>.
+ * @return The path to the filtered output file, never <code>null</code>.
+ * @throws IOException If the file could not be filtered.
+ * @since 2.0
+ */
+ public File filterFile( String srcPath, String dstPath, String
fileEncoding )
+ throws IOException
+ {
+ return filterFile( srcPath, dstPath, fileEncoding,
newDefaultFilterMap() );
+ }
+
+ /**
+ * Filters a text file by replacing some user-defined tokens.
+ *
+ * @param srcPath The path to the input file, relative to the base
directory, must not be
+ * <code>null</code>.
+ * @param dstPath The path to the output file, relative to the base
directory and possibly equal to the
+ * input file, must not be <code>null</code>.
+ * @param fileEncoding The file encoding to use, may be <code>null</code>
or empty to use the platform's default
+ * encoding.
+ * @param filterMap The mapping from tokens to replacement values, must
not be <code>null</code>.
* @return The path to the filtered output file, never <code>null</code>.
* @throws IOException If the file could not be filtered.
* @since 1.2
*/
- public File filterFile( String srcPath, String dstPath, String
fileEncoding, Map<String, String> filterProperties )
+ public File filterFile( String srcPath, String dstPath, String
fileEncoding, Map<String, String> filterMap )
throws IOException
{
File srcFile = new File( getBasedir(), srcPath );
String data = FileUtils.fileRead( srcFile, fileEncoding );
- for ( String token : filterProperties.keySet() )
+ for ( Map.Entry<String, String> entry : filterMap.entrySet() )
{
- String value = String.valueOf( filterProperties.get( token ) );
- data = StringUtils.replace( data, token, value );
+ data = StringUtils.replace( data, entry.getKey() ,
entry.getValue() );
}
File dstFile = new File( getBasedir(), dstPath );
@@ -1011,13 +1034,29 @@ public class Verifier
*
* @return The (modifiable) map with the default filter properties, never
<code>null</code>.
* @since 1.2
+ * @deprecated use {@link #newDefaultFilterMap()}
*/
+ @Deprecated
public Properties newDefaultFilterProperties()
{
Properties filterProperties = new Properties();
+ filterProperties.putAll( newDefaultFilterMap() );
+ return filterProperties;
+ }
+
+ /**
+ * Gets a new copy of the default filter map. These default filter map,
contains the tokens "@basedir@" and
+ * "@baseurl@" to the test's base directory and its base
<code>file:</code> URL, respectively.
+ *
+ * @return The (modifiable) map with the default filter map, never
<code>null</code>.
+ * @since 2.0
+ */
+ public Map<String, String> newDefaultFilterMap()
+ {
+ Map<String, String> filterMap = new HashMap<>();
String basedir = new File( getBasedir() ).getAbsolutePath();
- filterProperties.put( "@basedir@", basedir );
+ filterMap.put( "@basedir@", basedir );
/*
* NOTE: Maven fails to properly handle percent-encoded "file:" URLs
(WAGON-111) so don't use File.toURI() here
@@ -1029,9 +1068,9 @@ public class Verifier
baseurl = '/' + baseurl;
}
baseurl = "file://" + baseurl.replace( '\\', '/' );
- filterProperties.put( "@baseurl@", baseurl );
+ filterMap.put( "@baseurl@", baseurl );
- return filterProperties;
+ return filterMap;
}
/**
diff --git a/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
b/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
index d95356f..0531611 100644
--- a/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
+++ b/src/test/java/org/apache/maven/shared/verifier/VerifierTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
+import java.util.Map;
import java.util.Properties;
import org.junit.jupiter.api.Test;
@@ -32,6 +33,7 @@ import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class VerifierTest
{
@@ -118,4 +120,14 @@ public class VerifierTest
ForkedLauncherTest.expectFileLine( logFile, "Hello World from Maven
Home" );
}
+ @Test
+ void testDefaultFilterMap() throws VerificationException
+ {
+ Verifier verifier = new Verifier( "src/test/resources" );
+ Map<String, String> filterMap = verifier.newDefaultFilterMap();
+
+ assertEquals( 2, filterMap.size() );
+ assertTrue( filterMap.containsKey( "@basedir@" ) );
+ assertTrue( filterMap.containsKey( "@baseurl@" ) );
+ }
}