Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOXIASITETOOLS-109] handle more URI formats #10

Merged
merged 5 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( ":" ) )
michael-o marked this conversation as resolved.
Show resolved Hide resolved
{
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" ) );
michael-o marked this conversation as resolved.
Show resolved Hide resolved
}

@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