[Arakhnę-Dev] [134] - Use the new URISchemeType enumeration insteed of Strings.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 134
Author:   galland
Date:     2010-02-17 10:53:18 +0100 (Wed, 17 Feb 2010)
Log Message:
-----------
- Use the new URISchemeType enumeration insteed of Strings.
- Add function makeAbsolute(File, URL).

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
    trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-02-17 09:52:54 UTC (rev 133)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-02-17 09:53:18 UTC (rev 134)
@@ -77,7 +77,7 @@
 	 * @return <code>true</code> if the given URL uses a jar scheme.
 	 */
 	public static boolean isJarURL(URL url) {
-		return url!=null && "jar".equalsIgnoreCase(url.getProtocol()); //$NON-NLS-1$
+		return URISchemeType.JAR.isURL(url);
 	}
 	
 	/** Replies the jar part of the jar-scheme URL.
@@ -135,7 +135,7 @@
 	 */
 	public static URL toJarURL(File jarFile, String insideFile) throws MalformedURLException {
 		if (jarFile==null || insideFile==null) return null;
-		StringBuffer buf = new StringBuffer("jar:"); //$NON-NLS-1$
+		StringBuffer buf = new StringBuffer(URISchemeType.JAR.toString());
 		buf.append(jarFile.toURI().toURL().toExternalForm());
 		buf.append(JAR_URL_FILE_ROOT);
 		String path = insideFile.replace(File.separatorChar, URL_PATH_SEPARATOR_CHAR);
@@ -169,7 +169,7 @@
 	 */
 	public static URL toJarURL(URL jarFile, String insideFile) throws MalformedURLException {
 		if (jarFile==null || insideFile==null) return null;
-		StringBuffer buf = new StringBuffer("jar:"); //$NON-NLS-1$
+		StringBuffer buf = new StringBuffer(URISchemeType.JAR.toString());
 		buf.append(jarFile.toExternalForm());
 		buf.append(JAR_URL_FILE_ROOT);
 		String path = insideFile.replace(File.separatorChar, URL_PATH_SEPARATOR_CHAR);
@@ -1081,7 +1081,7 @@
 			}
 
 		}
