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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/SearchParticipantTests.java (-5 / +3 lines)
Lines 15-24 Link Here
15
import junit.framework.Test;
15
import junit.framework.Test;
16
16
17
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jdt.core.search.*;
18
import org.eclipse.jdt.core.search.*;
19
import org.eclipse.jdt.core.tests.util.Util;
22
20
23
/**
21
/**
24
 * Tests the search participant supprt.
22
 * Tests the search participant supprt.
Lines 96-102 Link Here
96
			assertTrue("Should have requested to index document", document.indexingRequested);
94
			assertTrue("Should have requested to index document", document.indexingRequested);
97
		} finally {
95
		} finally {
98
			deleteProject("P");
96
			deleteProject("P");
99
			getIndexLocation().toFile().delete();
97
			Util.delete(getIndexLocation().toFile());
100
		}
98
		}
101
	}
99
	}
102
100
Lines 114-120 Link Here
114
			assertTrue("Should have requested to index document", document.indexingRequested);
112
			assertTrue("Should have requested to index document", document.indexingRequested);
115
		} finally {
113
		} finally {
116
			deleteProject("P");
114
			deleteProject("P");
117
			getIndexLocation().toFile().delete();
115
			Util.delete(getIndexLocation().toFile());
118
		}
116
		}
119
	}
117
	}
120
118
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (-14 / +2 lines)
Lines 770-782 Link Here
770
		System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
770
		System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots");
771
	} finally {
771
	} finally {
772
		if (libDir != null) {
772
		if (libDir != null) {
773
			String[] libJars = libDir.list();
773
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
774
			if (libJars != null) {
775
				for (int i = 0, length = libJars.length; i < length; i++) {
776
					new File(libDir, libJars[i]).delete();
777
				}
778
			}
779
			libDir.delete();
780
		}
774
		}
781
		this.deleteProject("P");
775
		this.deleteProject("P");
782
		JavaCore.removeClasspathVariable("MyVar", null);
776
		JavaCore.removeClasspathVariable("MyVar", null);
Lines 808-820 Link Here
808
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
802
		assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root
809
	} finally {
803
	} finally {
810
		if (libDir != null) {
804
		if (libDir != null) {
811
			String[] libJars = libDir.list();
805
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
812
			if (libJars != null) {
813
				for (int i = 0, length = libJars.length; i < length; i++) {
814
					new File(libDir, libJars[i]).delete();
815
				}
816
			}
817
			libDir.delete();
818
		}
806
		}
819
		this.deleteProject("P");
807
		this.deleteProject("P");
820
		JavaCore.removeClasspathVariable("MyVar", null);
808
		JavaCore.removeClasspathVariable("MyVar", null);
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-1 / +2 lines)
Lines 22-27 Link Here
22
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.*;
23
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.core.compiler.CharOperation;
24
import org.eclipse.jdt.core.search.*;
24
import org.eclipse.jdt.core.search.*;
25
import org.eclipse.jdt.core.tests.util.Util;
25
import org.eclipse.jdt.internal.core.JavaElement;
26
import org.eclipse.jdt.internal.core.JavaElement;
26
import org.eclipse.jdt.internal.core.JavaModelStatus;
27
import org.eclipse.jdt.internal.core.JavaModelStatus;
27
28
Lines 961-967 Link Here
961
			resultCollector);
962
			resultCollector);
962
		
963
		
963
	} finally {
964
	} finally {
964
		externalJar.delete();
965
		Util.delete(externalJar);
965
		project.setRawClasspath(classpath, null);
966
		project.setRawClasspath(classpath, null);
966
	}
967
	}
967
	
968
	
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-21 / +4 lines)
Lines 604-632 Link Here
604
		return project;
604
		return project;
605
	}
605
	}
606
	public void deleteFile(File file) {
606
	public void deleteFile(File file) {
607
		file = file.getAbsoluteFile();
607
		int retryCount = 0;
608
		if (!file.exists())
608
		while (++retryCount <= 60) { // wait 1 minute at most
609
			return;
609
			if (org.eclipse.jdt.core.tests.util.Util.delete(file)) {
610
		if (file.isDirectory()) {
610
				break;
611
			String[] files = file.list();
612
			//file.list() can return null
613
			if (files != null) {
614
				for (int i = 0; i < files.length; ++i) {
615
					deleteFile(new File(file, files[i]));
616
				}
617
			}
618
		}
619
		boolean success = file.delete();
620
		int retryCount = 60; // wait 1 minute at most
621
		while (!success && --retryCount >= 0) {
622
			try {
623
				Thread.sleep(1000);
624
			} catch (InterruptedException e) {
625
			}
611
			}
626
			success = file.delete();
627
		}
612
		}
628
		if (success) return;
629
		System.err.println("Failed to delete " + file.getPath());
630
	}
613
	}
631
	protected void deleteProject(String projectName) throws CoreException {
614
	protected void deleteProject(String projectName) throws CoreException {
632
		IProject project = this.getProject(projectName);
615
		IProject project = this.getProject(projectName);
(-)batch/org/eclipse/jdt/internal/compiler/batch/messages.properties (-1 / +1 lines)
Lines 12-18 Link Here
12
12
13
### compiler 
13
### compiler 
14
compiler.name = Eclipse Java Compiler
14
compiler.name = Eclipse Java Compiler
15
compiler.version = 0.454_R30x
15
compiler.version = 0.454a_R30x
16
compiler.copyright = Copyright IBM Corp 2000, 2005. All rights reserved.
16
compiler.copyright = Copyright IBM Corp 2000, 2005. All rights reserved.
17
17
18
### scanning
18
### scanning
(-)buildnotes_jdt-core.html (+14 lines)
Lines 35-40 Link Here
35
  </tr>
35
  </tr>
36
</table>
36
</table>
37
37
38
<a name="v_454a_R30x"></a>
39
<p><hr><h1>
40
Eclipse Platform Build Notes&nbsp;<br>
41
Java Development Tooling Core</h1>
42
Eclipse SDK 3.0.2 Build - March 30, 2007
43
<br>Project org.eclipse.jdt.core v_454a_R30x
44
(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_454a_R30x">cvs</a>).
45
<h2>
46
What's new in this drop</h2>
47
48
<h3>Problem Reports Fixed</h3>
49
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=166977">166977</a>
50
[vista] Unexpected errors while running JDT/Core tests
51
38
<a name="v_454_R30x"></a>
52
<a name="v_454_R30x"></a>
39
<p><hr><h1>
53
<p><hr><h1>
40
Eclipse Platform Build Notes&nbsp;<br>
54
Eclipse Platform Build Notes&nbsp;<br>
(-)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 15230-15236 Link Here
15230
		},
15231
		},
15231
		"SUCCESS");
15232
		"SUCCESS");
15232
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15233
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15233
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15234
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15234
	
15235
	
15235
	this.runNegativeTest(
15236
	this.runNegativeTest(
15236
		new String[] {
15237
		new String[] {
Lines 15273-15279 Link Here
15273
		},
15274
		},
15274
		"SUCCESS");
15275
		"SUCCESS");
15275
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15276
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15276
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15277
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15277
	
15278
	
15278
	this.runNegativeTest(
15279
	this.runNegativeTest(
15279
		new String[] {
15280
		new String[] {
Lines 15321-15327 Link Here
15321
		},
15322
		},
15322
		"SUCCESS");
15323
		"SUCCESS");
15323
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15324
	// delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile)
15324
	new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete();
15325
	Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class"));
15325
	
15326
	
15326
	this.runNegativeTest(
15327
	this.runNegativeTest(
15327
		new String[] {
15328
		new String[] {
Lines 15516-15522 Link Here
15516
		false,
15517
		false,
15517
		null);	
15518
		null);	
15518
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15519
	// discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries
15519
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class").delete();
15520
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15520
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15521
	new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class"));
15521
	
15522
	
15522
	this.runNegativeTest(
15523
	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 226-234 Link Here
226
	if (CURRENT_TEST_SETUP == this) {
227
	if (CURRENT_TEST_SETUP == this) {
227
		RegressionTestSuite.fgJavaModel.close();
228
		RegressionTestSuite.fgJavaModel.close();
228
		RegressionTestSuite.fgJavaModel = null;
229
		RegressionTestSuite.fgJavaModel = null;
229
		new java.io.File(LOCAL_JDK + File.separator + "classes.zip").delete();
230
		Util.delete(new File(LOCAL_JDK));
230
		new java.io.File(LOCAL_JDK + File.separator + "src.zip").delete();
231
		new java.io.File(LOCAL_JDK).delete();
232
	}
231
	}
233
}
232
}
234
}
233
}
(-).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/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 102-108 Link Here
102
		if (fileNames != null) {
102
		if (fileNames != null) {
103
			for (int i = 0, max = fileNames.length; i < max; i++) {
103
			for (int i = 0, max = fileNames.length; i < max; i++) {
104
				if (fileNames[i].indexOf(className) != -1) {
104
				if (fileNames[i].indexOf(className) != -1) {
105
					new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete();
105
					Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]);
106
				}
106
				}
107
			}
107
			}
108
		}
108
		}
Lines 112-118 Link Here
112
		if (fileNames != null) {
112
		if (fileNames != null) {
113
			for (int i = 0, max = fileNames.length; i < max; i++) {
113
			for (int i = 0, max = fileNames.length; i < max; i++) {
114
				if (fileNames[i].indexOf(className) != -1) {
114
				if (fileNames[i].indexOf(className) != -1) {
115
					new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete();
115
					Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]);
116
				}
116
				}
117
			}
117
			}
118
		}
118
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java (-1 lines)
Lines 496-502 Link Here
496
		File outputDir = new File(OUTPUT_DIR);
496
		File outputDir = new File(OUTPUT_DIR);
497
		if (outputDir.exists()) {
497
		if (outputDir.exists()) {
498
			Util.flushDirectoryContent(outputDir);
498
			Util.flushDirectoryContent(outputDir);
499
			outputDir.delete();
500
		}
499
		}
501
	}
500
	}
502
}
501
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (-1 / +2 lines)
Lines 13-18 Link Here
13
import java.io.File;
13
import java.io.File;
14
import java.util.Hashtable;
14
import java.util.Hashtable;
15
15
16
import org.eclipse.jdt.core.tests.util.Util;
16
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
17
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
17
18
18
import junit.framework.Test;
19
import junit.framework.Test;
Lines 1514-1520 Link Here
1514
		},
1515
		},
1515
		"SUCCESS");
1516
		"SUCCESS");
1516
	// delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile)
1517
	// 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();
1518
	Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class"));
1518
	
1519
	
1519
	this.runConformTest(
1520
	this.runConformTest(
1520
		new String[] {
1521
		new String[] {
(-)plugin.xml (-1 / +2 lines)
Lines 15-21 Link Here
15
      <import plugin="org.junit"/>
15
      <import plugin="org.junit"/>
16
      <import plugin="org.eclipse.jdt.debug"/>
16
      <import plugin="org.eclipse.jdt.debug"/>
17
      <import plugin="org.eclipse.jdt.core"/>
17
      <import plugin="org.eclipse.jdt.core"/>
18
     <import plugin="org.eclipse.core.runtime.compatibility"/>    
18
     <import plugin="org.eclipse.core.runtime.compatibility"/>
19
     <import plugin="org.eclipse.core.resources"/>    
19
   </requires>
20
   </requires>
20
21
21
22
(-)src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java (-6 / +2 lines)
Lines 124-135 Link Here
124
	}
124
	}
125
	public void removeTempClass(String className) {
125
	public void removeTempClass(String className) {
126
		resetEnv(); // needed to reinitialize the caches
126
		resetEnv(); // needed to reinitialize the caches
127
		File sourceFile = new File(SOURCE_DIRECTORY + File.separator + className + ".java");
127
		Util.delete(SOURCE_DIRECTORY + File.separator + className + ".java");
128
		sourceFile.delete();
128
		Util.delete(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
129
	
130
		File binaryFile = new File(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class");
131
	
132
		binaryFile.delete();
133
	}
129
	}
134
	/*public static Test suite(Class evaluationTestClass) {
130
	/*public static Test suite(Class evaluationTestClass) {
135
		junit.framework.TestSuite suite = new junit.framework.TestSuite();
131
		junit.framework.TestSuite suite = new junit.framework.TestSuite();
(-)src/org/eclipse/jdt/core/tests/util/Util.java (-27 / +520 lines)
Lines 10-22 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.util;
11
package org.eclipse.jdt.core.tests.util;
12
12
13
import java.io.*;
13
import java.io.File;
14
import java.io.FileInputStream;
15
import java.io.FileNotFoundException;
16
import java.io.FileOutputStream;
17
import java.io.IOException;
18
import java.io.PrintWriter;
14
import java.net.ServerSocket;
19
import java.net.ServerSocket;
15
import java.util.Locale;
20
import java.util.Locale;
16
import java.util.Map;
21
import java.util.Map;
17
import java.util.zip.ZipEntry;
22
import java.util.zip.ZipEntry;
18
import java.util.zip.ZipOutputStream;
23
import java.util.zip.ZipOutputStream;
19
24
25
import org.eclipse.core.resources.IContainer;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
28
import org.eclipse.jdt.core.tests.compiler.regression.Requestor;
21
import org.eclipse.jdt.internal.compiler.Compiler;
29
import org.eclipse.jdt.internal.compiler.Compiler;
22
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
30
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
Lines 26-32 Link Here
26
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
34
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
27
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
35
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
28
public class Util {
36
public class Util {
29
	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
}
30
130
31
public static CompilationUnit[] compilationUnits(String[] testFiles) {
131
public static CompilationUnit[] compilationUnits(String[] testFiles) {
32
	int length = testFiles.length / 2;
132
	int length = testFiles.length / 2;
Lines 124-131 Link Here
124
		try {
224
		try {
125
			in = new FileInputStream(source);
225
			in = new FileInputStream(source);
126
			File destFile = new File(dest, source.getName());
226
			File destFile = new File(dest, source.getName());
127
			if (destFile.exists() && !destFile.delete()) {
227
			if (destFile.exists()) {
128
				throw new IOException(destFile + " is in use");
228
				if (!delete(destFile)) {
229
					throw new IOException(destFile + " is in use");
230
				}
129
			}
231
			}
130
		 	out = new FileOutputStream(destFile);
232
		 	out = new FileOutputStream(destFile);
131
			int bufferLength = 1024;
233
			int bufferLength = 1024;
Lines 163-168 Link Here
163
	zip(classesDir, jarPath);
265
	zip(classesDir, jarPath);
164
}
266
}
165
/**
267
/**
268
 * Delete a file or directory and insure that the file is no longer present
269
 * on file system. In case of directory, delete all the hierarchy underneath.
270
 * 
271
 * @param file The file or directory to delete
272
 * @return true iff the file was really delete, false otherwise
273
 */
