You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/09/22 20:25:29 UTC

[maven-verifier] 01/01: [MSHARED-1139] Calculate baseurl by means of Path and URI in Verifier#newDefaultFilterMap()/#verifyFilePresence()

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

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

commit 7eae6baf12db5900ff6ccb0dffc5b12163e58b33
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Sep 22 22:24:18 2022 +0200

    [MSHARED-1139] Calculate baseurl by means of Path and URI in Verifier#newDefaultFilterMap()/#verifyFilePresence()
---
 .../org/apache/maven/shared/verifier/Verifier.java | 23 +++++++---------------
 1 file changed, 7 insertions(+), 16 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 02035bd..39396e6 100644
--- a/src/main/java/org/apache/maven/shared/verifier/Verifier.java
+++ b/src/main/java/org/apache/maven/shared/verifier/Verifier.java
@@ -31,6 +31,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -868,20 +869,9 @@ public class Verifier
     {
         Map<String, String> filterMap = new HashMap<>();
 
-        String basedir = new File( getBasedir() ).getAbsolutePath();
-        filterMap.put( "@basedir@", basedir );
-
-        /*
-         * NOTE: Maven fails to properly handle percent-encoded "file:" URLs (WAGON-111) so don't use File.toURI() here
-         * and just do it the simple way.
-         */
-        String baseurl = basedir;
-        if ( !baseurl.startsWith( "/" ) )
-        {
-            baseurl = '/' + baseurl;
-        }
-        baseurl = "file://" + baseurl.replace( '\\', '/' );
-        filterMap.put( "@baseurl@", baseurl );
+        Path basedir = Paths.get( getBasedir() ).toAbsolutePath();
+        filterMap.put( "@basedir@", basedir.toString() );
+        filterMap.put( "@baseurl@", basedir.toUri().toASCIIString() );
 
         return filterMap;
     }
@@ -990,9 +980,10 @@ public class Verifier
     private void verifyFilePresence( String filePath, boolean wanted )
         throws VerificationException
     {
-        if ( filePath.indexOf( "!/" ) > 0 )
+        if ( filePath.contains( "!/" ) )
         {
-            String urlString = "jar:file:" + getBasedir() + "/" + filePath;
+            Path basedir = Paths.get( getBasedir() ).toAbsolutePath();
+            String urlString = "jar:" + basedir.toUri().toASCIIString() + "/" + filePath;
 
             InputStream is = null;
             try