ソースを参照

generics

tags/V1_6_10RC1
aclement 14年前
コミット
11a0bc2918

+ 119
- 160
util/src/org/aspectj/util/FileUtil.java ファイルの表示

public static final File DEFAULT_PARENT = new File("."); // XXX user.dir? public static final File DEFAULT_PARENT = new File("."); // XXX user.dir?


/** unmodifiable List of String source file suffixes (including leading ".") */ /** unmodifiable List of String source file suffixes (including leading ".") */
public static final List SOURCE_SUFFIXES = Collections.unmodifiableList(Arrays.asList(new String[] { ".java", ".aj" }));
public static final List<String> SOURCE_SUFFIXES = Collections.unmodifiableList(Arrays.asList(new String[] { ".java", ".aj" }));


public static final FileFilter ZIP_FILTER = new FileFilter() { public static final FileFilter ZIP_FILTER = new FileFilter() {
public boolean accept(File file) { public boolean accept(File file) {
} }


/** /**
* @return 0 if file has no source suffix or the length of the suffix
* otherwise
* @return 0 if file has no source suffix or the length of the suffix otherwise
*/ */
public static int sourceSuffixLength(File file) { public static int sourceSuffixLength(File file) {
return (null == file ? 0 : sourceSuffixLength(file.getPath())); return (null == file ? 0 : sourceSuffixLength(file.getPath()));
return 0; return 0;
} }


for (Iterator iter = SOURCE_SUFFIXES.iterator(); iter.hasNext();) {
String suffix = (String) iter.next();
for (Iterator<String> iter = SOURCE_SUFFIXES.iterator(); iter.hasNext();) {
String suffix = iter.next();
if (path.endsWith(suffix) || path.toLowerCase().endsWith(suffix)) { if (path.endsWith(suffix) || path.toLowerCase().endsWith(suffix)) {
return suffix.length(); return suffix.length();
} }
} }


/** /**
* @throws IllegalArgumentException unless file is readable and not a
* directory
* @throws IllegalArgumentException unless file is readable and not a directory
*/ */
public static void throwIaxUnlessCanWriteFile(File file, String label) { public static void throwIaxUnlessCanWriteFile(File file, String label) {
if (!canWriteFile(file)) { if (!canWriteFile(file)) {
} }


/** @return array same length as input, with String paths */ /** @return array same length as input, with String paths */
public static String[] getPaths(List files) {
public static String[] getPaths(List<File> files) {
final int size = (null == files ? 0 : files.size()); final int size = (null == files ? 0 : files.size());
if (0 == size) { if (0 == size) {
return new String[0]; return new String[0];
} }
String[] result = new String[size]; String[] result = new String[size];
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
File file = (File) files.get(i);
File file = files.get(i);
if (null != file) { if (null != file) {
result[i] = file.getPath(); result[i] = file.getPath();
} }
} }


/** /**
* Extract the name of a class from the path to its file. If the basedir is
* null, then the class is assumed to be in the default package unless the
* classFile has one of the top-level suffixes { com, org, java, javax } as
* a parent directory.
* Extract the name of a class from the path to its file. If the basedir is null, then the class is assumed to be in the default
* package unless the classFile has one of the top-level suffixes { com, org, java, javax } as a parent directory.
* *
* @param basedir the File of the base directory (prefix of classFile) * @param basedir the File of the base directory (prefix of classFile)
* @param classFile the File of the class to extract the name for * @param classFile the File of the class to extract the name for
* @throws IllegalArgumentException if classFile is null or does not end
* with ".class" or a non-null basedir is not a prefix of
* classFile
* @throws IllegalArgumentException if classFile is null or does not end with ".class" or a non-null basedir is not a prefix of
* classFile
*/ */
public static String fileToClassName(File basedir, File classFile) { public static String fileToClassName(File basedir, File classFile) {
LangUtil.throwIaxIfNull(classFile, "classFile"); LangUtil.throwIaxIfNull(classFile, "classFile");
} }


/** /**
* Normalize path for comparisons by rendering absolute, clipping basedir
* prefix, trimming and changing '\\' to '/'
* Normalize path for comparisons by rendering absolute, clipping basedir prefix, trimming and changing '\\' to '/'
* *
* @param file the File with the path to normalize * @param file the File with the path to normalize
* @param basedir the File for the prefix of the file to normalize - ignored
* if null
* @param basedir the File for the prefix of the file to normalize - ignored if null
* @return "" if null or normalized path otherwise * @return "" if null or normalized path otherwise
* @throws IllegalArgumentException if basedir is not a prefix of file * @throws IllegalArgumentException if basedir is not a prefix of file
*/ */
} }


/** /**
* Render a set of files to String as a path by getting absolute paths of
* each and delimiting with infix.
* Render a set of files to String as a path by getting absolute paths of each and delimiting with infix.
* *
* @param files the File[] to flatten - may be null or empty * @param files the File[] to flatten - may be null or empty
* @param infix the String delimiter internally between entries (if null,
* then use File.pathSeparator). (alias to
* <code>flatten(getAbsolutePaths(files), infix)</code>
* @return String with absolute paths to entries in order, delimited with
* infix
* @param infix the String delimiter internally between entries (if null, then use File.pathSeparator). (alias to
* <code>flatten(getAbsolutePaths(files), infix)</code>
* @return String with absolute paths to entries in order, delimited with infix
*/ */
public static String flatten(File[] files, String infix) { public static String flatten(File[] files, String infix) {
if (LangUtil.isEmpty(files)) { if (LangUtil.isEmpty(files)) {
} }


/** /**
* Normalize path for comparisons by rendering absolute trimming and
* changing '\\' to '/'
* Normalize path for comparisons by rendering absolute trimming and changing '\\' to '/'
* *
* @return "" if null or normalized path otherwise * @return "" if null or normalized path otherwise
*/ */
} }


/** /**
* Weakly normalize path for comparisons by trimming and changing '\\' to
* '/'
* Weakly normalize path for comparisons by trimming and changing '\\' to '/'
*/ */
public static String weakNormalize(String path) { public static String weakNormalize(String path) {
if (null != path) { if (null != path) {
} }


/** /**
* Get best File for the first-readable path in input paths, treating
* entries prefixed "sp:" as system property keys. Safe to call in static
* initializers.
* Get best File for the first-readable path in input paths, treating entries prefixed "sp:" as system property keys. Safe to
* call in static initializers.
* *
* @param paths the String[] of paths to check. * @param paths the String[] of paths to check.
* @return null if not found, or valid File otherwise * @return null if not found, or valid File otherwise
} }


/** /**
* Recursively delete some contents of dir, but not the dir itself. This
* deletes any subdirectory which is empty after its files are deleted.
* Recursively delete some contents of dir, but not the dir itself. This deletes any subdirectory which is empty after its files
* are deleted.
* *
* @return the total number of files deleted * @return the total number of files deleted
*/ */
} }


/** /**
* Recursively delete some contents of dir, but not the dir itself. If
* deleteEmptyDirs is true, this deletes any subdirectory which is empty
* after its files are deleted.
* Recursively delete some contents of dir, but not the dir itself. If deleteEmptyDirs is true, this deletes any subdirectory
* which is empty after its files are deleted.
* *
* @param dir the File directory (if a file, the the file is deleted) * @param dir the File directory (if a file, the the file is deleted)
* @return the total number of files deleted * @return the total number of files deleted
} }


/** /**
* Recursively copy files in fromDir (with any fromSuffix) to toDir,
* replacing fromSuffix with toSuffix if any. This silently ignores dirs and
* files that are not readable but throw IOException for directories that
* are not writable. This does not clean out the original contents of toDir.
* (subdirectories are not renamed per directory rules)
* Recursively copy files in fromDir (with any fromSuffix) to toDir, replacing fromSuffix with toSuffix if any. This silently
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean
* out the original contents of toDir. (subdirectories are not renamed per directory rules)
* *
* @param fromSuffix select files with this suffix - select all if null or
* empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file
* name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
* @param fromSuffix select files with this suffix - select all if null or empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
* @return the total number of files copied * @return the total number of files copied
*/ */
public static int copyDir(File fromDir, File toDir, final String fromSuffix, String toSuffix) throws IOException { public static int copyDir(File fromDir, File toDir, final String fromSuffix, String toSuffix) throws IOException {
// } // }


/** /**
* Recursively copy files in fromDir (with any fromSuffix) to toDir,
* replacing fromSuffix with toSuffix if any. This silently ignores dirs and
* files that are not readable but throw IOException for directories that
* are not writable. This does not clean out the original contents of toDir.
* (subdirectories are not renamed per directory rules) This calls any
* delegate FilenameFilter to collect any selected file.
* Recursively copy files in fromDir (with any fromSuffix) to toDir, replacing fromSuffix with toSuffix if any. This silently
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean
* out the original contents of toDir. (subdirectories are not renamed per directory rules) This calls any delegate
* FilenameFilter to collect any selected file.
* *
* @param fromSuffix select files with this suffix - select all if null or
* empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file
* name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
* @param fromSuffix select files with this suffix - select all if null or empty
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if
* fromSuffix is null or empty
* @return the total number of files copied * @return the total number of files copied
*/ */
public static int copyDir(File fromDir, File toDir, final String fromSuffix, final String toSuffix, final FileFilter delegate) public static int copyDir(File fromDir, File toDir, final String fromSuffix, final String toSuffix, final FileFilter delegate)
/** /**
* Recursively list files in srcDir. * Recursively list files in srcDir.
* *
* @return ArrayList with String paths of File under srcDir (relative to
* srcDir)
* @return ArrayList with String paths of File under srcDir (relative to srcDir)
*/ */
public static String[] listFiles(File srcDir) { public static String[] listFiles(File srcDir) {
ArrayList result = new ArrayList();
ArrayList<String> result = new ArrayList<String>();
if ((null != srcDir) && srcDir.canRead()) { if ((null != srcDir) && srcDir.canRead()) {
listFiles(srcDir, null, result); listFiles(srcDir, null, result);
} }
return (String[]) result.toArray(new String[0]);
return result.toArray(new String[0]);
} }


public static final FileFilter aspectjSourceFileFilter = new FileFilter() { public static final FileFilter aspectjSourceFileFilter = new FileFilter() {
/** /**
* Recursively list files in srcDir. * Recursively list files in srcDir.
* *
* @return ArrayList with String paths of File under srcDir (relative to
* srcDir)
* @return ArrayList with String paths of File under srcDir (relative to srcDir)
*/ */
public static File[] listFiles(File srcDir, FileFilter fileFilter) { public static File[] listFiles(File srcDir, FileFilter fileFilter) {
ArrayList result = new ArrayList();
ArrayList<File> result = new ArrayList<File>();
if ((null != srcDir) && srcDir.canRead()) { if ((null != srcDir) && srcDir.canRead()) {
listFiles(srcDir, result, fileFilter); listFiles(srcDir, result, fileFilter);
} }
return (File[]) result.toArray(new File[result.size()]);
return result.toArray(new File[result.size()]);
} }


/** /**
* *
* @return List of File objects * @return List of File objects
*/ */
public static List listClassFiles(File dir) {
ArrayList result = new ArrayList();
public static List<File> listClassFiles(File dir) {
ArrayList<File> result = new ArrayList<File>();
if ((null != dir) && dir.canRead()) { if ((null != dir) && dir.canRead()) {
listClassFiles(dir, result); listClassFiles(dir, result);
} }
/** /**
* Convert String[] paths to File[] as offset of base directory * Convert String[] paths to File[] as offset of base directory
* *
* @param basedir the non-null File base directory for File to create with
* paths
* @param basedir the non-null File base directory for File to create with paths
* @param paths the String[] of paths to create * @param paths the String[] of paths to create
* @return File[] with same length as paths * @return File[] with same length as paths
*/ */
/** /**
* Convert String[] paths to File[] as offset of base directory * Convert String[] paths to File[] as offset of base directory
* *
* @param basedir the non-null File base directory for File to create with
* paths
* @param basedir the non-null File base directory for File to create with paths
* @param paths the String[] of paths to create * @param paths the String[] of paths to create
* @param suffixes the String[] of suffixes to limit sources to - ignored if
* null
* @param suffixes the String[] of suffixes to limit sources to - ignored if null
* @return File[] with same length as paths * @return File[] with same length as paths
*/ */
public static File[] getBaseDirFiles(File basedir, String[] paths, String[] suffixes) { public static File[] getBaseDirFiles(File basedir, String[] paths, String[] suffixes) {
LangUtil.throwIaxIfNull(paths, "paths"); LangUtil.throwIaxIfNull(paths, "paths");
File[] result = null; File[] result = null;
if (!LangUtil.isEmpty(suffixes)) { if (!LangUtil.isEmpty(suffixes)) {
ArrayList list = new ArrayList();
ArrayList<File> list = new ArrayList<File>();
for (int i = 0; i < paths.length; i++) { for (int i = 0; i < paths.length; i++) {
String path = paths[i]; String path = paths[i];
for (int j = 0; j < suffixes.length; j++) { for (int j = 0; j < suffixes.length; j++) {
} }
} }
} }
result = (File[]) list.toArray(new File[0]);
result = list.toArray(new File[0]);
} else { } else {
result = new File[paths.length]; result = new File[paths.length];
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
} }


/** /**
* Copy files from source dir into destination directory, creating any
* needed directories. This differs from copyDir in not being recursive;
* each input with the source dir creates a full path. However, if the
* source is a directory, it is copied as such.
* Copy files from source dir into destination directory, creating any needed directories. This differs from copyDir in not
* being recursive; each input with the source dir creates a full path. However, if the source is a directory, it is copied as
* such.
* *
* @param srcDir an existing, readable directory containing relativePaths
* files
* @param relativePaths a set of paths relative to srcDir to readable File
* to copy
* @param srcDir an existing, readable directory containing relativePaths files
* @param relativePaths a set of paths relative to srcDir to readable File to copy
* @param destDir an existing, writable directory to copy files to * @param destDir an existing, writable directory to copy files to
* @throws IllegalArgumentException if input invalid, IOException if
* operations fail
* @throws IllegalArgumentException if input invalid, IOException if operations fail
*/ */
public static File[] copyFiles(File srcDir, String[] relativePaths, File destDir) throws IllegalArgumentException, IOException { public static File[] copyFiles(File srcDir, String[] relativePaths, File destDir) throws IllegalArgumentException, IOException {
final String[] paths = relativePaths; final String[] paths = relativePaths;
} }


/** /**
* Copy fromFile to toFile, handling file-file, dir-dir, and file-dir
* copies.
* Copy fromFile to toFile, handling file-file, dir-dir, and file-dir copies.
* *
* @param fromFile the File path of the file or directory to copy - must be
* readable
* @param toFile the File path of the target file or directory - must be
* writable (will be created if it does not exist)
* @param fromFile the File path of the file or directory to copy - must be readable
* @param toFile the File path of the target file or directory - must be writable (will be created if it does not exist)
*/ */
public static void copyFile(File fromFile, File toFile) throws IOException { public static void copyFile(File fromFile, File toFile) throws IOException {
LangUtil.throwIaxIfNull(fromFile, "fromFile"); LangUtil.throwIaxIfNull(fromFile, "fromFile");
} }


/** /**
* Ensure that the parent directory to path can be written. If the path has
* a null parent, DEFAULT_PARENT is tested. If the path parent does not
* exist, this tries to create it.
* Ensure that the parent directory to path can be written. If the path has a null parent, DEFAULT_PARENT is tested. If the path
* parent does not exist, this tries to create it.
* *
* @param path the File path whose parent should be writable * @param path the File path whose parent should be writable
* @return the File path of the writable parent directory * @return the File path of the writable parent directory
* @throws IllegalArgumentException if parent cannot be written or path is
* null.
* @throws IllegalArgumentException if parent cannot be written or path is null.
*/ */
public static File ensureParentWritable(File path) { public static File ensureParentWritable(File path) {
LangUtil.throwIaxIfNull(path, "path"); LangUtil.throwIaxIfNull(path, "path");
} }


/** /**
* Make a new temporary directory in the same directory that the system uses
* for temporary files, or if that files, in the current directory.
* Make a new temporary directory in the same directory that the system uses for temporary files, or if that files, in the
* current directory.
* *
* @param name the preferred (simple) name of the directory - may be null. * @param name the preferred (simple) name of the directory - may be null.
* @return File of an existing new temp dir, or null if unable to create * @return File of an existing new temp dir, or null if unable to create
} }


/** /**
* Get URL for a File. This appends "/" for directories. prints errors to
* System.err
* Get URL for a File. This appends "/" for directories. prints errors to System.err
* *
* @param file the File to convert to URL (not null) * @param file the File to convert to URL (not null)
*/ */
} }


/** /**
* Write contents to file, returning null on success or error message
* otherwise. This tries to make any necessary parent directories first.
* Write contents to file, returning null on success or error message otherwise. This tries to make any necessary parent
* directories first.
* *
* @param file the File to write (not null) * @param file the File to write (not null)
* @param contents the String to write (use "" if null) * @param contents the String to write (use "" if null)
public static boolean[] readBooleanArray(DataInputStream s) throws IOException { public static boolean[] readBooleanArray(DataInputStream s) throws IOException {
int len = s.readInt(); int len = s.readInt();
boolean[] ret = new boolean[len]; boolean[] ret = new boolean[len];
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
ret[i] = s.readBoolean(); ret[i] = s.readBoolean();
}
return ret; return ret;
} }


public static void writeBooleanArray(boolean[] a, DataOutputStream s) throws IOException { public static void writeBooleanArray(boolean[] a, DataOutputStream s) throws IOException {
int len = a.length; int len = a.length;
s.writeInt(len); s.writeInt(len);
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
s.writeBoolean(a[i]); s.writeBoolean(a[i]);
}
} }


/** /**
public static int[] readIntArray(DataInputStream s) throws IOException { public static int[] readIntArray(DataInputStream s) throws IOException {
int len = s.readInt(); int len = s.readInt();
int[] ret = new int[len]; int[] ret = new int[len];
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
ret[i] = s.readInt(); ret[i] = s.readInt();
}
return ret; return ret;
} }


public static void writeIntArray(int[] a, DataOutputStream s) throws IOException { public static void writeIntArray(int[] a, DataOutputStream s) throws IOException {
int len = a.length; int len = a.length;
s.writeInt(len); s.writeInt(len);
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
s.writeInt(a[i]); s.writeInt(a[i]);
}
} }


/** /**
public static String[] readStringArray(DataInputStream s) throws IOException { public static String[] readStringArray(DataInputStream s) throws IOException {
int len = s.readInt(); int len = s.readInt();
String[] ret = new String[len]; String[] ret = new String[len];
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
ret[i] = s.readUTF(); ret[i] = s.readUTF();
}
return ret; return ret;
} }


} }
int len = a.length; int len = a.length;
s.writeInt(len); s.writeInt(len);
for (int i = 0; i < len; i++)
for (int i = 0; i < len; i++) {
s.writeUTF(a[i]); s.writeUTF(a[i]);
}
} }


/** /**
StringBuffer b = new StringBuffer(); StringBuffer b = new StringBuffer();
while (true) { while (true) {
int ch = r.read(); int ch = r.read();
if (ch == -1)
if (ch == -1) {
break; break;
}
b.append((char) ch); b.append((char) ch);
} }
r.close(); r.close();


while (true) { while (true) {
int nRead = inStream.read(ba, readSoFar, size - readSoFar); int nRead = inStream.read(ba, readSoFar, size - readSoFar);
if (nRead == -1)
if (nRead == -1) {
break; break;
}
readSoFar += nRead; readSoFar += nRead;
if (readSoFar == size) { if (readSoFar == size) {
int newSize = size * 2; int newSize = size * 2;
// } // }


/** /**
* Do line-based search for literal text in source files, returning
* file:line where found.
* Do line-based search for literal text in source files, returning file:line where found.
* *
* @param sought the String text to seek in the file * @param sought the String text to seek in the file
* @param sources the List of String paths to the source files * @param sources the List of String paths to the source files
* @param listAll if false, only list first match in file * @param listAll if false, only list first match in file
* @param errorSink the PrintStream to print any errors to (one per line)
* (use null to silently ignore errors)
* @return List of String of the form file:line for each found entry (never
* null, might be empty)
* @param errorSink the PrintStream to print any errors to (one per line) (use null to silently ignore errors)
* @return List of String of the form file:line for each found entry (never null, might be empty)
*/ */
// OPTIMIZE only used by tests? move it out // OPTIMIZE only used by tests? move it out
public static List lineSeek(String sought, List sources, boolean listAll, PrintStream errorSink) {
public static List<String> lineSeek(String sought, List<String> sources, boolean listAll, PrintStream errorSink) {
if (LangUtil.isEmpty(sought) || LangUtil.isEmpty(sources)) { if (LangUtil.isEmpty(sought) || LangUtil.isEmpty(sources)) {
return Collections.EMPTY_LIST;
return Collections.emptyList();
} }
ArrayList result = new ArrayList();
for (Iterator iter = sources.iterator(); iter.hasNext();) {
String path = (String) iter.next();
ArrayList<String> result = new ArrayList<String>();
for (Iterator<String> iter = sources.iterator(); iter.hasNext();) {
String path = iter.next();
String error = lineSeek(sought, path, listAll, result); String error = lineSeek(sought, path, listAll, result);
if ((null != error) && (null != errorSink)) { if ((null != error) && (null != errorSink)) {
errorSink.println(error); errorSink.println(error);
} }


/** /**
* Do line-based search for literal text in source file, returning line
* where found as a String in the form {sourcePath}:line:column submitted to
* the collecting parameter sink. Any error is rendered to String and
* returned as the result.
* Do line-based search for literal text in source file, returning line where found as a String in the form
* {sourcePath}:line:column submitted to the collecting parameter sink. Any error is rendered to String and returned as the
* result.
* *
* @param sought the String text to seek in the file * @param sought the String text to seek in the file
* @param sources the List of String paths to the source files * @param sources the List of String paths to the source files
* @param listAll if false, only list first match in file * @param listAll if false, only list first match in file
* @param List sink the List for String entries of the form
* {sourcePath}:line:column
* @param List sink the List for String entries of the form {sourcePath}:line:column
* @return String error if any, or add String entries to sink * @return String error if any, or add String entries to sink
*/ */
public static String lineSeek(String sought, String sourcePath, boolean listAll, ArrayList sink) {
public static String lineSeek(String sought, String sourcePath, boolean listAll, ArrayList<String> sink) {
if (LangUtil.isEmpty(sought) || LangUtil.isEmpty(sourcePath)) { if (LangUtil.isEmpty(sought) || LangUtil.isEmpty(sourcePath)) {
return "nothing sought"; return "nothing sought";
} }
return LangUtil.unqualifiedClassName(e) + " reading " + sourcePath + ":" + lineNum; return LangUtil.unqualifiedClassName(e) + " reading " + sourcePath + ":" + lineNum;
} finally { } finally {
try { try {
if (null != fin)
if (null != fin) {
fin.close(); fin.close();
}
} catch (IOException e) { } catch (IOException e) {
} // ignore } // ignore
} }


public static BufferedOutputStream makeOutputStream(File file) throws FileNotFoundException { public static BufferedOutputStream makeOutputStream(File file) throws FileNotFoundException {
File parent = file.getParentFile(); File parent = file.getParentFile();
if (parent != null)
if (parent != null) {
parent.mkdirs(); parent.mkdirs();
}
return new BufferedOutputStream(new FileOutputStream(file)); return new BufferedOutputStream(new FileOutputStream(file));
} }


/** /**
* Sleep until after the last last-modified stamp from the files. * Sleep until after the last last-modified stamp from the files.
* *
* @param files the File[] of files to inspect for last modified times (this
* ignores null or empty files array and null or non-existing
* components of files array)
* @param files the File[] of files to inspect for last modified times (this ignores null or empty files array and null or
* non-existing components of files array)
* @return true if succeeded without 100 interrupts * @return true if succeeded without 100 interrupts
*/ */
public static boolean sleepPastFinalModifiedTime(File[] files) { public static boolean sleepPastFinalModifiedTime(File[] files) {
return LangUtil.sleepUntil(++delayUntil); return LangUtil.sleepUntil(++delayUntil);
} }


private static void listClassFiles(final File baseDir, ArrayList result) {
private static void listClassFiles(final File baseDir, ArrayList<File> result) {
File[] files = baseDir.listFiles(); File[] files = baseDir.listFiles();
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
File f = files[i]; File f = files[i];
} }
} }


private static void listFiles(final File baseDir, ArrayList result, FileFilter filter) {
private static void listFiles(final File baseDir, ArrayList<File> result, FileFilter filter) {
File[] files = baseDir.listFiles(); File[] files = baseDir.listFiles();
// hack https://bugs.eclipse.org/bugs/show_bug.cgi?id=48650 // hack https://bugs.eclipse.org/bugs/show_bug.cgi?id=48650
final boolean skipCVS = (!PERMIT_CVS && (filter == aspectjSourceFileFilter)); final boolean skipCVS = (!PERMIT_CVS && (filter == aspectjSourceFileFilter));
} }
listFiles(f, result, filter); listFiles(f, result, filter);
} else { } else {
if (filter.accept(f))
if (filter.accept(f)) {
result.add(f); result.add(f);
}
} }
} }
} }
return ((null != input) && (-1 == input.indexOf(File.pathSeparator))); return ((null != input) && (-1 == input.indexOf(File.pathSeparator)));
} }


private static void listFiles(final File baseDir, String dir, ArrayList result) {
private static void listFiles(final File baseDir, String dir, ArrayList<String> result) {
final String dirPrefix = (null == dir ? "" : dir + "/"); final String dirPrefix = (null == dir ? "" : dir + "/");
final File dirFile = (null == dir ? baseDir : new File(baseDir.getPath() + "/" + dir)); final File dirFile = (null == dir ? baseDir : new File(baseDir.getPath() + "/" + dir));
final String[] files = dirFile.list(); final String[] files = dirFile.list();
private FileUtil() { private FileUtil() {
} }


public static List makeClasspath(URL[] urls) {
List ret = new LinkedList();
public static List<String> makeClasspath(URL[] urls) {
List<String> ret = new LinkedList<String>();
if (urls != null) { if (urls != null) {
for (int i = 0; i < urls.length; i++) { for (int i = 0; i < urls.length; i++) {
ret.add(urls[i].getPath()); ret.add(urls[i].getPath());
} }


/** /**
* A pipe when run reads from an input stream to an output stream,
* optionally sleeping between reads.
* A pipe when run reads from an input stream to an output stream, optionally sleeping between reads.
* *
* @see #copyStream(InputStream, OutputStream) * @see #copyStream(InputStream, OutputStream)
*/ */
private final boolean closeOutput; private final boolean closeOutput;


/** /**
* If true, then continue processing stream until no characters are
* returned when halting.
* If true, then continue processing stream until no characters are returned when halting.
*/ */
private boolean finishStream; private boolean finishStream;


/** /**
* @param in the InputStream source to read * @param in the InputStream source to read
* @param out the OutputStream sink to write * @param out the OutputStream sink to write
* @param tryClosingStreams if true, then try closing both streams when
* done
* @param sleep milliseconds to delay between reads (pinned to 0..1
* minute)
* @param tryClosingStreams if true, then try closing both streams when done
* @param sleep milliseconds to delay between reads (pinned to 0..1 minute)
*/ */
Pipe(InputStream in, OutputStream out, long sleep, boolean closeInput, boolean closeOutput) { Pipe(InputStream in, OutputStream out, long sleep, boolean closeInput, boolean closeOutput) {
LangUtil.throwIaxIfNull(in, "in"); LangUtil.throwIaxIfNull(in, "in");
} }


/** /**
* Run the pipe. This halts on the first Throwable thrown or when a read
* returns -1 (for end-of-file) or on demand.
* Run the pipe. This halts on the first Throwable thrown or when a read returns -1 (for end-of-file) or on demand.
*/ */
public void run() { public void run() {
totalWritten = 0; totalWritten = 0;
* Tell the pipe to halt the next time it gains control. * Tell the pipe to halt the next time it gains control.
* *
* @param wait if true, this waits synchronously until pipe is done * @param wait if true, this waits synchronously until pipe is done
* @param finishStream if true, then continue until a read from the
* input stream returns no bytes, then halt.
* @return true if <code>run()</code> will return the next time it gains
* control
* @param finishStream if true, then continue until a read from the input stream returns no bytes, then halt.
* @return true if <code>run()</code> will return the next time it gains control
*/ */
public boolean halt(boolean wait, boolean finishStream) { public boolean halt(boolean wait, boolean finishStream) {
if (!halt) { if (!halt) {
} }


/** /**
* This is called when the pipe is completing. This implementation does
* nothing. Subclasses implement this to get notice. Note that
* halt(true, true) might or might not have completed before this method
* is called.
* This is called when the pipe is completing. This implementation does nothing. Subclasses implement this to get notice.
* Note that halt(true, true) might or might not have completed before this method is called.
*/ */
protected void completing(long totalWritten, Throwable thrown) { protected void completing(long totalWritten, Throwable thrown) {
} }

+ 1
- 1
util/src/org/aspectj/util/PartialOrder.java ファイルの表示



// ??? I don't like creating this data structure, but it does give good // ??? I don't like creating this data structure, but it does give good
// ??? separation of concerns. // ??? separation of concerns.
List sortList = new LinkedList(); // objects.size());
List<SortObject> sortList = new LinkedList<SortObject>(); // objects.size());
for (Iterator i = objects.iterator(); i.hasNext();) { for (Iterator i = objects.iterator(); i.hasNext();) {
addNewPartialComparable(sortList, (PartialComparable) i.next()); addNewPartialComparable(sortList, (PartialComparable) i.next());
} }

+ 647
- 649
util/testsrc/org/aspectj/util/FileUtilTest.java
ファイル差分が大きすぎるため省略します
ファイルの表示


読み込み中…
キャンセル
保存