This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
The following commit(s) were added to refs/heads/master by this push: new 314730f [DOXIASITETOOLS-109] handle more URI formats (#10) 314730f is described below commit 314730fd1fa41e3c9754e2dbe12f9ddb83ace50e Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Mon Mar 2 14:41:07 2020 -0500 [DOXIASITETOOLS-109] handle more URI formats (#10) * handle more URI formats * restore original behavior * fix test on Windows * fix test on Windows * more whitespace --- .../apache/maven/doxia/tools/DefaultSiteTool.java | 25 ++++++++-- .../maven/doxia/tools/DefaultSiteToolTest.java | 57 ++++++++++++++++++++++ .../org/apache/maven/doxia/tools/SiteToolTest.java | 3 +- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java index 002402b..f7cea88 100644 --- a/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java +++ b/doxia-integration-tools/src/main/java/org/apache/maven/doxia/tools/DefaultSiteTool.java @@ -126,7 +126,6 @@ public class DefaultSiteTool // Public methods // ---------------------------------------------------------------------- - /** {@inheritDoc} */ public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository, List<ArtifactRepository> remoteArtifactRepositories, DecorationModel decoration ) @@ -174,7 +173,6 @@ public class DefaultSiteTool return artifact; } - /** {@inheritDoc} */ public Artifact getDefaultSkinArtifact( ArtifactRepository localRepository, List<ArtifactRepository> remoteArtifactRepositories ) throws SiteToolException @@ -182,12 +180,27 @@ public class DefaultSiteTool return getSkinArtifactFromRepository( localRepository, remoteArtifactRepositories, new DecorationModel() ); } - /** {@inheritDoc} */ + /** + * This method is not implemented according to the URI specification and has many weird + * corner cases where it doesn't do the right thing. Please consider using a better + * implemented method from a different library such as org.apache.http.client.utils.URIUtils#resolve. + */ + @Deprecated public String getRelativePath( String to, String from ) { checkNotNull( "to", to ); checkNotNull( "from", from ); - + + if ( to.contains( ":" ) && from.contains( ":" ) ) + { + String toScheme = to.substring( 0, to.lastIndexOf( ':' ) ); + String fromScheme = from.substring( 0, from.lastIndexOf( ':' ) ); + if ( !toScheme.equals( fromScheme ) ) + { + return to; + } + } + URL toUrl = null; URL fromUrl = null; @@ -207,6 +220,7 @@ public class DefaultSiteTool catch ( MalformedURLException e1 ) { getLogger().warn( "Unable to load a URL for '" + to + "': " + e.getMessage() ); + return to; } } @@ -223,6 +237,7 @@ public class DefaultSiteTool catch ( MalformedURLException e1 ) { getLogger().warn( "Unable to load a URL for '" + from + "': " + e.getMessage() ); + return to; } } @@ -1496,7 +1511,7 @@ public class DefaultSiteTool final Properties properties = new Properties(); final String corePomProperties = "META-INF/maven/org.apache.maven/maven-core/pom.properties"; final InputStream in = MavenProject.class.getClassLoader().getResourceAsStream( corePomProperties ); - try + try { properties.load( in ); } diff --git a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java index 0d54c5b..1698e2d 100644 --- a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java +++ b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/DefaultSiteToolTest.java @@ -23,12 +23,28 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; + +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.console.ConsoleLogger; +import org.junit.Before; /** * @author <a href="mailto:vincent.sive...@gmail.com">Vincent Siveton</a> */ public class DefaultSiteToolTest { + + private DefaultSiteTool tool = new DefaultSiteTool(); + + @Before + public void setUp() { + Logger logger = new ConsoleLogger(Logger.LEVEL_WARN, "tool"); + tool.enableLogging(logger); + } + /** * test getNormalizedPath(). */ @@ -56,4 +72,45 @@ public class DefaultSiteToolTest assertEquals( "file:/Documents and Settings/", DefaultSiteTool.getNormalizedPath( "file://Documents and Settings/" ) ); } + + @SuppressWarnings("deprecation") + @Test + public void testGetRelativePath() + { + assertEquals( + ".." + File.separator + "bar.html", + tool.getRelativePath("http://example.com/foo/bar.html", "http://example.com/foo/baz.html")); + } + + @SuppressWarnings("deprecation") + @Test + public void testGetRelativePath_same() + { + assertTrue( + tool.getRelativePath( "http://example.com/foo/bar.html", "http://example.com/foo/bar.html" ).isEmpty() ); + } + + @SuppressWarnings("deprecation") + @Test + public void testGetRelativePath_differentSchemes() { + assertEquals( + "scp://example.com/foo/bar.html", + tool.getRelativePath( "scp://example.com/foo/bar.html", "http://example.com/foo/bar.html" ) ); + assertEquals( + "file:///tmp/bloop", + tool.getRelativePath( "file:///tmp/bloop", "scp://localhost:/tmp/blop" ) ); + } + + @SuppressWarnings("deprecation") + @Test + public void testGetRelativePath_differentDomains() { + assertEquals( + "https://example.org/bar.html", + tool.getRelativePath( "https://example.org/bar.html", "https://example.com/bar.html" ) ); + assertEquals( + "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/", + tool.getRelativePath( + "dav:https://nexus2.mysite.net:123/nexus/content/sites/site/mysite-child/2.0.0/", + "dav:https://nexus1.mysite.net:123/nexus/content/sites/site/mysite-parent/1.0.0/" )); + } } diff --git a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java index f19ab61..6e12e4c 100644 --- a/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java +++ b/doxia-integration-tools/src/test/java/org/apache/maven/doxia/tools/SiteToolTest.java @@ -155,12 +155,11 @@ public class SiteToolTest String to = "http://maven.apache.org/downloads.html"; String from = "http://maven.apache.org/index.html"; - // FIXME! assertEquals( "downloads.html", tool.getRelativePath( to, from ) ); // MSITE-600, MSHARED-203 to = "file:///tmp/bloop"; from = "scp://localhost:/tmp/blop"; - // FIXME! assertEquals( tool.getRelativePath( to, from ), to ); + assertEquals( tool.getRelativePath( to, from ), to ); // note: 'tmp' is the host here which is probably not the intention, but at least the result is correct to = "file://tmp/bloop";