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 2018/05/02 22:44:08 UTC

[maven] 01/01: [MNG-6386] ${project.baseUri} is not a valid URI (according to RFC 3986)

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

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

commit 9d29bb4d91e9545a9b5bc2957646ad42d5add210
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Fri Mar 30 22:07:18 2018 +0200

    [MNG-6386] ${project.baseUri} is not a valid URI (according to RFC 3986)
    
    File#toURI()#toString() produces a non-compliant URI making tools like
    Subversion or Git to choke on those URIs. Whereas Path#toUri()#toASCIIString()
    does the right job.
---
 .../AbstractStringBasedModelInterpolator.java      |  2 +-
 .../apache/maven/project/PomConstructionTest.java  | 81 ++++++++++++----------
 .../pom.xml                                        |  0
 .../AbstractStringBasedModelInterpolator.java      |  4 +-
 4 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java
index 913e2dd..996baef 100644
--- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java
+++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java
@@ -241,7 +241,7 @@ public abstract class AbstractStringBasedModelInterpolator
             {
                 if ( projectDir != null && "baseUri".equals( expression ) )
                 {
-                    return projectDir.getAbsoluteFile().toURI().toString();
+                    return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
                 }
                 return null;
             }
diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
index ba5e3a0..33b8968 100644
--- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
+++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
@@ -39,6 +39,7 @@ import org.codehaus.plexus.PlexusTestCase;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
 import org.eclipse.aether.repository.LocalRepository;
+import static org.junit.Assert.assertNotEquals;
 
 public class PomConstructionTest
     extends PlexusTestCase
@@ -140,9 +141,9 @@ public class PomConstructionTest
 
     /*MNG-3900*/
     public void testProfilePropertiesInterpolation()
-    	throws Exception
+        throws Exception
     {
-    	PomTestWrapper pom = buildPom( "profile-properties-interpolation", "interpolation-profile" );
+        PomTestWrapper pom = buildPom( "profile-properties-interpolation", "interpolation-profile" );
         assertEquals( "PASSED", pom.getValue( "properties[1]/test" ) );
         assertEquals( "PASSED", pom.getValue( "properties[1]/property" ) );
     }
@@ -1082,11 +1083,21 @@ public class PomConstructionTest
     }
 
     /* MNG-3760*/
-    public void testInterpolationOfBaseUrl()
+    public void testInterpolationOfBaseUri()
+        throws Exception
+    {
+        PomTestWrapper pom = buildPom( "baseuri-interpolation/pom.xml" );
+        assertNotEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
+    }
+
+    /* MNG-6386 */
+    public void testInterpolationOfRfc3986BaseUri()
         throws Exception
     {
-        PomTestWrapper pom = buildPom( "baseurl-interpolation/pom.xml" );
-        assertEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
+        PomTestWrapper pom = buildPom( "baseuri-interpolation/pom.xml" );
+        String prop1 = pom.getValue( "properties/prop1" ).toString();
+        assertEquals( pom.getBasedir().toPath().toUri().toASCIIString(), prop1 );
+        assertTrue( prop1.startsWith( "file:///" ) );
     }
 
     /* MNG-3811*/
@@ -1103,9 +1114,9 @@ public class PomConstructionTest
     }
 
     public void testPropertiesNoDuplication()
-    	throws Exception
+        throws Exception
     {
-    	PomTestWrapper pom = buildPom( "properties-no-duplication/sub" );	
+        PomTestWrapper pom = buildPom( "properties-no-duplication/sub" );
         assertEquals( 1, ( (Properties) pom.getValue( "properties" ) ).size() );
         assertEquals( "child", pom.getValue( "properties/pomProfile" ) );
     }
@@ -1416,9 +1427,9 @@ public class PomConstructionTest
 
     /*MNG-1957*/
     public void testJdkActivation()
