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

Collapse All | Expand All

(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java (-4 / +5 lines)
Lines 16-21 Link Here
16
import junit.framework.Test;
16
import junit.framework.Test;
17
17
18
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
18
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
19
import org.eclipse.jdt.core.tests.util.Util;
19
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
21
21
public class NegativeTest extends AbstractRegressionTest {
22
public class NegativeTest extends AbstractRegressionTest {
Lines 15355-15361 Link Here
15355
		},
15356
		},
15356
		"SUCCESS");
15357
		"SUCCESS");
15357
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15358
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15358
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15359
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15359
	
15360
	
15360
	this.runNegativeTest(
15361
	this.runNegativeTest(
15361
		new String[] {
15362
		new String[] {
Lines 15403-15409 Link Here
15403
		},
15404
		},
15404
		"SUCCESS");
15405
		"SUCCESS");
15405
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15406
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15406
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15407
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15407
	
15408
	
15408
	this.runNegativeTest(
15409
	this.runNegativeTest(
15409
		new String[] {
15410
		new String[] {
Lines 15453-15459 Link Here
15453
		},
15454
		},
15454
		"SUCCESS");
15455
		"SUCCESS");
15455
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15456
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15456
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15457
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15457
	
15458
	
15458
	this.runNegativeTest(
15459
	this.runNegativeTest(
15459
		new String[] {
15460
		new String[] {
Lines 15649-15655 Link Here
15649
		false,
15650
		false,
15650
		null);	
15651
		null);	
15651
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15652
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15652
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class").delete();
15653
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15653
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15654
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15654
	
15655
	
15655
	this.runNegativeTest(
15656
	this.runNegativeTest(
(-)Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java (-3 / +2 lines)
Lines 32-37 Link Here
32
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.core.runtime.IProgressMonitor;
33
import org.eclipse.core.runtime.Path;
33
import org.eclipse.core.runtime.Path;
34
import org.eclipse.jdt.core.JavaCore;
34
import org.eclipse.jdt.core.JavaCore;
35
import org.eclipse.jdt.core.tests.util.Util;
35
36
36
public class JavaModelRegressionTestSetup extends TestSetup {
37
public class JavaModelRegressionTestSetup extends TestSetup {
37
	public static JavaModelRegressionTestSetup CURRENT_TEST_SETUP = null;
38
	public static JavaModelRegressionTestSetup CURRENT_TEST_SETUP = null;
Lines 234-242 Link Here
234
	if (CURRENT_TEST_SETUP == this) {
235
	if (CURRENT_TEST_SETUP == this) {
235
		RegressionTestSuite.fgJavaModel.close();
236
		RegressionTestSuite.fgJavaModel.close();
236
		RegressionTestSuite.fgJavaModel = null;
237
		RegressionTestSuite.fgJavaModel = null;
237
		new java.io.File(LOCAL_JDK + File.separator + "classes.zip").delete();
238
		Util.delete(new File(LOCAL_JDK));
238
		new java.io.File(LOCAL_JDK + File.separator + "src.zip").delete();
239
		new java.io.File(LOCAL_JDK).delete();
240
	}
239
	}
241
}
240
}
242
}
241
}
(-)plugin.xml (-2 / +3 lines)
Lines 3-10 Link Here
3
<plugin
3
<plugin
4
   id="org.eclipse.jdt.core.tests"
4
   id="org.eclipse.jdt.core.tests"
5
   name="%pluginName"
5
   name="%pluginName"
6
   provider-name = "%providerName"
6
   version="3.2.1"
7
   version="3.2.1">
7
   provider-name="%providerName"
8
   class="org.eclipse.jdt.core.tests.JDTCoreTestsPlugin">
8
9
9
   <runtime>
10
   <runtime>
10
      <library name="jdtcoretests.jar">
11
      <library name="jdtcoretests.jar">
(-).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/model/ReconcilerTests.java (-2 / +16 lines)
Lines 871-878 Link Here
871
 * @test Ensures that changing an internal jar and refreshing takes the change into account
871
 * @test Ensures that changing an internal jar and refreshing takes the change into account
872
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
872
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
873
 */
873
 */
874
// TODO (frederic) put back when issue on Linux and Mac/OS will be fixed
874
public void testChangeInternalJar() throws CoreException, IOException {
875
public void _testChangeInternalJar() throws CoreException, IOException {
876
	IJavaProject project = getJavaProject("Reconciler");
875
	IJavaProject project = getJavaProject("Reconciler");
877
	String jarName = "b162621.jar";
876
	String jarName = "b162621.jar";
878
	try {
877
	try {
Lines 884-889 Link Here
884
		};
883
		};
885
		addLibrary(project, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
884
		addLibrary(project, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
886
885
886
		// Wait a little bit to be sure file system is aware of zip file creation
887
		try {
888
			Thread.sleep(1000);
889
		}
890
		catch (InterruptedException ie) {
891
			// skip
892
		}
893
887
		// Set working copy content with no error
894
		// Set working copy content with no error
888
		setUpWorkingCopy("/Reconciler/src/test/Test.java",
895
		setUpWorkingCopy("/Reconciler/src/test/Test.java",
889
			"package test;\n" + 
896
			"package test;\n" + 
Lines 932-937 Link Here
932
		}, jarPath, "1.4");
939
		}, jarPath, "1.4");
933
		project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
940
		project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
934
941
942
		try {
943
			Thread.sleep(1000);
944
		}
945
		catch (InterruptedException ie) {
946
			// skip
947
		}
948
935
		// Verify that error is gone
949
		// Verify that error is gone
936
		this.problemRequestor.initialize(contents.toCharArray());
950
		this.problemRequestor.initialize(contents.toCharArray());
937
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true, null, null);
951
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true, null, null);
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (-14 / +2 lines)
Lines 812-824 Link Here
812
		//System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
812
		//System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
813
	} finally {
813
	} finally {
814
		if (libDir != null) {
814
		if (libDir != null) {
815
			String[] libJars = libDir.list();
815
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
816
			if (libJars != null) {
817
				for (int i = 0, length = libJars.length; i < length; i++) {
818
					new File(libDir, libJars[i]).delete();
819
				}
820
			}
821
			libDir.delete();
822
		}
816
		}
823
		this.deleteProject("P");
817
		this.deleteProject("P");
824
		JavaCore.removeClasspathVariable("MyVar", null);
818
		JavaCore.removeClasspathVariable("MyVar", null);
Lines 851-863 Link Here
851
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
845
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
852
	} finally {
846
	} finally {
853
		if (libDir != null) {
847
		if (libDir != null) {
854
			String[] libJars = libDir.list();
848
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
855
			if (libJars != null) {
856
				for (int i = 0, length = libJars.length; i < length; i++) {
857
					new File(libDir, libJars[i]).delete();
858
				}
859
			}
860
			libDir.delete();
861
		}
849
		}
862
		this.deleteProject("P");
850
		this.deleteProject("P");
863
		JavaCore.removeClasspathVariable("MyVar", null);
851
		JavaCore.removeClasspathVariable("MyVar", null);
(-)src/org/eclipse/jdt/core/tests/model/JavadocPackageCompletionModelTest.java (-8 / +1 lines)
Lines 80-93 Link Here
80
		if (!PACKAGE_FILES.contains(packageDir)) {
80
		if (!PACKAGE_FILES.contains(packageDir)) {
81
			if (packageDir.exists()) {
81
			if (packageDir.exists()) {
82
				PACKAGE_FILES.add(packageDir);
82
				PACKAGE_FILES.add(packageDir);
83
				File[] dirs= packageDir.listFiles();
83
				Util.flushDirectoryContent(packageDir);
84
				for (int j=0, dl=dirs.length; j<dl; j++) {
85
					File[] files = dirs[j].listFiles();
86
					for (int k=0, fl=files.length; k<fl; k++) {
87
						files[k].delete();
88
					}
89
					dirs[j].delete();
90
				}
91
			} else if (packageDir.mkdirs()) {
84
			} else if (packageDir.mkdirs()) {
92
				PACKAGE_FILES.add(packageDir);
85
				PACKAGE_FILES.add(packageDir);
93
			} else {
86
			} else {
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java (-4 / +1 lines)
Lines 455-464 Link Here
455
			if (!PACKAGE_FILES.contains(packageDir)) {
455
			if (!PACKAGE_FILES.contains(packageDir)) {
456
				if (packageDir.exists()) {
456
				if (packageDir.exists()) {
457
					PACKAGE_FILES.add(packageDir);
457
					PACKAGE_FILES.add(packageDir);
458
					File[] files = packageDir.listFiles();
458
					Util.flushDirectoryContent(packageDir);
459
					for (int j=0, fl=files.length; j<fl; j++) {
460
						files[j].delete();
461
					}
462
				} else if (packageDir.mkdirs()) {
459
				} else if (packageDir.mkdirs()) {
463
					PACKAGE_FILES.add(packageDir);
460
					PACKAGE_FILES.add(packageDir);
464
				} else {
461
				} else {
(-)src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java (-2 / +2 lines)
Lines 439-447 Link Here
439
		);
439
		);
440
	} finally {
440
	} finally {
441
		if (externalJar1 != null)
441
		if (externalJar1 != null)
442
			new File(externalJar1).delete();
442
			Util.delete(externalJar1);
443
		if (externalJar2 != null)
443
		if (externalJar2 != null)
444
			new File(externalJar2).delete();
444
			Util.delete(externalJar2);
445
		deleteProject("P");
445
		deleteProject("P");
446
	}
446
	}
447
}
447
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests2.java (-2 / +16 lines)
Lines 2252-2259 Link Here
2252
 * @test Ensures that changing an internal jar and refreshing takes the change into account
2252
 * @test Ensures that changing an internal jar and refreshing takes the change into account
2253
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
2253
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621"
2254
 */
2254
 */
2255
// TODO (frederic) put back when issue on Linux and Mac/OS will be fixed
2255
public void testChangeInternalJar() throws CoreException, IOException {
2256
public void _testChangeInternalJar() throws CoreException, IOException {
2257
	IJavaProject currentProject = getJavaProject("Completion");
2256
	IJavaProject currentProject = getJavaProject("Completion");
2258
	String jarName = "b162621.jar";
2257
	String jarName = "b162621.jar";
2259
	try {
2258
	try {
Lines 2268-2273 Link Here
2268
		};
2267
		};
2269
		addLibrary(currentProject, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
2268
		addLibrary(currentProject, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4);
2270
2269
2270
		// Wait a little bit to be sure file system is aware of zip file creation
2271
		try {
2272
			Thread.sleep(1000);
2273
		}
2274
		catch (InterruptedException ie) {
2275
			// skip
2276
		}
2277
2271
		// Create compilation unit in which completion occurs
2278
		// Create compilation unit in which completion occurs
2272
		String path = "/Completion/src/test/Test.java";
2279
		String path = "/Completion/src/test/Test.java";
2273
		String source = "package test;\n" + 
2280
		String source = "package test;\n" + 
Lines 2306-2311 Link Here
2306
		}, jarPath, "1.4");
2313
		}, jarPath, "1.4");
2307
		currentProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
2314
		currentProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
2308
2315
2316
		try {
2317
			Thread.sleep(1000);
2318
		}
2319
		catch (InterruptedException ie) {
2320
			// skip
2321
		}
2322
2309
		// second completion
2323
		// second completion
2310
		requestor = new CompletionTestsRequestor2();
2324
		requestor = new CompletionTestsRequestor2();
2311
		unit.codeComplete(cursorLocation, requestor);
2325
		unit.codeComplete(cursorLocation, requestor);
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-1 / +2 lines)
Lines 21-26 Link Here
21
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.compiler.CharOperation;
22
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.search.*;
23
import org.eclipse.jdt.core.search.*;
24
import org.eclipse.jdt.core.tests.util.Util;
24
import org.eclipse.jdt.internal.core.JavaModelStatus;
25
import org.eclipse.jdt.internal.core.JavaModelStatus;
25
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
26
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
26
27
Lines 2073-2079 Link Here
2073
			this.resultCollector);
2074
			this.resultCollector);
2074
		
2075
		
2075
	} finally {
2076
	} finally {
2076
		externalJar.delete();
2077
		Util.delete(externalJar);
2077
		project.setRawClasspath(classpath, null);
2078
		project.setRawClasspath(classpath, null);
2078
	}
