View | Details | Raw Unified | Return to bug 166977 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileComparatorTest.java (-2 / +2 lines)
Lines 39-45 Link Here
39
		if (fileNames != null) {
39
		if (fileNames != null) {
40
			for (int i = 0, max = fileNames.length; i < max; i++) {
40
			for (int i = 0, max = fileNames.length; i < max; i++) {
41
				if (fileNames[i].indexOf(className) != -1) {
41
				if (fileNames[i].indexOf(className) != -1) {
42
					new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete();
42
					Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]);
43
				}
43
				}
44
			}
44
			}
45
		}
45
		}
Lines 49-55 Link Here
49
		if (fileNames != null) {
49
		if (fileNames != null) {
50
			for (int i = 0, max = fileNames.length; i < max; i++) {
50
			for (int i = 0, max = fileNames.length; i < max; i++) {
51
				if (fileNames[i].indexOf(className) != -1) {
51
				if (fileNames[i].indexOf(className) != -1) {
52
					new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete();
52
					Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]);
53
				}
53
				}
54
			}
54
			}
55
		}
55
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest.java (-2 / +2 lines)
Lines 122-128 Link Here
122
		if (fileNames != null) {
122
		if (fileNames != null) {
123
			for (int i = 0, max = fileNames.length; i < max; i++) {
123
			for (int i = 0, max = fileNames.length; i < max; i++) {
124
				if (fileNames[i].indexOf(className) != -1) {
124
				if (fileNames[i].indexOf(className) != -1) {
125
					new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete();
125
					Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]);
126
				}
126
				}
127
			}
127
			}
128
		}
128
		}
Lines 132-138 Link Here
132
		if (fileNames != null) {
132
		if (fileNames != null) {
133
			for (int i = 0, max = fileNames.length; i < max; i++) {
133
			for (int i = 0, max = fileNames.length; i < max; i++) {
134
				if (fileNames[i].indexOf(className) != -1) {
134
				if (fileNames[i].indexOf(className) != -1) {
135
					new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete();
135
					Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]);
136
				}
136
				}
137
			}
137
			}
138
		}
138
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java (-1 lines)
Lines 444-450 Link Here
444
		File outputDir = new File(OUTPUT_DIR);
444
		File outputDir = new File(OUTPUT_DIR);
445
		if (outputDir.exists()) {
445
		if (outputDir.exists()) {
446
			Util.flushDirectoryContent(outputDir);
446
			Util.flushDirectoryContent(outputDir);
447
			outputDir.delete();
448
		}
447
		}
449
		super.tearDown();
448
		super.tearDown();
450
	}
449
	}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java (-25 / +2 lines)
Lines 133-161 Link Here
133
	 * Specific method to let tests Sun javac compilation available...
133
	 * Specific method to let tests Sun javac compilation available...
134
	 #######################################*/
134
	 #######################################*/
135
	/*
135
	/*
136
	 * Cleans up the given directory by removing all the files it contains as well
137
	 * but leaving the directory.
138
	 * @throws TargetException if the target path could not be cleaned up
139
	 */
140
	protected void cleanupDirectory(File directory) {
141
		if (!directory.exists()) {
142
			return;
143
		}
144
		String[] fileNames = directory.list();
145
		for (int i = 0; i < fileNames.length; i++) {
146
			File file = new File(directory, fileNames[i]);
147
			if (file.isDirectory()) {
148
				cleanupDirectory(file);
149
			} else {
150
				if (!file.delete())
151
					System.out.println("Could not delete file " + file.getPath());
152
			}
153
		}
154
		if (!directory.delete())
155
			System.out.println("Could not delete directory " + directory.getPath());
156
	}
157
158
	/*
159
	 * Write given source test files in current output sub-directory.
136
	 * Write given source test files in current output sub-directory.
160
	 * Use test name for this sub-directory name (ie. test001, test002, etc...)
137
	 * Use test name for this sub-directory name (ie. test001, test002, etc...)
161
	 */
138
	 */
Lines 200-206 Link Here
200
	protected void runJavac(String[] testFiles, final String expectedProblemLog, final String expectedSuccessOutputString, boolean shouldFlushOutputDirectory) {
177
	protected void runJavac(String[] testFiles, final String expectedProblemLog, final String expectedSuccessOutputString, boolean shouldFlushOutputDirectory) {
201
		try {
178
		try {
202
			if (shouldFlushOutputDirectory)
179
			if (shouldFlushOutputDirectory)
203
				cleanupDirectory(new File(JAVAC_OUTPUT_DIR));
180
				Util.delete(JAVAC_OUTPUT_DIR);
204
181
205
			// Write files in dir
182
			// Write files in dir
206
			IPath dirFilePath = writeFiles(testFiles);
183
			IPath dirFilePath = writeFiles(testFiles);
Lines 333-339 Link Here
333
		} finally {
310
		} finally {
334
			// Clean up written file(s)
311
			// Clean up written file(s)
335
			IPath testDir =  new Path(Util.getOutputDirectory()).append(testName());
312
			IPath testDir =  new Path(Util.getOutputDirectory()).append(testName());
336
			cleanupDirectory(testDir.toFile());
313
			Util.delete(testDir.toFile());
337
		}
314
		}
338
	}
315
	}
339
316
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-16 / +25 lines)
Lines 155-178 Link Here
155
		String outFileName = printerWritersNameRoot + "out.txt", 
155
		String outFileName = printerWritersNameRoot + "out.txt", 
156
			   errFileName = printerWritersNameRoot + "err.txt";
156
			   errFileName = printerWritersNameRoot + "err.txt";
157
		Main batchCompiler;
157
		Main batchCompiler;
158
		try {
158
		PrintWriter out = null; 
159
			batchCompiler = new Main(new PrintWriter(new FileOutputStream(
159
		PrintWriter err = null; 
160
					outFileName)), new PrintWriter(new FileOutputStream(
161
					errFileName)), false);
162
		} catch (FileNotFoundException e) {
163
			System.out.println(getClass().getName() + '#' + getName());
164
			e.printStackTrace();
165
			throw new RuntimeException(e);
166
		}