-		if ("file".equalsIgnoreCase(uri.getScheme())) { //$NON-NLS-1$
+		if (URISchemeType.FILE.isURI(uri)) {
 			String auth = uri.getAuthority();
 			String path = uri.getPath();
 			if (path==null) path = uri.getRawPath();
@@ -1169,7 +1169,7 @@
 			
 			String resourceName;
 			
-			if (urlDescription.toLowerCase().startsWith("resource:")) { //$NON-NLS-1$
+			if (urlDescription.toLowerCase().startsWith(URISchemeType.RESOURCE.toString())) {
 				resourceName = urlDescription.substring(9);
 				return Resources.getResource(resourceName);
 			}
@@ -1178,7 +1178,7 @@
 			url = Resources.getResource(resourceName);
 			if (url!=null) return url;
 		}
-		else if (urlDescription.toLowerCase().startsWith("resource:")) { //$NON-NLS-1$
+		else if (urlDescription.toLowerCase().startsWith(URISchemeType.RESOURCE.toString())) {
 			return null;
 		}
 
@@ -1197,7 +1197,45 @@
 	}
 
 	/**
-	 * Make the given filename absolute from the given root if it is not already absolute. 
+	 * Make the given filename absolute from the given root if it is not already absolute.
+	 * <p>
+	 * <table border="1" width="100%">
+	 * <thead>
+	 * <tr>
+	 * <th><var>filename</var></th><th><var>current</var></th><th>Result</th>
+	 * </tr>
+	 * </thead>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>/path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>/myroot/path/to/file</code></td>
+	 * </tr>
+	 * </table>
 	 *
 	 * @param filename is the name to make absolute.
 	 * @param current is the current directory which permits to make absolute.
@@ -1224,76 +1262,328 @@
 	 */
 	public static boolean isFileBasedURL(URL url) {
 		if (url!=null) {
-			String scheme = url.getProtocol();
-			if ("file".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("http".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("https".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("ftp".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("ssh".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("jar".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
-			if ("resource".equalsIgnoreCase(scheme)) return true; //$NON-NLS-1$
+			return isFileBasedScheme(URISchemeType.getSchemeType(url));
 		}
 		return false;
 	}
+	
+	/** Replies if the given URL scheme is using a protocol which could be map to files.
+	 * 
+	 * @param scheme
+	 * @return <code>true</code> if the given scheme is a "file", "http", 
+	 * "https", "ftp", "ssh", "jar" or "resource", otherwise <code>false</code>.
+	 * @since 5.0
+	 */
+	public static boolean isFileBasedScheme(URISchemeType scheme) {
+		if (scheme!=null) {
+			return (scheme==URISchemeType.FILE
+					||
+					scheme==URISchemeType.HTTP
+					||
+					scheme==URISchemeType.HTTPS
+					||
+					scheme==URISchemeType.FTP
+					||
+					scheme==URISchemeType.SSH
+					||
+					scheme==URISchemeType.JAR
+					||
+					scheme==URISchemeType.RESOURCE);
+		}
+		return false;
+	}
 
 	/**
 	 * Make the given filename absolute from the given root if it is not already absolute. 
+	 * <p>
+	 * <table border="1" width="100%">
+	 * <thead>
+	 * <tr>
+	 * <th><var>filename</var></th><th><var>current</var></th><th>Result</th>
+	 * </tr>
+	 * </thead>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>file:/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:/path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>file:/myroot/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>http://host.com/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>http://host.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>http://host.com/path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>http://host.com/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>ftp://host.com/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>ftp://host.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>ftp://host.com/path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>ftp://host.com/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>ssh://host.com/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>ssh://host.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>ssh://host.com/path/to/file</code></td>
+	 * <td><code>/myroot</code></td>
+	 * <td><code>ssh://host.com/path/to/file</code></td>
+	 * </tr>
+	 * </table>
 	 *
 	 * @param filename is the name to make absolute.
 	 * @param current is the current directory which permits to make absolute.
 	 * @return an absolute filename.
 	 */
 	public static URL makeAbsolute(URL filename, File current) {
+		try {
+			return makeAbsolute(filename, current==null ? null : current.toURI().toURL());
+		}
+		catch(MalformedURLException _) {
+			//
+		}
+		return filename;
+	}
+
+	/**
+	 * Make the given filename absolute from the given root if it is not already absolute. 
+	 * <p>
+	 * <table border="1" width="100%">
+	 * <thead>
+	 * <tr>
+	 * <th><var>filename</var></th><th><var>current</var></th><th>Result</th>
+	 * </tr>
+	 * </thead>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>file:path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>file:/myroot/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>http://host.com/myroot/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>file:/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:/path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>file:/path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>http://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>ftp://host2.com/path/to/file</code></td>
+	 * </tr>
+	 * </table>
+	 *
+	 * @param filename is the name to make absolute.
+	 * @param current is the current directory which permits to make absolute.
+	 * @return an absolute filename.
+	 */
+	public static URL makeAbsolute(URL filename, URL current) {
 		if (filename==null) return null;
-		if (current!=null && isFileBasedURL(filename)) {
-			String scheme = filename.getProtocol();
-			if ("jar".equalsIgnoreCase(scheme)) { //$NON-NLS-1$
-				try {
-					String[] parts = filename.getPath().split(JAR_URL_FILE_ROOT);
-					URL u = makeAbsolute(new URL(parts[0]), current);
-					StringBuffer adr = new StringBuffer("jar:"); //$NON-NLS-1$
-					adr.append(u.toExternalForm());
-					for(int i=1; i<parts.length; i++) {
-						adr.append(JAR_URL_FILE_ROOT);
-						adr.append(parts[i]);
-					}
-					return new URL(adr.toString());
-				}
-				catch(MalformedURLException _) {
-					// Ignore error
-				}
+		URISchemeType scheme = URISchemeType.getSchemeType(filename);
+		switch(scheme) {
+		case JAR:
+			try {
+				URL jarUrl = getJarURL(filename);
+				jarUrl = makeAbsolute(jarUrl, current);
+				File jarFile = getJarFile(filename);
+				return toJarURL(jarUrl, jarFile);
 			}
-			else {
-				int port = filename.getPort();
-				try {
-					String absPath = filename.getPath();
-					if (!absPath.startsWith(URL_PATH_SEPARATOR)) {
-						URL rootUrl = current.toURI().toURL();
-						absPath = rootUrl.getPath()+URL_PATH_SEPARATOR+absPath;
-						return new URL(filename.getProtocol(), filename.getHost(), port, absPath);
+			catch(MalformedURLException _) {
+				// Ignore error
+			}
+			break;
+		case FILE:
+			{
+				File f = new File(filename.getFile());
+				if (!f.isAbsolute()) {
+					if (current!=null) {
+						return join(current, f);
 					}
 				}
-				catch (MalformedURLException e) {
-					//
-				}
 			}
+			break;
+		default:
+			// do not change the URL
 		}
 		return filename;
 	}
 
 	/**
 	 * Make the given filename absolute from the given root if it is not already absolute. 
+	 * <p>
+	 * <table border="1" width="100%">
+	 * <thead>
+	 * <tr>
+	 * <th><var>filename</var></th><th><var>current</var></th><th>Result</th>
+	 * </tr>
+	 * </thead>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>null</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>null</code></td>
+	 * </tr>
+	 * 
+	 * <tr>
+	 * <td><code>path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>file:/myroot/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>http://host.com/myroot/path/to/file</code></td>
+	 * </tr>
+	 * 
+	 * 
+	 * <tr>
+	 * <td><code>/path/to/file</code></td>
+	 * <td><code>null</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>/path/to/file</code></td>
+	 * <td><code>file:/myroot</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * <tr>
+	 * <td><code>/path/to/file</code></td>
+	 * <td><code>http://host.com/myroot</code></td>
+	 * <td><code>file:/path/to/file</code></td>
+	 * </tr>
+	 * </table>
 	 *
 	 * @param filename is the name to make absolute.
 	 * @param current is the current directory which permits to make absolute.
 	 * @return an absolute filename.
+	 * @since 5.0
 	 */
-	public static URL makeAbsolute(URL filename, URL current) {
-		if (current!=null && "file".equalsIgnoreCase(current.getProtocol())) { //$NON-NLS-1$
-			File cur = convertUrlToFile(current);
-			if (cur!=null) return makeAbsolute(filename, cur);
+	public static URL makeAbsolute(File filename, URL current) {
+		if (filename!=null) {
+			if (!filename.isAbsolute() && current!=null) {
+				return join(current, filename);
+			}
+			try {
+				return new URL(URISchemeType.FILE.toString()+filename.getPath());
+			}
+			catch (MalformedURLException _) {
+				// ignore error
+			}
 		}
-		return filename;
+		return null;
 	}
 
 	/** Replies the parent URL for the given URL.
@@ -1306,21 +1596,28 @@
 		String path = url.getPath();
 		String prefix, parentStr;
 
-		if ("jar".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$
-			int index = path.indexOf(JAR_URL_FILE_ROOT);
-			assert(index>0);
-			prefix = path.substring(0,index+1);
-			path = path.substring(index+1);
-			parentStr = URL_PATH_SEPARATOR;
+		switch(URISchemeType.getSchemeType(url)) {
+		case JAR:
+			{
+				int index = path.indexOf(JAR_URL_FILE_ROOT);
+				assert(index>0);
+				prefix = path.substring(0,index+1);
+				path = path.substring(index+1);
+				parentStr = URL_PATH_SEPARATOR;
+			}
+			break;
+		case FILE:
+			{
+				prefix = null;
+				parentStr = ".."+URL_PATH_SEPARATOR; //$NON-NLS-1$
+			}
+			break;
+		default:
+			{
+				prefix = null;
+				parentStr = URL_PATH_SEPARATOR;
+			}
 		}
-		else if ("file".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$
-			prefix = null;
-			parentStr = ".."+URL_PATH_SEPARATOR; //$NON-NLS-1$
-		}
-		else {
-			prefix = null;
-			parentStr = URL_PATH_SEPARATOR;
-		}
 		
 		if (path==null || "".equals(path)) path = parentStr; //$NON-NLS-1$
 		int index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR);

Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-02-17 09:52:54 UTC (rev 133)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-02-17 09:53:18 UTC (rev 134)
@@ -565,13 +565,13 @@
 	public void testMakeAbsoluteFileFile() {
 		File root = new File(File.separator+"myroot"); //$NON-NLS-1$
 
-		assertNull(FileSystem.makeAbsolute((File)null, null));
+		assertNull(FileSystem.makeAbsolute((File)null, (File)null));
 		assertNull(FileSystem.makeAbsolute((File)null, root));
 
 		assertEquals(new File(File.separator+"toto"), //$NON-NLS-1$
-				FileSystem.makeAbsolute(new File(File.separator+"toto"), null)); //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File(File.separator+"toto"), (File)null)); //$NON-NLS-1$
 		assertEquals(new File("toto"), //$NON-NLS-1$
-				FileSystem.makeAbsolute(new File("toto"), null)); //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("toto"), (File)null)); //$NON-NLS-1$
 
 		assertEquals(new File(File.separator+"toto"), //$NON-NLS-1$
 				FileSystem.makeAbsolute(new File(File.separator+"toto"), root)); //$NON-NLS-1$
@@ -637,7 +637,7 @@
 	/**
 	 * @throws Exception
 	 */
-	public void testMakeAbsoluteURLURL() throws Exception {
+	public void testMakeAbsoluteURLURL_withfileroot() throws Exception {
 		URL root = new File(File.separator+"myroot").toURI().toURL(); //$NON-NLS-1$
 
 		assertNull(FileSystem.makeAbsolute((URL)null, (URL)null));
@@ -692,6 +692,99 @@
 	/**
 	 * @throws Exception
 	 */
+	public void testMakeAbsoluteURLURL_withhttproot() throws Exception {
+		URL root = new URL("http://maven.arakhne.org";); //$NON-NLS-1$
+
+		assertNull(FileSystem.makeAbsolute((URL)null, (URL)null));
+		assertNull(FileSystem.makeAbsolute((URL)null, root));
+
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("file:/toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("file:toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("file:/toto"), root)); //$NON-NLS-1$
+		assertEquals(new URL("http://maven.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("file:toto"), root)); //$NON-NLS-1$
+
+		assertEquals(new URL("http://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("http://www.arakhne.org/toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("http://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("http://www.arakhne.org/./toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("http://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("http://www.arakhne.org/toto";), root)); //$NON-NLS-1$
+		assertEquals(new URL("http://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("http://www.arakhne.org/./toto";), root)); //$NON-NLS-1$
+
+		assertEquals(new URL("https://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("https://www.arakhne.org/toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("https://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("https://www.arakhne.org/./toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("https://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("https://www.arakhne.org/toto";), root)); //$NON-NLS-1$
+		assertEquals(new URL("https://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("https://www.arakhne.org/./toto";), root)); //$NON-NLS-1$
+
+		assertEquals(new URL("ftp://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("ftp://www.arakhne.org/toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("ftp://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("ftp://www.arakhne.org/./toto";), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("ftp://www.arakhne.org/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("ftp://www.arakhne.org/toto";), root)); //$NON-NLS-1$
+		assertEquals(new URL("ftp://www.arakhne.org/./toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("ftp://www.arakhne.org/./toto";), root)); //$NON-NLS-1$
+
+		assertEquals(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("jar:file:home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("jar:file:home/test/j.jar!/org/arakhne/vmutil/ff.properties"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("jar:file:/home/test/j.jar!/org/arakhne/vmutil/ff.properties"), root)); //$NON-NLS-1$
+		assertEquals(new URL("jar:http://maven.arakhne.org/home/test/j.jar!/org/arakhne/vmutil/ff.properties";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new URL("jar:file:home/test/j.jar!/org/arakhne/vmutil/ff.properties"), root)); //$NON-NLS-1$
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void testMakeAbsoluteFileURL_withfileroot() throws Exception {
+		URL root = new URL("http://maven.arakhne.org/myroot";); //$NON-NLS-1$
+
+		assertNull(FileSystem.makeAbsolute((File)null, (URL)null));
+		assertNull(FileSystem.makeAbsolute((File)null, root));
+
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("/toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("/toto"), root)); //$NON-NLS-1$
+		assertEquals(new URL("http://maven.arakhne.org/myroot/toto";), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("toto"), root)); //$NON-NLS-1$
+	}
+
+	/**
+	 * @throws Exception
+	 */
+	public void testMakeAbsoluteFileURL_withhttproot() throws Exception {
+		URL root = new File(File.separator+"myroot").toURI().toURL(); //$NON-NLS-1$
+
+		assertNull(FileSystem.makeAbsolute((File)null, (URL)null));
+		assertNull(FileSystem.makeAbsolute((File)null, root));
+
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("/toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("toto"), (URL)null)); //$NON-NLS-1$
+		assertEquals(new URL("file:/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("/toto"), root)); //$NON-NLS-1$
+		assertEquals(new URL("file:/myroot/toto"), //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("toto"), root)); //$NON-NLS-1$
+	}
+
+	/**
+	 * @throws Exception
+	 */
 	public void testGetParentURLURL() throws Exception {
 		assertEquals(
 				new URL("http://www.arakhne.org/";), //$NON-NLS-1$


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/