2079
	}
2079
	
2080
	
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-58 / +10 lines)
Lines 1145-1173 Link Here
1145
		return project;
1145
		return project;
1146
	}
1146
	}
1147
	public void deleteFile(File file) {
1147
	public void deleteFile(File file) {
1148
		file = file.getAbsoluteFile();
1148
		int retryCount = 0;
1149
		if (!file.exists())
1149
		while (++retryCount <= 60) { // wait 1 minute at most
1150
			return;
1150
			if (org.eclipse.jdt.core.tests.util.Util.delete(file)) {
1151
		if (file.isDirectory()) {
1151
				break;
1152
			String[] files = file.list();
1153
			//file.list() can return null
1154
			if (files != null) {
1155
				for (int i = 0; i < files.length; ++i) {
1156
					deleteFile(new File(file, files[i]));
1157
				}
1158
			}
1159
		}
1160
		boolean success = file.delete();
1161
		int retryCount = 60; // wait 1 minute at most
1162
		while (!success && --retryCount >= 0) {
1163
			try {
1164
				Thread.sleep(1000);
1165
			} catch (InterruptedException e) {
1166
			}
1152
			}
1167
			success = file.delete();
1168
		}
1153
		}
1169
		if (success) return;
1170
		System.err.println("Failed to delete " + file.getPath());
1171
	}
1154
	}
