Skip to content

Commit 8e0efaa

Browse files
committed
[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.
1 parent 5beb347 commit 8e0efaa

File tree

4 files changed

+49
-38
lines changed

4 files changed

+49
-38
lines changed

maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public Object getValue( String expression )
241241
{
242242
if ( projectDir != null && "baseUri".equals( expression ) )
243243
{
244-
return projectDir.getAbsoluteFile().toURI().toString();
244+
return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
245245
}
246246
return null;
247247
}

maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.eclipse.aether.DefaultRepositorySystemSession;
4040
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
4141
import org.eclipse.aether.repository.LocalRepository;
42+
import static org.junit.Assert.assertNotEquals;
4243

4344
public class PomConstructionTest
4445
extends PlexusTestCase
@@ -140,9 +141,9 @@ public void testPluginConfigProperties()
140141

141142
/*MNG-3900*/
142143
public void testProfilePropertiesInterpolation()
143-
throws Exception
144+
throws Exception
144145
{
145-
PomTestWrapper pom = buildPom( "profile-properties-interpolation", "interpolation-profile" );
146+
PomTestWrapper pom = buildPom( "profile-properties-interpolation", "interpolation-profile" );
146147
assertEquals( "PASSED", pom.getValue( "properties[1]/test" ) );
147148
assertEquals( "PASSED", pom.getValue( "properties[1]/property" ) );
148149
}
@@ -1082,11 +1083,21 @@ public void testXmlWhitespaceHandling()
10821083
}
10831084

10841085
/* MNG-3760*/
1085-
public void testInterpolationOfBaseUrl()
1086+
public void testInterpolationOfBaseUri()
1087+
throws Exception
1088+
{
1089+
PomTestWrapper pom = buildPom( "baseuri-interpolation/pom.xml" );
1090+
assertNotEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
1091+
}
1092+
1093+
/* MNG-6386 */
1094+
public void testInterpolationOfRfc3986BaseUri()
10861095
throws Exception
10871096
{
1088-
PomTestWrapper pom = buildPom( "baseurl-interpolation/pom.xml" );
1089-
assertEquals( pom.getBasedir().toURI().toString(), pom.getValue( "properties/prop1" ).toString() );
1097+
PomTestWrapper pom = buildPom( "baseuri-interpolation/pom.xml" );
1098+
String prop1 = pom.getValue( "properties/prop1" ).toString();
1099+
assertEquals( pom.getBasedir().toPath().toUri().toASCIIString(), prop1 );
1100+
assertTrue( prop1.startsWith( "file:///" ) );
10901101
}
10911102

10921103
/* MNG-3811*/
@@ -1103,9 +1114,9 @@ public void testReportingPluginConfig()
11031114
}
11041115

11051116
public void testPropertiesNoDuplication()
1106-
throws Exception
1117+
throws Exception
11071118
{
1108-
PomTestWrapper pom = buildPom( "properties-no-duplication/sub" );
1119+
PomTestWrapper pom = buildPom( "properties-no-duplication/sub" );
11091120
assertEquals( 1, ( (Properties) pom.getValue( "properties" ) ).size() );
11101121
assertEquals( "child", pom.getValue( "properties/pomProfile" ) );
11111122
}
@@ -1416,17 +1427,17 @@ public void testBuildExtensionInheritance()
14161427

14171428
/*MNG-1957*/
14181429
public void testJdkActivation()
1419-
throws Exception
1420-
{
1421-
Properties props = new Properties();
1430+
throws Exception
1431+
{
1432+
Properties props = new Properties();
14221433
props.put( "java.version", "1.5.0_15" );
14231434

14241435
PomTestWrapper pom = buildPom( "jdk-activation", props );
14251436
assertEquals( 3, pom.getMavenProject().getActiveProfiles().size() );
14261437
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty3" ) );
14271438
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty2" ) );
14281439
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty1" ) );
1429-
}
1440+
}
14301441

14311442
/* MNG-2174 */
14321443
public void testProfilePluginMngDependencies()
@@ -1464,54 +1475,54 @@ public void testPluginManagementInheritance()
14641475
}
14651476

14661477
public void testProfilePlugins()
1467-
throws Exception
1468-
{
1478+
throws Exception
1479+
{
14691480
PomTestWrapper pom = this.buildPom( "profile-plugins", "standard" );
14701481
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
14711482
assertEquals( "maven-assembly2-plugin", pom.getValue( "build/plugins[2]/artifactId" ) );
1472-
}
1483+
}
14731484

14741485
public void testPluginInheritanceSimple()
1475-
throws Exception
1476-
{
1486+
throws Exception
1487+
{
14771488
PomTestWrapper pom = this.buildPom( "plugin-inheritance-simple/sub" );
1478-
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
1479-
}
1489+
assertEquals( 2, ( (List<?>) pom.getValue( "build/plugins" ) ).size() );
1490+
}
14801491

14811492
public void testPluginManagementDuplicate()
1482-
throws Exception
1483-
{
1493+
throws Exception
1494+
{
14841495
PomTestWrapper pom = this.buildPom( "plugin-management-duplicate/sub" );
14851496
assertEquals( 12, ( (List<?>) pom.getValue( "build/pluginManagement/plugins" ) ).size() );
1486-
}
1497+
}
14871498

14881499
public void testDistributionManagement()
1489-
throws Exception
1490-
{
1500+
throws Exception
1501+
{
14911502
PomTestWrapper pom = this.buildPom( "distribution-management" );
14921503
assertEquals( "legacy", pom.getValue( "distributionManagement/repository/layout" ) );
1493-
}
1504+
}
14941505

14951506
public void testDependencyScopeInheritance()
1496-
throws Exception
1497-
{
1507+
throws Exception
1508+
{
14981509
PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" );
14991510
String scope = (String) pom.getValue( "dependencies[1]/scope" );
15001511
assertEquals( "compile", scope );
1501-
}
1512+
}
15021513

15031514
public void testDependencyScope()
1504-
throws Exception
1505-
{
1506-
buildPom( "dependency-scope/sub" );
1507-
}
1515+
throws Exception
1516+
{
1517+
buildPom( "dependency-scope/sub" );
1518+
}
15081519

15091520
//This will fail on a validation error if incorrect
15101521
public void testDependencyManagementWithInterpolation()
1511-
throws Exception
1512-
{
1513-
buildPom( "dependency-management-with-interpolation/sub" );
1514-
}
1522+
throws Exception
1523+
{
1524+
buildPom( "dependency-management-with-interpolation/sub" );
1525+
}
15151526

15161527
public void testInterpolationWithSystemProperty()
15171528
throws Exception

maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract class AbstractStringBasedModelInterpolator
6161
public static final String CHANGELIST_PROPERTY = "changelist";
6262

6363
public static final String REVISION_PROPERTY = "revision";
64-
64+
6565
private static final List<String> PROJECT_PREFIXES = Arrays.asList( "pom.", "project." );
6666

6767
private static final Collection<String> TRANSLATED_PATH_EXPRESSIONS;
@@ -158,7 +158,7 @@ public Object getValue( String expression )
158158
{
159159
if ( "baseUri".equals( expression ) )
160160
{
161-
return projectDir.getAbsoluteFile().toURI().toString();
161+
return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
162162
}
163163
return null;
164164
}

0 commit comments

Comments
 (0)