167
		boolean compileOK;
160
		boolean compileOK;
168
		try {
161
		try {
169
			final String[] tokenizeCommandLine = Main.tokenize(commandLine);
162
			try {
170
			compileOK = batchCompiler.compile(tokenizeCommandLine);
163
				out = new PrintWriter(new FileOutputStream(outFileName));
171
		} catch (RuntimeException e) {
164
				err = new PrintWriter(new FileOutputStream(errFileName));
172
			compileOK = false;
165
				batchCompiler = new Main(out, err, false);
173
			System.out.println(getClass().getName() + '#' + getName());
166
			} catch (FileNotFoundException e) {
174
			e.printStackTrace();
167
				System.out.println(getClass().getName() + '#' + getName());
175
			throw e;
168
				e.printStackTrace();
169
				throw new RuntimeException(e);
170
			}
171
			try {
172
				final String[] tokenizeCommandLine = Main.tokenize(commandLine);
173
				compileOK = batchCompiler.compile(tokenizeCommandLine);
174
			} catch (RuntimeException e) {
175
				compileOK = false;
176
				System.out.println(getClass().getName() + '#' + getName());
177
				e.printStackTrace();
178
				throw e;
179
			}
180
		} finally {
181
			if (out != null)
182
				out.close();
183
			if (err != null)
184
				err.close();
176
		}
185
		}
177
		String outOutputString = Util.fileContent(outFileName), 
186
		String outOutputString = Util.fileContent(outFileName), 
178
		       errOutputString = Util.fileContent(errFileName);
187
		       errOutputString = Util.fileContent(errFileName);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (-1 / +1 lines)
Lines 1514-1520 Link Here
1514
		},
1514
		},
1515
		"SUCCESS");
1515
		"SUCCESS");
1516
	// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
1516
	// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
1517
	new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class").delete();
1517
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class"));
1518
	
1518
	