1172
	protected void deleteFolder(IPath folderPath) throws CoreException {
1155
	protected void deleteFolder(IPath folderPath) throws CoreException {
1173
		deleteResource(getFolder(folderPath));
1156
		deleteResource(getFolder(folderPath));
Lines 1200-1243 Link Here
1200
	 * Delete this resource.
1183
	 * Delete this resource.
1201
	 */
1184
	 */
1202
	public void deleteResource(IResource resource) throws CoreException {
1185
	public void deleteResource(IResource resource) throws CoreException {
1203
		CoreException lastException = null;
1204
		try {
1205
			resource.delete(true, null);
1206
			return;
1207
		} catch (CoreException e) {
1208
			lastException = e;
1209
			// just print for info
1210
			System.out.println(e.getMessage() + " [" + resource.getFullPath() + "]");
1211
		} catch (IllegalArgumentException iae) {
1212
			// just print for info
1213
			System.out.println(iae.getMessage() + " [" + resource.getFullPath() + "]");
1214
		}
1215
		int retryCount = 0; // wait 1 minute at most
1186
		int retryCount = 0; // wait 1 minute at most
1216
		while (resource.isAccessible() && ++retryCount <= 60) {
1187
		while (++retryCount <= 60) {
1217
			System.out.println("Running GC and waiting 1s...");
1188
			if (!org.eclipse.jdt.core.tests.util.Util.delete(resource)) {
1218
			try {
1219
				System.gc();
1189
				System.gc();
1220
				Thread.sleep(1000);
1221
			} catch (InterruptedException e) {
1222
			}
1190
			}
1223
			try {
1224
				resource.delete(true, null);
1225
			} catch (CoreException e) {
1226
				lastException = e;
1227
				// just print for info
1228
				System.out.println("Retry "+retryCount+": "+ e.getMessage() + " [" + resource.getFullPath() + "]");
1229
			} catch (IllegalArgumentException iae) {
1230
				// just print for info
1231
				System.out.println("Retry "+retryCount+": "+ iae.getMessage() + " [" + resource.getFullPath() + "]");
1232
			}
1233
		}
1234
		if (!resource.isAccessible()) {
1235
			System.out.println("Succeed to delete resource [" + resource.getFullPath() + "]");
1236
			return;
1237
		}
1238
		System.err.println("Failed to delete resource [" + resource.getFullPath() + "]");
1239
		if (lastException != null) {
1240
			throw lastException;
1241
		}
1191
		}
1242
	}
1192
	}
1243
	/**
1193
	/**
Lines 1685-1692 Link Here
1685
		IProject project = javaProject.getProject();
1635
		IProject project = javaProject.getProject();
1686
		String projectPath = '/' + project.getName() + '/';
1636
		String projectPath = '/' + project.getName() + '/';
1687
		removeLibraryEntry(javaProject, new Path(projectPath + jarName));
1637
		removeLibraryEntry(javaProject, new Path(projectPath + jarName));
1688
		project.getFile(jarName).delete(false, null);
1638
		org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(jarName));
1689
		project.getFile(sourceZipName).delete(false, null);
1639
		if (sourceZipName != null && sourceZipName.length() != 0) {
1640
			org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(sourceZipName));
1641
		}
1690
	}
1642
	}
1691
	protected void removeLibraryEntry(IJavaProject project, Path path) throws JavaModelException {
1643
	protected void removeLibraryEntry(IJavaProject project, Path path) throws JavaModelException {
1692
		IClasspathEntry[] entries = project.getRawClasspath();
1644
		IClasspathEntry[] entries = project.getRawClasspath();
(-)src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java (-25 / +3 lines)
Lines 89-95 Link Here
89
//	protected final static String JUNIT_PROJECT_NAME = "junit";
89
//	protected final static String JUNIT_PROJECT_NAME = "junit";
90
//	protected static IJavaProject JUNIT_PROJECT;
90
//	protected static IJavaProject JUNIT_PROJECT;
91
	
91
	
92
	// Compilaiton variable
92
	// Compilation variable
93
	public static final String COMPILER_OUTPUT_DIR;
93
	public static final String COMPILER_OUTPUT_DIR;
94
	static {
94
	static {
95
		String outputDir = null;
95
		String outputDir = null;
Lines 836-863 Link Here
836
		this.scenarioComment.append(warnings);
836
		this.scenarioComment.append(warnings);
837
	}
837
	}
838
838
839
	/**
840
	 * Delete a directory from file system.
841
	 * @param directory
842
	 */
843
	protected void cleanupDirectory(File directory) {
844
		if (!directory.isDirectory() || !directory.exists()) {
845
			return;
846
		}
847
		String[] fileNames = directory.list();
848
		for (int i = 0; i < fileNames.length; i++) {
849
			File file = new File(directory, fileNames[i]);
850
			if (file.isDirectory()) {
851
				cleanupDirectory(file);
852
			} else {
853
				if (!file.delete())
854
					System.out.println("Could not delete file " + file.getPath()); //$NON-NLS-1$
855
			}
856
		}
857
		if (!directory.delete())
858
			System.out.println("Could not delete directory " + directory.getPath()); //$NON-NLS-1$
859
	}
860
861
	/*
839
	/*
862
	 * Clear given options
840
	 * Clear given options
863
	 */
841
	 */
Lines 925-931 Link Here
925
			}
903
			}
926
		}
904
		}
927
		if (!"none".equals(COMPILER_OUTPUT_DIR)) {
905
		if (!"none".equals(COMPILER_OUTPUT_DIR)) {
928
			cleanupDirectory(new File(COMPILER_OUTPUT_DIR));
906
			Util.delete(COMPILER_OUTPUT_DIR);
929
		}
907
		}
930
		warnings = warmup.globalWarningsCount;
908
		warnings = warmup.globalWarningsCount;
931
		if (!log) Util.writeToFile(errStrWriter.toString(), logFileName);
909
		if (!log) Util.writeToFile(errStrWriter.toString(), logFileName);
Lines 957-963 Link Here
957
			}
935
			}
958
			stopMeasuring();
936
			stopMeasuring();
959
			if (!"none".equals(COMPILER_OUTPUT_DIR)) {
937
			if (!"none".equals(COMPILER_OUTPUT_DIR)) {
960
				cleanupDirectory(new File(COMPILER_OUTPUT_DIR));
938
				Util.delete(COMPILER_OUTPUT_DIR);
961
			}
939
			}
962
		}
940
		}
963
		
941
		
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java (-5 / +5 lines)
Lines 365-375 Link Here
365
		createOutputTestDirectory(Character.toUpperCase(testName.charAt(0)) + 
365
		createOutputTestDirectory(Character.toUpperCase(testName.charAt(0)) + 
366
				testName.substring(1));
366
				testName.substring(1));
367
		System.out.println("Write test file to " + 
367
		System.out.println("Write test file to " + 
368
				this.outputTestDirectoryPath + "...");
368
				this.outputTestDirectory.getPath() + "...");
