summaryrefslogtreecommitdiff
path: root/sources
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
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')
-rw-r--r--sources/scalac/symtab/classfile/CLRPackageParser.java28
-rw-r--r--sources/scalac/util/ClassPath.java120
2 files changed, 75 insertions, 73 deletions
diff --git a/sources/scalac/symtab/classfile/CLRPackageParser.java b/sources/scalac/symtab/classfile/CLRPackageParser.java
index 2af865101c..2378a7378e 100644
--- a/sources/scalac/symtab/classfile/CLRPackageParser.java
+++ b/sources/scalac/symtab/classfile/CLRPackageParser.java
@@ -13,6 +13,8 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
+import java.util.LinkedHashSet;
import java.io.File;
@@ -73,9 +75,8 @@ public class CLRPackageParser extends SymbolLoader {
private boolean initialized = false;
public void init() {
if (initialized) return;
- String[] asnames = scalac.util.ClassPath.parse(global.args.assemrefs.value);
- for (int i = 0; i < asnames.length; i++)
- assemrefs.add(asnames[i]);
+ scalac.util.ClassPath.addFilesInPath(
+ assemrefs, global.args.assemrefs.value);
Assembly mscorlib = findAssembly("mscorlib.dll");
Type.initMSCORLIB(mscorlib);
@@ -155,20 +156,17 @@ public class CLRPackageParser extends SymbolLoader {
protected final java.util.List assemblies = new LinkedList();
- protected final java.util.List assemrefs = new LinkedList();
+ protected final java.util.Set/*<File>*/ assemrefs = new LinkedHashSet();
/** Load the assembly with the given name
*/
private Assembly findAssembly(String name) {
// see if the assembly is referenced directly
- File file = null;
- Assembly assem = null;
for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- String assemname = (String)assems.next();
- file = new File(assemname);
+ File file = (File)assems.next();
if (!file.getName().equals(name))
continue;
- assem = Assembly.LoadFrom(file.getPath());
+ Assembly assem = Assembly.LoadFrom(file.getPath());
if (assem != null) {
assems.remove();
assemblies.add(assem);
@@ -177,12 +175,12 @@ public class CLRPackageParser extends SymbolLoader {
}
// look in directories specified with the '-r' option
for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- File d = new File((String)assems.next());
+ File d = (File)assems.next();
if (!d.isDirectory())
continue;
- file = new File(d, name);
+ File file = new File(d, name);
if (file.exists()) {
- assem = Assembly.LoadFrom(file.getPath());
+ Assembly assem = Assembly.LoadFrom(file.getPath());
if (assem != null) {
assemblies.add(assem);
return assem;
@@ -190,9 +188,9 @@ public class CLRPackageParser extends SymbolLoader {
}
}
// try in the current directory
- file = new File(".", name);
+ File file = new File(".", name);
if (file.exists()) {
- assem = Assembly.LoadFrom(file.getPath());
+ Assembly assem = Assembly.LoadFrom(file.getPath());
if (assem != null) {
assemblies.add(assem);
return assem;
@@ -208,7 +206,7 @@ public class CLRPackageParser extends SymbolLoader {
private void findAllAssemblies() {
//System.out.println("assembly references left: " + assemrefs);
for (Iterator assems = assemrefs.iterator(); assems.hasNext();) {
- File f = new File((String)assems.next());
+ File f = (File)assems.next();
if (f.isFile()) {
Assembly assem = Assembly.LoadFrom(f.getPath());
if (assem != null) {
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
*/