Skip to content

Commit

Permalink
[MNG-6386] ${project.baseUri} is not a valid URI (according to RFC 3986)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michael-o committed May 7, 2018
1 parent 5beb347 commit 8e0efaa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public Object getValue( String expression )
{
if ( projectDir != null && "baseUri".equals( expression ) )
{
return projectDir.getAbsoluteFile().toURI().toString();
return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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
Expand Down Expand Up @@ -140,9 +141,9 @@ public void testPluginConfigProperties()

/*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" ) );
}
Expand Down Expand Up @@ -1082,11 +1083,21 @@ public void testXmlWhitespaceHandling()
}

/* 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*/
Expand All @@ -1103,9 +1114,9 @@ public void testReportingPluginConfig()
}

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" ) );
}
Expand Down Expand Up @@ -1416,17 +1427,17 @@ public void testBuildExtensionInheritance()

/*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 );
assertEquals( 3, pom.getMavenProject().getActiveProfiles().size() );
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty3" ) );
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty2" ) );
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty1" ) );
}
}

/* MNG-2174 */
public void testProfilePluginMngDependencies()
Expand Down Expand Up @@ -1464,54 +1475,54 @@ public void testPluginManagementInheritance()
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,7 +158,7 @@ public Object getValue( String expression )
{
if ( "baseUri".equals( expression ) )
{
return projectDir.getAbsoluteFile().toURI().toString();
return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString();
}
return null;
}
Expand Down

0 comments on commit 8e0efaa

Please sign in to comment.