summaryrefslogtreecommitdiff
path: root/sources/scalac/util
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-21 19:25:23 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-21 19:25:23 +0000
commit834473088e288d8550a2916bdfd38294757b9059 (patch)
tree4d0b46cb52b31c57b62014513b4aafd7e90f3457 /sources/scalac/util
parent25ebed6d598d62394212cb331d111e203c9310ec (diff)
downloadscala-834473088e288d8550a2916bdfd38294757b9059.tar.gz
scala-834473088e288d8550a2916bdfd38294757b9059.tar.bz2
scala-834473088e288d8550a2916bdfd38294757b9059.zip
- Added functions to gather files from paths an...
- Added functions to gather files from paths and extension dirs in ClassPath
Diffstat (limited to 'sources/scalac/util')
-rw-r--r--sources/scalac/util/ClassPath.java120
1 files changed, 62 insertions, 58 deletions
diff --git a/sources/scalac/util/ClassPath.java b/sources/scalac/util/ClassPath.java
index 310f2945c1..1009eb75e1 100644
--- a/sources/scalac/util/ClassPath.java
+++ b/sources/scalac/util/ClassPath.java
@@ -8,8 +8,12 @@
package scalac.util;
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
import scala.tools.util.AbstractFile;
@@ -43,6 +47,52 @@ public class ClassPath {
System.getProperty("java.ext.dirs", "");
//########################################################################
+ // Public Functions
+
+ /**
+ * Adds all zip and jar archives found in the specified extension
+ * directory path to the specified file set. See also remark about
+ * file order in method "addFilesFromPath".
+ */
+ public static void addArchivesInExtDirPath(Set/*<File>*/files,String path){
+ Set extdirs = new LinkedHashSet();
+ addFilesInPath(extdirs, path);
+ for (Iterator i = extdirs.iterator(); i.hasNext(); )
+ addArchivesInExtDir(files, (File)i.next());
+ }
+
+ /**
+ * Adds all zip and jar archives found in the specified extension
+ * directory to the specified file set. See also remark about file
+ * order in method "addFilesFromPath".
+ */
+ public static void addArchivesInExtDir(Set/*<File>*/ files, File extdir) {
+ String[] names = extdir.list();
+ if (names == null) return;
+ for (int i = 0; i < names.length; i++) {
+ if (names[i].endsWith(".jar") || names[i].endsWith(".zip")) {
+ File archive = new File(extdir, names[i]);
+ if (archive.isFile()) files.add(archive);
+ }
+ }
+ }
+
+ /**
+ * Parses the specified path and adds all files that exist to the
+ * specified file set. If order needs to be preserved, one should
+ * pass in an order preserving implementation of Set.
+ */
+ public static void addFilesInPath(Set/*<File>*/ files, String path) {
+ path += PATH_SEPARATOR;
+ for (int i = 0; i < path.length(); ) {
+ int j = path.indexOf(PATH_SEPARATOR, i);
+ File file = new File(path.substring(i, j));
+ if (file.exists()) files.add(file);
+ i = j + 1;
+ }
+ }
+
+ //########################################################################
// Private Functions
/** Returns the default boot class path. */
@@ -92,68 +142,22 @@ public class ClassPath {
path.substring(1, index + 1) + BOOTCLASSPATH +
path.substring(index + 1, path.length() - 1);
}
- String path = "";
- path = appendPath(path, bootclasspath);
- path = appendExtDirs(path, extdirs);
- path = appendPath(path, classpath);
- path = appendPath(path, sourcepath);
- root = parse(path.substring(1));
- }
-
- /** append an additional path
- */
- protected static String appendPath(String path, String addpath) {
- return addpath == null ? path : path + PATH_SEPARATOR + addpath;
- }
-
- /** append files from the extension directories
- */
- protected String appendExtDirs(String path, String extdirs) {
- if (extdirs != null) {
- extdirs += PATH_SEPARATOR;
- int length = extdirs.length();
- int i = 0;
- while (i < length) {
- int k = extdirs.indexOf(PATH_SEPARATOR, i);
- String dirname = extdirs.substring(i, k);
- String[] ext;
- if ((dirname != null) &&
- (dirname.length() > 0) &&
- ((ext = new File(dirname).list()) != null)) {
- if (!dirname.endsWith(FILE_SEPARATOR))
- dirname += FILE_SEPARATOR;
- for (int j = 0; j < ext.length; j++)
- if (ext[j].endsWith(".jar") ||
- ext[j].endsWith(".zip"))
- path = appendPath(path, dirname + ext[j]);
- }
- i = k + 1;
- }
+ Set files = new LinkedHashSet();
+ addFilesInPath(files, bootclasspath);
+ addArchivesInExtDirPath(files, extdirs);
+ addFilesInPath(files, classpath);
+ addFilesInPath(files, sourcepath);
+ ArrayList dirs = new ArrayList(files.size());
+ for (Iterator i = files.iterator(); i.hasNext(); ) {
+ File file = (File)i.next();
+ if (file.exists()) dirs.add(file.getPath());
}
- return path;
+ this.root = (String[])dirs.toArray(new String[dirs.size()]);
}
//########################################################################
// Public Methods
- /** parse a class path specification and return an array
- * of existing class file locations
- */
- public static String[] parse(String path) {
- path += PATH_SEPARATOR;
- Vector components = new Vector();
- int i = 0;
- while (i < path.length()) {
- int j = path.indexOf(PATH_SEPARATOR, i);
- String subpath = path.substring(i, j);
- if (new File(subpath).exists())
- components.add(subpath);
- i = j + 1;
- }
- return (String[])components.toArray(
- new String[components.size()]);
- }
-
/** find file with given name in class path and return an abstract
* file representation
*/