369
		for (int i=0, length=testFiles.length; i<length; i++) {
369
		for (int i=0, length=testFiles.length; i<length; i++) {
370
			String contents = testFiles[i+1];
370
			String contents = testFiles[i+1];
371
			String fileName = testFiles[i++];
371
			String fileName = testFiles[i++];
372
			String dirFileName = this.outputTestDirectoryPath.toString();
372
			String dirFileName = this.outputTestDirectory.getPath();
373
			if (fileName.indexOf("Visibility")>0) {
373
			if (fileName.indexOf("Visibility")>0) {
374
				continue;
374
				continue;
375
			} else {
375
			} else {
Lines 411-417 Link Here
411
			// Cleanup javac output dir if needed
411
			// Cleanup javac output dir if needed
412
			File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
412
			File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
413
			if (shouldFlushOutputDirectory) {
413
			if (shouldFlushOutputDirectory) {
414
				cleanupDirectory(javacOutputDirectory);
414
				Util.delete(javacOutputDirectory);
415
			}
415
			}
416
			
416
			
417
			// Write files in dir
417
			// Write files in dir
Lines 442-448 Link Here
442
442
443
			// Launch process
443
			// Launch process
444
			compileProcess = Runtime.getRuntime().exec(
444
			compileProcess = Runtime.getRuntime().exec(
445
				cmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
445
				cmdLine.toString(), null, this.outputTestDirectory);
446
446
447
			// Log errors
447
			// Log errors
448
      Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");            
448
      Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");            
Lines 548-554 Link Here
548
			//           the test itself
548
			//           the test itself
549
		} 
549
		} 
550
		finally {
550
		finally {
551
			cleanupDirectory(outputTestDirectoryPath.toFile());
551
			Util.delete(outputTestDirectory);
552
		}
552
		}
553
	}
553
	}
554
	
554
	
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java (-30 / +6 lines)
Lines 259-265 Link Here
259
		if (fileNames != null) {
259
		if (fileNames != null) {
260
			for (int i = 0, max = fileNames.length; i < max; i++) {
260
			for (int i = 0, max = fileNames.length; i < max; i++) {
261
				if (fileNames[i].indexOf(className) != -1) {
261
				if (fileNames[i].indexOf(className) != -1) {
262
					new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete();
262
					Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]);
263
				}
263
				}
264
			}
264
			}
265
		}
265
		}
Lines 269-275 Link Here
269
		if (fileNames != null) {
269
		if (fileNames != null) {
270
			for (int i = 0, max = fileNames.length; i < max; i++) {
270
			for (int i = 0, max = fileNames.length; i < max; i++) {
271
				if (fileNames[i].indexOf(className) != -1) {
271
				if (fileNames[i].indexOf(className) != -1) {
272
					new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete();
272
					Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]);
273
				}
273
				}
274
			}
274
			}
275
		}
275
		}
Lines 883-889 Link Here
883
		File outputDir = new File(OUTPUT_DIR);
883
		File outputDir = new File(OUTPUT_DIR);
884
		if (outputDir.exists()) {
884
		if (outputDir.exists()) {
885
			Util.flushDirectoryContent(outputDir);
885
			Util.flushDirectoryContent(outputDir);
886
			outputDir.delete();
887
		}
886
		}
888
		super.tearDown();
887
		super.tearDown();
889
		if (RUN_JAVAC) {
888
		if (RUN_JAVAC) {
Lines 978-1006 Link Here
978
	 * Specific method to let tests Sun javac compilation available...
977
	 * Specific method to let tests Sun javac compilation available...
979
	 #######################################*/
978
	 #######################################*/
980
	/*
979
	/*
981
	 * Cleans up the given directory by removing all the files it contains as well
982
	 * but leaving the directory.
983
	 * @throws TargetException if the target path could not be cleaned up
984
	 */
985
	protected void cleanupDirectory(File directory) {
986
		if (!directory.exists()) {
987
			return;
988
		}
989
		String[] fileNames = directory.list();
990
		for (int i = 0; i < fileNames.length; i++) {
991
			File file = new File(directory, fileNames[i]);
992
			if (file.isDirectory()) {
993
				cleanupDirectory(file);
994
			} else {
995
				if (!file.delete())
996
					System.out.println("Could not delete file " + file.getPath());
997
			}
998
		}
999
		if (!directory.delete())
1000
			System.out.println("Could not delete directory " + directory.getPath());
1001
	}
1002
1003
	/*
1004
	 * Write given source test files in current output sub-directory.
980
	 * Write given source test files in current output sub-directory.
1005
	 * Use test name for this sub-directory name (ie. test001, test002, etc...)
981
	 * Use test name for this sub-directory name (ie. test001, test002, etc...)
1006
	 */
982
	 */
Lines 1051-1057 Link Here
1051
			// Cleanup javac output dir if needed
1027
			// Cleanup javac output dir if needed
1052
			File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
1028
			File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR);
1053
			if (shouldFlushOutputDirectory) {
1029
			if (shouldFlushOutputDirectory) {
1054
				cleanupDirectory(javacOutputDirectory);
1030
				Util.delete(javacOutputDirectory);
1055
			}
1031
			}
1056
			
1032
			
1057
			// Write files in dir
1033
			// Write files in dir
Lines 1082-1088 Link Here
1082
1058
1083
			// Launch process
1059
			// Launch process
1084
			compileProcess = Runtime.getRuntime().exec(
1060
			compileProcess = Runtime.getRuntime().exec(
1085
				cmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
1061
				cmdLine.toString(), null, this.outputTestDirectory);
1086
1062
1087
			// Log errors
1063
			// Log errors
1088
      Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");            
1064
      Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR");            
Lines 1147-1153 Link Here
1147
						javaCmdLine.append(cp);
1123
						javaCmdLine.append(cp);
1148
						javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.')));
1124
						javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.')));
1149
							// assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes
1125
							// assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes
1150
						execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectoryPath.toFile());
1126
						execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectory);
1151
						Logger logger = new Logger(execProcess.getInputStream(), "");
1127
						Logger logger = new Logger(execProcess.getInputStream(), "");
1152
						// PREMATURE implement consistent error policy
1128
						// PREMATURE implement consistent error policy
1153
	     				logger.start();
1129
	     				logger.start();
Lines 1216-1222 Link Here
1216
		} 
1192
		} 
1217
		finally {
1193
		finally {
1218
			// Clean up written file(s)
1194
			// Clean up written file(s)
1219
			cleanupDirectory(outputTestDirectoryPath.toFile());
1195
			Util.delete(outputTestDirectory);
1220
		}
1196
		}
1221
	}
1197
	}
1222
1198
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-3 / +3 lines)
Lines 1682-1688 Link Here
1682
	        "",
1682
	        "",
1683
	        true);
1683
	        true);
1684
		if (jarCreated) {
1684
		if (jarCreated) {
1685
			new File(libPath).delete();
1685
			Util.delete(libPath);
1686
		}
1686
		}
