Author: jvanzyl
Date: Mon May 28 14:57:05 2007
New Revision: 542333
URL: http://svn.apache.org/viewvc?view=rev&rev=542333
Log:
o missing bits of commits for previous patches
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
(with props)
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
(with props)
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
(with props)
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
(with props)
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java?view=auto&rev=542333
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
(added)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
Mon May 28 14:57:05 2007
@@ -0,0 +1,194 @@
+package org.apache.maven.doxia.site.decoration.inheritance;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.codehaus.plexus.util.StringUtils;
+
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ */
+
+/**
+ * This class holds an instance of a maven path. This consists of a relative
path (e.g. images/maven-logo.png) and a
+ * base reference which can also be a relative path (e.g. '.' or '../doxia')
or an URL that is used for an absolute
+ * anchor.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ * @version $Id$
+ */
+
+public class PathDescriptor
+{
+ private final URL baseUrl;
+
+ private final URL pathUrl;
+
+ private final String relativePath;
+
+ public PathDescriptor( final String path ) throws MalformedURLException
+ {
+ this( (URL) null, path );
+ }
+
+ public PathDescriptor( final String base, final String path ) throws
MalformedURLException
+ {
+ this( PathDescriptor.buildBaseUrl( base ), path );
+ }
+
+ public PathDescriptor( final URL baseUrl, final String path ) throws
MalformedURLException
+ {
+ this.baseUrl = baseUrl;
+
+ URL pathUrl = null;
+ String relativePath = null;
+ try
+ {
+ pathUrl = new URL( path );
+ }
+ catch ( MalformedURLException e )
+ {
+ try
+ {
+ pathUrl = buildUrl( baseUrl, path );
+ }
+ catch ( MalformedURLException e2 )
+ {
+ // If we got an absolute path passed in and end here, then the
path
+ // is converted to relative because we have no reference URL
anyway
+ // to which it has been anchored.
+ if ( path != null && path.startsWith( "/" ) )
+ {
+ relativePath = path.substring( 1 );
+ }
+ else
+ {
+ relativePath = path;
+ }
+ }
+ }
+ this.pathUrl = pathUrl;
+ this.relativePath = relativePath;
+ }
+
+ private static final URL buildBaseUrl( final String base ) throws
MalformedURLException
+ {
+ if ( base == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ return new URL( base );
+ }
+ catch ( MalformedURLException e )
+ {
+ return new File( base ).toURL();
+ }
+ }
+
+ private static final URL buildUrl( final URL baseUrl, final String path )
throws MalformedURLException
+ {
+ if ( baseUrl == null )
+ {
+ throw new MalformedURLException( "Base is null!" );
+ }
+
+ if ( path == null )
+ {
+ return baseUrl;
+ }
+
+ if ( baseUrl.getProtocol().equals( "file" ) )
+ {
+ return new File( baseUrl.getFile(), path ).toURL();
+ }
+
+ if ( path.startsWith( "/" ) && baseUrl.getPath().endsWith( "/" ) )
+ {
+ return new URL( baseUrl, path.substring( 1 ) );
+ }
+
+ return new URL( baseUrl, path );
+ }
+
+ public boolean isFile()
+ {
+ return isRelative() || pathUrl.getProtocol().equals( "file" );
+ }
+
+ public boolean isRelative()
+ {
+ return pathUrl == null;
+ }
+
+ public URL getBaseUrl()
+ {
+ return baseUrl;
+ }
+
+ public URL getPathUrl()
+ {
+ return pathUrl;
+ }
+
+ public String getPath()
+ {
+ if ( getPathUrl() != null )
+ {
+ if ( isFile() )
+ {
+ return StringUtils.stripEnd( getPathUrl().getPath(), "/" );
+ }
+ else
+ {
+ return getPathUrl().getPath();
+ }
+ }
+ else
+ {
+ return relativePath;
+ }
+ }
+
+ public String getLocation()
+ {
+ if ( isFile() )
+ {
+ if ( getPathUrl() != null )
+ {
+ return StringUtils.stripEnd( getPathUrl().getFile(), "/" );
+ }
+ else
+ {
+ return relativePath;
+ }
+ }
+ else
+ {
+ return getPathUrl().toExternalForm();
+ }
+ }
+
+ public String toString()
+ {
+ StringBuffer res =
+ new StringBuffer( ( StringUtils.isNotEmpty( relativePath ) ) ?
relativePath : String.valueOf( pathUrl ) );
+ res.append( " (Base: " ).append( baseUrl ).append( ") Location: "
).append( getLocation() );
+ return res.toString();
+ }
+}
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptor.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java?view=auto&rev=542333
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
(added)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
Mon May 28 14:57:05 2007
@@ -0,0 +1,262 @@
+package org.apache.maven.doxia.site.decoration.inheritance;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+/*
+ * Copyright 2004-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ */
+
+/**
+ * Utilitites that allow conversion of old and new pathes and URLs relative to
each other.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ * @version $Id$
+ */
+public abstract class PathUtils
+{
+ private PathUtils()
+ {
+ }
+
+ public static final PathDescriptor convertPath( final PathDescriptor
oldPath, final PathDescriptor newPath )
+ throws MalformedURLException
+ {
+ String relative = getRelativePath( oldPath, newPath );
+
+ if ( relative == null )
+ {
+ return oldPath;
+ }
+
+ return new PathDescriptor( relative );
+ }
+
+ public static final String getRelativePath( final PathDescriptor
oldPathDescriptor,
+ final PathDescriptor
newPathDescriptor ) throws MalformedURLException
+ {
+ // Cannot convert from URL to file.
+ if ( oldPathDescriptor.isFile() )
+ {
+ if ( !newPathDescriptor.isFile() )
+ {
+ // We want to convert from a file to an URL. This is normally
not possible...
+ if ( oldPathDescriptor.isRelative() )
+ {
+ // unless the old path is a relative path. Then we might
convert an existing
+ // site into a new URL using resolvePaths()...
+ return oldPathDescriptor.getPath();
+ }
+ else
+ {
+ // The old path is not relative. Bail out.
+ return null;
+ }
+ }
+ }
+
+ // Don't optimize to else. This might also be old.isFile && new.isFile
...
+ if ( !oldPathDescriptor.isFile() )
+ {
+ // URLs, determine if they share protocol and domain info
+ URL oldUrl = oldPathDescriptor.getPathUrl();
+ URL newUrl = newPathDescriptor.getPathUrl();
+
+ if ( ( newUrl.getProtocol().equalsIgnoreCase( oldUrl.getProtocol()
) )
+ && ( newUrl.getHost().equalsIgnoreCase(
oldUrl.getHost() ) )
+ && ( newUrl.getPort() == oldUrl.getPort() ) )
+ {
+ // Both pathes point to the same site. So we can use relative
pathes.
+
+ String oldPath = oldPathDescriptor.getPath();
+ String newPath = newPathDescriptor.getPath();
+
+ return getRelativeWebPath( newPath, oldPath );
+ }
+ else
+ {
+ // Different sites. No relative Path possible.
+ return null;
+ }
+ }
+ else
+ {
+ // Both Descriptors point to a path. We can build a relative path.
+ String oldPath = oldPathDescriptor.getPath();
+ String newPath = newPathDescriptor.getPath();
+
+ if ( oldPath == null || newPath == null )
+ {
+ // One of the sites has a strange URL. no relative path
possible, bail out.
+ return null;
+ }
+
+ return getRelativeFilePath( oldPath, newPath );
+ }
+ }
+
+ /**
+ * This method can calculate the relative path between two pathes on a web
site.
+ */
+ public static final String getRelativeWebPath( final String oldPath, final
String newPath )
+ {
+ String resultPath = buildRelativePath( newPath, oldPath, '/' );
+
+ if ( newPath.endsWith( "/" ) && !resultPath.endsWith( "/" ) )
+ {
+ return resultPath + "/";
+ }
+ else
+ {
+ return resultPath;
+ }
+ }
+
+ /**
+ * This method can calculate the relative path between two pathes on a
file system.
+ */
+ public static final String getRelativeFilePath( final String oldPath,
final String newPath )
+ {
+ // normalise the path delimiters
+ String fromPath = new File( oldPath ).getPath();
+ String toPath = new File( newPath ).getPath();
+
+ // strip any leading slashes if its a windows path
+ if ( toPath.matches( "^\\[a-zA-Z]:" ) )
+ {
+ toPath = toPath.substring( 1 );
+ }
+ if ( fromPath.matches( "^\\[a-zA-Z]:" ) )
+ {
+ fromPath = fromPath.substring( 1 );
+ }
+
+ // lowercase windows drive letters.
+ if ( fromPath.startsWith( ":", 1 ) )
+ {
+ fromPath = fromPath.substring( 0, 1 ).toLowerCase() +
fromPath.substring( 1 );
+ }
+ if ( toPath.startsWith( ":", 1 ) )
+ {
+ toPath = toPath.substring( 0, 1 ).toLowerCase() +
toPath.substring( 1 );
+ }
+
+ // check for the presence of windows drives. No relative way of
+ // traversing from one to the other.
+ if ( ( toPath.startsWith( ":", 1 ) && fromPath.startsWith( ":", 1 ) )
+ && ( !toPath.substring( 0, 1 ).equals(
fromPath.substring( 0, 1 ) ) ) )
+ {
+ // they both have drive path element but they dont match, no
+ // relative path
+ return null;
+ }
+
+ if ( ( toPath.startsWith( ":", 1 ) && !fromPath.startsWith( ":", 1 ) )
+ || ( !toPath.startsWith( ":", 1 ) &&
fromPath.startsWith( ":", 1 ) ) )
+ {
+ // one has a drive path element and the other doesnt, no relative
+ // path.
+ return null;
+ }
+
+ String resultPath = buildRelativePath( toPath, fromPath,
File.separatorChar );
+
+ if ( newPath.endsWith( File.separator ) && !resultPath.endsWith(
File.separator ) )
+ {
+ return resultPath + File.separator;
+ }
+ else
+ {
+ return resultPath;
+ }
+ }
+
+ private static final String buildRelativePath( final String toPath, final
String fromPath, final char separatorChar )
+ {
+ // use tokeniser to traverse paths and for lazy checking
+ StringTokenizer toTokeniser = new StringTokenizer( toPath,
String.valueOf( separatorChar ) );
+ StringTokenizer fromTokeniser = new StringTokenizer( fromPath,
String.valueOf( separatorChar ) );
+
+ int count = 0;
+
+ // walk along the to path looking for divergence from the from path
+ while ( toTokeniser.hasMoreTokens() && fromTokeniser.hasMoreTokens() )
+ {
+ if ( separatorChar == '\\' )
+ {
+ if ( !fromTokeniser.nextToken().equalsIgnoreCase(
toTokeniser.nextToken() ) )
+ {
+ break;
+ }
+ }
+ else
+ {
+ if ( !fromTokeniser.nextToken().equals(
toTokeniser.nextToken() ) )
+ {
+ break;
+ }
+ }
+
+ count++;
+ }
+
+ // reinitialise the tokenisers to count positions to retrieve the
+ // gobbled token
+
+ toTokeniser = new StringTokenizer( toPath, String.valueOf(
separatorChar ) );
+ fromTokeniser = new StringTokenizer( fromPath, String.valueOf(
separatorChar ) );
+
+ while ( count-- > 0 )
+ {
+ fromTokeniser.nextToken();
+ toTokeniser.nextToken();
+ }
+
+ String relativePath = "";
+
+ // add back refs for the rest of from location.
+ while ( fromTokeniser.hasMoreTokens() )
+ {
+ fromTokeniser.nextToken();
+
+ relativePath += "..";
+
+ if ( fromTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+ }
+
+ if ( relativePath.length() != 0 && toTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+
+ // add fwd fills for whatevers left of newPath.
+ while ( toTokeniser.hasMoreTokens() )
+ {
+ relativePath += toTokeniser.nextToken();
+
+ if ( toTokeniser.hasMoreTokens() )
+ {
+ relativePath += separatorChar;
+ }
+ }
+ return relativePath;
+ }
+}
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/main/java/org/apache/maven/doxia/site/decoration/inheritance/PathUtils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java?view=auto&rev=542333
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
(added)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
Mon May 28 14:57:05 2007
@@ -0,0 +1,63 @@
+package org.apache.maven.doxia.site.decoration.inheritance;
+
+import junit.framework.TestCase;
+
+/*
+ * 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.
+ */
+
+/**
+ * Testcase for DOXIA-91 problems. All tests make sure that a passed in null
will not generate any path conversion but
+ * just returns the old path.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ */
+
+public class Doxia91Test extends TestCase
+{
+
+ public void testOldPathNull() throws Exception
+ {
+ PathDescriptor oldPath = new PathDescriptor( null );
+ PathDescriptor newPath = new PathDescriptor( "http://www.apache.org/"
);
+
+ PathDescriptor diff = PathUtils.convertPath( oldPath, newPath );
+
+ assertEquals( diff, oldPath );
+ }
+
+ public void testNewPathNull() throws Exception
+ {
+ PathDescriptor oldPath = new PathDescriptor( "http://www.apache.org/",
"file:///home/henning/foo" );
+ PathDescriptor newPath = new PathDescriptor( null );
+
+ PathDescriptor diff = PathUtils.convertPath( oldPath, newPath );
+
+ assertEquals( diff, oldPath );
+ }
+
+ public void testBothPathNull() throws Exception
+ {
+ PathDescriptor oldPath = new PathDescriptor( null );
+ PathDescriptor newPath = new PathDescriptor( null );
+
+ PathDescriptor diff = PathUtils.convertPath( oldPath, newPath );
+
+ assertEquals( diff, oldPath );
+ }
+}
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/Doxia91Test.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
URL:
http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java?view=auto&rev=542333
==============================================================================
---
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
(added)
+++
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
Mon May 28 14:57:05 2007
@@ -0,0 +1,452 @@
+package org.apache.maven.doxia.site.decoration.inheritance;
+
+/*
+ * 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;
+
+/**
+ * Test the PathDescriptor creation under various circumstances.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
+ */
+
+public class PathDescriptorTest extends TestCase
+{
+
+ public void testAbsPath() throws Exception
+ {
+ String path = "absolutePath";
+
+ PathDescriptor desc = new PathDescriptor( "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testRelPath() throws Exception
+ {
+ String path = "relativePath";
+
+ PathDescriptor desc = new PathDescriptor( path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testEmptyAbsPath() throws Exception
+ {
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testEmptyRelPath() throws Exception
+ {
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullPath() throws Exception
+ {
+ String path = null;
+
+ PathDescriptor desc = new PathDescriptor( path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNull( desc.getPath() );
+ assertNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullBaseAbsPath() throws Exception
+ {
+ String base = null;
+ String path = "absolutePath";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullBaseRelPath() throws Exception
+ {
+ String base = null;
+ String path = "relativePath";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullBaseEmptyAbsPath() throws Exception
+ {
+ String base = null;
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullBaseEmptyRelPath() throws Exception
+ {
+ String base = null;
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testNullBaseNullPath() throws Exception
+ {
+ String base = null;
+ String path = null;
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertTrue( desc.isRelative() );
+ assertNull( desc.getBaseUrl() );
+ assertNull( desc.getPathUrl() );
+ assertNull( desc.getPath() );
+ assertNull( desc.getLocation() );
+ assertEquals( "wrong path", path, desc.getPath() );
+ assertEquals( "wrong location", path, desc.getLocation() );
+ }
+
+ public void testUrlBaseAbsPath() throws Exception
+ {
+ String base = "http://maven.apache.org/";
+ String path = "absolutePath";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertFalse( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + path, desc.getLocation() );
+ }
+
+ public void testUrlBaseRelPath() throws Exception
+ {
+ String base = "http://maven.apache.org/";
+ String path = "relativePath";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertFalse( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + path, desc.getLocation() );
+ }
+
+ public void testUrlBaseEmptyAbsPath() throws Exception
+ {
+ String base = "http://maven.apache.org/";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertFalse( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + path, desc.getLocation() );
+ }
+
+ public void testUrlBaseEmptyRelPath() throws Exception
+ {
+ String base = "http://maven.apache.org/";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertFalse( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + path, desc.getLocation() );
+ }
+
+ public void testUrlBaseNullPath() throws Exception
+ {
+ String base = "http://maven.apache.org/";
+ String path = null;
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertFalse( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", "/", desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testFileBaseAbsPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "absolutePath";
+
+ PathDescriptor desc = new PathDescriptor( "file://" + base, "/" + path
);
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base + "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + "/" + path, desc.getLocation()
);
+ }
+
+ public void testFileBaseRelPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "relativePath";
+
+ PathDescriptor desc = new PathDescriptor( "file://" + base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base + "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + "/" + path, desc.getLocation()
);
+ }
+
+ public void testFileBaseEmptyAbsPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( "file://" + base, "/" + path
);
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testFileBaseEmptyRelPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( "file://" + base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testFileBaseNullPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = null;
+
+ PathDescriptor desc = new PathDescriptor( "file://" + base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testPathBaseAbsPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "absolutePath";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base + "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + "/" + path, desc.getLocation()
);
+ }
+
+ public void testPathBaseRelPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "relativePath";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base + "/" + path, desc.getPath() );
+ assertEquals( "wrong location", base + "/" + path, desc.getLocation()
);
+ }
+
+ public void testPathBaseEmptyAbsPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, "/" + path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testPathBaseEmptyRelPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = "";
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+
+ public void testPathBaseNullPath() throws Exception
+ {
+ String base = "/tmp/foo";
+ String path = null;
+
+ PathDescriptor desc = new PathDescriptor( base, path );
+
+ assertTrue( desc.isFile() );
+ assertFalse( desc.isRelative() );
+ assertNotNull( desc.getBaseUrl() );
+ assertNotNull( desc.getPathUrl() );
+ assertNotNull( desc.getPath() );
+ assertNotNull( desc.getLocation() );
+ assertEquals( "wrong path", base, desc.getPath() );
+ assertEquals( "wrong location", base, desc.getLocation() );
+ }
+}
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/doxia/doxia-sitetools/trunk/doxia-decoration-model/src/test/java/org/apache/maven/doxia/site/decoration/inheritance/PathDescriptorTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"