1519
	this.runConformTest(
1519
	this.runConformTest(
1520
		new String[] {
1520
		new String[] {
(-)plugin.xml (-1 / +2 lines)
Lines 17-23 Link Here
17
      <import plugin="org.eclipse.jdt.debug"/>
17
      <import plugin="org.eclipse.jdt.debug"/>
18
      <import plugin="org.eclipse.jdt.core"/>
18
      <import plugin="org.eclipse.jdt.core"/>
19
     <import plugin="org.eclipse.core.runtime.compatibility"/>
19
     <import plugin="org.eclipse.core.runtime.compatibility"/>
20
     <import plugin="org.eclipse.test.performance"/>    
20
     <import plugin="org.eclipse.test.performance"/>
21
     <import plugin="org.eclipse.core.resources"/>    
21
   </requires>
22
   </requires>
22
23
23
24
(-)src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java (-6 / +2 lines)
Lines 155-166 Link Here
155
	}
155
	}
156
	public void removeTempClass(String className) {
156
	public void removeTempClass(String className) {
157
		resetEnv(); // needed to reinitialize the caches
157
		resetEnv(); // needed to reinitialize the caches
158
		File sourceFile = new File(SOURCE_DIRECTORY + File.separator + className + ".java");
158
		Util.delete(SOURCE_DIRECTORY + File.separator + className + ".java");
159
		sourceFile.delete();
159
		Util.delete(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
160
	
161
		File binaryFile = new File(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
162
	
163
		binaryFile.delete();
164
	}
160
	}
165
	/*public static Test suite(Class evaluationTestClass) {
161
	/*public static Test suite(Class evaluationTestClass) {
166
		junit.framework.TestSuite suite = new junit.framework.TestSuite();
162
		junit.framework.TestSuite suite = new junit.framework.TestSuite();
(-)src/org/eclipse/jdt/core/tests/util/Util.java (-26 / +514 lines)
Lines 19-24 Link Here
19
import java.util.zip.ZipInputStream;
19
import java.util.zip.ZipInputStream;
20
import java.util.zip.ZipOutputStream;
20
import java.util.zip.ZipOutputStream;
21
21
22
import org.eclipse.core.resources.IContainer;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.jdt.core.compiler.IProblem;
25
import org.eclipse.jdt.core.compiler.IProblem;
23
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
26
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
24
import org.eclipse.jdt.internal.compiler.Compiler;
27
import org.eclipse.jdt.internal.compiler.Compiler;
Lines 31-37 Link Here
31
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
34
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
32
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
35
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
33
public class Util {
36
public class Util {
34
	public static String OUTPUT_DIRECTORY = "comptest";
37
// Trace for delete operation
38
/*
39
 * Maximum time wasted repeating delete operations while running JDT/Core tests.
40
 */
41
private static int DELETE_MAX_TIME = 0;
42
/**
43
 * Trace deletion operations while running JDT/Core tests.
44
 */
45
public static boolean DELETE_DEBUG = false;
46
/**
47
 * Maximum of time in ms to wait in deletion operation while running JDT/Core tests.
48
 * Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000).
49
 * <br>
50
 * To avoid too many loops while waiting, the ten first ones are done waiting
51
 * 10ms before repeating, the ten loops after are done waiting 100ms and
52
 * the other loops are done waiting 1s...
53
 */
54
public static int DELETE_MAX_WAIT = 10000;
55
56
// Output directory initialization
57
/**
58
 * Initially, output directory was located in System.getProperty("user.home")+"\comptest".
59
 * To allow user to run several compiler tests at the same time, main output directory
60
 * is now located in a sub-directory of "comptest" which name is "run."+<code>System.currentMilliseconds</code>.
61
 * 
62
 * @see #DELAY_BEFORE_CLEAN_PREVIOUS
63
 */
64
private final static String OUTPUT_DIRECTORY;
65
/**
66
 * Let user specify the delay in hours before output directories are removed from file system
67
 * while starting a new test run. Default value is 2 hours.
68
 * <p>
69
 * Note that this value may be a float and so have time less than one hour.
70
 * If value is 0 or negative, then all previous run directories will be removed...
71
 * 
72
 * @see #OUTPUT_DIRECTORY
73
 */
74
private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay");
75
/*
76
 * Static initializer to clean directories created while running previous test suites.
77
 */
78
static {
79
	// Get delay for cleaning sub-directories
80
	long millisecondsPerHour = 1000L * 3600L;
81
	long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours
82
	try {
83
		if (DELAY_BEFORE_CLEAN_PREVIOUS != null) {
84
			float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS);
85
			delay = (int) (millisecondsPerHour * hours);
86
		}
87
	}
88
	catch (NumberFormatException nfe) {
89
		// use default
90
	}
91
92
	// Get output directory root from system properties
93
	String container = System.getProperty("jdt.test.output_directory");
94
	if (container == null){
95
		container = System.getProperty("user.home");
96
	}
97
	if (container == null) {
98
		container = ".";	// use current directory
99
	}
100
	
101
	// Get file for root directory
102
	if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') {
103
		container = Character.toUpperCase(container.charAt(0)) + container.substring(1);
104
	}
105
	File dir = new File(new File(container), "comptest");
106
107
	// If root directory already exists, clean it
108
	if (dir.exists()) {
109
		long now = System.currentTimeMillis();
110
		if ((now - dir.lastModified()) > delay) {
111
			// remove all directory content
112
			flushDirectoryContent(dir);
113
		} else {
114
			// remove only old sub-dirs
115
			File[] testDirs = dir.listFiles();
116
			for (int i=0,l=testDirs.length; i<l; i++) {
117
				if (testDirs[i].isDirectory()) {
118
					if ((now - testDirs[i].lastModified()) > delay) {
119
						delete(testDirs[i]);
120
					}
121
				}
122
			}
123
		}
124
	}
125
126
	// Computed test run directory name based on current time
127
	File dateDir = new File(dir, "run."+System.currentTimeMillis());
128
	OUTPUT_DIRECTORY = dateDir.getPath();
129
}
35
130
36
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) {
131
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) {
37
	problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
132
	problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
Lines 146-153 Link Here
146
		try {
241
		try {
147
			in = new FileInputStream(source);
242
			in = new FileInputStream(source);
148
			File destFile = new File(dest, source.getName());
243
			File destFile = new File(dest, source.getName());
149
			if (destFile.exists() && !destFile.delete()) {
244
			if (destFile.exists()) {
150
				throw new IOException(destFile + " is in use");
245
				if (!delete(destFile)) {
246
					throw new IOException(destFile + " is in use");
247
				}
151
			}
248
			}
152
		 	out = new FileOutputStream(destFile);
249
		 	out = new FileOutputStream(destFile);
153
			int bufferLength = 1024;
250
			int bufferLength = 1024;
Lines 218-223 Link Here
218
	zip(sourcesDir, zipPath);
315
	zip(sourcesDir, zipPath);
219
}
316
}
220
/**
317
/**
318
 * Delete a file or directory and insure that the file is no longer present
319
 * on file system. In case of directory, delete all the hierarchy underneath.
320
 * 
321
 * @param file The file or directory to delete
322
 * @return true iff the file was really delete, false otherwise
323
 */
324
public static boolean delete(File file) {
325
	// flush all directory content
326
	if (file.isDirectory()) {
327
		flushDirectoryContent(file);
328
	}
329
	// remove file
330
	file.delete();
331
	if (isFileDeleted(file)) {
332
		return true;
333
	}
334
	return waitUntilFileDeleted(file);
335
}
336
/**
337
 * Delete a file or directory and insure that the file is no longer present
338
 * on file system. In case of directory, delete all the hierarchy underneath.
339
 * 
340
 * @param resource The resource to delete
341
 * @return true iff the file was really delete, false otherwise
342
 */
343
public static boolean delete(IResource resource) {
344
	try {
345
		resource.delete(true, null);
346
		if (isResourceDeleted(resource)) {
347
			return true;
348
		}
349
	}
350
	catch (CoreException e) {
351
		//	skip
352
	}
353
	return waitUntilResourceDeleted(resource);
354
}
355
/**
356
 * Delete a file or directory and insure that the file is no longer present
357
 * on file system. In case of directory, delete all the hierarchy underneath.
358
 * 
359
 * @param path The path of the file or directory to delete
360
 * @return true iff the file was really delete, false otherwise
361
 */
362
public static boolean delete(String path) {
363
	return delete(new File(path));
364
}
365
/**
221
 * Generate a display string from the given String.
366
 * Generate a display string from the given String.
222
 * @param inputString the given input string
367
 * @param inputString the given input string
223
 *
368
 *
Lines 433-448 Link Here
433
 * no-op if not a directory.
578
 * no-op if not a directory.
434
 */
579
 */
435
public static void flushDirectoryContent(File dir) {
580
public static void flushDirectoryContent(File dir) {
436
	if (dir.isDirectory()) {
581
	File[] files = dir.listFiles();
437
		String[] files = dir.list();
582
	if (files == null) return;
438
		if (files == null) return;
583
	for (int i = 0, max = files.length; i < max; i++) {
439
		for (int i = 0, max = files.length; i < max; i++) {
584
		delete(files[i]);
440
			File current = new File(dir, files[i]);
441
			if (current.isDirectory()) {
442
				flushDirectoryContent(current);
443
			}
444
			current.delete();
445
		}
446
	}
585
	}
447
}
586
}
448
/**
587
/**
Lines 499-509 Link Here
499
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
638
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
500
*/
639
*/
501
public static String getOutputDirectory() {
640
public static String getOutputDirectory() {
502
	String container = System.getProperty("user.home");
641
	return OUTPUT_DIRECTORY;
503
	if (container == null){
642
}
504
		return null;
643
/**
644
 * Returns the parent's child file matching the given file or null if not found.
645
 * 
646
 * @param file The searched file in parent
647
 * @return The parent's child matching the given file or null if not found.
648
 */
649
private static File getParentChildFile(File file) {
650
	File parent = file.getParentFile();
651
	if (parent == null || !parent.exists()) return null;
652
	File[] files = parent.listFiles();
653
	int length = files==null ? 0 : files.length;
654
	if (length > 0) {
655
		for (int i=0; i<length; i++) {
656
			if (files[i] == file) {
657
				return files[i];
658
			} else if (files[i].equals(file)) {
659
				return files[i];
660
			} else if (files[i].getPath().equals(file.getPath())) {
661
				return files[i];
662
			}
663
		}
505
	}
664
	}
506
	return toNativePath(container) + File.separator + OUTPUT_DIRECTORY;
665
	return null;
666
}
667
/**
668
 * Returns parent's child resource matching the given resource or null if not found.
669
 * 
670
 * @param resource The searched file in parent
671
 * @return The parent's child matching the given file or null if not found.
672
 */
673
private static IResource getParentChildResource(IResource resource) {
674
	IContainer parent = resource.getParent();
675
	if (parent == null || !parent.exists()) return null;
676
	try {
677
		IResource[] members = parent.members();
678
		int length = members ==null ? 0 : members.length;
679
		if (length > 0) {
680
			for (int i=0; i<length; i++) {
681
				if (members[i] == resource) {
682
					return members[i];
683
				} else if (members[i].equals(resource)) {
684
					return members[i];
685
				} else if (members[i].getFullPath().equals(resource.getFullPath())) {
686
					return members[i];
687
				}
688
			}
689
		}
690
	}
691
	catch (CoreException ce) {
692
		// skip
693
	}
694
	return null;
695
}
696
/**
697
 * Returns the test name from stack elements info.
698
 * 
699
 * @return The name of the test currently running
700
 */
701
private static String getTestName() {
702
	StackTraceElement[] elements = new Exception().getStackTrace();
703
	int idx = 0, length=elements.length;
704
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
705
		// loop until JDT/Core class appears in the stack
706
	}
707
	if (idx<length) {
708
		StackTraceElement testElement = null;
709
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
710
			testElement = elements[idx++];
711
		}
712
		if (testElement != null) {
713
			return testElement.getClassName() + " - " + testElement.getMethodName();
714
		}
715
	}
716
	return "?";
507
}
717
}
508
/**
718
/**
509
 * Returns the next available port number on the local host.
719
 * Returns the next available port number on the local host.
Lines 545-550 Link Here
545
	return buffer.toString();
755
	return buffer.toString();
546
}
756
}
547
/**
757
/**
758
 * Returns whether a file is really deleted or not.
759
 * Does not only rely on {@link File#exists()} method but also
760
 * look if it's not in its parent children {@link #getParentChildFile(File)}.
761
 * 
762
 * @param file The file to test if deleted
763
 * @return true if the file does not exist and was not found in its parent children.
764
 */
