You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2009/03/27 22:52:08 UTC
svn commit: r759364 - in /maven/components/trunk:
maven-project-builder/src/main/java/org/apache/maven/project/processor/
maven-project/src/test/java/org/apache/maven/project/
maven-project/src/test/resources-project-builder/percent-encoded-url/
Author: sisbell
Date: Fri Mar 27 21:52:08 2009
New Revision: 759364
URL: http://svn.apache.org/viewvc?rev=759364&view=rev
Log:
[MNG-4087] decoding project urls.
Added:
maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/
maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/pom.xml
Modified:
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java
maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java
maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java?rev=759364&r1=759363&r2=759364&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/BaseProcessor.java Fri Mar 27 21:52:08 2009
@@ -20,8 +20,11 @@
*/
+import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -97,7 +100,22 @@
return parent;
}
- protected String normalizeUri(String u, String artifactId, Model parent)
+ protected String decodeUrl(String uri)
+ {
+ if(uri == null)
+ {
+ return null;
+ }
+
+ try {
+ return URLDecoder.decode(uri, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ return null;
+ }
+
+ }
+
+ protected String normalizeUriWithRelativePath(String u, String artifactId, Model parent)
{
if(u == null)
{
@@ -109,12 +127,12 @@
URI uri = new URI(u + "/"
+ getModulePathAdjustment(parent, artifactId));
- String normalized = uri.normalize().toString();
+ String normalized = uri.normalize().toASCIIString();
if("file".equals(uri.getScheme()))//UNC Paths
{
normalized = normalized.replaceFirst("/", slashes);
}
- return normalized;
+ return decodeUrl(normalized);
}
catch (URISyntaxException e) {
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java?rev=759364&r1=759363&r2=759364&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/DistributionManagementProcessor.java Fri Mar 27 21:52:08 2009
@@ -21,6 +21,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.DistributionManagement;
@@ -109,7 +110,7 @@
}
}
- private static void copyRepository( DeploymentRepository source, DeploymentRepository target )
+ private void copyRepository( DeploymentRepository source, DeploymentRepository target )
{
if ( target.getId() == null )
{
@@ -123,7 +124,7 @@
if ( target.getUrl() == null )
{
- target.setUrl( source.getUrl() );
+ target.setUrl( decodeUrl(source.getUrl()) );
}
if ( target.getName() == null )
@@ -150,16 +151,16 @@
{
if ( isChild )
{
- target.setUrl( source.getUrl() );
+ target.setUrl( decodeUrl(source.getUrl()) );
}
else
{
- target.setUrl(normalizeUri(source.getUrl(), artifactId, parent));
+ target.setUrl(normalizeUriWithRelativePath(source.getUrl(), artifactId, parent));
}
}
else
{
- target.setUrl( target.getUrl() + (target.getUrl().endsWith("/") ? "" : "/")+ artifactId );
+ target.setUrl( decodeUrl(target.getUrl() + (target.getUrl().endsWith("/") ? "" : "/")+ artifactId) );
}
}
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java?rev=759364&r1=759363&r2=759364&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ModelProcessor.java Fri Mar 27 21:52:08 2009
@@ -19,22 +19,15 @@
* under the License.
*/
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
-import org.apache.maven.shared.model.ModelProperty;
/*
* hold original pom
@@ -127,15 +120,15 @@
if ( c.getUrl() != null )
{
- t.setUrl(c.getUrl());
+ t.setUrl(decodeUrl(c.getUrl()));
}
else if(p != null && p.getUrl() != null)
{
- t.setUrl( normalizeUri(p.getUrl(), t.getArtifactId(), p) );
+ t.setUrl( normalizeUriWithRelativePath(p.getUrl(), t.getArtifactId(), p) );
}
else if (t.getUrl() != null)
{
- t.setUrl( t.getUrl() + "/" + t.getArtifactId() );
+ t.setUrl( decodeUrl(t.getUrl() + "/" + t.getArtifactId()) );
}
//Dependencies
Modified: maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java?rev=759364&r1=759363&r2=759364&view=diff
==============================================================================
--- maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java (original)
+++ maven/components/trunk/maven-project-builder/src/main/java/org/apache/maven/project/processor/ScmProcessor.java Fri Mar 27 21:52:08 2009
@@ -21,6 +21,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URLDecoder;
import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
@@ -48,14 +49,14 @@
{
if(c != null && c.getUrl() != null)
{
- t.setUrl(c.getUrl() );
+ t.setUrl(decodeUrl(c.getUrl()) );
}
else if(p != null && p.getUrl() != null)
{
- t.setUrl( normalizeUri(p.getUrl(), artifactId, parent));
+ t.setUrl( normalizeUriWithRelativePath(p.getUrl(), artifactId, parent));
}
else if(t.getUrl() != null) {
- t.setUrl( t.getUrl() + "/" + artifactId );
+ t.setUrl( decodeUrl(t.getUrl() + "/" + artifactId) );
}
}
@@ -63,14 +64,14 @@
{
if(c!= null && c.getConnection() != null)
{
- t.setConnection(c.getConnection());
+ t.setConnection(decodeUrl(c.getConnection()));
}
else if(p != null && p.getConnection() != null)
{
- t.setConnection( normalizeUri(p.getConnection(), artifactId, parent));
+ t.setConnection( normalizeUriWithRelativePath(p.getConnection(), artifactId, parent));
}
else if(t.getConnection() != null) {
- t.setConnection( t.getConnection() + "/" + artifactId );
+ t.setConnection( decodeUrl(t.getConnection() + "/" + artifactId) );
}
}
@@ -78,14 +79,14 @@
{
if(c!= null && c.getDeveloperConnection() != null)
{
- t.setDeveloperConnection(c.getDeveloperConnection());
+ t.setDeveloperConnection(decodeUrl(c.getDeveloperConnection()));
}
else if(p != null && p.getDeveloperConnection() != null)
{
- t.setDeveloperConnection( normalizeUri(p.getDeveloperConnection(), artifactId, parent) );
+ t.setDeveloperConnection( normalizeUriWithRelativePath(p.getDeveloperConnection(), artifactId, parent) );
}
else if(t.getDeveloperConnection() != null){
- t.setDeveloperConnection( t.getDeveloperConnection() + "/" + artifactId );
+ t.setDeveloperConnection( decodeUrl(t.getDeveloperConnection() + "/" + artifactId) );
}
}
Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=759364&r1=759363&r2=759364&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java (original)
+++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java Fri Mar 27 21:52:08 2009
@@ -922,13 +922,20 @@
throws Exception
{
PomTestWrapper pom = this.buildPom( "url-append/child" );
- System.out.println(pom.getDomainModel().asString());
assertEquals("http://project.url/child", pom.getValue( "url" ));
assertEquals("http://viewvc.project.url/child", pom.getValue( "scm/url" ));
assertEquals("http://scm.project.url/child", pom.getValue( "scm/connection" ));
assertEquals("https://scm.project.url/child", pom.getValue( "scm/developerConnection" ));
assertEquals("http://site.project.url/child", pom.getValue( "distributionManagement/site/url" ));
- }
+ }
+
+ /** MNG-4087 */
+ public void testPercentEncodedUrl()
+ throws Exception
+ {
+ PomTestWrapper pom = this.buildPom( "percent-encoded-url" );
+ assertEquals("@baseurl@/target/repo", pom.getValue( "distributionManagement/repository/url" ));
+ }
public void testPluginConfigurationUsingAttributesWithoutPluginManagement()
throws Exception
Added: maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/pom.xml
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/pom.xml?rev=759364&view=auto
==============================================================================
--- maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/pom.xml (added)
+++ maven/components/trunk/maven-project/src/test/resources-project-builder/percent-encoded-url/pom.xml Fri Mar 27 21:52:08 2009
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.mng4087</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>Maven Integration Test :: MNG-4087</name>
+ <description>
+ Test that deployment to a file:// repository decodes percent-encoded characters.
+ </description>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <!-- NOTE: The last URL part is intentionally percent-encoded and should be decoded to "repo" -->
+ <url>@baseurl@/target/%72%65%70%6F</url>
+ </repository>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.its.plugins</groupId>
+ <artifactId>maven-it-plugin-artifact</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ <configuration>
+ <mainFile>pom.xml</mainFile>
+ </configuration>
+ <executions>
+ <execution>
+ <id>test</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>set</goal>
+ <goal>install</goal>
+ <goal>deploy</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>