0) {
continue;
} else {
@@ -412,7 +412,7 @@
// Cleanup javac output dir if needed
File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
if (shouldFlushOutputDirectory) {
- cleanupDirectory(javacOutputDirectory);
+ Util.delete(javacOutputDirectory);
}
// Write files in dir
@@ -443,7 +443,7 @@
// Launch process
compileProcess = Runtime.getRuntime().exec(
- cmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
+ cmdLine.toString(), null, this.outputTestDirectory);
// Log errors
Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");
@@ -549,7 +549,7 @@
// the test itself
}
finally {
- cleanupDirectory(outputTestDirectoryPath.toFile());
+ Util.delete(outputTestDirectory);
}
}
Index: src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java,v
retrieving revision 1.71
diff -u -r1.71 AbstractRegressionTest.java
--- src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 7 Dec 2006 10:00:15 -0000 1.71
+++ src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 20 Dec 2006 15:36:50 -0000
@@ -202,28 +202,6 @@
/*######################################
* Specific method to let tests Sun javac compilation available...
#######################################*/
- /*
- * Cleans up the given directory by removing all the files it contains as well
- * but leaving the directory.
- * @throws TargetException if the target path could not be cleaned up
- */
- protected void cleanupDirectory(File directory) {
- if (!directory.exists()) {
- return;
- }
- String[] fileNames = directory.list();
- for (int i = 0; i < fileNames.length; i++) {
- File file = new File(directory, fileNames[i]);
- if (file.isDirectory()) {
- cleanupDirectory(file);
- } else {
- if (!file.delete())
- System.out.println("Could not delete file " + file.getPath());
- }
- }
- if (!directory.delete())
- System.out.println("Could not delete directory " + directory.getPath());
- }
protected void compileAndDeploy(String source, String directoryName, String className) {
File directory = new File(SOURCE_DIRECTORY);
if (!directory.exists()) {
@@ -474,7 +452,7 @@
if (fileNames != null) {
for (int i = 0, max = fileNames.length; i < max; i++) {
if (fileNames[i].indexOf(className) != -1) {
- new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete();
+ Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]);
}
}
}
@@ -484,7 +462,7 @@
if (fileNames != null) {
for (int i = 0, max = fileNames.length; i < max; i++) {
if (fileNames[i].indexOf(className) != -1) {
- new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete();
+ Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]);
}
}
}
@@ -795,7 +773,7 @@
// Cleanup javac output dir if needed
File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
if (shouldFlushOutputDirectory) {
- cleanupDirectory(javacOutputDirectory);
+ Util.delete(javacOutputDirectory);
}
// Write files in dir
@@ -826,7 +804,7 @@
// Launch process
compileProcess = Runtime.getRuntime().exec(
- cmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
+ cmdLine.toString(), null, this.outputTestDirectory);
// Log errors
Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");
@@ -891,7 +869,7 @@
javaCmdLine.append(cp);
javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.')));
// assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes
- execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
+ execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectory);
Logger logger = new Logger(execProcess.getInputStream(), "");
// PREMATURE implement consistent error policy
logger.start();
@@ -960,7 +938,7 @@
}
finally {
// Clean up written file(s)
- cleanupDirectory(outputTestDirectoryPath.toFile());
+ Util.delete(outputTestDirectory);
}
}
/**
@@ -1314,7 +1292,7 @@
// clean up output dir
File outputDir = new File(OUTPUT_DIR);
if (outputDir.exists()) {
- Util.rmdir(outputDir);
+ Util.flushDirectoryContent(outputDir);
}
super.tearDown();
if (RUN_JAVAC) {
Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v
retrieving revision 1.96
diff -u -r1.96 BatchCompilerTest.java
--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 19 Dec 2006 23:16:43 -0000 1.96
+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 20 Dec 2006 15:36:51 -0000
@@ -1747,7 +1747,7 @@
"",
true);
if (jarCreated) {
- new File(libPath).delete();
+ Util.delete(libPath);
}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88364 - -extdirs extends the classpath before -classpath
@@ -2375,11 +2375,11 @@
false);
final String userDir = System.getProperty("user.dir");
File f = new File(userDir, "X.java");
- if (!f.delete()) {
+ if (!Util.delete(f)) {
System.out.println("Could not delete X");
}
f = new File(userDir, "p" + File.separator + "Y.java");
- if (!f.delete()) {
+ if (!Util.delete(f)) {
System.out.println("Could not delete Y");
}
@@ -3285,8 +3285,8 @@
} catch (IOException e) {
fail("could not create jar file");
}
- new File(outputDirName + File.separator + "Y.class").delete();
- new File(outputDirName + File.separator + "Y.java").delete();
+ Util.delete(outputDirName + File.separator + "Y.class");
+ Util.delete(outputDirName + File.separator + "Y.java");
this.runConformTest(
new String[] {
"d/X.java",
@@ -3334,8 +3334,8 @@
} catch (IOException e) {
fail("could not create jar file");
}
- new File(outputDirName + File.separator + "Y.class").delete();
- new File(outputDirName + File.separator + "Y.java").delete();
+ Util.delete(outputDirName + File.separator + "Y.class");
+ Util.delete(outputDirName + File.separator + "Y.java");
this.runConformTest(
new String[] {
"d/X.java",
@@ -4145,7 +4145,7 @@
"public class X {}");
Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar");
if (standardXOutputFile.exists()) {
- standardXOutputFile.delete();
+ Util.delete(standardXOutputFile);
}
} catch (IOException e) {
fail("could not create jar file");
@@ -4197,7 +4197,7 @@
"public class X {}");
Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar");
if (standardXOutputFile.exists()) {
- standardXOutputFile.delete();
+ Util.delete(standardXOutputFile);
}
} catch (IOException e) {
fail("could not create jar file");
@@ -4248,7 +4248,7 @@
"public class X {}");
Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar");
if (standardXOutputFile.exists()) {
- standardXOutputFile.delete();
+ Util.delete(standardXOutputFile);
}
} catch (IOException e) {
fail("could not create jar file");
Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v
retrieving revision 1.65
diff -u -r1.65 LookupTest.java
--- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 7 Dec 2006 16:03:36 -0000 1.65
+++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 20 Dec 2006 15:36:51 -0000
@@ -1516,7 +1516,7 @@
},
"SUCCESS");
// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
- new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class").delete();
+ Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class"));
this.runConformTest(
new String[] {
Index: src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java,v
retrieving revision 1.31
diff -u -r1.31 DebugEvaluationTest.java
--- src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 3 Oct 2006 15:19:13 -0000 1.31
+++ src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 20 Dec 2006 15:36:52 -0000
@@ -156,12 +156,8 @@
}
public void removeTempClass(String className) {
resetEnv(); // needed to reinitialize the caches
- File sourceFile = new File(SOURCE_DIRECTORY + File.separator + className + ".java");
- sourceFile.delete();
-
- File binaryFile = new File(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
-
- binaryFile.delete();
+ Util.delete(SOURCE_DIRECTORY + File.separator + className + ".java");
+ Util.delete(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
}
/*public static Test suite(Class evaluationTestClass) {
junit.framework.TestSuite suite = new junit.framework.TestSuite();
Index: src/org/eclipse/jdt/core/tests/util/Util.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v
retrieving revision 1.52
diff -u -r1.52 Util.java
--- src/org/eclipse/jdt/core/tests/util/Util.java 11 Oct 2006 09:15:32 -0000 1.52
+++ src/org/eclipse/jdt/core/tests/util/Util.java 20 Dec 2006 15:36:52 -0000
@@ -15,6 +15,9 @@
import java.util.*;
import java.util.zip.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
import org.eclipse.jdt.internal.compiler.Compiler;
@@ -27,6 +30,25 @@
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
public class Util {
+ // Trace for delete operation
+ /*
+ * Maximum time wasted repeating delete operations while running JDT/Core tests.
+ */
+ private static int DELETE_MAX_TIME = 0;
+ /**
+ * Trace deletion operations while running JDT/Core tests.
+ */
+ public static boolean DELETE_DEBUG = false;
+ /**
+ * Maximum of time in ms to wait in deletion operation while running JDT/Core tests.
+ * Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000).
+ *
+ * To avoid too many loops while waiting, the ten first ones are done waiting
+ * 10ms before repeating, the ten loops after are done waiting 100ms and
+ * the other loops are done waiting 1s...
+ */
+ public static int DELETE_MAX_WAIT = 10000;
+
private static final boolean DEBUG = false;
/**
* Initially, output directory was located in System.getProperty("user.home")+"\comptest".
@@ -37,7 +59,7 @@
*/
private final static String OUTPUT_DIRECTORY;
/**
- * Let user specify the delay in hours before output directories are removed from file system
+ * Let user specify the delay in hours before output directories are removed from file system
* while starting a new test run. Default value is 2 hours.
*
* Note that this value may be a float and so have time less than one hour.
@@ -90,7 +112,7 @@
for (int i=0,l=testDirs.length; i delay) {
- rmdir(testDirs[i]);
+ delete(testDirs[i]);
}
}
}
@@ -242,8 +264,10 @@
try {
in = new FileInputStream(source);
File destFile = new File(dest, source.getName());
- if (destFile.exists() && !destFile.delete()) {
- throw new IOException(destFile + " is in use");
+ if (destFile.exists()) {
+ if (!Util.delete(destFile)) {
+ throw new IOException(destFile + " is in use");
+ }
}
out = new FileOutputStream(destFile);
int bufferLength = 1024;
@@ -316,6 +340,54 @@
zip(sourcesDir, zipPath);
}
/**
+ * Delete a file or directory and insure that the file is no longer present
+ * on file system. In case of directory, delete all the hierarchy underneath.
+ *
+ * @param file The file or directory to delete
+ * @return true iff the file was really delete, false otherwise
+ */
+public static boolean delete(File file) {
+ // flush all directory content
+ if (file.isDirectory()) {
+ flushDirectoryContent(file);
+ }
+ // remove file
+ file.delete();
+ if (isFileDeleted(file)) {
+ return true;
+ }
+ return waitUntilFileDeleted(file);
+}
+/**
+ * Delete a file or directory and insure that the file is no longer present
+ * on file system. In case of directory, delete all the hierarchy underneath.
+ *
+ * @param resource The resource to delete
+ * @return true iff the file was really delete, false otherwise
+ */
+public static boolean delete(IResource resource) {
+ try {
+ resource.delete(true, null);
+ if (isResourceDeleted(resource)) {
+ return true;
+ }
+ }
+ catch (CoreException e) {
+ // skip
+ }
+ return waitUntilResourceDeleted(resource);
+}
+/**
+ * Delete a file or directory and insure that the file is no longer present
+ * on file system. In case of directory, delete all the hierarchy underneath.
+ *
+ * @param path The path of the file or directory to delete
+ * @return true iff the file was really delete, false otherwise
+ */
+public static boolean delete(String path) {
+ return delete(new File(path));
+}
+/**
* Generate a display string from the given String.
* @param inputString the given input string
*
@@ -527,32 +599,14 @@
writeToFile(displayString, destinationFilePath);
}
/**
- * Delete a directory and all its hierarchy if not empty
- *
- * @param dir The directory to delete
- */
-public static void rmdir(File dir) {
- // flush all directory content
- flushDirectoryContent(dir);
- // remove dir
- dir.delete();
-}
-/**
* Flush content of a given directory (leaving it empty),
* no-op if not a directory.
*/
public static void flushDirectoryContent(File dir) {
- if (dir.isDirectory()) {
- String[] files = dir.list();
- if (files == null) return;
- for (int i = 0, max = files.length; i < max; i++) {
- File current = new File(dir, files[i]);
- if (current.isDirectory()) {
- flushDirectoryContent(current);
- }
- if (!current.delete())
- System.err.println("Could not delete " + current.getName());
- }
+ File[] files = dir.listFiles();
+ if (files == null) return;
+ for (int i = 0, max = files.length; i < max; i++) {
+ delete(files[i]);
}
}
/**
@@ -645,6 +699,81 @@
public static String getOutputDirectory() {
return OUTPUT_DIRECTORY;
}
+/**
+ * Returns the parent's child file matching the given file or null if not found.
+ *
+ * @param file The searched file in parent
+ * @return The parent's child matching the given file or null if not found.
+ */
+private static File getParentChildFile(File file) {
+ File parent = file.getParentFile();
+ if (parent == null || !parent.exists()) return null;
+ File[] files = parent.listFiles();
+ int length = files==null ? 0 : files.length;
+ if (length > 0) {
+ for (int i=0; i 0) {
+ for (int i=0; i
+ * read {@link File#canRead()}
+ * write {@link File#canWrite()}
+ * exists {@link File#exists()}
+ * is file {@link File#isFile()}
+ * is directory {@link File#isDirectory()}
+ * is hidden {@link File#isHidden()}
+ *
+ * May recurse several level in parents hierarchy.
+ * May also display children, but then will not recusre in parent
+ * hierarchy to avoid infinite loop...
+ *
+ * @param file The file to display information
+ * @param indent Number of tab to print before the information
+ * @param recurse Display also information on recurse
th parents in hierarchy.
+ * If negative then display children information instead.
+ */
+private static void printFileInfo(File file, int indent, int recurse) {
+ String tab = "";
+ for (int i=0; i 0) {
+ boolean children = recurse < 0;
+ System.out.print(tab+" + children: ");
+ if (children) System.out.println();
+ for (int i=0; i0) System.out.print(", ");
+ System.out.print(files[i].getName());
+ if (files[i].isDirectory()) System.out.print("[dir]");
+ else if (files[i].isFile()) System.out.print("[file]");
+ else System.out.print("[?]");
+ }
+ }
+ if (!children) System.out.println();
+ }
+ if (recurse > 0) {
+ File parent = file.getParentFile();
+ if (parent != null) printFileInfo(parent, indent+1, recurse-1);
+ }
+}
+/**
+ * Print stack trace with only JDT/Core elements.
+ *
+ * @param exception Exception of the stack trace. May be null, then a fake exception is used.
+ * @param indent Number of tab to display before the stack elements to display.
+ */
+private static void printJdtCoreStackTrace(Exception exception, int indent) {
+ String tab = "";
+ for (int i=0; i "+testElement);
+ }
+ } else {
+ exception.printStackTrace(System.out);
+ }
+}
+/**
* Makes the given path a path using native path separators as returned by File.getPath()
* and trimming any extra slash.
*/
@@ -729,6 +981,157 @@
}
}
}
+/**
+ * Wait until the file is _really_ deleted on file system.
+ *
+ * @param file Deleted file
+ * @return true if the file was finally deleted, false otherwise
+ */
+private static boolean waitUntilFileDeleted(File file) {
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting "+file);
+ printJdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): ");
+ }
+ int count = 0;
+ int delay = 10; // ms
+ int maxRetry = DELETE_MAX_WAIT / delay;
+ int time = 0;
+ while (count < maxRetry) {
+ try {
+ count++;
+ Thread.sleep(delay);
+ time += delay;
+ if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
+ if (DELETE_DEBUG) System.out.print('.');
+ if (file.exists()) {
+ if (file.delete()) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ }
+ if (isFileDeleted(file)) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ // Increment waiting delay exponentially
+ if (count >= 10 && delay <= 100) {
+ count = 1;
+ delay *= 10;
+ maxRetry = DELETE_MAX_WAIT / delay;
+ if ((DELETE_MAX_WAIT%delay) != 0) {
+ maxRetry++;
+ }
+ }
+ }
+ catch (InterruptedException ie) {
+ break; // end loop
+ }
+ }
+ if (!DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting "+file);
+ printJdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ }
+ System.out.println();
+ System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
+ System.out.println();
+ return false;
+}
+/**
+ * Wait until a resource is _really_ deleted on file system.
+ *
+ * @param resource Deleted resource
+ * @return true if the file was finally deleted, false otherwise
+ */
+private static boolean waitUntilResourceDeleted(IResource resource) {
+ File file = resource.getLocation().toFile();
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting resource "+resource);
+ printJdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): ");
+ }
+ int count = 0;
+ int delay = 10; // ms
+ int maxRetry = DELETE_MAX_WAIT / delay;
+ int time = 0;
+ while (count < maxRetry) {
+ try {
+ count++;
+ Thread.sleep(delay);
+ time += delay;
+ if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
+ if (DELETE_DEBUG) System.out.print('.');
+ if (resource.isAccessible()) {
+ try {
+ resource.delete(true, null);
+ if (isResourceDeleted(resource) && isFileDeleted(file)) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ }
+ catch (CoreException e) {
+ // skip
+ }
+ }
+ if (isResourceDeleted(resource) && isFileDeleted(file)) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ // Increment waiting delay exponentially
+ if (count >= 10 && delay <= 100) {
+ count = 1;
+ delay *= 10;
+ maxRetry = DELETE_MAX_WAIT / delay;
+ if ((DELETE_MAX_WAIT%delay) != 0) {
+ maxRetry++;
+ }
+ }
+ }
+ catch (InterruptedException ie) {
+ break; // end loop
+ }
+ }
+ if (!DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting resource "+resource);
+ printJdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ }
+ System.out.println();
+ System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
+ System.out.println();
+ return false;
+}
public static void writeToFile(String contents, String destinationFilePath) {
File destFile = new File(destinationFilePath);
FileOutputStream output = null;
@@ -752,7 +1155,9 @@
public static void zip(File rootDir, String zipPath) throws IOException {
ZipOutputStream zip = null;
try {
- zip = new ZipOutputStream(new FileOutputStream(zipPath));
+ File zipFile = new File(zipPath);
+ if (zipFile.exists()) delete(zipFile);
+ zip = new ZipOutputStream(new FileOutputStream(zipFile));
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
} finally {
if (zip != null) {
@@ -761,20 +1166,19 @@
}
}
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
- String[] list = dir.list();
- if (list != null) {
- for (int i = 0, length = list.length; i < length; i++) {
- String name = list[i];
- File file = new File(dir, name);
- if (file.isDirectory()) {
- zip(file, zip, rootPathLength);
- } else {
+ File[] files = dir.listFiles();
+ if (files != null) {
+ for (int i = 0, length = files.length; i < length; i++) {
+ File file = files[i];
+ if (file.isFile()) {
String path = file.getPath();
path = path.substring(rootPathLength);
ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
zip.putNextEntry(entry);
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
zip.closeEntry();
+ } else {
+ zip(file, zip, rootPathLength);
}
}
}
Index: src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java,v
retrieving revision 1.28
diff -u -r1.28 AbstractCompilerTest.java
--- src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 23 Nov 2006 15:42:33 -0000 1.28
+++ src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 20 Dec 2006 15:36:52 -0000
@@ -458,9 +458,8 @@
}
// Output files management
- protected IPath
- outputRootDirectoryPath = new Path(Util.getOutputDirectory()),
- outputTestDirectoryPath;
+ protected IPath outputRootDirectoryPath = new Path(Util.getOutputDirectory());
+ protected File outputTestDirectory;
/**
* Create a test specific output directory as a subdirectory of
@@ -470,11 +469,9 @@
* @param suffixPath a valid relative path for the subdirectory
*/
protected void createOutputTestDirectory(String suffixPath) {
- this.outputTestDirectoryPath =
- ((IPath) this.outputRootDirectoryPath.clone()).append(suffixPath);
- File dir = this.outputTestDirectoryPath.toFile();
- if (!dir.exists()) {
- dir.mkdirs();
+ this.outputTestDirectory = new File(this.outputRootDirectoryPath.toFile(), suffixPath);
+ if (!this.outputTestDirectory.exists()) {
+ this.outputTestDirectory.mkdirs();
}
}
/*
@@ -488,15 +485,14 @@
for (int i = 0, length = testFiles.length; i < length; ) {
String fileName = testFiles[i++];
String contents = testFiles[i++];
- IPath filePath =
- ((IPath) this.outputTestDirectoryPath.clone()).append(fileName);
+ File file = new File(this.outputTestDirectory, fileName);
if (fileName.lastIndexOf('/') >= 0) {
- File dir = filePath.removeLastSegments(1).toFile();
+ File dir = file.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
}
- Util.writeToFile(contents, filePath.toString());
+ Util.writeToFile(contents, file.getPath());
}
}
Index: src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java,v
retrieving revision 1.11
diff -u -r1.11 LocalVirtualMachine.java
--- src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java 10 May 2006 18:07:26 -0000 1.11
+++ src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java 20 Dec 2006 15:36:52 -0000
@@ -12,6 +12,8 @@
import java.io.*;
+import org.eclipse.jdt.core.tests.util.Util;
+
/**
* Wrapper around the external process that is running a local VM.
* This allows to kill this process when we exit this vm.
@@ -46,11 +48,11 @@
this.process.destroy();
}
}
-/**
+/*
* Cleans up the given directory by removing all the files it contains as well
* but leaving the directory.
* @throws TargetException if the target path could not be cleaned up
- */
+ *
private void cleanupDirectory(File directory) throws TargetException {
if (!directory.exists()) {
return;
@@ -70,6 +72,7 @@
}
}
}
+*/
/**
* Cleans up this context's target path by removing all the files it contains
* but leaving the directory.
@@ -79,11 +82,11 @@
if (this.evalTargetPath == null) return;
String targetPath = this.evalTargetPath;
if (LocalVMLauncher.TARGET_HAS_FILE_SYSTEM) {
- cleanupDirectory(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY));
- cleanupDirectory(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY));
+ Util.delete(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY));
+ Util.delete(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY));
File file = new File(targetPath, RuntimeConstants.SUPPORT_ZIP_FILE_NAME);
- // workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet
+ /* workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet
int count = 10;
for (int i = 0; i < count; i++) {
if (file.delete()) {
@@ -94,11 +97,12 @@
} catch (InterruptedException e) {
}
}
- if (file.exists()) {
+ */
+ if (!Util.delete(file)) {
throw new TargetException("Could not delete " + file.getPath());
}
} else {
- cleanupDirectory(new File(targetPath));
+ Util.delete(targetPath);
}
}
/**
#P org.eclipse.jdt.core.tests.builder
Index: src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java,v
retrieving revision 1.48
diff -u -r1.48 TestingEnvironment.java
--- src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 15 Nov 2006 14:11:16 -0000 1.48
+++ src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 20 Dec 2006 15:36:54 -0000
@@ -16,6 +16,7 @@
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
+import org.eclipse.jdt.core.tests.util.Util;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.core.ClasspathEntry;
@@ -601,35 +602,24 @@
return (IProject)fProjects.get(projectPath.lastSegment());
}
-private File tmpDirectory;
-File getTmpDirectory() {
- if (this.tmpDirectory == null) {
- this.tmpDirectory = new File(System.getProperty("java.io.tmpdir") +
- File.separator + "org.eclipse.jdt.core.builder.tests.tmp");
- if (this.tmpDirectory.exists() && !this.tmpDirectory.isDirectory()) {
- this.tmpDirectory.delete();
+ private File tmpDirectory;
+ File getTmpDirectory() {
+ if (this.tmpDirectory == null) {
+ this.tmpDirectory = new File(System.getProperty("java.io.tmpdir") +
+ File.separator + "org.eclipse.jdt.core.builder.tests.tmp");
+ if (this.tmpDirectory.exists() && !this.tmpDirectory.isDirectory()) {
+ Util.delete(this.tmpDirectory);
+ }
+ this.tmpDirectory.mkdir();
+ }
+ return this.tmpDirectory;
+ }
+ void deleteTmpDirectory() {
+ if (this.tmpDirectory != null) {
+ Util.delete(this.tmpDirectory);
+ this.tmpDirectory = null;
}
- this.tmpDirectory.mkdir();
}
- return this.tmpDirectory;
-}
-void deleteTmpDirectory() {
- if (this.tmpDirectory != null) {
- deleteDirectory(this.tmpDirectory);
- this.tmpDirectory = null;
- }
-}
-private void deleteDirectory(File dir) {
- File[] files = dir.listFiles();
- for (int i = 0 ; i < files.length ; i++) {
- if (files[i].isDirectory()) {
- deleteDirectory(files[i]);
- } else {
- files[i].delete();
- }
- }
- dir.delete();
-}
/**
* Returns the workspace.