765
public static boolean isFileDeleted(File file) {
766
	return !file.exists() && getParentChildFile(file) == null;
767
}
768
public static boolean isMacOS() {
769
	return System.getProperty("os.name").indexOf("Mac") != -1;
770
}
771
/**
772
 * Returns whether a resource is really deleted or not.
773
 * Does not only rely on {@link IResource#isAccessible()} method but also
774
 * look if it's not in its parent children {@link #getParentChildResource(IResource)}.
775
 * 
776
 * @param resource The resource to test if deleted
777
 * @return true if the resource is not accessible and was not found in its parent children.
778
 */
779
public static boolean isResourceDeleted(IResource resource) {
780
	return !resource.isAccessible() && getParentChildResource(resource) == null;
781
}
782
/**
783
 * Print given file information with specified indentation.
784
 * These information are:<ul>
785
 * 	<li>read {@link File#canRead()}</li>
786
 * 	<li>write {@link File#canWrite()}</li>
787
 * 	<li>exists {@link File#exists()}</li>
788
 * 	<li>is file {@link File#isFile()}</li>
789
 * 	<li>is directory {@link File#isDirectory()}</li>
790
 * 	<li>is hidden {@link File#isHidden()}</li>
791
 * </ul>
792
 * May recurse several level in parents hierarchy.
793
 * May also display children, but then will not recusre in parent
794
 * hierarchy to avoid infinite loop...
795
 * 
796
 * @param file The file to display information
797
 * @param indent Number of tab to print before the information
798
 * @param recurse Display also information on <code>recurse</code>th parents in hierarchy.
799
 * 	If negative then display children information instead.
800
 */
801
private static void printFileInfo(File file, int indent, int recurse) {
802
	String tab = "";
803
	for (int i=0; i<indent; i++) tab+="\t";
804
	System.out.print(tab+"- "+file.getName()+" file info: ");
805
	String sep = "";
806
	if (file.canRead()) {
807
		System.out.print("read");
808
		sep = ", ";
809
	}
810
	if (file.canWrite()) {
811
		System.out.print(sep+"write");
812
		sep = ", ";
813
	}
814
	if (file.exists()) {
815
		System.out.print(sep+"exist");
816
		sep = ", ";
817
	}
818
	if (file.isDirectory()) {
819
		System.out.print(sep+"dir");
820
		sep = ", ";
821
	}
822
	if (file.isFile()) {
823
		System.out.print(sep+"file");
824
		sep = ", ";
825
	}
826
	if (file.isHidden()) {
827
		System.out.print(sep+"hidden");
828
		sep = ", ";
829
	}
830
	System.out.println();
831
	File[] files = file.listFiles();
832
	int length = files==null ? 0 : files.length;
833
	if (length > 0) {
834
		boolean children = recurse < 0;
835
		System.out.print(tab+"	+ children: ");
836
		if (children) System.out.println();
837
		for (int i=0; i<length; i++) {
838
			if (children) { // display children
839
				printFileInfo(files[i], indent+2, -1);
840
			} else {
841
				if (i>0) System.out.print(", ");
842
				System.out.print(files[i].getName());
843
				if (files[i].isDirectory()) System.out.print("[dir]");
844
				else if (files[i].isFile()) System.out.print("[file]");
845
				else System.out.print("[?]");
846
			}
847
		}
848
		if (!children) System.out.println();
849
	}
850
	if (recurse > 0) {
851
		File parent = file.getParentFile();
852
		if (parent != null) printFileInfo(parent, indent+1, recurse-1);
853
	}
854
	}