274
public static boolean delete(File file) {
275
	// flush all directory content
276
	if (file.isDirectory()) {
277
		flushDirectoryContent(file);
278
	}
279
	// remove file
280
	file.delete();
281
	if (isFileDeleted(file)) {
282
		return true;
283
	}
284
	return waitUntilFileDeleted(file);
285
}
286
/**
287
 * Delete a file or directory and insure that the file is no longer present
288
 * on file system. In case of directory, delete all the hierarchy underneath.
289
 * 
290
 * @param resource The resource to delete
291
 * @return true iff the file was really delete, false otherwise
292
 */
293
public static boolean delete(IResource resource) {
294
	try {
295
		resource.delete(true, null);
296
		if (isResourceDeleted(resource)) {
297
			return true;
298
		}
299
	}
300
	catch (CoreException e) {
301
		//	skip
302
	}
303
	return waitUntilResourceDeleted(resource);
304
}
305
/**
306
 * Delete a file or directory and insure that the file is no longer present
307
 * on file system. In case of directory, delete all the hierarchy underneath.
308
 * 
309
 * @param path The path of the file or directory to delete
310
 * @return true iff the file was really delete, false otherwise
311
 */
312
public static boolean delete(String path) {
313
	return delete(new File(path));
314
}
315
/**
166
 * Generate a display string from the given String.
316
 * Generate a display string from the given String.
167
 * @param indent number of tabs are added at the begining of each line.
317
 * @param indent number of tabs are added at the begining of each line.
168
 *
318
 *
Lines 362-377 Link Here
362
 * no-op if not a directory.
512
 * no-op if not a directory.
363
 */
