From 0cf64817f95e6b5d545ac310f53502ef815f0811 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Thu, 3 May 2018 23:01:45 +0200 Subject: [PATCH] [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. --- .../apache/maven/it/IntegrationTestSuite.java | 1 + .../it/MavenITmng3760BaseUriPropertyTest.java | 2 +- .../it/MavenITmng6386BaseUriPropertyTest.java | 100 ++++++++++++++++++ .../resources/mng-6386-это по-русский/pom.xml | 61 +++++++++++ .../src/test/resources/mng-6386/pom.xml | 61 +++++++++++ 5 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6386BaseUriPropertyTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-6386-это по-русский/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-6386/pom.xml diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index ca46e3a330..9dcef0b2c0 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -106,6 +106,7 @@ public class IntegrationTestSuite // ------------------------------------------------------------------------------------------------------------- // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137 + suite.addTestSuite( MavenITmng6386BaseUriPropertyTest.class ); suite.addTestSuite( MavenITmng6330RelativePath.class ); suite.addTestSuite( MavenITmng6240PluginExtensionAetherProvider.class ); suite.addTestSuite( MavenITmng6223FindBasedir.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3760BaseUriPropertyTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3760BaseUriPropertyTest.java index 4e42ce6f5e..41163308df 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3760BaseUriPropertyTest.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3760BaseUriPropertyTest.java @@ -37,7 +37,7 @@ public class MavenITmng3760BaseUriPropertyTest public MavenITmng3760BaseUriPropertyTest() { - super( "(2.1.0-M1,3.0-alpha-1),(3.0-alpha-2,)" ); // 2.1.0-M2+ + super( "(2.1.0-M1,3.0-alpha-1),(3.0-alpha-2,3.5.4)" ); // 2.1.0-M2+ } public void testitMNG3760() diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6386BaseUriPropertyTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6386BaseUriPropertyTest.java new file mode 100644 index 0000000000..3214ce6f9a --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6386BaseUriPropertyTest.java @@ -0,0 +1,100 @@ +package org.apache.maven.it; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.util.Properties; + +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.ResourceExtractor; +import org.apache.maven.shared.utils.Os; + +/** + * This is a test set for MNG-6386. + */ +public class MavenITmng6386BaseUriPropertyTest + extends AbstractMavenIntegrationTestCase +{ + + public MavenITmng6386BaseUriPropertyTest() + { + super( "[3.5.4,)" ); + } + + public void testitMNG6386() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6386" ).getCanonicalFile(); + + Verifier verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.setLogFileName( "log-basic.txt" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + Properties props = verifier.loadProperties( "target/profile.properties" ); + String pomProperty = props.getProperty( "project.properties.pomProperty" ); + // set via project + assertEquals( testDir.toPath().toUri().toASCIIString(), pomProperty ); + // check that baseUri begins with file:/// + assertTrue( pomProperty.startsWith( "file:///" ) ); + } + + public void testitMNG6386UnicodeChars() + throws Exception + { + String fileEncoding = System.getProperty( "file.encoding" ); + /* + * Unfortunately, AbstractMavenIntegrationTestCase still uses JUnit 3.8 which does not have + * Assume, so we cannot make assumptions and skip the test on non-compatible systems. + */ + if ( Os.isFamily( Os.FAMILY_WINDOWS ) || + "UTF-8".equalsIgnoreCase( fileEncoding ) || "UTF8".equalsIgnoreCase( fileEncoding ) ) + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6386-это по-русский" ).getCanonicalFile(); + + Verifier verifier = newVerifier( testDir.getAbsolutePath() ); + verifier.setAutoclean( false ); + verifier.deleteDirectory( "target" ); + verifier.setLogFileName( "log-basic.txt" ); + verifier.executeGoal( "validate" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + Properties props = verifier.loadProperties( "target/profile.properties" ); + String pomProperty = props.getProperty( "project.properties.pomProperty" ); + // set via project + assertEquals( testDir.toPath().toUri().toASCIIString(), pomProperty ); + // check that baseUri begins with file:/// + assertTrue( pomProperty.startsWith( "file:///" ) ); + // check that baseUri ends with это по-русский/ + assertTrue( pomProperty.endsWith( "%D1%8D%D1%82%D0%BE%20%D0%BF%D0%BE-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9/" ) ); + } + else + { + System.out.println(); + System.out.println( "[WARNING] Skipping MNG-6386 Unicode Chars Test on incompatible encoding: " + fileEncoding ); + System.out.println(); + } + } + +} diff --git a/its/core-it-suite/src/test/resources/mng-6386-это по-русский/pom.xml b/its/core-it-suite/src/test/resources/mng-6386-это по-русский/pom.xml new file mode 100644 index 0000000000..fe7dacf5b0 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6386-это по-русский/pom.xml @@ -0,0 +1,61 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng6386 + child + 0.1 + + Maven Integration Test :: MNG-6386 (Unicode Chars) + + Test project.baseUri property (RFC 3986 compliance). + + + + + + org.apache.maven.its.plugins + maven-it-plugin-expression + 2.1-SNAPSHOT + + + validate + + eval + + + target/profile.properties + + project/properties + + + + + + + + + + ${project.baseUri} + + diff --git a/its/core-it-suite/src/test/resources/mng-6386/pom.xml b/its/core-it-suite/src/test/resources/mng-6386/pom.xml new file mode 100644 index 0000000000..8ecb6012c9 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6386/pom.xml @@ -0,0 +1,61 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng6386 + child + 0.1 + + Maven Integration Test :: MNG-6386 + + Test project.baseUri property (RFC 3986 compliance). + + + + + + org.apache.maven.its.plugins + maven-it-plugin-expression + 2.1-SNAPSHOT + + + validate + + eval + + + target/profile.properties + + project/properties + + + + + + + + + + ${project.baseUri} + +