[Arakhnę-Dev] [287] * Fixing the functions to retreive the OS UUID and serial number on unix OS .

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


Revision: 287
Author:   galland
Date:     2011-09-15 19:56:37 +0200 (Thu, 15 Sep 2011)
Log Message:
-----------
* Fixing the functions to retreive the OS UUID and serial number on unix OS.

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

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2011-09-13 13:04:21 UTC (rev 286)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2011-09-15 17:56:37 UTC (rev 287)
@@ -33,6 +33,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.nio.channels.Channels;
 import java.nio.channels.FileChannel;
 import java.nio.channels.ReadableByteChannel;
@@ -121,17 +122,36 @@
 	
 	private static Boolean isFileCompatibleWithURL = null;
 
-	/** Decode the given string.
+	/** Replace the HTML entities by the current charset characters.
 	 * 
 	 * @param s
 	 * @return decoded string or <var>s/<var>.
-	 * @throws UnsupportedEncodingException 
 	 */
-	private static String decodeURL(String s) throws UnsupportedEncodingException {
+	private static String decodeHTMLEntities(String s) {
 		if (s==null) return null;
-		return URLDecoder.decode(s, Charset.defaultCharset().displayName());
+		try {
+			return URLDecoder.decode(s, Charset.defaultCharset().displayName());
+		}
+		catch (UnsupportedEncodingException _) {
+			return s;
+		}
 	}
 	
+	/** Replace the special characters by HTML entities.
+	 * 
+	 * @param s
+	 * @return decoded string or <var>s/<var>.
+	 */
+	private static String encodeHTMLEntities(String s) {
+		if (s==null) return null;
+		try {
+			return URLEncoder.encode(s, Charset.defaultCharset().displayName());
+		}
+		catch (UnsupportedEncodingException _) {
+			return s;
+		}
+	}
+
 	/** Decode the given file to obtain a string representation
 	 * which is compatible with the URL standard.
 	 * This function was introduced to have a work around
@@ -204,7 +224,7 @@
 		if (isJarURL(url)) {
 			String path = url.getPath();
 			int idx = path.lastIndexOf(JAR_URL_FILE_ROOT);
-			if (idx>=0) return new File(path.substring(idx+1));
+			if (idx>=0) return new File(decodeHTMLEntities(path.substring(idx+1)));
 		}
 		return null;
 	}
@@ -363,13 +383,12 @@
 			if (prefix!=null) {
 				return toJarURL(prefix, path);
 			}
-			path = decodeURL(path);
 			URI uri = new URI(
 					filename.getProtocol(), 
 					filename.getUserInfo(), 
 					filename.getHost(), 
 					filename.getPort(), 
-					path,
+					decodeHTMLEntities(path),
 					null,
 					null);
 			return uri.toURL();
@@ -441,12 +460,16 @@
 			idx = fullPath.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end);
 		}
 		while (idx>=0 && end>=0 && idx>=end);
+		String r;
 		if (idx<0) {
 			if (end<fullPath.length()-1)
-				return fullPath.substring(0, end+1);
-			return fullPath;
+				r = fullPath.substring(0, end+1);
+			else
+				r = fullPath;
 		}
-		return fullPath.substring(idx+1, end+1);
+		else 
+			r = fullPath.substring(idx+1, end+1);
+		return decodeHTMLEntities(r);
 	}
 
 	/** Reply the basename of the specified file without the last extension.
@@ -529,8 +552,8 @@
 		else
 			basename = largeBasename.substring(idx+1, end+1);
 		idx = basename.lastIndexOf(getFileExtensionCharacter());
-		if (idx<0) return basename;
-		return basename.substring(0,idx);
+		if (idx>=0) basename = basename.substring(0,idx);
+		return decodeHTMLEntities(basename);
 	}
 
 	/** Reply the basename of the specified file without all the extensions.
@@ -608,8 +631,8 @@
 			basename = largeBasename.substring(idx+1, end+1);
 
 		idx = basename.indexOf(getFileExtensionCharacter());
-		if (idx<0) return basename;
-		return basename.substring(0,idx);
+		if (idx>=0) basename = basename.substring(0,idx);
+		return decodeHTMLEntities(basename);
 	}
 
 	/** Reply the extension of the specified file.
@@ -645,7 +668,7 @@
 		String largeBasename = largeBasename(filename);
 		int idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
 		if (idx<=0) return ""; //$NON-NLS-1$
-		return largeBasename.substring(idx);
+		return decodeHTMLEntities(largeBasename.substring(idx));
 	}
 
 	/** Reply all the extensions of the specified file.
@@ -674,7 +697,9 @@
 		String[] parts = largeBasename.split(Pattern.quote(Character.toString(getFileExtensionCharacter())));
 		if (parts.length<=1) return new String[0];
 		String[] r = new String[parts.length-1];
-		System.arraycopy(parts, 1, r, 0, r.length);
+		for(int i=0; i<r.length; ++i) {
+			r[i] = decodeHTMLEntities(parts[i+1]);
+		}
 		return r;
 	}
 
@@ -699,7 +724,11 @@
 		if (isJarURL(filename))
 			return split(getJarFile(filename));
 		path = filename.getPath();
-		return path.split(Pattern.quote(URL_PATH_SEPARATOR));
+		String[] tab = path.split(Pattern.quote(URL_PATH_SEPARATOR));
+		for(int i=0; i<tab.length; ++i) {
+			tab[i] = decodeHTMLEntities(tab[i]);
+		}
+		return tab;
 	}
 
 	/** Join the parts of a path and append them to the given File.
@@ -782,8 +811,8 @@
 					urlBase.getUserInfo(), 
 					urlBase.getHost(), 
 					urlBase.getPort(), 
-					decodeURL(buf.toString()),
-					decodeURL(urlBase.getQuery()),
+					decodeHTMLEntities(buf.toString()),
+					decodeHTMLEntities(urlBase.getQuery()),
 					urlBase.getRef());
 			return uri.toURL();
 		}
@@ -831,8 +860,8 @@
 					urlBase.getUserInfo(), 
 					urlBase.getHost(), 
 					urlBase.getPort(), 
-					decodeURL(buf.toString()),
-					decodeURL(urlBase.getQuery()),
+					decodeHTMLEntities(buf.toString()),
+					decodeHTMLEntities(urlBase.getQuery()),
 					urlBase.getRef());
 			return uri.toURL();
 		}
@@ -917,8 +946,8 @@
 		if (filename==null) return null;
 		String path = filename.getPath();
 		int idx = path.lastIndexOf(URL_PATH_SEPARATOR);
-		StringBuffer buf = new StringBuffer((idx<0) ? "" : path.substring(0, idx+1)); //$NON-NLS-1$
-		String largeBasename = path.substring(idx+1);
+		StringBuffer buf = new StringBuffer((idx<0) ? "" : decodeHTMLEntities(path.substring(0, idx+1))); //$NON-NLS-1$
+		String largeBasename = decodeHTMLEntities(path.substring(idx+1));
 		idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
 		if (idx<0) return filename;
 		buf.append(largeBasename.substring(0, idx));
@@ -935,8 +964,8 @@
 					filename.getUserInfo(), 
 					filename.getHost(), 
 					filename.getPort(), 
-					decodeURL(buf.toString()),
-					decodeURL(filename.getQuery()),
+					buf.toString(),
+					decodeHTMLEntities(filename.getQuery()),
 					filename.getRef());
 			return uri.toURL();
 		}
@@ -994,8 +1023,8 @@
 			end --;
 			idx = path.lastIndexOf(URL_PATH_SEPARATOR, end-1);
 		}
-		StringBuffer buf = new StringBuffer((idx<0) ? "" : path.substring(0, idx+1)); //$NON-NLS-1$
-		String largeBasename = path.substring(idx+1, end);
+		StringBuffer buf = new StringBuffer((idx<0) ? "" : decodeHTMLEntities(path.substring(0, idx+1))); //$NON-NLS-1$
+		String largeBasename = decodeHTMLEntities(path.substring(idx+1, end));
 		idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
 		if (idx<0) {
 			buf.append(largeBasename);
@@ -1020,8 +1049,8 @@
 					filename.getUserInfo(), 
 					filename.getHost(), 
 					filename.getPort(), 
-					decodeURL(buf.toString()),
-					decodeURL(filename.getQuery()),
+					buf.toString(),
+					encodeHTMLEntities(filename.getQuery()),
 					filename.getRef());
 			return uri.toURL();
 		}
@@ -1516,14 +1545,10 @@
 			try {
 				uri = new URI(url.getProtocol(), url.getUserInfo(), url
 						.getHost(), url.getPort(), 
-						decodeURL(url.getPath()),
-						decodeURL(url.getQuery()),
+						decodeHTMLEntities(url.getPath()),
+						decodeHTMLEntities(url.getQuery()),
 						url.getRef());
 			}
-			catch(UnsupportedEncodingException e1) {
-				// The URL is broken beyond automatic repair
-				throw new IllegalArgumentException("broken URL: " + url); //$NON-NLS-1$
-			}
 			catch (URISyntaxException e1) {
 				// The URL is broken beyond automatic repair
 				throw new IllegalArgumentException("broken URL: " + url); //$NON-NLS-1$
@@ -1539,10 +1564,10 @@
 			if (path!=null) {
 				if (auth==null || "".equals(auth)) { //$NON-NLS-1$
 					// absolute filename in URI
-					return new File(path);
+					return new File(decodeHTMLEntities(path));
 				}
 				// relative filename in URI, extract it directly
-				return new File(auth+path);
+				return new File(decodeHTMLEntities(auth+path));
 			}
 		}
 		throw new IllegalArgumentException("not a file URL: "+url); //$NON-NLS-1$

Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2011-09-13 13:04:21 UTC (rev 286)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2011-09-15 17:56:37 UTC (rev 287)
@@ -61,6 +61,9 @@
 	private static final String PARENT_TEST_URL3 = "jar:jar:http://www.arakhne.org/j.jar!/inner/myjar.jar!/org/arakhne/vmutil/";; //$NON-NLS-1$
 	private static final String JARPART_TEST_URL3 = "jar:http://www.arakhne.org/j.jar!/inner/myjar.jar";; //$NON-NLS-1$
 	private static final String JOIN_TEST_URL3 = "jar:jar:http://www.arakhne.org/j.jar!/inner/myjar.jar!/org/arakhne/vmutil/file.x.z.z/home/test.x.z.z";; //$NON-NLS-1$
+
+	private static final String STRING_WITH_SPACE = "/the path/to/file with space.toto"; //$NON-NLS-1$
+	private static final URL URL_WITH_SPACE;
 	
 	static {
 		try {
@@ -83,6 +86,7 @@
 			pu3 = new URL(PARENT_TEST_URL1);
 			pu7 = new URL(PARENT_TEST_URL2);
 			pu13 = new URL(PARENT_TEST_URL3);
+			URL_WITH_SPACE = new File(STRING_WITH_SPACE).toURI().toURL();
 		}
 		catch(Throwable e) {
 			throw new AssertionFailedError(e.getLocalizedMessage());
@@ -220,33 +224,47 @@
 	}
 	
 	/**
+	 * @throws Exception
 	 */
-	public void testIsJarURLURL() {
+	public void testIsJarURLURL() throws Exception {
 		assertFalse(FileSystem.isJarURL(u1));
 		assertFalse(FileSystem.isJarURL(u2));
 		assertFalse(FileSystem.isJarURL(u3));
 		assertTrue(FileSystem.isJarURL(u7));
 		assertTrue(FileSystem.isJarURL(u13));
+
+		assertFalse(FileSystem.isJarURL(new URL("file:"+STRING_WITH_SPACE)));  //$NON-NLS-1$
+		assertFalse(FileSystem.isJarURL(URL_WITH_SPACE));
 	}
 	
 	/**
+	 * @throws Exception
 	 */
-	public void testGetJarURLURL() {
+	public void testGetJarURLURL() throws Exception {
 		assertNull(FileSystem.getJarURL(u1));
 		assertNull(FileSystem.getJarURL(u2));
 		assertNull(FileSystem.getJarURL(u3));
 		assertEquals(u11, FileSystem.getJarURL(u7));
 		assertEquals(u14, FileSystem.getJarURL(u13));
+
+		assertEquals(new URL("file:"+STRING_WITH_SPACE),  //$NON-NLS-1$
+				FileSystem.getJarURL(new URL("jar:file:"+STRING_WITH_SPACE+"!/titi")));  //$NON-NLS-1$//$NON-NLS-2$
+		assertNull(FileSystem.getJarFile(URL_WITH_SPACE));
 	}
 
 	/**
+	 * @throws Exception
 	 */
-	public void testGetJarFileURL() {
+	public void testGetJarFileURL() throws Exception {
 		assertNull(FileSystem.getJarFile(u1));
 		assertNull(FileSystem.getJarFile(u2));
 		assertNull(FileSystem.getJarFile(u3));
 		assertEquals(f4, FileSystem.getJarFile(u7));
 		assertEquals(f4, FileSystem.getJarFile(u13));
+
+		assertEquals(new File("/titi"),  //$NON-NLS-1$
+				FileSystem.getJarFile(new URL("jar:file:"+STRING_WITH_SPACE+"!/titi")));  //$NON-NLS-1$//$NON-NLS-2$
+		assertNull(FileSystem.getJarFile(URL_WITH_SPACE));
 	}
 
 	/**
@@ -286,6 +304,9 @@
 		assertEquals(new URL("file", "", "/"),  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
 				FileSystem.dirname(f2));
 		assertNull(FileSystem.dirname(new File("/"))); //$NON-NLS-1$
+
+		assertEquals(new URL("file:/the path/to"),  //$NON-NLS-1$
+				FileSystem.dirname(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -307,6 +328,11 @@
 		
 		assertEquals(new URL("file", "", "/a/b%20c/"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 				FileSystem.dirname(new File("/a/b c/d.txt").toURI().toURL())); //$NON-NLS-1$
+
+		assertEquals(new URL("file:/the%20path/to/"),  //$NON-NLS-1$
+				FileSystem.dirname(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals(new URL("file:/the%20path/to/"),  //$NON-NLS-1$
+				FileSystem.dirname(URL_WITH_SPACE));
 	}
 
 	/**
@@ -331,6 +357,9 @@
 		catch(AssertionError _) {
 			//
 		}
+
+		assertEquals("file with space.toto",  //$NON-NLS-1$
+				FileSystem.largeBasename(STRING_WITH_SPACE));
 	}
 
 	/**
@@ -340,6 +369,9 @@
 		assertEquals("home", FileSystem.largeBasename(f2)); //$NON-NLS-1$
 		assertEquals("a.b.c", FileSystem.largeBasename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("", FileSystem.largeBasename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals("file with space.toto",  //$NON-NLS-1$
+				FileSystem.largeBasename(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -361,6 +393,11 @@
 		catch(AssertionError _) {
 			//
 		}
+
+		assertEquals("file with space.toto",  //$NON-NLS-1$
+				FileSystem.largeBasename(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals("file with space.toto",  //$NON-NLS-1$
+				FileSystem.largeBasename(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -385,6 +422,9 @@
 		catch(AssertionError _) {
 			//
 		}
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.basename(STRING_WITH_SPACE));
 	}
 
 	/**
@@ -394,6 +434,9 @@
 		assertEquals("home", FileSystem.basename(f2)); //$NON-NLS-1$
 		assertEquals("a.b", FileSystem.basename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("", FileSystem.basename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.basename(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -415,6 +458,11 @@
 		catch(AssertionError _) {
 			//
 		}
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.basename(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.basename(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -426,6 +474,9 @@
 		assertEquals("", FileSystem.shortBasename("")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("terrain_physx", FileSystem.shortBasename("D:\\vivus_test\\export dae\\yup\\terrain_physx.dae")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("terrain_physx", FileSystem.shortBasename("file:D:\\vivus_test\\export dae\\yup\\terrain_physx.dae")); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.shortBasename(STRING_WITH_SPACE));
 	}
 
 	/**
@@ -435,6 +486,9 @@
 		assertEquals("home", FileSystem.shortBasename(f2)); //$NON-NLS-1$
 		assertEquals("a", FileSystem.shortBasename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("", FileSystem.shortBasename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.shortBasename(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -456,6 +510,11 @@
 		catch(AssertionError _) {
 			//
 		}
+
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.shortBasename(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals("file with space",  //$NON-NLS-1$
+				FileSystem.shortBasename(URL_WITH_SPACE));
 	}
 
 	/**
@@ -465,6 +524,9 @@
 		assertEquals("", FileSystem.extension(f2)); //$NON-NLS-1$
 		assertEquals(".c", FileSystem.extension(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("", FileSystem.extension(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals(".toto",  //$NON-NLS-1$
+				FileSystem.extension(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -478,6 +540,11 @@
 		assertEquals(".z", FileSystem.extension(u13)); //$NON-NLS-1$
 		assertEquals(".c", FileSystem.extension(new URL("file:///a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals("", FileSystem.extension(new URL("file://"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals(".toto",  //$NON-NLS-1$
+				FileSystem.extension(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals(".toto",  //$NON-NLS-1$
+				FileSystem.extension(URL_WITH_SPACE));
 	}
 
 	/**
@@ -487,6 +554,9 @@
 		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(f2)));
 		assertTrue(Arrays.equals(new String[]{"b","c"}, FileSystem.extensions(new File("/a.b.c/")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(new File("/")))); //$NON-NLS-1$
+
+		assertTrue(Arrays.equals(new String[] {"toto"},  //$NON-NLS-1$
+				FileSystem.extensions(new File(STRING_WITH_SPACE))));
 	}
 
 	/**
@@ -499,6 +569,9 @@
 		assertTrue(Arrays.equals(new String[]{"x","z","z"}, FileSystem.extensions(u7))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[]{"b","c"}, FileSystem.extensions(new URL("file:///a.b.c/")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(new URL("file://")))); //$NON-NLS-1$
+
+		assertTrue(Arrays.equals(new String[] {"toto"},  //$NON-NLS-1$
+				FileSystem.extensions(new File(STRING_WITH_SPACE))));
 	}
 
 	/**
@@ -517,11 +590,21 @@
 					"home", //$NON-NLS-1$
 				},
 				FileSystem.split(f2)));
+
+		assertTrue(Arrays.equals(
+				new String[] {
+							"", //$NON-NLS-1$
+							"the path", //$NON-NLS-1$
+							"to", //$NON-NLS-1$
+							"file with space.toto" //$NON-NLS-1$
+				},
+				FileSystem.split(new File(STRING_WITH_SPACE))));
 	}
 
 	/**
+	 * @throws Exception
 	 */
-	public void testSplitURL() {
+	public void testSplitURL() throws Exception {
 		String[] tab;
 		
 		tab = FileSystem.split(u1);
@@ -562,6 +645,23 @@
 					"file.x.z.z", //$NON-NLS-1$
 				},
 				tab));
+
+		assertTrue(Arrays.equals(
+				new String[] {
+							"", //$NON-NLS-1$
+							"the path", //$NON-NLS-1$
+							"to", //$NON-NLS-1$
+							"file with space.toto" //$NON-NLS-1$
+				},
+				FileSystem.split(new URL("file:"+STRING_WITH_SPACE)))); //$NON-NLS-1$
+		assertTrue(Arrays.equals(
+				new String[] {
+							"", //$NON-NLS-1$
+							"the path", //$NON-NLS-1$
+							"to", //$NON-NLS-1$
+							"file with space.toto" //$NON-NLS-1$
+				},
+				FileSystem.split(URL_WITH_SPACE)));
 	}
 
 	/**
@@ -614,6 +714,11 @@
 				"", //$NON-NLS-1$
 				"home", //$NON-NLS-1$
 				"test.x.z.z")); //$NON-NLS-1$
+
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b"),  //$NON-NLS-1$
+				FileSystem.join(new URL("file:"+STRING_WITH_SPACE), "a", "b"));  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b"),  //$NON-NLS-1$
+				FileSystem.join(URL_WITH_SPACE, "a", "b")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -640,6 +745,11 @@
 				FileSystem.join(u13,
 				new File(File.separator+"home"), //$NON-NLS-1$
 				new File("test.x.z.z"))); //$NON-NLS-1$
+		
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b"),  //$NON-NLS-1$
+				FileSystem.join(new URL("file:"+STRING_WITH_SPACE), new File("a"), new File("b"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b"),  //$NON-NLS-1$
+				FileSystem.join(URL_WITH_SPACE, new File("a"), new File("b"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -651,11 +761,17 @@
 		assertFalse(FileSystem.hasExtension(f1, "")); //$NON-NLS-1$
 		assertTrue(FileSystem.hasExtension(f2, "")); //$NON-NLS-1$
 		assertFalse(FileSystem.hasExtension(f2, ".z")); //$NON-NLS-1$
+
+		assertTrue(FileSystem.hasExtension(new File(STRING_WITH_SPACE), ".toto"));  //$NON-NLS-1$
+		assertTrue(FileSystem.hasExtension(new File(STRING_WITH_SPACE), "toto"));  //$NON-NLS-1$
+		assertFalse(FileSystem.hasExtension(new File(STRING_WITH_SPACE), ".zip"));  //$NON-NLS-1$
+		assertFalse(FileSystem.hasExtension(new File(STRING_WITH_SPACE), "zip"));  //$NON-NLS-1$
 	}
 
 	/**
+	 * @throws Exception
 	 */
-	public void testHasExtensionURLString() {
+	public void testHasExtensionURLString() throws Exception {
 		assertTrue(FileSystem.hasExtension(u1, ".z")); //$NON-NLS-1$
 		assertTrue(FileSystem.hasExtension(u1, "z")); //$NON-NLS-1$
 		assertFalse(FileSystem.hasExtension(u1, ".x")); //$NON-NLS-1$
@@ -670,6 +786,15 @@
 		assertTrue(FileSystem.hasExtension(u7, "z")); //$NON-NLS-1$
 		assertFalse(FileSystem.hasExtension(u7, ".x")); //$NON-NLS-1$
 		assertFalse(FileSystem.hasExtension(u7, "")); //$NON-NLS-1$
+
+		assertTrue(FileSystem.hasExtension(new URL("file:"+STRING_WITH_SPACE), ".toto"));  //$NON-NLS-1$ //$NON-NLS-2$
+		assertTrue(FileSystem.hasExtension(new URL("file:"+STRING_WITH_SPACE), "toto"));  //$NON-NLS-1$ //$NON-NLS-2$
+		assertFalse(FileSystem.hasExtension(new URL("file:"+STRING_WITH_SPACE), ".zip"));  //$NON-NLS-1$ //$NON-NLS-2$
+		assertFalse(FileSystem.hasExtension(new URL("file:"+STRING_WITH_SPACE), "zip"));  //$NON-NLS-1$ //$NON-NLS-2$
+		assertTrue(FileSystem.hasExtension(URL_WITH_SPACE, ".toto")); //$NON-NLS-1$
+		assertTrue(FileSystem.hasExtension(URL_WITH_SPACE, "toto")); //$NON-NLS-1$
+		assertFalse(FileSystem.hasExtension(URL_WITH_SPACE, ".zip")); //$NON-NLS-1$
+		assertFalse(FileSystem.hasExtension(URL_WITH_SPACE, "zip")); //$NON-NLS-1$
 	}
 
 	/**
@@ -677,6 +802,9 @@
 	public void testRemoveExtensionFile() {
 		assertEquals(new File("/home/test.x.z"), FileSystem.removeExtension(f1)); //$NON-NLS-1$
 		assertEquals(new File("/home"), FileSystem.removeExtension(f2)); //$NON-NLS-1$
+
+		assertEquals(new File("/the path/to/file with space"),  //$NON-NLS-1$
+				FileSystem.removeExtension(new File(STRING_WITH_SPACE)));
 	}
 
 	/**
@@ -689,6 +817,11 @@
 				FileSystem.removeExtension(u2));
 		assertEquals(u5, FileSystem.removeExtension(u3));
 		assertEquals(u9, FileSystem.removeExtension(u7));
+
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space"),  //$NON-NLS-1$
+				FileSystem.removeExtension(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space"),  //$NON-NLS-1$
+				FileSystem.removeExtension(URL_WITH_SPACE));
 	}
 
 	/**
@@ -696,6 +829,9 @@
 	public void testReplaceExtensionFileString() {
 		assertEquals(new File("/home/test.x.z.toto"), FileSystem.replaceExtension(f1, ".toto")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals(new File("/home.toto"), FileSystem.replaceExtension(f2, ".toto")); //$NON-NLS-1$ //$NON-NLS-2$
+
+		assertEquals(new File("/the path/to/file with space.zip"),  //$NON-NLS-1$
+				FileSystem.replaceExtension(new File(STRING_WITH_SPACE), ".zip")); //$NON-NLS-1$
 	}
 
 	/**
@@ -708,6 +844,11 @@
 				FileSystem.replaceExtension(u2, ".toto")); //$NON-NLS-1$
 		assertEquals(u6, FileSystem.replaceExtension(u3, ".toto")); //$NON-NLS-1$
 		assertEquals(u10, FileSystem.replaceExtension(u7, ".toto")); //$NON-NLS-1$
+
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.zip"),  //$NON-NLS-1$
+				FileSystem.replaceExtension(new URL("file:"+STRING_WITH_SPACE), ".zip")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.zip"),  //$NON-NLS-1$
+				FileSystem.replaceExtension(URL_WITH_SPACE, ".zip")); //$NON-NLS-1$
 	}
 
 	/**
@@ -716,6 +857,9 @@
 		assertEquals(new File("/home/test.x.z.z"), FileSystem.addExtension(f1, ".z")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals(new File("/home/test.x.z.z.toto"), FileSystem.addExtension(f1, ".toto")); //$NON-NLS-1$ //$NON-NLS-2$
 		assertEquals(new File("/home.toto"), FileSystem.addExtension(f2, ".toto")); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		assertEquals(new File(STRING_WITH_SPACE+".zip"), //$NON-NLS-1$
+				FileSystem.addExtension(new File(STRING_WITH_SPACE), "zip")); //$NON-NLS-1$
 	}
 
 	/**
@@ -728,6 +872,9 @@
 				FileSystem.addExtension(u1, ".toto")); //$NON-NLS-1$
 		assertEquals(new File("/home.toto").toURI().toURL(), //$NON-NLS-1$ 
 				FileSystem.addExtension(u2, ".toto")); //$NON-NLS-1$
+		
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto.zip"), //$NON-NLS-1$
+				FileSystem.addExtension(new URL("file:"+STRING_WITH_SPACE), ".zip")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -811,12 +958,15 @@
 				 FileSystem.convertStringToURL("org/arakhne/vmutil/test.txt", true)); //$NON-NLS-1$
 		assertEquals(testResourceFileRel,
 				 FileSystem.convertStringToURL("org/arakhne/vmutil/test.txt", false)); //$NON-NLS-1$
+
+		assertEquals(new URL("file:"+STRING_WITH_SPACE),  //$NON-NLS-1$
+				FileSystem.convertStringToURL(STRING_WITH_SPACE, false));
 	}
 
 	/**
 	 * @throws Exception
 	 */
-	public void testConvertUrlToFile() throws Exception {
+	public void testConvertURLToFile() throws Exception {
 		assertEquals(f1,
 				 FileSystem.convertURLToFile(new URL("file:"+f1.getAbsolutePath()))); //$NON-NLS-1$
 
@@ -839,6 +989,11 @@
 
 		assertEquals(new File("/toto").getCanonicalPath(), //$NON-NLS-1$
 				 FileSystem.convertURLToFile(new URL("file:/toto")).getCanonicalPath()); //$NON-NLS-1$
+
+		assertEquals(new File(STRING_WITH_SPACE),
+				FileSystem.convertURLToFile(new URL("file:"+STRING_WITH_SPACE))); //$NON-NLS-1$
+		assertEquals(new File(STRING_WITH_SPACE),
+				FileSystem.convertURLToFile(URL_WITH_SPACE));
 	}
 	
 	/**
@@ -1042,6 +1197,11 @@
 				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$
+
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b/c"),  //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("a/b/c"), new URL("file:"+STRING_WITH_SPACE)));  //$NON-NLS-1$//$NON-NLS-2$
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto/a/b/c"),  //$NON-NLS-1$
+				FileSystem.makeAbsolute(new File("a/b/c"), URL_WITH_SPACE));  //$NON-NLS-1$
 	}
 
 	/**
@@ -1176,6 +1336,11 @@
 		assertEquals(
 				new URL("jar:file:test.jar!/"), //$NON-NLS-1$
 				FileSystem.getParentURL(new URL("jar:file:test.jar!/"))); //$NON-NLS-1$
+
+		assertEquals(new URL("file:/the path/to/"),  //$NON-NLS-1$
+				FileSystem.getParentURL(new URL("file:"+STRING_WITH_SPACE)));  //$NON-NLS-1$
+		assertEquals(new URL("file:/the%20path/to/"),  //$NON-NLS-1$
+				FileSystem.getParentURL(URL_WITH_SPACE));
 	}
 	
 	/**
@@ -1201,6 +1366,9 @@
 		finally {
 			URLHandlerUtil.uninstallArakhneHandlers();
 		}
+
+		assertEquals(new URL("file:/the%20path/to/file%20with%20space.toto"),  //$NON-NLS-1$
+				FileSystem.convertFileToURL(new File(STRING_WITH_SPACE)));
 	}
 	
 	/**

Modified: trunk/arakhneVmutils/native/josuuid/src/main/native/unixos.c
===================================================================
--- trunk/arakhneVmutils/native/josuuid/src/main/native/unixos.c	2011-09-13 13:04:21 UTC (rev 286)
+++ trunk/arakhneVmutils/native/josuuid/src/main/native/unixos.c	2011-09-15 17:56:37 UTC (rev 287)
@@ -27,7 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-# include <unistd.h>
+#include <unistd.h>
 
 #include "osmacro.h"
 #include "utils.h"
@@ -139,38 +139,30 @@
 /* Replies the serial number of the system */
 char* getOSSerial(int enableSuperUser, int enableGUI) {
 	char* result = NULL;
-	if (whichCommand("hal-get-property")) {
-		result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial");
+	if (whichCommand("udevadm")) {
+		result = runCommand("udevadm info -q property -n /dev/sda|grep ID_SERIAL_SHORT=|cut -d= -f2 2>/dev/null");
 		if (result!=NULL) {
 			trim(&result);
 		}
-		else {
-			result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.serial");
-			if (result!=NULL) {
-				trim(&result);
-			}
+	}
+	if (result==NULL && whichCommand("udevadm")) {
+		result = runCommand("udevadm info -q property -n /dev/hda|grep ID_SERIAL_SHORT=|cut -d= -f2 2>/dev/null");
+		if (result!=NULL) {
+			trim(&result);
 		}
-		return result;
 	}
-	if (result==NULL && whichCommand("dmidecode")) {
-		if (enableSuperUser && enableGUI && whichCommand("gksudo")) {
-			result = runCommand("gksudo -- dmidecode -s system-serial-number");
-			if (result!=NULL) {
-				trim(&result);
-			}
+	if (result==NULL && whichCommand("hal-get-property")) {
+		result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.serial 2>/dev/null");
+		if (result!=NULL) {
+			trim(&result);
 		}
-		if (enableSuperUser && result==NULL && whichCommand("sudo")) {
-			result = runCommand("sudo -A -- dmidecode -s system-serial-number");
+		else {
+			result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.serial 2>/dev/null");
 			if (result!=NULL) {
 				trim(&result);
 			}
 		}
-		if (result==NULL) {
-			result = runCommand("dmidecode -s system-serial-number");
-			if (result!=NULL) {
-				trim(&result);
-			}
-		}
+		return result;
 	}
 	/* no way to obtain the serial number */
 	return result;
@@ -179,37 +171,29 @@
 /* Replies the UUID of the system */
 char* getOSUUID(int enableSuperUser, int enableGUI) {
 	char* result = NULL;
-	if (whichCommand("hal-get-property")) {
-		result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid");
+	if (whichCommand("udevadm")) {
+		result = runCommand("udevadm info -q property -n /dev/sda|grep ID_SERIAL=|cut -d= -f2 2>/dev/null");
 		if (result!=NULL) {
 			trim(&result);
 		}
-		else {
-			result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.uuid");
-			if (result!=NULL) {
-				trim(&result);
-			}
+	}
+	if (result==NULL && whichCommand("udevadm")) {
+		result = runCommand("udevadm info -q property -n /dev/hda|grep ID_SERIAL=|cut -d= -f2 2>/dev/null");
+		if (result!=NULL) {
+			trim(&result);
 		}
 	}
-	if (result==NULL && whichCommand("dmidecode")) {
-		if (enableSuperUser && enableGUI && whichCommand("gksudo")) {
-			result = runCommand("gksudo -- dmidecode -s system-uuid");
-			if (result!=NULL) {
-				trim(&result);
-			}
+	if (result==NULL && whichCommand("hal-get-property")) {
+		result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid 2>/dev/null");
+		if (result!=NULL) {
+			trim(&result);
 		}
-		if (enableSuperUser && result==NULL && whichCommand("sudo")) {
-			result = runCommand("sudo -A -- dmidecode -s system-uuid");
+		else {
+			result = runCommand("hal-get-property --udi /org/freedesktop/Hal/devices/computer --key smbios.system.uuid 2>/dev/null");
 			if (result!=NULL) {
 				trim(&result);
 			}
 		}
-		if (result==NULL) {
-			result = runCommand("dmidecode -s system-uuid");
-			if (result!=NULL) {
-				trim(&result);
-			}
-		}
 	}
 	/* no way to obtain the UUID */
 	return result;


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