513
 */
364
public static void flushDirectoryContent(File dir) {
514
public static void flushDirectoryContent(File dir) {
365
	if (dir.isDirectory()) {
515
	File[] files = dir.listFiles();
366
		String[] files = dir.list();
516
	if (files == null) return;
367
		if (files == null) return;
517
	for (int i = 0, max = files.length; i < max; i++) {
368
		for (int i = 0, max = files.length; i < max; i++) {
518
		delete(files[i]);
369
			File current = new File(dir, files[i]);
370
			if (current.isDirectory()) {
371
				flushDirectoryContent(current);
372
			}
373
			current.delete();
374
		}
375
	}
519
	}
376
}
520
}
377
/**
521
/**
Lines 428-438 Link Here
428
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
572
 * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()]
429
*/
573
*/
430
public static String getOutputDirectory() {
574
public static String getOutputDirectory() {
431
	String container = System.getProperty("user.home");
575
	return OUTPUT_DIRECTORY;
432
	if (container == null){
576
}
433
		return null;
577
/**
578
 * Returns the parent's child file matching the given file or null if not found.
579
 * 
580
 * @param file The searched file in parent
581
 * @return The parent's child matching the given file or null if not found.
582
 */
583
private static File getParentChildFile(File file) {
584
	File parent = file.getParentFile();
585
	if (parent == null || !parent.exists()) return null;
586
	File[] files = parent.listFiles();
587
	int length = files==null ? 0 : files.length;
588
	if (length > 0) {
589
		for (int i=0; i<length; i++) {
590
			if (files[i] == file) {
591
				return files[i];
592
			} else if (files[i].equals(file)) {
593
				return files[i];
594
			} else if (files[i].getPath().equals(file.getPath())) {
595
				return files[i];
596
			}
597
		}
598
	}
599
	return null;
600
}
601
/**
602
 * Returns parent's child resource matching the given resource or null if not found.
603
 * 
604
 * @param resource The searched file in parent
605
 * @return The parent's child matching the given file or null if not found.
606
 */
607
private static IResource getParentChildResource(IResource resource) {
608
	IContainer parent = resource.getParent();
609
	if (parent == null || !parent.exists()) return null;
610
	try {
611
		IResource[] members = parent.members();
612
		int length = members ==null ? 0 : members.length;
613
		if (length > 0) {
614
			for (int i=0; i<length; i++) {
615
				if (members[i] == resource) {
616
					return members[i];
617
				} else if (members[i].equals(resource)) {
618
					return members[i];
619
				} else if (members[i].getFullPath().equals(resource.getFullPath())) {
620
					return members[i];
621
				}
622
			}
623
		}
624
	}
625
	catch (CoreException ce) {
626
		// skip
627
	}
628
	return null;
629
}
630
/**
631
 * Returns the test name from stack elements info.
632
 * 
633
 * @return The name of the test currently running
634
 */
635
private static String getTestName() {
636
	StackTraceElement[] elements = new Exception().getStackTrace();
637
	int idx = 0, length=elements.length;
638
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
639
		// loop until JDT/Core class appears in the stack
640
	}
641
	if (idx<length) {
642
		StackTraceElement testElement = null;
643
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
644
			testElement = elements[idx++];
645
		}
646
		if (testElement != null) {
647
			return testElement.getClassName() + " - " + testElement.getMethodName();
648
		}
434
	}
649
	}