1687
	}
1687
	}
1688
	//	 https://bugs.eclipse.org/bugs/show_bug.cgi?id=88364 - -extdirs extends the classpath before -classpath
1688
	//	 https://bugs.eclipse.org/bugs/show_bug.cgi?id=88364 - -extdirs extends the classpath before -classpath
Lines 2280-2290 Link Here
2280
		        false);
2280
		        false);
2281
		final String userDir = System.getProperty("user.dir");
2281
		final String userDir = System.getProperty("user.dir");
2282
		File f = new File(userDir, "X.java");
2282
		File f = new File(userDir, "X.java");
2283
		if (!f.delete()) {
2283
		if (!Util.delete(f)) {
2284
			System.out.println("Could not delete X");
2284
			System.out.println("Could not delete X");
2285
		}
2285
		}
2286
		f = new File(userDir, "p" + File.separator + "Y.java");
2286
		f = new File(userDir, "p" + File.separator + "Y.java");
2287
		if (!f.delete()) {
2287
		if (!Util.delete(f)) {
2288
			System.out.println("Could not delete Y");
2288
			System.out.println("Could not delete Y");
2289
		}
2289
		}
2290
		
2290
		
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (-1 / +1 lines)
Lines 1516-1522 Link Here
1516
		},
1516
		},
1517
		"SUCCESS");
1517
		"SUCCESS");
1518
	// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
1518
	// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
1519
	new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class").delete();
1519
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class"));
1520
	
1520
	
