You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2010/04/03 00:07:05 UTC
svn commit: r930411 - in /maven/maven-3/trunk:
maven-core/src/test/java/org/apache/maven/project/
maven-core/src/test/resources-project-builder/unc-path/
maven-core/src/test/resources-project-builder/url-inheritance/
maven-model-builder/src/main/java/o...
Author: bentmann
Date: Fri Apr 2 22:07:04 2010
New Revision: 930411
URL: http://svn.apache.org/viewvc?rev=930411&view=rev
Log:
[MNG-3133] DefaultModelInheritence::appendPath assumes it is operating on interpolated/literal paths
Added:
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java (with props)
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java (with props)
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java (with props)
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java (with props)
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java (with props)
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/ (with props)
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java (with props)
Modified:
maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
maven/maven-3/trunk/maven-core/src/test/resources-project-builder/unc-path/pom.xml
maven/maven-3/trunk/maven-core/src/test/resources-project-builder/url-inheritance/pom.xml
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/PathTranslatingPostProcessor.java
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java
Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java (original)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java Fri Apr 2 22:07:04 2010
@@ -600,7 +600,7 @@ public class PomConstructionTest
{
PomTestWrapper pom = buildPom( "url-inheritance/sub" );
assertEquals( "http://parent.url/child", pom.getValue( "url" ) );
- assertEquals( "http://parent.url/org/", pom.getValue( "organization/url" ) );
+ assertEquals( "http://parent.url/org", pom.getValue( "organization/url" ) );
assertEquals( "http://parent.url/license.txt", pom.getValue( "licenses[1]/url" ) );
assertEquals( "http://parent.url/viewvc/child", pom.getValue( "scm/url" ) );
assertEquals( "http://parent.url/scm/child", pom.getValue( "scm/connection" ) );
@@ -619,7 +619,7 @@ public class PomConstructionTest
{
PomTestWrapper pom = buildPom( "url-inheritance/another-parent/sub" );
assertEquals( "http://parent.url/ap/child", pom.getValue( "url" ) );
- assertEquals( "http://parent.url/org/", pom.getValue( "organization/url" ) );
+ assertEquals( "http://parent.url/org", pom.getValue( "organization/url" ) );
assertEquals( "http://parent.url/license.txt", pom.getValue( "licenses[1]/url" ) );
assertEquals( "http://parent.url/viewvc/ap/child", pom.getValue( "scm/url" ) );
assertEquals( "http://parent.url/scm/ap/child", pom.getValue( "scm/connection" ) );
Modified: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/unc-path/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/resources-project-builder/unc-path/pom.xml?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/resources-project-builder/unc-path/pom.xml (original)
+++ maven/maven-3/trunk/maven-core/src/test/resources-project-builder/unc-path/pom.xml Fri Apr 2 22:07:04 2010
@@ -35,7 +35,7 @@
<distributionManagement>
<site>
<id>site</id>
- <url>file:////host/site/</url>
+ <url>file:////host/site</url>
</site>
</distributionManagement>
</project>
Modified: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/url-inheritance/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/resources-project-builder/url-inheritance/pom.xml?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/resources-project-builder/url-inheritance/pom.xml (original)
+++ maven/maven-3/trunk/maven-core/src/test/resources-project-builder/url-inheritance/pom.xml Fri Apr 2 22:07:04 2010
@@ -32,10 +32,10 @@ under the License.
Test that inheritance of certain URLs automatically appends the child's artifact id.
</description>
- <url>http://parent.url/</url>
+ <url>http://parent.url</url>
<organization>
<name>parent-org</name>
- <url>http://parent.url/org/</url>
+ <url>http://parent.url/org</url>
</organization>
<licenses>
<license>
Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java Fri Apr 2 22:07:04 2010
@@ -45,6 +45,7 @@ import org.apache.maven.model.management
import org.apache.maven.model.management.PluginManagementInjector;
import org.apache.maven.model.normalization.ModelNormalizer;
import org.apache.maven.model.path.ModelPathTranslator;
+import org.apache.maven.model.path.ModelUrlNormalizer;
import org.apache.maven.model.plugin.LifecycleBindingsInjector;
import org.apache.maven.model.plugin.PluginConfigurationExpander;
import org.apache.maven.model.plugin.ReportConfigurationExpander;
@@ -84,6 +85,9 @@ public class DefaultModelBuilder
private ModelPathTranslator modelPathTranslator;
@Requirement
+ private ModelUrlNormalizer modelUrlNormalizer;
+
+ @Requirement
private SuperPomProvider superPomProvider;
@Requirement
@@ -225,6 +229,8 @@ public class DefaultModelBuilder
resultModel = interpolateModel( resultModel, request, problems );
resultData.setModel( resultModel );
+ modelUrlNormalizer.normalize( resultModel, request );
+
resultData.setGroupId( resultModel.getGroupId() );
resultData.setArtifactId( resultModel.getArtifactId() );
resultData.setVersion( resultModel.getVersion() );
Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java Fri Apr 2 22:07:04 2010
@@ -24,6 +24,7 @@ import org.apache.maven.model.building.M
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.path.PathTranslator;
+import org.apache.maven.model.path.UrlNormalizer;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.InterpolationException;
@@ -95,6 +96,9 @@ public abstract class AbstractStringBase
@Requirement
private PathTranslator pathTranslator;
+ @Requirement
+ private UrlNormalizer urlNormalizer;
+
private Interpolator interpolator;
private RecursionInterceptor recursionInterceptor;
@@ -187,16 +191,14 @@ public abstract class AbstractStringBase
final File projectDir,
final ModelBuildingRequest config )
{
+ List<InterpolationPostProcessor> processors = new ArrayList<InterpolationPostProcessor>( 2 );
if ( projectDir != null )
{
- return Collections.singletonList( new PathTranslatingPostProcessor( PROJECT_PREFIXES,
- TRANSLATED_PATH_EXPRESSIONS,
- projectDir, pathTranslator ) );
- }
- else
- {
- return Collections.emptyList();
+ processors.add( new PathTranslatingPostProcessor( PROJECT_PREFIXES, TRANSLATED_PATH_EXPRESSIONS,
+ projectDir, pathTranslator ) );
}
+ processors.add( new UrlNormalizingPostProcessor( urlNormalizer ) );
+ return processors;
}
protected String interpolateInternal( String src, List<? extends ValueSource> valueSources,
Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/PathTranslatingPostProcessor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/PathTranslatingPostProcessor.java?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/PathTranslatingPostProcessor.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/PathTranslatingPostProcessor.java Fri Apr 2 22:07:04 2010
@@ -60,7 +60,7 @@ class PathTranslatingPostProcessor
}
}
- return value;
+ return null;
}
}
Added: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,68 @@
+package org.apache.maven.model.interpolation;
+
+/*
+ * 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.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.model.path.UrlNormalizer;
+import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
+
+/**
+ * Ensures that expressions referring to URLs evaluate to normalized URLs.
+ *
+ * @author Benjamin Bentmann
+ */
+class UrlNormalizingPostProcessor
+ implements InterpolationPostProcessor
+{
+
+ private static final Set<String> urlExpressions;
+
+ static
+ {
+ Set<String> expressions = new HashSet<String>();
+ expressions.add( "project.url" );
+ expressions.add( "project.scm.url" );
+ expressions.add( "project.scm.connection" );
+ expressions.add( "project.scm.developerConnection" );
+ expressions.add( "project.distributionManagement.site.url" );
+
+ urlExpressions = expressions;
+ }
+
+ private UrlNormalizer normalizer;
+
+ public UrlNormalizingPostProcessor( UrlNormalizer normalizer )
+ {
+ this.normalizer = normalizer;
+ }
+
+ public Object execute( String expression, Object value )
+ {
+ if ( value != null && urlExpressions.contains( expression ) )
+ {
+ return normalizer.normalize( value.toString() );
+ }
+
+ return null;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/UrlNormalizingPostProcessor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java?rev=930411&r1=930410&r2=930411&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java Fri Apr 2 22:07:04 2010
@@ -22,11 +22,9 @@ package org.apache.maven.model.merge;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.StringTokenizer;
import org.apache.maven.model.BuildBase;
import org.apache.maven.model.CiManagement;
@@ -560,80 +558,39 @@ public class MavenModelMerger
private String appendPath( String parentPath, String childPath, String pathAdjustment )
{
- String uncleanPath = parentPath;
-
- if ( pathAdjustment != null && pathAdjustment.length() > 0 )
- {
- uncleanPath += "/" + pathAdjustment;
- }
-
- if ( childPath != null )
- {
- uncleanPath += "/" + childPath;
- }
-
- String cleanedPath = "";
-
- int protocolIdx = uncleanPath.indexOf( "://" );
-
- if ( protocolIdx > -1 )
- {
- cleanedPath = uncleanPath.substring( 0, protocolIdx + 3 );
- uncleanPath = uncleanPath.substring( protocolIdx + 3 );
- }
-
- if ( uncleanPath.startsWith( "//" ) )
- {
- // preserve leading double slash for UNC paths like "file:////host/pom.xml"
- cleanedPath += "//";
- }
- else if ( uncleanPath.startsWith( "/" ) )
- {
- cleanedPath += "/";
- }
-
- return cleanedPath + resolvePath( uncleanPath );
+ String path = parentPath;
+ path = concatPath( path, pathAdjustment );
+ path = concatPath( path, childPath );
+ return path;
}
- private String resolvePath( String uncleanPath )
+ private String concatPath( String base, String path )
{
- LinkedList<String> pathElements = new LinkedList<String>();
-
- StringTokenizer tokenizer = new StringTokenizer( uncleanPath, "/" );
+ String result = base;
- while ( tokenizer.hasMoreTokens() )
+ if ( path != null && path.length() > 0 )
{
- String token = tokenizer.nextToken();
-
- if ( token.equals( "" ) )
+ if ( ( result.endsWith( "/" ) && !path.startsWith( "/" ) )
+ || ( !result.endsWith( "/" ) && path.startsWith( "/" ) ) )
{
- // Empty path entry ("...//.."), remove.
+ result += path;
}
- else if ( token.equals( ".." ) )
+ else if ( result.endsWith( "/" ) && path.startsWith( "/" ) )
{
- if ( !pathElements.isEmpty() )
- {
- pathElements.removeLast();
- }
+ result += path.substring( 1 );
}
else
{
- pathElements.addLast( token );
+ result += '/';
+ result += path;
}
- }
-
- StringBuilder cleanedPath = new StringBuilder( 128 );
-
- while ( !pathElements.isEmpty() )
- {
- cleanedPath.append( pathElements.removeFirst() );
- if ( !pathElements.isEmpty() )
+ if ( base.endsWith( "/" ) && !result.endsWith( "/" ) )
{
- cleanedPath.append( '/' );
+ result += '/';
}
}
- return cleanedPath.toString();
+ return result;
}
}
Added: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,77 @@
+package org.apache.maven.model.path;
+
+/*
+ * 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 org.apache.maven.model.DistributionManagement;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Scm;
+import org.apache.maven.model.Site;
+import org.apache.maven.model.building.ModelBuildingRequest;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+
+/**
+ * Normalizes URLs to remove the ugly parent references "../" that got potentially inserted by URL adjustment during
+ * model inheritance.
+ *
+ * @author Benjamin Bentmann
+ */
+@Component( role = ModelUrlNormalizer.class )
+public class DefaultModelUrlNormalizer
+ implements ModelUrlNormalizer
+{
+
+ @Requirement
+ private UrlNormalizer urlNormalizer;
+
+ public void normalize( Model model, ModelBuildingRequest request )
+ {
+ if ( model == null )
+ {
+ return;
+ }
+
+ model.setUrl( normalize( model.getUrl() ) );
+
+ Scm scm = model.getScm();
+ if ( scm != null )
+ {
+ scm.setUrl( normalize( scm.getUrl() ) );
+ scm.setConnection( normalize( scm.getConnection() ) );
+ scm.setDeveloperConnection( normalize( scm.getDeveloperConnection() ) );
+ }
+
+ DistributionManagement dist = model.getDistributionManagement();
+ if ( dist != null )
+ {
+ Site site = dist.getSite();
+ if ( site != null )
+ {
+ site.setUrl( normalize( site.getUrl() ) );
+ }
+ }
+ }
+
+ private String normalize( String url )
+ {
+ return urlNormalizer.normalize( url );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,61 @@
+package org.apache.maven.model.path;
+
+/*
+ * 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 org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * Normalizes a URL.
+ *
+ * @author Benjamin Bentmann
+ */
+@Component( role = UrlNormalizer.class )
+public class DefaultUrlNormalizer
+ implements UrlNormalizer
+{
+
+ public String normalize( String url )
+ {
+ String result = url;
+
+ if ( result != null )
+ {
+ result = result.replaceAll( "(?<![:/])/+", "/" );
+
+ while ( true )
+ {
+ int idx = result.indexOf( "/../" );
+ if ( idx <= 0 )
+ {
+ break;
+ }
+ int parent = result.lastIndexOf( '/', idx - 1 );
+ if ( parent < 0 )
+ {
+ break;
+ }
+ result = result.substring( 0, parent ) + result.substring( idx + 3 );
+ }
+ }
+
+ return result;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultUrlNormalizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,42 @@
+package org.apache.maven.model.path;
+
+/*
+ * 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 org.apache.maven.model.Model;
+import org.apache.maven.model.building.ModelBuildingRequest;
+
+/**
+ * Normalizes URLs to remove the ugly parent references "../" that got potentially inserted by URL adjustment during
+ * model inheritance.
+ *
+ * @author Benjamin Bentmann
+ */
+public interface ModelUrlNormalizer
+{
+
+ /**
+ * Normalizes the well-known URLs of the specified model.
+ *
+ * @param model The model whose URLs should be normalized, may be {@code null}.
+ * @param request The model building request that holds further settings, must not be {@code null}.
+ */
+ void normalize( Model model, ModelBuildingRequest request );
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/ModelUrlNormalizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,39 @@
+package org.apache.maven.model.path;
+
+/*
+ * 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.
+ */
+
+/**
+ * Normalizes a URL to remove the ugly parent references "../" that got potentially inserted by URL adjustment during
+ * model inheritance.
+ *
+ * @author Benjamin Bentmann
+ */
+public interface UrlNormalizer
+{
+
+ /**
+ * Normalizes the specified URL.
+ *
+ * @param url The URL to normalize, may be {@code null}.
+ * @return The normalized URL or {@code null} if the input was {@code null}.
+ */
+ String normalize( String url );
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/
------------------------------------------------------------------------------
bugtraq:label = Enter issue ID:
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/
------------------------------------------------------------------------------
bugtraq:message = Issue id: %BUGID%
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/
------------------------------------------------------------------------------
bugtraq:number = false
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/
------------------------------------------------------------------------------
bugtraq:url = http://jira.codehaus.org/browse/%BUGID%
Added: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java?rev=930411&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java (added)
+++ maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java Fri Apr 2 22:07:04 2010
@@ -0,0 +1,84 @@
+package org.apache.maven.model.path;
+
+/*
+ * 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 junit.framework.TestCase;
+
+/**
+ * @author Benjamin Bentmann
+ */
+public class DefaultUrlNormalizerTest
+ extends TestCase
+{
+
+ private UrlNormalizer normalizer;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ normalizer = new DefaultUrlNormalizer();
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ normalizer = null;
+
+ super.tearDown();
+ }
+
+ private String normalize( String url )
+ {
+ return normalizer.normalize( url );
+ }
+
+ public void testNullSafe()
+ {
+ assertNull( normalize( null ) );
+ }
+
+ public void testTrailingSlash()
+ {
+ assertEquals( "", normalize( "" ) );
+ assertEquals( "http://server.org/dir", normalize( "http://server.org/dir" ) );
+ assertEquals( "http://server.org/dir/", normalize( "http://server.org/dir/" ) );
+ }
+
+ public void testRemovalOfParentRefs()
+ {
+ assertEquals( "http://server.org/child", normalize( "http://server.org/parent/../child" ) );
+ assertEquals( "http://server.org/child", normalize( "http://server.org/grand/parent/../../child" ) );
+ }
+
+ public void testRemovalOfDoubleSlashes()
+ {
+ assertEquals( "http://server.org/dir/", normalize( "http://server.org/dir//" ) );
+ assertEquals( "http://server.org/parent/child", normalize( "http://server.org/parent//child" ) );
+
+ assertEquals( "file:////UNC/server", normalize( "file:////UNC/server" ) );
+ assertEquals( "[fetch=]http://server.org/[push=]ssh://server.org/",
+ normalize( "[fetch=]http://server.org/[push=]ssh://server.org/" ) );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision