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 0745def398b25bbcf62579f65da2e5e59b534179 Author: Michael Osipov <[email protected]> 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 f4b2c1d..752fdc8 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; @@ -942,20 +943,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; } @@ -1064,9 +1054,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
