You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/09/01 18:47:49 UTC

[maven-verifier] branch MSHARED-1124 updated (ea1ee9d -> da29bf0)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MSHARED-1124
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git


 discard ea1ee9d  [MSHARED-1124] Add new version of methods filterFile and newDefaultFilterMap
     new da29bf0  [MSHARED-1124] Add new version of methods filterFile and newDefaultFilterMap

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ea1ee9d)
            \
             N -- N -- N   refs/heads/MSHARED-1124 (da29bf0)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/test/java/org/apache/maven/shared/verifier/VerifierTest.java | 2 --
 1 file changed, 2 deletions(-)


[maven-verifier] 01/01: [MSHARED-1124] Add new version of methods filterFile and newDefaultFilterMap

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MSHARED-1124
in repository https://gitbox.apache.org/repos/asf/maven-verifier.git

commit da29bf042f8cff3e8928489d6adebccd6de150ca
Author: Slawomir Jaranowski <s....@gmail.com>
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@" ) );
+    }
 }