435
	return toNativePath(container) + File.separator + OUTPUT_DIRECTORY;
650
	return "?";
436
}
651
}
437
/**
652
/**
438
 * Returns the next available port number on the local host.
653
 * Returns the next available port number on the local host.
Lines 456-461 Link Here
456
	return -1;
671
	return -1;
457
}
672
}
458
/**
673
/**
674
 * Returns whether a file is really deleted or not.
675
 * Does not only rely on {@link File#exists()} method but also
676
 * look if it's not in its parent children {@link #getParentChildFile(File)}.
677
 * 
678
 * @param file The file to test if deleted
679
 * @return true if the file does not exist and was not found in its parent children.
680
 */
681
public static boolean isFileDeleted(File file) {
682
	return !file.exists() && getParentChildFile(file) == null;
683
}
684
public static boolean isMacOS() {
685
	return System.getProperty("os.name").indexOf("Mac") != -1;
686
}
687
/**
688
 * Returns whether a resource is really deleted or not.
689
 * Does not only rely on {@link IResource#isAccessible()} method but also
690
 * look if it's not in its parent children {@link #getParentChildResource(IResource)}.
691
 * 
692
 * @param resource The resource to test if deleted
693
 * @return true if the resource is not accessible and was not found in its parent children.
694
 */
695
public static boolean isResourceDeleted(IResource resource) {
696
	return !resource.isAccessible() && getParentChildResource(resource) == null;
697
}
698
/**
699
 * Print given file information with specified indentation.
700
 * These information are:<ul>
701
 * 	<li>read {@link File#canRead()}</li>
702
 * 	<li>write {@link File#canWrite()}</li>
703
 * 	<li>exists {@link File#exists()}</li>
704
 * 	<li>is file {@link File#isFile()}</li>
705
 * 	<li>is directory {@link File#isDirectory()}</li>
706
 * 	<li>is hidden {@link File#isHidden()}</li>
707
 * </ul>
708
 * May recurse several level in parents hierarchy.
709
 * May also display children, but then will not recusre in parent
710
 * hierarchy to avoid infinite loop...
711
 * 
712
 * @param file The file to display information
713
 * @param indent Number of tab to print before the information
714
 * @param recurse Display also information on <code>recurse</code>th parents in hierarchy.
715
 * 	If negative then display children information instead.
716
 */