855
	/**
856
	 * Print stack trace with only JDT/Core elements.
857
	 * 
858
	 * @param exception Exception of the stack trace. May be null, then a fake exception is used.
859
	 * @param indent Number of tab to display before the stack elements to display.
860
	 */
861
	private static void printJdtCoreStackTrace(Exception exception, int indent) {
862
	String tab = "";
863
	for (int i=0; i<indent; i++) tab+="\t";
864
	StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace();
865
	int idx = 0, length=elements.length;
866
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
867
		// loop until JDT/Core class appears in the stack
868
	}
869
	if (idx<length) {
870
		System.out.print(tab+"- stack trace");
871
		if (exception == null)
872
			System.out.println(":");
873
		else
874
			System.out.println(" for exception "+exception+":");
875
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
876
			StackTraceElement testElement = elements[idx++];
877
			System.out.println(tab+"	-> "+testElement);
878
		}
879
	} else {
880
		exception.printStackTrace(System.out);
881
	}
882
	}
883
	/**
548
 * Makes the given path a path using native path separators as returned by File.getPath()
884
 * Makes the given path a path using native path separators as returned by File.getPath()
549
 * and trimming any extra slash.
885
 * and trimming any extra slash.
550
 */
886
 */
Lines 607-612 Link Here
607
		}
943
		}
608
	}
944
	}
609
}
945
}
946
/**
947
 * Wait until the file is _really_ deleted on file system.
948
 * 
949
 * @param file Deleted file
950
 * @return true if the file was finally deleted, false otherwise
951
 */