1521
	this.runConformTest(
1521
	this.runConformTest(
1522
		new String[] {
1522
		new String[] {
(-)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 (-27 / +512 lines)
Lines 25-30 Link Here
25
import java.util.zip.ZipInputStream;
25
import java.util.zip.ZipInputStream;
26
import java.util.zip.ZipOutputStream;
26
import java.util.zip.ZipOutputStream;
27
27
28
import org.eclipse.core.resources.IContainer;
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.jdt.core.compiler.IProblem;
31
import org.eclipse.jdt.core.compiler.IProblem;
29
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
32
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
30
import org.eclipse.jdt.internal.compiler.Compiler;
33
import org.eclipse.jdt.internal.compiler.Compiler;
Lines 37-44 Link Here
37
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
40
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
38
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
41
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
39
public class Util {
42
public class Util {
43
	// Trace for delete operation
44
	/*
45
	 * Maximum time wasted repeating delete operations while running JDT/Core tests.
46
	 */
47
	private static int DELETE_MAX_TIME = 0;
48
	/**
49
	 * Trace deletion operations while running JDT/Core tests.
50
	 */
51
	public static boolean DELETE_DEBUG = false;
52
	/**
53
	 * Maximum of time in ms to wait in deletion operation while running JDT/Core tests.
54
	 * Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000).
55
	 * <br>
56
	 * To avoid too many loops while waiting, the ten first ones are done waiting
57
	 * 10ms before repeating, the ten loops after are done waiting 100ms and
58
	 * the other loops are done waiting 1s...
59
	 */
60
	public static int DELETE_MAX_WAIT = 10000;
61
40
	private static final boolean DEBUG = false;
62
	private static final boolean DEBUG = false;
41
	public static String OUTPUT_DIRECTORY = "comptest";
63
64
	// Output directory initialization
65
	/**
66
	 * Initially, output directory was located in System.getProperty("user.home")+"\comptest".
67
	 * To allow user to run several compiler tests at the same time, main output directory
68
	 * is now located in a sub-directory of "comptest" which name is "run."+<code>System.currentMilliseconds</code>.
69
	 * 
70
	 * @see #DELAY_BEFORE_CLEAN_PREVIOUS
71
	 */
72
	private final static String OUTPUT_DIRECTORY;
73
	/**
74
	 * Let user specify the delay in hours before output directories are removed from file system
75
	 * while starting a new test run. Default value is 2 hours.
76
	 * <p>
77
	 * Note that this value may be a float and so have time less than one hour.
78
	 * If value is 0 or negative, then all previous run directories will be removed...
79
	 * 
80
	 * @see #OUTPUT_DIRECTORY
81
	 */
82
	private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay");
83
	/*
84
	 * Static initializer to clean directories created while running previous test suites.
85
	 */
86
	static {
87
		// Get delay for cleaning sub-directories
88
		long millisecondsPerHour = 1000L * 3600L;
89
		long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours
90
		try {
91
			if (DELAY_BEFORE_CLEAN_PREVIOUS != null) {
92
				float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS);
93
				delay = (int) (millisecondsPerHour * hours);
94
			}
95
		}
96
		catch (NumberFormatException nfe) {
97
			// use default
98
		}
99
100
		// Get output directory root from system properties
101
		String container = System.getProperty("jdt.test.output_directory");
102
		if (container == null){
103
			container = System.getProperty("user.home");
104
		}
105
		if (container == null) {
106
			container = ".";	// use current directory
107
		}
108
		
109
		// Get file for root directory
110
		if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') {
111
			container = Character.toUpperCase(container.charAt(0)) + container.substring(1);
112
		}
113
		File dir = new File(new File(container), "comptest");
114
115
		// If root directory already exists, clean it
116
		if (dir.exists()) {
117
			long now = System.currentTimeMillis();
118
			if ((now - dir.lastModified()) > delay) {
119
				// remove all directory content
120
				flushDirectoryContent(dir);
121
			} else {
122
				// remove only old sub-dirs
123
				File[] testDirs = dir.listFiles();
124
				for (int i=0,l=testDirs.length; i<l; i++) {
125
					if (testDirs[i].isDirectory()) {
126
						if ((now - testDirs[i].lastModified()) > delay) {
127
							delete(testDirs[i]);
128
						}
129
					}
130
				}
131
			}
132
		}
133
134
		// Computed test run directory name based on current time
135
		File dateDir = new File(dir, "run."+System.currentTimeMillis());
136
		OUTPUT_DIRECTORY = dateDir.getPath();
137
	}
42
138
43
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) {
139
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) {
44
	problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
140
	problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING"));
Lines 158-165 Link Here
158
		try {
254
		try {
159
			in = new FileInputStream(source);
255
			in = new FileInputStream(source);
160
			File destFile = new File(dest, source.getName());
256
			File destFile = new File(dest, source.getName());
161
			if (destFile.exists() && !destFile.delete()) {
257
			if (destFile.exists()) {
162
				throw new IOException(destFile + " is in use");
258
				if (!delete(destFile)) {
259
					throw new IOException(destFile + " is in use");
260
				}
163
			}
261
			}
164
		 	out = new FileOutputStream(destFile);
262
		 	out = new FileOutputStream(destFile);
165
			int bufferLength = 1024;
263
			int bufferLength = 1024;
Lines 231-236 Link Here
231
	zip(sourcesDir, zipPath);
329
	zip(sourcesDir, zipPath);
232
}
330
}
233
/**
331
/**
332
 * Delete a file or directory and insure that the file is no longer present
333
 * on file system. In case of directory, delete all the hierarchy underneath.
334
 * 
335
 * @param file The file or directory to delete
336
 * @return true iff the file was really delete, false otherwise
337
 */
338
public static boolean delete(File file) {
339
	// flush all directory content
340
	if (file.isDirectory()) {
341
		flushDirectoryContent(file);
342
	}
343
	// remove file
344
	file.delete();
345
	if (isFileDeleted(file)) {
346
		return true;
347
	}
348
	return waitUntilFileDeleted(file);
349
}
350
/**
351
 * Delete a file or directory and insure that the file is no longer present
352
 * on file system. In case of directory, delete all the hierarchy underneath.
353
 * 
354
 * @param resource The resource to delete
355
 * @return true iff the file was really delete, false otherwise
356
 */
357
public static boolean delete(IResource resource) {
358
	try {
359
		resource.delete(true, null);
360
		if (isResourceDeleted(resource)) {
361
			return true;
362
		}
363
	}
364
	catch (CoreException e) {
365
		//	skip
366
	}
367
	return waitUntilResourceDeleted(resource);
368
}
369
/**
370
 * Delete a file or directory and insure that the file is no longer present
371
 * on file system. In case of directory, delete all the hierarchy underneath.
372
 * 
373
 * @param path The path of the file or directory to delete
374
 * @return true iff the file was really delete, false otherwise
375
 */
376
public static boolean delete(String path) {
377
	return delete(new File(path));
378
}
379
/**
234
 * Generate a display string from the given String.
380
 * Generate a display string from the given String.
235
 * @param inputString the given input string
381
 * @param inputString the given input string
236
 *
382
 *
Lines 446-462 Link Here
446
 * no-op if not a directory.
592
 * no-op if not a directory.
447
 */
593
 */
448
public static void flushDirectoryContent(File dir) {
594
public static void flushDirectoryContent(File dir) {
449
	if (dir.isDirectory()) {
595
	File[] files = dir.listFiles();
450
		String[] files = dir.list();
596
	if (files == null) return;
451
		if (files == null) return;
597
	for (int i = 0, max = files.length; i < max; i++) {
452
		for (int i = 0, max = files.length; i < max; i++) {
598
		delete(files[i]);
453
			File current = new File(dir, files[i]);
454
			if (current.isDirectory()) {
455
				flushDirectoryContent(current);
456
			}
457
			if (!current.delete()) 
458
				System.err.println("Could not delete " + current.getName());
459
		}
460
	}
599
	}
461
}
600
}
462
/**
601
/**
Lines 547-557 Link Here
547
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
686
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
548
*/
687
*/
549
public static String getOutputDirectory() {
688
public static String getOutputDirectory() {
550
	String container = System.getProperty("user.home");
689
	return OUTPUT_DIRECTORY;
551
	if (container == null){
690
}
552
		return null;
691
/**
692
 * Returns the parent's child file matching the given file or null if not found.
693
 * 
694
 * @param file The searched file in parent
695
 * @return The parent's child matching the given file or null if not found.
696
 */
697
private static File getParentChildFile(File file) {
698
	File parent = file.getParentFile();
699
	if (parent == null || !parent.exists()) return null;
700
	File[] files = parent.listFiles();
701
	int length = files==null ? 0 : files.length;
702
	if (length > 0) {
703
		for (int i=0; i<length; i++) {
704
			if (files[i] == file) {
705
				return files[i];
706
			} else if (files[i].equals(file)) {
707
				return files[i];
708
			} else if (files[i].getPath().equals(file.getPath())) {
709
				return files[i];
710
			}
711
		}
712
	}
713
	return null;
714
}
715
/**
716
 * Returns parent's child resource matching the given resource or null if not found.
717
 * 
718
 * @param resource The searched file in parent
719
 * @return The parent's child matching the given file or null if not found.
720
 */
721
private static IResource getParentChildResource(IResource resource) {
722
	IContainer parent = resource.getParent();
723
	if (parent == null || !parent.exists()) return null;
724
	try {
725
		IResource[] members = parent.members();
726
		int length = members ==null ? 0 : members.length;
727
		if (length > 0) {
728
			for (int i=0; i<length; i++) {
729
				if (members[i] == resource) {
730
					return members[i];
731
				} else if (members[i].equals(resource)) {
732
					return members[i];
733
				} else if (members[i].getFullPath().equals(resource.getFullPath())) {
734
					return members[i];
735
				}
736
			}
737
		}
738
	}
739
	catch (CoreException ce) {
740
		// skip
553
	}
741
	}
554
	return toNativePath(container) + File.separator + OUTPUT_DIRECTORY;
742
	return null;
743
}
744
/**
745
 * Returns the test name from stack elements info.
746
 * 
747
 * @return The name of the test currently running
748
 */
749
private static String getTestName() {
750
	StackTraceElement[] elements = new Exception().getStackTrace();
751
	int idx = 0, length=elements.length;
752
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
753
		// loop until JDT/Core class appears in the stack
754
	}
755
	if (idx<length) {
756
		StackTraceElement testElement = null;
757
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
758
			testElement = elements[idx++];
759
		}
760
		if (testElement != null) {
761
			return testElement.getClassName() + " - " + testElement.getMethodName();
762
		}
763
	}
764
	return "?";
555
}
765
}
556
public static String indentString(String inputString, int indent) {
766
public static String indentString(String inputString, int indent) {
557
	if (inputString == null)
767
	if (inputString == null)
Lines 571-580 Link Here
571
	}
781
	}
572
	return buffer.toString();
782
	return buffer.toString();
573
}
783
}
784
/**
785
 * Returns whether a file is really deleted or not.
786
 * Does not only rely on {@link File#exists()} method but also
787
 * look if it's not in its parent children {@link #getParentChildFile(File)}.
788
 * 
789
 * @param file The file to test if deleted
790
 * @return true if the file does not exist and was not found in its parent children.
791
 */
792
public static boolean isFileDeleted(File file) {
793
	return !file.exists() && getParentChildFile(file) == null;
794
}
574
public static boolean isMacOS() {
795
public static boolean isMacOS() {
575
	return System.getProperty("os.name").indexOf("Mac") != -1;
796
	return System.getProperty("os.name").indexOf("Mac") != -1;
576
}
797
}
577
/**
798
/**
799
 * Returns whether a resource is really deleted or not.
800
 * Does not only rely on {@link IResource#isAccessible()} method but also
801
 * look if it's not in its parent children {@link #getParentChildResource(IResource)}.
802
 * 
803
 * @param resource The resource to test if deleted
804
 * @return true if the resource is not accessible and was not found in its parent children.
805
 */
