Skip to content

Commit

Permalink
[DOXIASITETOOLS-109] handle more URI formats (#10)
Browse files Browse the repository at this point in the history
* handle more URI formats

* restore original behavior

* fix test on Windows

* fix test on Windows

* more whitespace
  • Loading branch information
elharo authored Mar 2, 2020
1 parent abbe987 commit 314730f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public class DefaultSiteTool
// Public methods
// ----------------------------------------------------------------------

/** {@inheritDoc} */
public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepository,
List<ArtifactRepository> remoteArtifactRepositories,
DecorationModel decoration )
Expand Down Expand Up @@ -174,20 +173,34 @@ public Artifact getSkinArtifactFromRepository( ArtifactRepository localRepositor
return artifact;
}

/** {@inheritDoc} */
public Artifact getDefaultSkinArtifact( ArtifactRepository localRepository,
List<ArtifactRepository> remoteArtifactRepositories )
throws SiteToolException
{
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;

Expand All @@ -207,6 +220,7 @@ public String getRelativePath( String to, String from )
catch ( MalformedURLException e1 )
{
getLogger().warn( "Unable to load a URL for '" + to + "': " + e.getMessage() );
return to;
}
}

Expand All @@ -223,6 +237,7 @@ public String getRelativePath( String to, String from )
catch ( MalformedURLException e1 )
{
getLogger().warn( "Unable to load a URL for '" + from + "': " + e.getMessage() );
return to;
}
}

Expand Down Expand Up @@ -1496,7 +1511,7 @@ private static String getMavenVersion()
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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,28 @@

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.siveton@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().
*/
Expand Down Expand Up @@ -56,4 +72,45 @@ public void testGetNormalizedPath()
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/" ));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ public void testGetRelativePath()

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";
Expand Down

0 comments on commit 314730f

Please sign in to comment.