Mail Archive Home | fractal-commits List | August 2008 Index
| <-- Date Index --> | <-- Thread Index --> |
Externalize in Utils the function retrieving the URL from a file.
--- trunk/juliac/compiler/src/main/java/org/objectweb/fractal/juliac/Utils.java 2008-08-30 20:04:27 UTC (rev 8423)
+++ trunk/juliac/compiler/src/main/java/org/objectweb/fractal/juliac/Utils.java 2008-08-30 20:34:00 UTC (rev 8424)
@@ -24,6 +24,8 @@
package org.objectweb.fractal.juliac;
import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import org.objectweb.fractal.api.Type;
import org.objectweb.fractal.api.type.ComponentType;
@@ -372,4 +374,33 @@
String trim = src.substring(i,j+1);
return trim;
}
+
+ /**
+ * Return the URL corresponding to the specified file.
+ *
+ * @param f the file
+ * @return the corresponding URL
+ */
+ public static URL toURL( File f )
+ throws MalformedURLException {
+
+ /*
+ * A / after file: is mandatory under Windows, however two
+ * slashes lead to Malformed URLs under Unix. Hence, the / after
+ * file: is only added in the case of Windows.
+ *
+ * Trailing / is mandatory under Windows, else the resource is
+ * not understood as a directory. Putting the / in new File()
+ * does not work as File.getAbsolutePath() removes it.
+ * When the file does not exist, it is assumed to be a directory
+ * which will be created latter on.
+ */
+ String ap = f.getAbsolutePath();
+ String fname = "file:"+ (ap.startsWith("/") ? ap : ("/"+ap));
+ if( f.isDirectory() || !f.exists() ) {
+ fname += '/';
+ }
+ URL url = "" URL(fname);
+ return url;
+ }
}
--- trunk/juliac/mojo/src/main/java/org/objectweb/fractal/juliac/JuliacMojoClassPathElements.java 2008-08-30 20:04:27 UTC (rev 8423)
+++ trunk/juliac/mojo/src/main/java/org/objectweb/fractal/juliac/JuliacMojoClassPathElements.java 2008-08-30 20:34:00 UTC (rev 8424)
@@ -76,33 +76,16 @@
URL[] urls = new URL[classpaths.size()];
int i = 0;
- for (String classpath : classpaths) {
-
- /*
- * A / after file: is mandatory under Windows, however two
- * slashes lead to Malformed URLs under Unix. Hence, the / after
- * file: is only added in the case of Windows.
- *
- * Trailing / is mandatory under Windows, else the resource is
- * not understood as a directory. Putting the / in new File()
- * does not work as File.getAbsolutePath() removes it.
- * When the file does not exist, it is assumed to be a directory
- * which will be created latter on.
- */
+ for (String classpath : classpaths) {
File f = new File(classpath);
- String ap = f.getAbsolutePath();
- String fname = "file:"+ (ap.startsWith("/") ? ap : ("/"+ap));
- if( f.isDirectory() || !f.exists() ) {
- fname += '/';
- }
-
- urls[i] = new URL(fname);
+ urls[i] = Utils.toURL(f);
i++;
}
return urls;
}
+
// --------------------------------------------------------------------
// Methods for adding elements in the classpath
// --------------------------------------------------------------------
| <-- Date Index --> | <-- Thread Index --> |
Powered by MHonArc.
Copyright © 2006-2007, OW2 Consortium | contact | webmaster.