-    	throws Exception
-	{
-    	Properties props = new Properties();
+        throws Exception
+    {
+        Properties props = new Properties();
         props.put( "java.version", "1.5.0_15" );
 
         PomTestWrapper pom = buildPom( "jdk-activation", props );
@@ -1426,7 +1437,7 @@ public class PomConstructionTest
         assertEquals( "PASSED", pom.getValue( "properties/jdkProperty3" ) );
         assertEquals( "PASSED", pom.getValue( "properties/jdkProperty2" ) );
         assertEquals( "PASSED", pom.getValue( "properties/jdkProperty1" ) );
-	}
+    }
 
     /* MNG-2174 */
     public void testProfilePluginMngDependencies()
@@ -1464,54 +1475,54 @@ public class PomConstructionTest
     }
 
     public void testProfilePlugins()
-	    throws Exception
-	{
+        throws Exception
+    {
         PomTestWrapper pom = this.buildPom( "profile-plugins", "standard" );
         assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
         assertEquals( "maven-assembly2-plugin", pom.getValue( "build/plugins[2]/artifactId" ) );
-	}
+    }
 
     public void testPluginInheritanceSimple()
-	    throws Exception
-	{
+        throws Exception
+    {
         PomTestWrapper pom = this.buildPom( "plugin-inheritance-simple/sub" );
-	    assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
-	}
+        assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
+    }
 
     public void testPluginManagementDuplicate()
-	    throws Exception
-	{
+        throws Exception
+    {
         PomTestWrapper pom = this.buildPom( "plugin-management-duplicate/sub" );
         assertEquals( 12, ( (List<?>) pom.getValue( "build/pluginManagement/plugins" ) ).size() );
-	}
+    }
 
     public void testDistributionManagement()
-	    throws Exception
-	{
+        throws Exception
+    {
         PomTestWrapper pom = this.buildPom( "distribution-management" );
         assertEquals( "legacy", pom.getValue( "distributionManagement/repository/layout" ) );
-	}
+    }
 
     public void testDependencyScopeInheritance()
-	    throws Exception
-	{
+        throws Exception
+    {
         PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" );
         String scope = (String) pom.getValue( "dependencies[1]/scope" );
         assertEquals( "compile", scope );
-	}
+    }
 
     public void testDependencyScope()
-	    throws Exception
-	{
-	    buildPom( "dependency-scope/sub" );
-	}
+        throws Exception
+    {
+        buildPom( "dependency-scope/sub" );
+    }
 
     //This will fail on a validation error if incorrect
     public void testDependencyManagementWithInterpolation()
-	    throws Exception
-	{
-	    buildPom( "dependency-management-with-interpolation/sub" );
-	}
+        throws Exception
+    {
+        buildPom( "dependency-management-with-interpolation/sub" );
+    }
 
     public void testInterpolationWithSystemProperty()
         throws Exception
diff --git a/maven-core/src/test/resources-project-builder/baseurl-interpolation/pom.xml b/maven-core/src/test/resources-project-builder/baseuri-interpolation/pom.xml
similarity index 100%
rename from maven-core/src/test/resources-project-builder/baseurl-interpolation/pom.xml
rename to maven-core/src/test/resources-project-builder/baseuri-interpolation/pom.xml
diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java
index ae8a35e..0322f89 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java
@@ -61,7 +61,7 @@ public abstract class AbstractStringBasedModelInterpolator
     public static final String CHANGELIST_PROPERTY = "changelist";
 
     public static final String REVISION_PROPERTY = "revision";
-    
+
     private static final List<String> PROJECT_PREFIXES = Arrays.asList( "pom.", "project." );
 
     private static final Collection<String> TRANSLATED_PATH_EXPRESSIONS;
@@ -158,7 +158,7 @@ public abstract class AbstractStringBasedModelInterpolator
                 {
                     if ( "baseUri".equals( expression ) )
                     {
-                        return projectDir.getAbsoluteFile().toURI().toString();
+                        return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
                     }
                     return null;
                 }

-- 
To stop receiving notification emails like this one, please contact
michaelo@apache.org.