952
private static boolean waitUntilFileDeleted(File file) {
953
	if (DELETE_DEBUG) {
954
		System.out.println();
955
		System.out.println("WARNING in test: "+getTestName());
956
		System.out.println("	- problems occured while deleting "+file);
957
		printJdtCoreStackTrace(null, 1);
958
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
959
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
960
	}
961
	int count = 0;
962
	int delay = 10; // ms
963
	int maxRetry = DELETE_MAX_WAIT / delay;
964
	int time = 0;
965
	while (count < maxRetry) {
966
		try {
967
			count++;
968
			Thread.sleep(delay);
969
			time += delay;
970
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
971
			if (DELETE_DEBUG) System.out.print('.');
972
			if (file.exists()) {
973
				if (file.delete()) {
974
					// SUCCESS
975
					if (DELETE_DEBUG) {
976
						System.out.println();
977
						System.out.println("	=> file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
978
						System.out.println();
979
					}
980
					return true;
981
				}
982
			}
983
			if (isFileDeleted(file)) {
984
				// SUCCESS
985
				if (DELETE_DEBUG) {
986
					System.out.println();
987
					System.out.println("	=> file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
988
					System.out.println();
989
				}
990
				return true;
991
			}
992
			// Increment waiting delay exponentially
993
			if (count >= 10 && delay <= 100) {
994
				count = 1;
995
				delay *= 10;
996
				maxRetry = DELETE_MAX_WAIT / delay;
997
				if ((DELETE_MAX_WAIT%delay) != 0) {
998
					maxRetry++;
999
				}
1000
			}
1001
		}
1002
		catch (InterruptedException ie) {
1003
			break; // end loop
1004
		}
1005
	}
1006
	if (!DELETE_DEBUG) {
1007
		System.out.println();
1008
		System.out.println("WARNING in test: "+getTestName());
1009
		System.out.println("	- problems occured while deleting "+file);
1010
		printJdtCoreStackTrace(null, 1);
1011
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1012
	}
1013
	System.out.println();
1014
	System.out.println("	!!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
1015
	System.out.println();
1016
	return false;
1017
}
1018
/**
1019
 * Wait until a resource is _really_ deleted on file system.
1020
 * 
1021
 * @param resource Deleted resource
1022
 * @return true if the file was finally deleted, false otherwise
1023
 */
1024
private static boolean waitUntilResourceDeleted(IResource resource) {
1025
	File file = resource.getLocation().toFile();
1026
	if (DELETE_DEBUG) {
1027
		System.out.println();
1028
		System.out.println("WARNING in test: "+getTestName());
1029
		System.out.println("	- problems occured while deleting resource "+resource);
1030
		printJdtCoreStackTrace(null, 1);
1031
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1032
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
1033
	}
1034
	int count = 0;
1035
	int delay = 10; // ms
1036
	int maxRetry = DELETE_MAX_WAIT / delay;
1037
	int time = 0;
1038
	while (count < maxRetry) {
1039
		try {
1040
			count++;
1041
			Thread.sleep(delay);
1042
			time += delay;
1043
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
1044
			if (DELETE_DEBUG) System.out.print('.');
1045
			if (resource.isAccessible()) {
1046
				try {
1047
					resource.delete(true, null);
1048
					if (isResourceDeleted(resource) && isFileDeleted(file)) {
1049
						// SUCCESS
1050
						if (DELETE_DEBUG) {
1051
							System.out.println();
1052
							System.out.println("	=> resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1053
							System.out.println();
1054
						}
1055
						return true;
1056
					}
1057
				}
1058
				catch (CoreException e) {
1059
					//	skip
1060
				}
1061
			}
1062
			if (isResourceDeleted(resource) && isFileDeleted(file)) {
1063
				// SUCCESS
1064
				if (DELETE_DEBUG) {
1065
					System.out.println();
1066
					System.out.println("	=> resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1067
					System.out.println();
1068
				}
1069
				return true;
1070
			}
1071
			// Increment waiting delay exponentially
1072
			if (count >= 10 && delay <= 100) {
1073
				count = 1;
1074
				delay *= 10;
1075
				maxRetry = DELETE_MAX_WAIT / delay;
1076
				if ((DELETE_MAX_WAIT%delay) != 0) {
1077
					maxRetry++;
1078
				}
1079
			}
1080
		}
1081
		catch (InterruptedException ie) {
1082
			break; // end loop
1083
		}
1084
	}
1085
	if (!DELETE_DEBUG) {
1086
		System.out.println();
1087
		System.out.println("WARNING in test: "+getTestName());
1088
		System.out.println("	- problems occured while deleting resource "+resource);
1089
		printJdtCoreStackTrace(null, 1);
1090
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1091
	}
1092
	System.out.println();
1093
	System.out.println("	!!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
1094
	System.out.println();
1095
	return false;
1096
}
610
public static void writeToFile(String contents, String destinationFilePath) {
1097
public static void writeToFile(String contents, String destinationFilePath) {
611
	File destFile = new File(destinationFilePath);
1098
	File destFile = new File(destinationFilePath);
612
	FileOutputStream output = null;
1099
	FileOutputStream output = null;
Lines 630-636 Link Here
630
public static void zip(File rootDir, String zipPath) throws IOException {
1117
public static void zip(File rootDir, String zipPath) throws IOException {
631
	ZipOutputStream zip = null;
1118
	ZipOutputStream zip = null;
632
	try {
1119
	try {
633
		zip  = new ZipOutputStream(new FileOutputStream(zipPath));
1120
		File zipFile = new File(zipPath);
1121
		if (zipFile.exists()) delete(zipFile);
1122
		zip = new ZipOutputStream(new FileOutputStream(zipFile));
634
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
1123
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
635
	} finally {
1124
	} finally {
636
		if (zip != null) {
1125
		if (zip != null) {
Lines 639-658 Link Here
639
	}
1128
	}
640
}
1129
}
641
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
1130
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
642
	String[] list = dir.list();
1131
	File[] files = dir.listFiles();
643
	if (list != null) {
1132
	if (files != null) {
644
		for (int i = 0, length = list.length; i < length; i++) {
1133
		for (int i = 0, length = files.length; i < length; i++) {
645
			String name = list[i];
1134
			File file = files[i];
646
			File file = new File(dir, name);
1135
			if (file.isFile()) {
647
			if (file.isDirectory()) {
648
				zip(file, zip, rootPathLength);
649
			} else {
650
				String path = file.getPath();
1136
				String path = file.getPath();
651
				path = path.substring(rootPathLength);
1137
				path = path.substring(rootPathLength);
652
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
1138
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
653
				zip.putNextEntry(entry);
1139
				zip.putNextEntry(entry);
654
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
1140
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
655
				zip.closeEntry();
1141
				zip.closeEntry();
1142
			} else {
1143
				zip(file, zip, rootPathLength);
656
			}
1144
			}
657
		}
1145
		}
658
	}
1146
	}
(-)src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java (-7 / +11 lines)
Lines 12-17 Link Here
12
12
13
import java.io.*;
13
import java.io.*;
14
14
15
import org.eclipse.jdt.core.tests.util.Util;
16
15
/**
17
/**
16
 * Wrapper around the external process that is running a local VM.
18
 * Wrapper around the external process that is running a local VM.
17
 * This allows to kill this process when we exit this vm.
19
 * This allows to kill this process when we exit this vm.
Lines 46-56 Link Here
46
		this.process.destroy();
48
		this.process.destroy();
47
	}
49
	}
48
}
50
}
49
/**
51
/*
50
 * Cleans up the given directory by removing all the files it contains as well
52
 * Cleans up the given directory by removing all the files it contains as well
51
 * but leaving the directory.
53
 * but leaving the directory.
52
 * @throws TargetException if the target path could not be cleaned up
54
 * @throws TargetException if the target path could not be cleaned up
53
 */
55
 *
54
private void cleanupDirectory(File directory) throws TargetException {
56
private void cleanupDirectory(File directory) throws TargetException {
55
	if (!directory.exists()) {
57
	if (!directory.exists()) {
56
		return;
58
		return;
Lines 70-75 Link Here
70
		}
72
		}
71
	}
73
	}
72
}
74
}
75
*/
73
/**
76
/**
74
 * Cleans up this context's target path by removing all the files it contains
77
 * Cleans up this context's target path by removing all the files it contains
75
 * but leaving the directory.
78
 * but leaving the directory.
Lines 79-89 Link Here
79
	if (this.evalTargetPath == null) return;
82
	if (this.evalTargetPath == null) return;
80
	String targetPath = this.evalTargetPath;
83
	String targetPath = this.evalTargetPath;
81
	if (LocalVMLauncher.TARGET_HAS_FILE_SYSTEM) {
84
	if (LocalVMLauncher.TARGET_HAS_FILE_SYSTEM) {
82
		cleanupDirectory(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY));
85
		Util.delete(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY));
83
		cleanupDirectory(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY));
86
		Util.delete(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY));
84
		File file = new File(targetPath, RuntimeConstants.SUPPORT_ZIP_FILE_NAME);
87
		File file = new File(targetPath, RuntimeConstants.SUPPORT_ZIP_FILE_NAME);
85
88
86
		// workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet
89
		/* workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet
87
		int count = 10;
90
		int count = 10;
88
		for (int i = 0; i < count; i++) {
91
		for (int i = 0; i < count; i++) {
89
			if (file.delete()) {
92
			if (file.delete()) {
Lines 94-104 Link Here
94
			} catch (InterruptedException e) {
97
			} catch (InterruptedException e) {
95
			}
98
			}
96
		}
99
		}
97
		if (file.exists()) {
100
		*/
101
		if (!Util.delete(file)) {
98
			throw new TargetException("Could not delete " + file.getPath());
102
			throw new TargetException("Could not delete " + file.getPath());
99
		}
103
		}
100
	} else {
104
	} else {
101
		cleanupDirectory(new File(targetPath));
105
		Util.delete(targetPath);
102
	}
106
	}
103
}
107
}
104
/**
108
/**
(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java (-4 / +5 lines)
Lines 6-11 Link Here
6
import junit.framework.Test;
6
import junit.framework.Test;
7
7
8
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
8
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
9
import org.eclipse.jdt.core.tests.util.Util;
9
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
10
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
10
11
11
public class NegativeTest extends AbstractRegressionTest {
12
public class NegativeTest extends AbstractRegressionTest {
Lines 15312-15318 Link Here
15312
		},
15313
		},
15313
		"SUCCESS");
15314
		"SUCCESS");
15314
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15315
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15315
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15316
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15316
	
15317
	
15317
	this.runNegativeTest(
15318
	this.runNegativeTest(
15318
		new String[] {
15319
		new String[] {
Lines 15360-15366 Link Here
15360
		},
15361
		},
15361
		"SUCCESS");
15362
		"SUCCESS");
15362
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15363
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15363
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15364
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15364
	
15365
	
15365
	this.runNegativeTest(
15366
	this.runNegativeTest(
15366
		new String[] {
15367
		new String[] {
Lines 15410-15416 Link Here
15410
		},
15411
		},
15411
		"SUCCESS");
15412
		"SUCCESS");
15412
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15413
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15413
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15414
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15414
	
15415
	
15415
	this.runNegativeTest(
15416
	this.runNegativeTest(
15416
		new String[] {
15417
		new String[] {
Lines 15606-15612 Link Here
15606
		false,
15607
		false,
15607
		null);	
15608
		null);	
15608
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15609
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15609
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class").delete();
15610
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15610
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15611
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15611
	
15612
	
15612
	this.runNegativeTest(
15613
	this.runNegativeTest(
(-)Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java (-3 / +2 lines)
Lines 22-27 Link Here
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.jdt.core.JavaCore;
24
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.tests.util.Util;
25
26
26
public class JavaModelRegressionTestSetup extends TestSetup {
27
public class JavaModelRegressionTestSetup extends TestSetup {
27
	public static JavaModelRegressionTestSetup CURRENT_TEST_SETUP = null;
28
	public static JavaModelRegressionTestSetup CURRENT_TEST_SETUP = null;
Lines 224-232 Link Here
224
	if (CURRENT_TEST_SETUP == this) {
225
	if (CURRENT_TEST_SETUP == this) {
225
		RegressionTestSuite.fgJavaModel.close();
226
		RegressionTestSuite.fgJavaModel.close();
226
		RegressionTestSuite.fgJavaModel = null;
227
		RegressionTestSuite.fgJavaModel = null;
227
		new java.io.File(LOCAL_JDK + File.separator + "classes.zip").delete();
228
		Util.delete(new File(LOCAL_JDK));
228
		new java.io.File(LOCAL_JDK + File.separator + "src.zip").delete();
229
		new java.io.File(LOCAL_JDK).delete();
230
	}
229
	}
231
}
230
}
232
}
231
}
(-).options (+8 lines)
Added Link Here
1
# Turn on debug tracing for org.eclipse.jdt.core.tests plugin
2
org.eclipse.jdt.core.tests/debug=true
3
4
# Reports deletion activity
5
org.eclipse.jdt.core.tests/debug/delete=false
6
7
# Maximum time in ms waiting for delete operation succeed
8
org.eclipse.jdt.core.tests/debug/delete/wait=10000
(-)Eclipse (+80 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests;
12
13
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.core.runtime.Plugin;
15
import org.eclipse.jdt.core.tests.util.Util;
16
import org.osgi.framework.BundleContext;
17
18
public class JDTCoreTestsPlugin extends Plugin {
19
20
// The shared plugin instance.
21
private static JDTCoreTestsPlugin JDT_CORE_TESTS_PLUGIN;
22
23
/**
24
 * The plug-in identifier of the JDT/Core tests support
25
 * (value <code>"org.eclipse.jdt.core.tests"</code>).
26
 */
27
public static final String PLUGIN_ID = "org.eclipse.jdt.core.tests" ; //$NON-NLS-1$
28
29
private static final String DELETE_DEBUG = PLUGIN_ID + "/debug/delete" ; //$NON-NLS-1$
30
private static final String DELETE_MAX_WAIT = PLUGIN_ID + "/debug/delete/wait" ; //$NON-NLS-1$
31
32
/**
33
 * The constructor.
34
 */
35
public JDTCoreTestsPlugin() {
36
	JDT_CORE_TESTS_PLUGIN = this;
37
}
38
39
/**
40
 * This method is called upon plug-in activation
41
 */
42
public void start(BundleContext context) throws Exception {
43
	super.start(context);
44
	configurePluginDebugOptions();
45
}
46
47
/**
48
 * This method is called when the plug-in is stopped
49
 */
50
public void stop(BundleContext context) throws Exception {
51
	super.stop(context);
52
	JDT_CORE_TESTS_PLUGIN = null;
53
}
54
55
/**
56
 * Returns the shared instance.
57
 */
58
public static JDTCoreTestsPlugin getDefault() {
59
	return JDT_CORE_TESTS_PLUGIN;
60
}
61
62
/**
63
 * Configure the plugin with respect to option settings defined in ".options" file
64
 */
65
void configurePluginDebugOptions(){
66
	if(isDebugging()){
67
		String option = Platform.getDebugOption(DELETE_DEBUG);
68
		if(option != null) {
69
			Util.DELETE_DEBUG = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
70
		}
71
		option = Platform.getDebugOption(DELETE_MAX_WAIT);
72
		if(option != null) {
73
			int wait = Integer.parseInt(option);
74
			if (wait > 1000 && wait <= 60000) { // between 1 and 60 seconds, else use default value (10s)
75
				Util.DELETE_MAX_WAIT = wait;
76
			}
77
		}
78
	}
79
}
80
}
(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java (-23 / +1 lines)
Lines 519-525 Link Here
519
				}
519
				}
520
				errorsCount = main.globalErrorsCount;
520
				errorsCount = main.globalErrorsCount;
521
			}