717
private static void printFileInfo(File file, int indent, int recurse) {
718
	String tab = "";
719
	for (int i=0; i<indent; i++) tab+="\t";
720
	System.out.print(tab+"- "+file.getName()+" file info: ");
721
	String sep = "";
722
	if (file.canRead()) {
723
		System.out.print("read");
724
		sep = ", ";
725
	}
726
	if (file.canWrite()) {
727
		System.out.print(sep+"write");
728
		sep = ", ";
729
	}
730
	if (file.exists()) {
731
		System.out.print(sep+"exist");
732
		sep = ", ";
733
	}
734
	if (file.isDirectory()) {
735
		System.out.print(sep+"dir");
736
		sep = ", ";
737
	}
738
	if (file.isFile()) {
739
		System.out.print(sep+"file");
740
		sep = ", ";
741
	}
742
	if (file.isHidden()) {
743
		System.out.print(sep+"hidden");
744
		sep = ", ";
745
	}
746
	System.out.println();
747
	File[] files = file.listFiles();
748
	int length = files==null ? 0 : files.length;
749
	if (length > 0) {
750
		boolean children = recurse < 0;
751
		System.out.print(tab+"	+ children: ");
752
		if (children) System.out.println();
753
		for (int i=0; i<length; i++) {
754
			if (children) { // display children
755
				printFileInfo(files[i], indent+2, -1);
756
			} else {
757
				if (i>0) System.out.print(", ");
758
				System.out.print(files[i].getName());
759
				if (files[i].isDirectory()) System.out.print("[dir]");
760
				else if (files[i].isFile()) System.out.print("[file]");
761
				else System.out.print("[?]");
762
			}
763
		}
764
		if (!children) System.out.println();
765
	}
766
	if (recurse > 0) {
767
		File parent = file.getParentFile();
768
		if (parent != null) printFileInfo(parent, indent+1, recurse-1);
769
	}
770
}
771
/**
772
 * Print stack trace with only JDT/Core elements.
773
 * 
774
 * @param exception Exception of the stack trace. May be null, then a fake exception is used.
775
 * @param indent Number of tab to display before the stack elements to display.
776
 */
