[Arakhnę-Dev] [156] Add ClasspathUtil.

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


Revision: 156
Author:   galland
Date:     2010-06-09 09:37:14 +0200 (Wed, 09 Jun 2010)
Log Message:
-----------
Add ClasspathUtil.

Added Paths:
-----------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java
    trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java

Added: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java	2010-06-09 07:37:14 UTC (rev 156)
@@ -0,0 +1,75 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2005-2010 Stéphane GALLAND
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.vmutil;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Current classpath and associated utility functions.
+ * 
+ * @author Stéphane GALLAND <galland@xxxxxxxxxxx>
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid org.arakhne.afc
+ * @mavenartifactid arakhneVmutils
+ * @since 5.0
+ */
+public class ClasspathUtil {
+
+	private static URL[] startupClasspath = null;
+	
+	/** Replies the classpath at start of the virtual machine.
+	 * 
+	 * @return the startup classpath, never <code>null</code>.
+	 */
+	public static URL[] getStartupClasspath() {
+		if (startupClasspath==null) {
+			URL[] urls;
+			String paths = System.getProperty("java.class.path"); //$NON-NLS-1$
+			if (paths==null || "".equals(paths)) { //$NON-NLS-1$
+				urls = new URL[0];
+			}
+			else {
+				String[] pathList = paths.split(File.pathSeparator);
+				if (pathList==null || pathList.length==0) {
+					urls = new URL[0];
+				}
+				else {
+					List<URL> urlList = new ArrayList<URL>(pathList.length);
+					URL u;
+					for(String p : pathList) {
+						u = FileSystem.convertStringToUrl(p, true);
+						if (u!=null) {
+							urlList.add(u);
+						}
+					}
+					urls = new URL[urlList.size()];
+					urlList.toArray(urls);
+				}
+			}
+			startupClasspath = urls;
+		}
+		return startupClasspath;
+	}
+
+}
\ No newline at end of file

Added: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java	                        (rev 0)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java	2010-06-09 07:37:14 UTC (rev 156)
@@ -0,0 +1,67 @@
+/* $Id$
+ * 
+ * Copyright (C) 2007-09 St&eacute;phane GALLAND
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.vmutil;
+
+import java.io.File;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+/**
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ * @mavengroupid org.arakhne.afc
+ * @mavenartifactid arakhneVmutils
+ */
+public class ClasspathUtilTest extends TestCase {
+
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	/**
+	 */
+	public void testGetStartupClasspath() {
+		URL[] urls = ClasspathUtil.getStartupClasspath();
+		assertNotNull(urls);
+		
+		String[] paths = System.getProperty("java.class.path").split(File.pathSeparator); //$NON-NLS-1$
+		
+		assertEquals(paths.length, urls.length);
+		
+		for(int i=0; i<paths.length; i++) {
+			URL u = FileSystem.convertStringToUrl(paths[i], true);
+			assertEquals(u, urls[i]);
+		}
+	}
+	
+}


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