521
			}
522
			cleanupDirectory(new File(bins));
522
			Util.delete(bins);
523
			warnings = main.globalWarningsCount;
523
			warnings = main.globalWarningsCount;
524
		}
524
		}
525
		
525
		
Lines 540-567 Link Here
540
		this.scenarioComment.append(warnings);
540
		this.scenarioComment.append(warnings);
541
	}
541
	}
542
542
543
	/**
544
	 * Delete a directory from file system.
545
	 * @param directory
546
	 */
547
	protected void cleanupDirectory(File directory) {
548
		if (!directory.isDirectory() || !directory.exists()) {
549
			return;
550
		}
551
		String[] fileNames = directory.list();
552
		for (int i = 0; i < fileNames.length; i++) {
553
			File file = new File(directory, fileNames[i]);
554
			if (file.isDirectory()) {
555
				cleanupDirectory(file);
556
			} else {
557
				if (!file.delete())
558
					System.out.println("Could not delete file " + file.getPath()); //$NON-NLS-1$
559
			}
560
		}
561
		if (!directory.delete())
562
			System.out.println("Could not delete directory " + directory.getPath()); //$NON-NLS-1$
563
	}
564
565
	private void collectAllFiles(File root, ArrayList collector, FileFilter fileFilter) {
543
	private void collectAllFiles(File root, ArrayList collector, FileFilter fileFilter) {
566
		File[] files = root.listFiles(fileFilter);
544
		File[] files = root.listFiles(fileFilter);
567
		for (int i = 0; i < files.length; i++) {
545
		for (int i = 0; i < files.length; i++) {
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (-14 / +2 lines)
Lines 841-853 Link Here
841
		//System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
841
		//System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
842
	} finally {
842
	} finally {
843
		if (libDir != null) {
843
		if (libDir != null) {
844
			String[] libJars = libDir.list();
844
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
845
			if (libJars != null) {
846
				for (int i = 0, length = libJars.length; i < length; i++) {
847
					new File(libDir, libJars[i]).delete();
848
				}
849
			}
850
			libDir.delete();
851
		}
845
		}
852
		this.deleteProject("P");
846
		this.deleteProject("P");
853
		JavaCore.removeClasspathVariable("MyVar", null);
847
		JavaCore.removeClasspathVariable("MyVar", null);
Lines 880-892 Link Here
880
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
874
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
881
	} finally {
875
	} finally {
882
		if (libDir != null) {
876
		if (libDir != null) {
883
			String[] libJars = libDir.list();
877
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
884
			if (libJars != null) {
885
				for (int i = 0, length = libJars.length; i < length; i++) {
886
					new File(libDir, libJars[i]).delete();
887
				}
888
			}
889
			libDir.delete();
890
		}
878
		}
891
		this.deleteProject("P");
879
		this.deleteProject("P");
892
		JavaCore.removeClasspathVariable("MyVar", null);
880
		JavaCore.removeClasspathVariable("MyVar", null);
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-2 / +2 lines)
Lines 380-388 Link Here
380
		);
380
		);
381
	} finally {
381
	} finally {
382
		if (externalJar1 != null)
382
		if (externalJar1 != null)
383
			new File(externalJar1).delete();
383
			Util.delete(externalJar1);
384
		if (externalJar2 != null)
384
		if (externalJar2 != null)
385
			new File(externalJar2).delete();
385
			Util.delete(externalJar2);
386
		deleteProject("P");
386
		deleteProject("P");
387
	}
