]> source.dussan.org Git - aspectj.git/commitdiff
support for finding files at runtime, for javarun/aspectpath
authorwisberg <wisberg>
Wed, 6 Oct 2004 10:27:23 +0000 (10:27 +0000)
committerwisberg <wisberg>
Wed, 6 Oct 2004 10:27:23 +0000 (10:27 +0000)
testing/src/org/aspectj/testing/harness/bridge/Sandbox.java

index 0e1fe9737abd8a658cb8ddf8ffe424b3170be048..2af724585923fdf9a9fc199d968dff1a5761dea8 100644 (file)
 package org.aspectj.testing.harness.bridge;
 
 import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.aspectj.bridge.ICommand;
 import org.aspectj.bridge.IMessage;
@@ -327,6 +330,25 @@ public class Sandbox {
         return testBaseSrcDir;
     }
     
+    /**
+     * Get the files with names (case-sensitive)
+     * under the staging or test base directories.
+     * @param names
+     * @return
+     */
+    File[] findFiles(final String[] names) {
+        ArrayList result = new ArrayList();
+        NamesFilter filter = new NamesFilter(names);
+        File[] bases = { testBaseDir, sandboxDir };
+        for (int i = 0; i < bases.length; i++) {
+            File base = bases[i];
+            if ((null == base) || !base.canRead()) {
+                continue;
+            }
+            result.addAll(Arrays.asList(FileUtil.listFiles(base, filter)));
+        }
+        return (File[]) result.toArray(new File[0]);
+    }
     File getTestBaseSrcDir(JavaRun caller) {
         LangUtil.throwIaxIfNull(caller, "caller");
         return testBaseSrcDir;
@@ -491,4 +513,23 @@ public class Sandbox {
         LangUtil.throwIaxIfNull(caller, "caller");
         return bootClasspath;
     }
+    private static class NamesFilter implements FileFilter {
+        private final String[] names;
+        private NamesFilter(String[] names) {
+            this.names = names;
+        }
+        public boolean accept(File file) {
+            if (null != file) {
+                String name = file.getName();
+                if (null != name) {
+                    for (int i = 0; i < names.length; i++) {
+                        if (name.equals(names[i])) {
+                            return true;
+                        }
+                    }
+                }
+            }
+            return false;
+        }
+    }
 }