806
public static boolean isResourceDeleted(IResource resource) {
807
	return !resource.isAccessible() && getParentChildResource(resource) == null;
808
}
809
/**
810
 * Print given file information with specified indentation.
811
 * These information are:<ul>
812
 * 	<li>read {@link File#canRead()}</li>
813
 * 	<li>write {@link File#canWrite()}</li>
814
 * 	<li>exists {@link File#exists()}</li>
815
 * 	<li>is file {@link File#isFile()}</li>
816
 * 	<li>is directory {@link File#isDirectory()}</li>
817
 * 	<li>is hidden {@link File#isHidden()}</li>
818
 * </ul>
819
 * May recurse several level in parents hierarchy.
820
 * May also display children, but then will not recusre in parent
821
 * hierarchy to avoid infinite loop...
822
 * 
823
 * @param file The file to display information
824
 * @param indent Number of tab to print before the information
825
 * @param recurse Display also information on <code>recurse</code>th parents in hierarchy.
826
 * 	If negative then display children information instead.
827
 */
828
private static void printFileInfo(File file, int indent, int recurse) {
829
	String tab = "";
830
	for (int i=0; i<indent; i++) tab+="\t";
831
	System.out.print(tab+"- "+file.getName()+" file info: ");
832
	String sep = "";
833
	if (file.canRead()) {
834
		System.out.print("read");
835
		sep = ", ";
836
	}
837
	if (file.canWrite()) {
838
		System.out.print(sep+"write");
839
		sep = ", ";
840
	}
841
	if (file.exists()) {
842
		System.out.print(sep+"exist");
843
		sep = ", ";
844
	}
845
	if (file.isDirectory()) {
846
		System.out.print(sep+"dir");
847
		sep = ", ";
848
	}
849
	if (file.isFile()) {
850
		System.out.print(sep+"file");
851
		sep = ", ";
852
	}
853
	if (file.isHidden()) {
854
		System.out.print(sep+"hidden");
855
		sep = ", ";
856
	}
857
	System.out.println();
858
	File[] files = file.listFiles();
859
	int length = files==null ? 0 : files.length;
860
	if (length > 0) {
861
		boolean children = recurse < 0;
862
		System.out.print(tab+"	+ children: ");
863
		if (children) System.out.println();
864
		for (int i=0; i<length; i++) {
865
			if (children) { // display children
866
				printFileInfo(files[i], indent+2, -1);
867
			} else {
868
				if (i>0) System.out.print(", ");
869
				System.out.print(files[i].getName());
870
				if (files[i].isDirectory()) System.out.print("[dir]");
871
				else if (files[i].isFile()) System.out.print("[file]");
872
				else System.out.print("[?]");
873
			}
874
		}
875
		if (!children) System.out.println();
876
	}
877
	if (recurse > 0) {
878
		File parent = file.getParentFile();
879
		if (parent != null) printFileInfo(parent, indent+1, recurse-1);
880
	}
881
}
882
/**
883
 * Print stack trace with only JDT/Core elements.
884
 * 
885
 * @param exception Exception of the stack trace. May be null, then a fake exception is used.
886
 * @param indent Number of tab to display before the stack elements to display.
887
 */
888
private static void printJdtCoreStackTrace(Exception exception, int indent) {
889
	String tab = "";
890
	for (int i=0; i<indent; i++) tab+="\t";
891
	StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace();
892
	int idx = 0, length=elements.length;
893
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
894
		// loop until JDT/Core class appears in the stack
895
	}
896
	if (idx<length) {
897
		System.out.print(tab+"- stack trace");
898
		if (exception == null)
899
			System.out.println(":");
900
		else
901
			System.out.println(" for exception "+exception+":");
902
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
903
			StackTraceElement testElement = elements[idx++];
904
			System.out.println(tab+"	-> "+testElement);
905
		}
906
	} else {
907
		exception.printStackTrace(System.out);
908
	}
909
}
910
/**
578
 * Makes the given path a path using native path separators as returned by File.getPath()
911
 * Makes the given path a path using native path separators as returned by File.getPath()
579
 * and trimming any extra slash.
912
 * and trimming any extra slash.
580
 */
913
 */
Lines 637-642 Link Here
637
		}
970
		}
638
	}
971
	}
639
}
972
}
973
/**
974
 * Wait until the file is _really_ deleted on file system.
975
 * 
976
 * @param file Deleted file
977
 * @return true if the file was finally deleted, false otherwise
978
 */