777
private static void printJdtCoreStackTrace(Exception exception, int indent) {
778
	String tab = "";
779
	for (int i=0; i<indent; i++) tab+="\t";
780
	StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace();
781
	int idx = 0, length=elements.length;
782
	while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) {
783
		// loop until JDT/Core class appears in the stack
784
	}
785
	if (idx<length) {
786
		System.out.print(tab+"- stack trace");
787
		if (exception == null)
788
			System.out.println(":");
789
		else
790
			System.out.println(" for exception "+exception+":");
791
		while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) {
792
			StackTraceElement testElement = elements[idx++];
793
			System.out.println(tab+"	-> "+testElement);
794
		}
795
	} else {
796
		exception.printStackTrace(System.out);
797
	}
798
}
799
/**
459
 * Makes the given path a path using native path separators as returned by File.getPath()
800
 * Makes the given path a path using native path separators as returned by File.getPath()
460
 * and trimming any extra slash.
801
 * and trimming any extra slash.
461
 */
802
 */
Lines 466-471 Link Here
466
			nativePath.substring(0, nativePath.length() - 1) :
807
			nativePath.substring(0, nativePath.length() - 1) :
467
			nativePath;
808
			nativePath;
468
}
809
}
810
/**
811
 * Wait until the file is _really_ deleted on file system.
812
 * 
813
 * @param file Deleted file
814
 * @return true if the file was finally deleted, false otherwise
815
 */
