[Arakhnę-Dev] [162] * Bug fix: because Windows operating system uses '\' has file separator, some regular expression patterns in ReflectionUtil are failing when running under Windows . |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
- To: dev@xxxxxxxxxxx
- Subject: [Arakhnę-Dev] [162] * Bug fix: because Windows operating system uses '\' has file separator, some regular expression patterns in ReflectionUtil are failing when running under Windows .
- From: subversion@xxxxxxxxxxxxx
- Date: Mon, 12 Jul 2010 16:20:06 +0200
Revision: 162
Author: galland
Date: 2010-07-12 16:20:05 +0200 (Mon, 12 Jul 2010)
Log Message:
-----------
* Bug fix: because Windows operating system uses '\' has file separator, some regular expression patterns in ReflectionUtil are failing when running under Windows.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/MACNumber.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java
trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ClasspathUtil.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -24,6 +24,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Pattern;
/**
* Current classpath and associated utility functions.
@@ -50,7 +51,7 @@
urls = new URL[0];
}
else {
- String[] pathList = paths.split(File.pathSeparator);
+ String[] pathList = paths.split(Pattern.quote(File.pathSeparator));
if (pathList==null || pathList.length==0) {
urls = new URL[0];
}
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/DynamicURLClassLoader.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -45,6 +45,7 @@
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.jar.Attributes.Name;
+import java.util.regex.Pattern;
import sun.misc.Resource;
import sun.misc.URLClassPath;
@@ -530,7 +531,7 @@
private static URL[] mergeClassPath(URL... urls) {
String path = System.getProperty("java.class.path"); //$NON-NLS-1$
String separator = System.getProperty("path.separator"); //$NON-NLS-1$
- String[] parts = path.split(separator);
+ String[] parts = path.split(Pattern.quote(separator));
URL[] u = new URL[parts.length+urls.length];
for(int i=0; i<parts.length; i++) {
try {
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -570,7 +570,7 @@
public static String[] extensions(File filename) {
if (filename==null) return new String[0];
String largeBasename = largeBasename(filename);
- String[] parts = largeBasename.split("["+getFileExtensionCharacter()+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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);
@@ -585,7 +585,7 @@
public static String[] extensions(URL filename) {
if (filename==null) return new String[0];
String largeBasename = largeBasename(filename);
- String[] parts = largeBasename.split("["+getFileExtensionCharacter()+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ 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);
@@ -599,7 +599,7 @@
*/
public static String[] split(File filename) {
if (filename==null) return new String[0];
- return filename.getPath().split("["+File.separatorChar+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return filename.getPath().split(Pattern.quote(File.separator));
}
/** Replies the parts of a path.
@@ -614,7 +614,7 @@
path = getJarFile(filename).getPath();
else
path = filename.getPath();
- return path.split("["+URL_PATH_SEPARATOR_CHAR+"]"); //$NON-NLS-1$ //$NON-NLS-2$
+ return path.split(Pattern.quote(URL_PATH_SEPARATOR));
}
/** Join the parts of a path and append them to the given File.
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/MACNumber.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/MACNumber.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/MACNumber.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
/** A MACNumber is the unique number associated to a network interface.
*
@@ -54,7 +55,7 @@
*/
public static MACNumber[] parse(String addresses) {
if ((addresses==null)||("".equals(addresses))) return new MACNumber[0]; //$NON-NLS-1$
- String[] adrs = addresses.split(Character.toString(MACNUMBER_SEPARATOR));
+ String[] adrs = addresses.split(Pattern.quote(Character.toString(MACNUMBER_SEPARATOR)));
ArrayList<MACNumber> list = new ArrayList<MACNumber>();
for (String adr : adrs) {
list.add(new MACNumber(adr));
@@ -73,7 +74,7 @@
*/
public static String[] parseAsString(String addresses) {
if ((addresses==null)||("".equals(addresses))) return new String[0]; //$NON-NLS-1$
- String[] adrs = addresses.split(Character.toString(MACNUMBER_SEPARATOR));
+ String[] adrs = addresses.split(Pattern.quote(Character.toString(MACNUMBER_SEPARATOR)));
ArrayList<String> list = new ArrayList<String>();
for (String adr : adrs) {
list.add(new MACNumber(adr).toString());
@@ -287,7 +288,7 @@
public MACNumber(String address) {
if (address==null)
throw new IllegalArgumentException("mac address not 6 bytes long"); //$NON-NLS-1$
- String[] parts = address.split(":"); //$NON-NLS-1$
+ String[] parts = address.split(Pattern.quote(":")); //$NON-NLS-1$
if (parts.length!=6)
throw new IllegalArgumentException("mac address not 6 bytes long"); //$NON-NLS-1$
this.bytes = new byte[6];
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -253,7 +253,8 @@
public static Collection<Class<?>> getPackageClasses(String packageName) {
Collection<Class<?>> classes = new ArrayList<Class<?>>();
- String[] entries = System.getProperty("java.class.path").split(System.getProperty("path.separator")); //$NON-NLS-1$//$NON-NLS-2$
+ String[] entries = System.getProperty("java.class.path").split( //$NON-NLS-1$
+ Pattern.quote(System.getProperty("path.separator"))); //$NON-NLS-1$
String lentry;
for(String path : entries) {
@@ -366,7 +367,8 @@
* @param result is the list of subclasses which will be filled by this function.
*/
public static <T> void getSubClasses(Class<T> className, boolean allowAbstract, boolean allowInterface, boolean allowEnum, Collection<Class<? extends T>> result) {
- String[] entries = System.getProperty("java.class.path").split(System.getProperty("path.separator")); //$NON-NLS-1$//$NON-NLS-2$
+ String[] entries = System.getProperty("java.class.path").split( //$NON-NLS-1$
+ Pattern.quote(System.getProperty("path.separator"))); //$NON-NLS-1$
String lentry;
for(String path : entries) {
Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java 2010-07-12 14:11:41 UTC (rev 161)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ClasspathUtilTest.java 2010-07-12 14:20:05 UTC (rev 162)
@@ -21,6 +21,7 @@
import java.io.File;
import java.net.URL;
+import java.util.regex.Pattern;
import junit.framework.TestCase;
@@ -54,7 +55,8 @@
URL[] urls = ClasspathUtil.getStartupClasspath();
assertNotNull(urls);
- String[] paths = System.getProperty("java.class.path").split(File.pathSeparator); //$NON-NLS-1$
+ String[] paths = System.getProperty("java.class.path").split( //$NON-NLS-1$
+ Pattern.quote(File.pathSeparator));
assertEquals(paths.length, urls.length);