387
	}
388
}
388
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-1 / +2 lines)
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.*;
21
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.search.*;
22
import org.eclipse.jdt.core.search.*;
23
import org.eclipse.jdt.core.tests.util.Util;
23
import org.eclipse.jdt.internal.core.JavaModelStatus;
24
import org.eclipse.jdt.internal.core.JavaModelStatus;
24
25
25
/**
26
/**
Lines 2020-2026 Link Here
2020
				this.resultCollector);
2021
				this.resultCollector);
2021
			
2022
			
2022
		} finally {
2023
		} finally {
2023
			externalJar.delete();
2024
			Util.delete(externalJar);
2024
			project.setRawClasspath(classpath, null);
2025
			project.setRawClasspath(classpath, null);
2025
		}
2026
		}
2026
		
2027
		
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-21 / +4 lines)
Lines 979-1007 Link Here
979
		return project;
979
		return project;
980
	}
980
	}
981
	public void deleteFile(File file) {
981
	public void deleteFile(File file) {
982
		file = file.getAbsoluteFile();
982
		int retryCount = 0;
983
		if (!file.exists())
983
		while (++retryCount <= 60) { // wait 1 minute at most
984
			return;
984
			if (org.eclipse.jdt.core.tests.util.Util.delete(file)) {
985
		if (file.isDirectory()) {
985
				break;
986
			String[] files = file.list();
987
			//file.list() can return null
988
			if (files != null) {
989
				for (int i = 0; i < files.length; ++i) {
990
					deleteFile(new File(file, files[i]));
991
				}
992
			}
993
		}
994
		boolean success = file.delete();
995
		int retryCount = 60; // wait 1 minute at most
996
		while (!success && --retryCount >= 0) {
997
			try {
998
				Thread.sleep(1000);
999
			} catch (InterruptedException e) {
1000
			}
986
			}
1001
			success = file.delete();
1002
		}
987
		}
1003
		if (success) return;
1004
		System.err.println("Failed to delete " + file.getPath());
1005
	}
988
	}
1006
	protected void deleteFolder(IPath folderPath) throws CoreException {
989
	protected void deleteFolder(IPath folderPath) throws CoreException {
1007
		deleteResource(getFolder(folderPath));
990
		deleteResource(getFolder(folderPath));

Return to bug 166977