816
private static boolean waitUntilFileDeleted(File file) {
817
	if (DELETE_DEBUG) {
818
		System.out.println();
819
		System.out.println("WARNING in test: "+getTestName());
820
		System.out.println("	- problems occured while deleting "+file);
821
		printJdtCoreStackTrace(null, 1);
822
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
823
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
824
	}
825
	int count = 0;
826
	int delay = 10; // ms
827
	int maxRetry = DELETE_MAX_WAIT / delay;
828
	int time = 0;
829
	while (count < maxRetry) {
830
		try {
831
			count++;
832
			Thread.sleep(delay);
833
			time += delay;
834
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
835
			if (DELETE_DEBUG) System.out.print('.');
836
			if (file.exists()) {
837
				if (file.delete()) {
838
					// SUCCESS
839
					if (DELETE_DEBUG) {
840
						System.out.println();
841
						System.out.println("	=> file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
842
						System.out.println();
843
					}
844
					return true;
845
				}
846
			}
847
			if (isFileDeleted(file)) {
848
				// SUCCESS
849
				if (DELETE_DEBUG) {
850
					System.out.println();
851
					System.out.println("	=> file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
852
					System.out.println();
853
				}
854
				return true;
855
			}
856
			// Increment waiting delay exponentially
857
			if (count >= 10 && delay <= 100) {
858
				count = 1;
859
				delay *= 10;
860
				maxRetry = DELETE_MAX_WAIT / delay;
861
				if ((DELETE_MAX_WAIT%delay) != 0) {
862
					maxRetry++;
863
				}
864
			}
865
		}
866
		catch (InterruptedException ie) {
867
			break; // end loop
868
		}
869
	}
870
	if (!DELETE_DEBUG) {
871
		System.out.println();
872
		System.out.println("WARNING in test: "+getTestName());
873
		System.out.println("	- problems occured while deleting "+file);
874
		printJdtCoreStackTrace(null, 1);
875
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
876
	}
877
	System.out.println();
878
	System.out.println("	!!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
879
	System.out.println();
880
	return false;
881
}
882
/**
883
 * Wait until a resource is _really_ deleted on file system.
884
 * 
885
 * @param resource Deleted resource
886
 * @return true if the file was finally deleted, false otherwise
887
 */
888
private static boolean waitUntilResourceDeleted(IResource resource) {
889
	File file = resource.getLocation().toFile();
890
	if (DELETE_DEBUG) {
891
		System.out.println();
892
		System.out.println("WARNING in test: "+getTestName());
893
		System.out.println("	- problems occured while deleting resource "+resource);
894
		printJdtCoreStackTrace(null, 1);
895
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
896
		System.out.print("	- wait for ("+DELETE_MAX_WAIT+"ms max): ");
897
	}
898
	int count = 0;
899
	int delay = 10; // ms
900
	int maxRetry = DELETE_MAX_WAIT / delay;
901
	int time = 0;
902
	while (count < maxRetry) {
903
		try {
904
			count++;
905
			Thread.sleep(delay);
906
			time += delay;
907
			if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
908
			if (DELETE_DEBUG) System.out.print('.');
909
			if (resource.isAccessible()) {
910
				try {
911
					resource.delete(true, null);
912
					if (isResourceDeleted(resource) && isFileDeleted(file)) {
913
						// SUCCESS
914
						if (DELETE_DEBUG) {
915
							System.out.println();
916
							System.out.println("	=> resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
917
							System.out.println();
918
						}
919
						return true;
920
					}
921
				}
922
				catch (CoreException e) {
923
					//	skip
924
				}
925
			}
926
			if (isResourceDeleted(resource) && isFileDeleted(file)) {
927
				// SUCCESS
928
				if (DELETE_DEBUG) {
929
					System.out.println();
930
					System.out.println("	=> resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
931
					System.out.println();
932
				}
933
				return true;
934
			}
935
			// Increment waiting delay exponentially
936
			if (count >= 10 && delay <= 100) {
937
				count = 1;
938
				delay *= 10;
939
				maxRetry = DELETE_MAX_WAIT / delay;
940
				if ((DELETE_MAX_WAIT%delay) != 0) {
941
					maxRetry++;
942
				}
943
			}
944
		}
945
		catch (InterruptedException ie) {
946
			break; // end loop
947
		}
948
	}
949
	if (!DELETE_DEBUG) {
950
		System.out.println();
951
		System.out.println("WARNING in test: "+getTestName());
952
		System.out.println("	- problems occured while deleting resource "+resource);
953
		printJdtCoreStackTrace(null, 1);
954
		printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
955
	}
956
	System.out.println();
957
	System.out.println("	!!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
958
	System.out.println();
959
	return false;
960
}
469
public static void writeToFile(String contents, String destinationFilePath) {
961
public static void writeToFile(String contents, String destinationFilePath) {
470
	File destFile = new File(destinationFilePath);
962
	File destFile = new File(destinationFilePath);
471
	FileOutputStream output = null;
963
	FileOutputStream output = null;
Lines 489-495 Link Here
489
public static void zip(File rootDir, String zipPath) throws IOException {
981
public static void zip(File rootDir, String zipPath) throws IOException {
490
	ZipOutputStream zip = null;
982
	ZipOutputStream zip = null;
491
	try {
983
	try {
492
		zip  = new ZipOutputStream(new FileOutputStream(zipPath));
984
		File zipFile = new File(zipPath);
985
		if (zipFile.exists()) delete(zipFile);
986
		zip = new ZipOutputStream(new FileOutputStream(zipFile));
493
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
987
		zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash
494
	} finally {
988
	} finally {
495
		if (zip != null) {
989
		if (zip != null) {
Lines 498-517 Link Here
498
	}
992
	}
499
}
993
}
500
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
994
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException {
501
	String[] list = dir.list();
995
	File[] files = dir.listFiles();
502
	if (list != null) {
996
	if (files != null) {
503
		for (int i = 0, length = list.length; i < length; i++) {
997
		for (int i = 0, length = files.length; i < length; i++) {
504
			String name = list[i];
998
			File file = files[i];
505
			File file = new File(dir, name);
999
			if (file.isFile()) {
506
			if (file.isDirectory()) {
507
				zip(file, zip, rootPathLength);
508
			} else {
509
				String path = file.getPath();
1000
				String path = file.getPath();
510
				path = path.substring(rootPathLength);
1001
				path = path.substring(rootPathLength);
511
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
1002
				ZipEntry entry = new ZipEntry(path.replace('\\', '/'));
512
				zip.putNextEntry(entry);
1003
				zip.putNextEntry(entry);
513
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
1004
				zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file));
514
				zip.closeEntry();
1005
				zip.closeEntry();
1006
			} else {
1007
				zip(file, zip, rootPathLength);
515
			}
1008
			}
516
		}
1009
		}
517
	}
1010
	}
(-)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