OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | August 2008 Index

<--  Date Index  --> <--  Thread Index  -->

[fractal-commits] [8424] trunk/juliac: Externalize in Utils the function retrieving the URL from a file.


Title: [8424] trunk/juliac: Externalize in Utils the function retrieving the URL from a file.
Revision
8424
Author
seintur
Date
2008-08-30 22:34:00 +0200 (Sat, 30 Aug 2008)

Log Message

Externalize in Utils the function retrieving the URL from a file.

Modified Paths

Diff

Modified: trunk/juliac/compiler/src/main/java/org/objectweb/fractal/juliac/Utils.java (8423 => 8424)


--- 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;
+    }
 }

Modified: trunk/juliac/mojo/src/main/java/org/objectweb/fractal/juliac/JuliacMojoClassPathElements.java (8423 => 8424)


--- 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  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.