979
private static boolean waitUntilFileDeleted(File file) {
980
	if (DELETE_DEBUG) {
981
		System.out.println();
982
		System.out.println("WARNING in test: "+getTestName());
983
		System.out.println("	- problems occured while deleting "+file);
984
		printJdtCoreStackTrace(null, 1);
985
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
986
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
987
	}
988
	int count = 0;
989
	int delay = 10; // ms
990
	int maxRetry = DELETE_MAX_WAIT / delay;
991
	int time = 0;
992
	while (count < maxRetry) {
993
		try {
994
			count++;
995
			Thread.sleep(delay);
996
			time += delay;
997
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
998
			if (DELETE_DEBUG) System.out.print('.');
999
			if (file.exists()) {
1000
				if (file.delete()) {
1001
					// SUCCESS
1002
					if (DELETE_DEBUG) {
1003
						System.out.println();
1004
						System.out.println("	=> file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1005
						System.out.println();
1006
					}
1007
					return true;
1008
				}
1009
			}
1010
			if (isFileDeleted(file)) {
1011
				// SUCCESS
1012
				if (DELETE_DEBUG) {
1013
					System.out.println();
1014
					System.out.println("	=> file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1015
					System.out.println();
1016
				}
1017
				return true;
1018
			}
1019
			// Increment waiting delay exponentially
1020
			if (count >= 10 && delay <= 100) {
1021
				count = 1;
1022
				delay *= 10;
1023
				maxRetry = DELETE_MAX_WAIT / delay;
1024
				if ((DELETE_MAX_WAIT%delay) != 0) {
1025
					maxRetry++;
1026
				}
1027
			}
1028
		}
1029
		catch (InterruptedException ie) {
1030
			break; // end loop
1031
		}
1032
	}
1033
	if (!DELETE_DEBUG) {
1034
		System.out.println();
1035
		System.out.println("WARNING in test: "+getTestName());
1036
		System.out.println("	- problems occured while deleting "+file);
1037
		printJdtCoreStackTrace(null, 1);
1038
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1039
	}
1040
	System.out.println();
1041
	System.out.println("	!!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
1042
	System.out.println();
1043
	return false;
1044
}
1045
/**
1046
 * Wait until a resource is _really_ deleted on file system.
1047
 * 
1048
 * @param resource Deleted resource
1049
 * @return true if the file was finally deleted, false otherwise
1050
 */
1051
private static boolean waitUntilResourceDeleted(IResource resource) {
1052
	File file = resource.getLocation().toFile();
1053
	if (DELETE_DEBUG) {
1054
		System.out.println();
1055
		System.out.println("WARNING in test: "+getTestName());
1056
		System.out.println("	- problems occured while deleting resource "+resource);
1057
		printJdtCoreStackTrace(null, 1);
1058
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1059
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
1060
	}
1061
	int count = 0;
1062
	int delay = 10; // ms
1063
	int maxRetry = DELETE_MAX_WAIT / delay;
1064
	int time = 0;
1065
	while (count < maxRetry) {
1066
		try {
1067
			count++;
1068
			Thread.sleep(delay);
1069
			time += delay;
1070
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
1071
			if (DELETE_DEBUG) System.out.print('.');
1072
			if (resource.isAccessible()) {
1073
				try {
1074
					resource.delete(true, null);
1075
					if (isResourceDeleted(resource) && isFileDeleted(file)) {
1076
						// SUCCESS
1077
						if (DELETE_DEBUG) {
1078
							System.out.println();
1079
							System.out.println("	=> resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1080
							System.out.println();
1081
						}
1082
						return true;
1083
					}
1084
				}
1085
				catch (CoreException e) {
1086
					//	skip
1087
				}
1088
			}
1089
			if (isResourceDeleted(resource) && isFileDeleted(file)) {
1090
				// SUCCESS
1091
				if (DELETE_DEBUG) {
1092
					System.out.println();
1093
					System.out.println("	=> resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
1094
					System.out.println();
1095
				}
1096
				return true;
1097
			}
1098
			// Increment waiting delay exponentially
1099
			if (count >= 10 && delay <= 100) {
1100
				count = 1;
1101
				delay *= 10;
1102
				maxRetry = DELETE_MAX_WAIT / delay;
1103
				if ((DELETE_MAX_WAIT%delay) != 0) {
1104
					maxRetry++;
1105
				}
1106
			}
1107
		}
1108
		catch (InterruptedException ie) {
1109
			break; // end loop
1110
		}
1111
	}
1112
	if (!DELETE_DEBUG) {
1113
		System.out.println();
1114
		System.out.println("WARNING in test: "+getTestName());
1115
		System.out.println("	- problems occured while deleting resource "+resource);
1116
		printJdtCoreStackTrace(null, 1);
1117
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
1118
	}
1119
	System.out.println();
1120
	System.out.println("	!!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
1121
	System.out.println();
1122
	return false;
1123
}
640
public static void writeToFile(String contents, String destinationFilePath) {
1124
public static void writeToFile(String contents, String destinationFilePath) {
641
	File destFile = new File(destinationFilePath);
1125
	File destFile = new File(destinationFilePath);
642
	FileOutputStream output = null;
1126
	FileOutputStream output = null;
Lines 660-666 Link Here
660
public static void zip(File rootDir, String zipPath) throws IOException {
1144
public static void zip(File rootDir, String zipPath) throws IOException {
661
	ZipOutputStream zip = null;
1145
	ZipOutputStream zip = null;
662
	try {
1146
	try {
663
		zip  = new ZipOutputStream(new FileOutputStream(zipPath));
1147
		File zipFile = new File(zipPath);
1148
		if (zipFile.exists()) delete(zipFile);
1149
		zip = new ZipOutputStream(new FileOutputStream(zipFile));
664
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
1150
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
665
	} finally {
1151
	} finally {
666
		if (zip != null) {
1152
		if (zip != null) {
Lines 669-688 Link Here
669
	}
1155
	}
670
}
1156
}
671
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
1157
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
672
	String[] list = dir.list();
1158
	File[] files = dir.listFiles();
673
	if (list != null) {
1159
	if (files != null) {
674
		for (int i = 0, length = list.length; i < length; i++) {
1160
		for (int i = 0, length = files.length; i < length; i++) {
675
			String name = list[i];
1161
			File file = files[i];
676
			File file = new File(dir, name);
1162
			if (file.isFile()) {
677
			if (file.isDirectory()) {
678
				zip(file, zip, rootPathLength);
679
			} else {
680
				String path = file.getPath();
1163
				String path = file.getPath();
681
				path = path.substring(rootPathLength);
1164
				path = path.substring(rootPathLength);
682
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
1165
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
683
				zip.putNextEntry(entry);
1166
				zip.putNextEntry(entry);
684
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
1167
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
685
				zip.closeEntry();
1168
				zip.closeEntry();
1169
			} else {
1170
				zip(file, zip, rootPathLength);
686
			}
1171
			}
687
		}
1172
		}
688
	}
1173
	}
(-)src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java (-12 / +8 lines)
Lines 416-424 Link Here
416
	}
416
	}
417
	
417
	
418
	// Output files management
418
	// Output files management
419
	protected IPath 
419
	protected IPath outputRootDirectoryPath = new Path(Util.getOutputDirectory());
420
		outputRootDirectoryPath = new Path(Util.getOutputDirectory()),
420
	protected File outputTestDirectory;
421
		outputTestDirectoryPath;
422
421
423
	/**
422
	/**
424
	 * Create a test specific output directory as a subdirectory of 
423
	 * Create a test specific output directory as a subdirectory of 
Lines 428-438 Link Here
428
	 * @param suffixPath a valid relative path for the subdirectory
427
	 * @param suffixPath a valid relative path for the subdirectory
429
	 */
428
	 */
430
	protected void createOutputTestDirectory(String suffixPath) {
429
	protected void createOutputTestDirectory(String suffixPath) {
431
		this.outputTestDirectoryPath = 
430
		this.outputTestDirectory =  new File(this.outputRootDirectoryPath.toFile(), suffixPath);
432
			((IPath) this.outputRootDirectoryPath.clone()).append(suffixPath);
431
		if (!this.outputTestDirectory.exists()) {
433
		File dir = this.outputTestDirectoryPath.toFile();
432
			this.outputTestDirectory.mkdirs();
434
		if (!dir.exists()) {
435
			dir.mkdirs();
436
		}
433
		}
437
	}
434
	}
438
	/*
435
	/*
Lines 446-460 Link Here
446
		for (int i = 0, length = testFiles.length; i < length; ) {
443
		for (int i = 0, length = testFiles.length; i < length; ) {
447
			String fileName = testFiles[i++];
444
			String fileName = testFiles[i++];
448
			String contents = testFiles[i++];
445
			String contents = testFiles[i++];
449
			IPath filePath = 
446
			File file = new File(this.outputTestDirectory, fileName);
450
				((IPath) this.outputTestDirectoryPath.clone()).append(fileName);
451
			if (fileName.lastIndexOf('/') >= 0) {
447
			if (fileName.lastIndexOf('/') >= 0) {
452
				File dir = filePath.removeLastSegments(1).toFile();
448
				File dir = file.getParentFile();
453
				if (!dir.exists()) {
449
				if (!dir.exists()) {
454
					dir.mkdirs();
450
					dir.mkdirs();
455
				}
451
				}
456
			}
452
			}
457
			Util.writeToFile(contents, filePath.toString());
453
			Util.writeToFile(contents, file.getPath());
458
		}
454
		}
459
	}
455
	}
460
	
456
	
(-)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
/**

Return to bug 166977