Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 55967 Details for
Bug 166977
[vista] Unexpected errors while running JDT/Core tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch for 3.3
v17.txt (text/plain), 58.53 KB, created by
Frederic Fusier
on 2006-12-20 11:00:11 EST
(
hide
)
Description:
Proposed patch for 3.3
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2006-12-20 11:00:11 EST
Size:
58.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.2 >diff -u -r1.2 MANIFEST.MF >--- META-INF/MANIFEST.MF 20 Oct 2006 11:01:54 -0000 1.2 >+++ META-INF/MANIFEST.MF 20 Dec 2006 15:25:43 -0000 >@@ -24,3 +24,4 @@ > org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)" > Eclipse-LazyStart: true > Bundle-RequiredExecutionEnvironment: J2SE-1.4 >+Bundle-Activator: org.eclipse.jdt.core.tests.JDTCoreTestsPlugin >Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java,v >retrieving revision 1.295 >diff -u -r1.295 NegativeTest.java >--- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 24 Nov 2006 17:07:29 -0000 1.295 >+++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 20 Dec 2006 15:25:42 -0000 >@@ -16,6 +16,7 @@ > import junit.framework.Test; > > import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest; >+import org.eclipse.jdt.core.tests.util.Util; > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > > public class NegativeTest extends AbstractRegressionTest { >@@ -15360,7 +15361,7 @@ > }, > "SUCCESS"); > // delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile) >- new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete(); >+ Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class")); > > this.runNegativeTest( > new String[] { >@@ -15408,7 +15409,7 @@ > }, > "SUCCESS"); > // delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile) >- new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete(); >+ Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class")); > > this.runNegativeTest( > new String[] { >@@ -15458,7 +15459,7 @@ > }, > "SUCCESS"); > // delete binary file SecretClass (i.e. simulate removing it from classpath for subsequent compile) >- new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class").delete(); >+ Util.delete(new File(OUTPUT_DIR, "plugin3" + File.separator + "SecretClass.class")); > > this.runNegativeTest( > new String[] { >@@ -15654,7 +15655,7 @@ > false, > null); > // discard LoopB.class and replace it with copy LoopB1.class so as to create cycle in binaries >- new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class").delete(); >+ Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class")); > new File(OUTPUT_DIR, "p" + File.separator + "LoopB1.class").renameTo(new File(OUTPUT_DIR, "p" + File.separator + "LoopB.class")); > > this.runNegativeTest( >Index: Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java,v >retrieving revision 1.34 >diff -u -r1.34 JavaModelRegressionTestSetup.java >--- Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java 27 Sep 2006 15:02:00 -0000 1.34 >+++ Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java 20 Dec 2006 15:25:42 -0000 >@@ -236,9 +236,7 @@ > if (CURRENT_TEST_SETUP == this) { > RegressionTestSuite.fgJavaModel.close(); > RegressionTestSuite.fgJavaModel = null; >- new java.io.File(LOCAL_JDK + File.separator + "classes.zip").delete(); >- new java.io.File(LOCAL_JDK + File.separator + "src.zip").delete(); >- new java.io.File(LOCAL_JDK).delete(); >+ Util.delete(new File(LOCAL_JDK)); > } > } > } >Index: .options >=================================================================== >RCS file: .options >diff -N .options >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ .options 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,8 @@ >+# Turn on debug tracing for org.eclipse.jdt.core.tests plugin >+org.eclipse.jdt.core.tests/debug=true >+ >+# Reports deletion activity >+org.eclipse.jdt.core.tests/debug/delete=false >+ >+# Maximum time in ms waiting for delete operation succeed >+org.eclipse.jdt.core.tests/debug/delete/wait=10000 >Index: Eclipse Java Tests Runner/org/eclipse/jdt/core/tests/JDTCoreTestsPlugin.java >=================================================================== >RCS file: Eclipse Java Tests Runner/org/eclipse/jdt/core/tests/JDTCoreTestsPlugin.java >diff -N Eclipse Java Tests Runner/org/eclipse/jdt/core/tests/JDTCoreTestsPlugin.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse Java Tests Runner/org/eclipse/jdt/core/tests/JDTCoreTestsPlugin.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,80 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jdt.core.tests; >+ >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Plugin; >+import org.eclipse.jdt.core.tests.util.Util; >+import org.osgi.framework.BundleContext; >+ >+public class JDTCoreTestsPlugin extends Plugin { >+ >+// The shared plugin instance. >+private static JDTCoreTestsPlugin JDT_CORE_TESTS_PLUGIN; >+ >+/** >+ * The plug-in identifier of the JDT/Core tests support >+ * (value <code>"org.eclipse.jdt.core.tests"</code>). >+ */ >+public static final String PLUGIN_ID = "org.eclipse.jdt.core.tests" ; //$NON-NLS-1$ >+ >+private static final String DELETE_DEBUG = PLUGIN_ID + "/debug/delete" ; //$NON-NLS-1$ >+private static final String DELETE_MAX_WAIT = PLUGIN_ID + "/debug/delete/wait" ; //$NON-NLS-1$ >+ >+/** >+ * The constructor. >+ */ >+public JDTCoreTestsPlugin() { >+ JDT_CORE_TESTS_PLUGIN = this; >+} >+ >+/** >+ * This method is called upon plug-in activation >+ */ >+public void start(BundleContext context) throws Exception { >+ super.start(context); >+ configurePluginDebugOptions(); >+} >+ >+/** >+ * This method is called when the plug-in is stopped >+ */ >+public void stop(BundleContext context) throws Exception { >+ super.stop(context); >+ JDT_CORE_TESTS_PLUGIN = null; >+} >+ >+/** >+ * Returns the shared instance. >+ */ >+public static JDTCoreTestsPlugin getDefault() { >+ return JDT_CORE_TESTS_PLUGIN; >+} >+ >+/** >+ * Configure the plugin with respect to option settings defined in ".options" file >+ */ >+void configurePluginDebugOptions(){ >+ if(isDebugging()){ >+ String option = Platform.getDebugOption(DELETE_DEBUG); >+ if(option != null) { >+ Util.DELETE_DEBUG = option.equalsIgnoreCase("true") ; //$NON-NLS-1$ >+ } >+ option = Platform.getDebugOption(DELETE_MAX_WAIT); >+ if(option != null) { >+ int wait = Integer.parseInt(option); >+ if (wait > 1000 && wait <= 60000) { // between 1 and 60 seconds, else use default value (10s) >+ Util.DELETE_MAX_WAIT = wait; >+ } >+ } >+ } >+} >+} >#P org.eclipse.jdt.core.tests.performance >Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java,v >retrieving revision 1.36 >diff -u -r1.36 FullSourceWorkspaceTests.java >--- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 28 Sep 2006 14:14:57 -0000 1.36 >+++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 20 Dec 2006 15:36:45 -0000 >@@ -836,10 +836,10 @@ > this.scenarioComment.append(warnings); > } > >- /** >+ /* > * Delete a directory from file system. > * @param directory >- */ >+ * > protected void cleanupDirectory(File directory) { > if (!directory.isDirectory() || !directory.exists()) { > return; >@@ -857,6 +857,7 @@ > if (!directory.delete()) > System.out.println("Could not delete directory " + directory.getPath()); //$NON-NLS-1$ > } >+ */ > > /* > * Clear given options >@@ -925,7 +926,7 @@ > } > } > if (!"none".equals(COMPILER_OUTPUT_DIR)) { >- cleanupDirectory(new File(COMPILER_OUTPUT_DIR)); >+ Util.delete(COMPILER_OUTPUT_DIR); > } > warnings = warmup.globalWarningsCount; > if (!log) Util.writeToFile(errStrWriter.toString(), logFileName); >@@ -957,7 +958,7 @@ > } > stopMeasuring(); > if (!"none".equals(COMPILER_OUTPUT_DIR)) { >- cleanupDirectory(new File(COMPILER_OUTPUT_DIR)); >+ Util.delete(COMPILER_OUTPUT_DIR); > } > } > >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/DeleteTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/DeleteTests.java,v >retrieving revision 1.20 >diff -u -r1.20 DeleteTests.java >--- src/org/eclipse/jdt/core/tests/model/DeleteTests.java 20 Oct 2006 01:45:46 -0000 1.20 >+++ src/org/eclipse/jdt/core/tests/model/DeleteTests.java 20 Dec 2006 15:36:48 -0000 >@@ -18,6 +18,7 @@ > import org.eclipse.core.runtime.OperationCanceledException; > > import org.eclipse.jdt.core.*; >+import org.eclipse.jdt.core.tests.util.Util; > import org.eclipse.jdt.core.util.IClassFileReader; > > import junit.framework.Test; >@@ -196,7 +197,7 @@ > ICompilationUnit cu = getCompilationUnit("P/X.java"); > > startDeltas(); >- file.delete(false, null); >+ Util.delete(file); > assertTrue("Should be able to delete a CU", !cu.exists()); > assertDeltas( > "Unexpected delta", >@@ -808,7 +809,7 @@ > ); > IClassFile classFile = getClassFile("P78128", "lib.jar", "p", "X.class"); > ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.ALL); >- javaProject.getProject().delete(false, null); >+ Util.delete(javaProject.getProject()); > } finally { > if (getProject("P78128").exists()) > System.gc(); >Index: src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java,v >retrieving revision 1.75 >diff -u -r1.75 JavaProjectTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 12 Sep 2006 10:35:07 -0000 1.75 >+++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 20 Dec 2006 15:36:48 -0000 >@@ -894,13 +894,7 @@ > //System.out.println((System.currentTimeMillis() - start)+ "ms for "+roots.length+" roots"); > } finally { > if (libDir != null) { >- String[] libJars = libDir.list(); >- if (libJars != null) { >- for (int i = 0, length = libJars.length; i < length; i++) { >- new File(libDir, libJars[i]).delete(); >- } >- } >- libDir.delete(); >+ org.eclipse.jdt.core.tests.util.Util.delete(libDir); > } > this.deleteProject("P"); > JavaCore.removeClasspathVariable("MyVar", null); >@@ -933,13 +927,7 @@ > assertEquals("unexpected root raw entry:", classpath[0], rawEntry); // ensure first entry is associated to the root > } finally { > if (libDir != null) { >- String[] libJars = libDir.list(); >- if (libJars != null) { >- for (int i = 0, length = libJars.length; i < length; i++) { >- new File(libDir, libJars[i]).delete(); >- } >- } >- libDir.delete(); >+ org.eclipse.jdt.core.tests.util.Util.delete(libDir); > } > this.deleteProject("P"); > JavaCore.removeClasspathVariable("MyVar", null); >Index: src/org/eclipse/jdt/core/tests/model/JavadocPackageCompletionModelTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavadocPackageCompletionModelTest.java,v >retrieving revision 1.9 >diff -u -r1.9 JavadocPackageCompletionModelTest.java >--- src/org/eclipse/jdt/core/tests/model/JavadocPackageCompletionModelTest.java 29 Mar 2006 04:03:06 -0000 1.9 >+++ src/org/eclipse/jdt/core/tests/model/JavadocPackageCompletionModelTest.java 20 Dec 2006 15:36:49 -0000 >@@ -80,14 +80,7 @@ > if (!PACKAGE_FILES.contains(packageDir)) { > if (packageDir.exists()) { > PACKAGE_FILES.add(packageDir); >- File[] dirs= packageDir.listFiles(); >- for (int j=0, dl=dirs.length; j<dl; j++) { >- File[] files = dirs[j].listFiles(); >- for (int k=0, fl=files.length; k<fl; k++) { >- files[k].delete(); >- } >- dirs[j].delete(); >- } >+ Util.flushDirectoryContent(packageDir); > } else if (packageDir.mkdirs()) { > PACKAGE_FILES.add(packageDir); > } else { >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java,v >retrieving revision 1.9 >diff -u -r1.9 AbstractJavadocCompletionModelTest.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java 27 Jun 2006 09:53:09 -0000 1.9 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java 20 Dec 2006 15:36:48 -0000 >@@ -455,10 +455,7 @@ > if (!PACKAGE_FILES.contains(packageDir)) { > if (packageDir.exists()) { > PACKAGE_FILES.add(packageDir); >- File[] files = packageDir.listFiles(); >- for (int j=0, fl=files.length; j<fl; j++) { >- files[j].delete(); >- } >+ Util.delete(packageDir); > } else if (packageDir.mkdirs()) { > PACKAGE_FILES.add(packageDir); > } else { >Index: src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java,v >retrieving revision 1.65 >diff -u -r1.65 TypeHierarchyTests.java >--- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 1 Oct 2006 13:29:46 -0000 1.65 >+++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 20 Dec 2006 15:36:49 -0000 >@@ -501,9 +501,9 @@ > ); > } finally { > if (externalJar1 != null) >- new File(externalJar1).delete(); >+ Util.delete(externalJar1); > if (externalJar2 != null) >- new File(externalJar2).delete(); >+ Util.delete(externalJar2); > deleteProject("P"); > } > } >Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v >retrieving revision 1.156 >diff -u -r1.156 JavaSearchTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 17 Dec 2006 17:18:45 -0000 1.156 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 20 Dec 2006 15:36:48 -0000 >@@ -20,6 +20,7 @@ > import org.eclipse.core.runtime.*; > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.search.*; >+import org.eclipse.jdt.core.tests.util.Util; > import org.eclipse.jdt.internal.core.JavaModelStatus; > > /** >@@ -2072,7 +2073,7 @@ > this.resultCollector); > > } finally { >- externalJar.delete(); >+ Util.delete(externalJar); > project.setRawClasspath(classpath, null); > } > >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.177 >diff -u -r1.177 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 6 Nov 2006 12:08:55 -0000 1.177 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 20 Dec 2006 15:36:48 -0000 >@@ -1170,29 +1170,12 @@ > return project; > } > public void deleteFile(File file) { >- file = file.getAbsoluteFile(); >- if (!file.exists()) >- return; >- if (file.isDirectory()) { >- String[] files = file.list(); >- //file.list() can return null >- if (files != null) { >- for (int i = 0; i < files.length; ++i) { >- deleteFile(new File(file, files[i])); >- } >- } >- } >- boolean success = file.delete(); >- int retryCount = 60; // wait 1 minute at most >- while (!success && --retryCount >= 0) { >- try { >- Thread.sleep(1000); >- } catch (InterruptedException e) { >+ int retryCount = 0; >+ while (++retryCount <= 60) { // wait 1 minute at most >+ if (org.eclipse.jdt.core.tests.util.Util.delete(file)) { >+ break; > } >- success = file.delete(); > } >- if (success) return; >- System.err.println("Failed to delete " + file.getPath()); > } > protected void deleteFolder(IPath folderPath) throws CoreException { > deleteResource(getFolder(folderPath)); >@@ -1231,44 +1214,11 @@ > * Delete this resource. > */ > public void deleteResource(IResource resource) throws CoreException { >- CoreException lastException = null; >- try { >- resource.delete(true, null); >- return; >- } catch (CoreException e) { >- lastException = e; >- // just print for info >- System.out.println(e.getMessage() + " [" + resource.getFullPath() + "]"); >- } catch (IllegalArgumentException iae) { >- // just print for info >- System.out.println(iae.getMessage() + " [" + resource.getFullPath() + "]"); >- } > int retryCount = 0; // wait 1 minute at most >- while (resource.isAccessible() && ++retryCount <= 60) { >- System.out.println("Running GC and waiting 1s..."); >- try { >+ while (++retryCount <= 60) { >+ if (!org.eclipse.jdt.core.tests.util.Util.delete(resource)) { > System.gc(); >- Thread.sleep(1000); >- } catch (InterruptedException e) { > } >- try { >- resource.delete(true, null); >- } catch (CoreException e) { >- lastException = e; >- // just print for info >- System.out.println("Retry "+retryCount+": "+ e.getMessage() + " [" + resource.getFullPath() + "]"); >- } catch (IllegalArgumentException iae) { >- // just print for info >- System.out.println("Retry "+retryCount+": "+ iae.getMessage() + " [" + resource.getFullPath() + "]"); >- } >- } >- if (!resource.isAccessible()) { >- System.out.println("Succeed to delete resource [" + resource.getFullPath() + "]"); >- return; >- } >- System.err.println("Failed to delete resource [" + resource.getFullPath() + "]"); >- if (lastException != null) { >- throw lastException; > } > } > /** >@@ -1716,9 +1666,9 @@ > IProject project = javaProject.getProject(); > String projectPath = '/' + project.getName() + '/'; > removeLibraryEntry(javaProject, new Path(projectPath + jarName)); >- project.getFile(jarName).delete(false, null); >+ org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(jarName)); > if (sourceZipName != null && sourceZipName.length() != 0) { >- project.getFile(sourceZipName).delete(false, null); >+ org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(sourceZipName)); > } > } > protected void removeLibraryEntry(Path path) throws JavaModelException { >Index: src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java,v >retrieving revision 1.44 >diff -u -r1.44 ModifyingResourceTests.java >--- src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java 20 Dec 2006 15:20:00 -0000 1.44 >+++ src/org/eclipse/jdt/core/tests/model/ModifyingResourceTests.java 20 Dec 2006 15:36:49 -0000 >@@ -209,7 +209,8 @@ > } > protected IClassFile createClassFile(String libPath, String classFileRelativePath, String contents) throws CoreException { > IClassFile classFile = getClassFile(libPath + "/" + classFileRelativePath); >- classFile.getResource().delete(false, null); >+// classFile.getResource().delete(false, null); >+ Util.delete(classFile.getResource()); > IJavaProject javaProject = classFile.getJavaProject(); > IProject project = javaProject.getProject(); > String sourcePath = project.getLocation().toOSString() + File.separatorChar + classFile.getType().getElementName() + ".java"; >Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v >retrieving revision 1.222 >diff -u -r1.222 ASTConverter15Test.java >--- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 14 Dec 2006 20:11:36 -0000 1.222 >+++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 20 Dec 2006 15:36:47 -0000 >@@ -5980,7 +5980,8 @@ > }; > Util.compile(pathsAndContents, options, classesPath); > folder.refreshLocal(IResource.DEPTH_INFINITE, null); >- folder.getFolder("p").getFile("Bin.class").delete(false, null); >+// folder.getFolder("p").getFile("Bin.class").delete(false, null); >+ Util.delete(folder.getFolder("p").getFile("Bin.class")); > this.workingCopy = getWorkingCopy("/P/src/X.java", true/*resolve*/); > String contents = > "public class X {\n" + >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java,v >retrieving revision 1.38 >diff -u -r1.38 JavadocTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 23 Jun 2006 07:57:25 -0000 1.38 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 20 Dec 2006 15:36:51 -0000 >@@ -366,11 +366,11 @@ > createOutputTestDirectory(Character.toUpperCase(testName.charAt(0)) + > testName.substring(1)); > System.out.println("Write test file to " + >- this.outputTestDirectoryPath + "..."); >+ this.outputTestDirectory.getPath() + "..."); > for (int i=0, length=testFiles.length; i<length; i++) { > String contents = testFiles[i+1]; > String fileName = testFiles[i++]; >- String dirFileName = this.outputTestDirectoryPath.toString(); >+ String dirFileName = this.outputTestDirectory.getPath(); > if (fileName.indexOf("Visibility")>0) { > continue; > } else { >@@ -412,7 +412,7 @@ > // Cleanup javac output dir if needed > File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR); > if (shouldFlushOutputDirectory) { >- cleanupDirectory(javacOutputDirectory); >+ Util.delete(javacOutputDirectory); > } > > // Write files in dir >@@ -443,7 +443,7 @@ > > // Launch process > compileProcess = Runtime.getRuntime().exec( >- cmdLine.toString(), null, this.outputTestDirectoryPath.toFile()); >+ cmdLine.toString(), null, this.outputTestDirectory); > > // Log errors > Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); >@@ -549,7 +549,7 @@ > // the test itself > } > finally { >- cleanupDirectory(outputTestDirectoryPath.toFile()); >+ Util.delete(outputTestDirectory); > } > } > >Index: src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java,v >retrieving revision 1.71 >diff -u -r1.71 AbstractRegressionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 7 Dec 2006 10:00:15 -0000 1.71 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 20 Dec 2006 15:36:50 -0000 >@@ -202,28 +202,6 @@ > /*###################################### > * Specific method to let tests Sun javac compilation available... > #######################################*/ >- /* >- * Cleans up the given directory by removing all the files it contains as well >- * but leaving the directory. >- * @throws TargetException if the target path could not be cleaned up >- */ >- protected void cleanupDirectory(File directory) { >- if (!directory.exists()) { >- return; >- } >- String[] fileNames = directory.list(); >- for (int i = 0; i < fileNames.length; i++) { >- File file = new File(directory, fileNames[i]); >- if (file.isDirectory()) { >- cleanupDirectory(file); >- } else { >- if (!file.delete()) >- System.out.println("Could not delete file " + file.getPath()); >- } >- } >- if (!directory.delete()) >- System.out.println("Could not delete directory " + directory.getPath()); >- } > protected void compileAndDeploy(String source, String directoryName, String className) { > File directory = new File(SOURCE_DIRECTORY); > if (!directory.exists()) { >@@ -474,7 +452,7 @@ > if (fileNames != null) { > for (int i = 0, max = fileNames.length; i < max; i++) { > if (fileNames[i].indexOf(className) != -1) { >- new File(SOURCE_DIRECTORY + File.separator + fileNames[i]).delete(); >+ Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]); > } > } > } >@@ -484,7 +462,7 @@ > if (fileNames != null) { > for (int i = 0, max = fileNames.length; i < max; i++) { > if (fileNames[i].indexOf(className) != -1) { >- new File(EVAL_DIRECTORY + File.separator + fileNames[i]).delete(); >+ Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]); > } > } > } >@@ -795,7 +773,7 @@ > // Cleanup javac output dir if needed > File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR); > if (shouldFlushOutputDirectory) { >- cleanupDirectory(javacOutputDirectory); >+ Util.delete(javacOutputDirectory); > } > > // Write files in dir >@@ -826,7 +804,7 @@ > > // Launch process > compileProcess = Runtime.getRuntime().exec( >- cmdLine.toString(), null, this.outputTestDirectoryPath.toFile()); >+ cmdLine.toString(), null, this.outputTestDirectory); > > // Log errors > Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); >@@ -891,7 +869,7 @@ > javaCmdLine.append(cp); > javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.'))); > // assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes >- execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectoryPath.toFile()); >+ execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectory); > Logger logger = new Logger(execProcess.getInputStream(), ""); > // PREMATURE implement consistent error policy > logger.start(); >@@ -960,7 +938,7 @@ > } > finally { > // Clean up written file(s) >- cleanupDirectory(outputTestDirectoryPath.toFile()); >+ Util.delete(outputTestDirectory); > } > } > /** >@@ -1314,7 +1292,7 @@ > // clean up output dir > File outputDir = new File(OUTPUT_DIR); > if (outputDir.exists()) { >- Util.rmdir(outputDir); >+ Util.flushDirectoryContent(outputDir); > } > super.tearDown(); > if (RUN_JAVAC) { >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v >retrieving revision 1.96 >diff -u -r1.96 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 19 Dec 2006 23:16:43 -0000 1.96 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 20 Dec 2006 15:36:51 -0000 >@@ -1747,7 +1747,7 @@ > "", > true); > if (jarCreated) { >- new File(libPath).delete(); >+ Util.delete(libPath); > } > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88364 - -extdirs extends the classpath before -classpath >@@ -2375,11 +2375,11 @@ > false); > final String userDir = System.getProperty("user.dir"); > File f = new File(userDir, "X.java"); >- if (!f.delete()) { >+ if (!Util.delete(f)) { > System.out.println("Could not delete X"); > } > f = new File(userDir, "p" + File.separator + "Y.java"); >- if (!f.delete()) { >+ if (!Util.delete(f)) { > System.out.println("Could not delete Y"); > } > >@@ -3285,8 +3285,8 @@ > } catch (IOException e) { > fail("could not create jar file"); > } >- new File(outputDirName + File.separator + "Y.class").delete(); >- new File(outputDirName + File.separator + "Y.java").delete(); >+ Util.delete(outputDirName + File.separator + "Y.class"); >+ Util.delete(outputDirName + File.separator + "Y.java"); > this.runConformTest( > new String[] { > "d/X.java", >@@ -3334,8 +3334,8 @@ > } catch (IOException e) { > fail("could not create jar file"); > } >- new File(outputDirName + File.separator + "Y.class").delete(); >- new File(outputDirName + File.separator + "Y.java").delete(); >+ Util.delete(outputDirName + File.separator + "Y.class"); >+ Util.delete(outputDirName + File.separator + "Y.java"); > this.runConformTest( > new String[] { > "d/X.java", >@@ -4145,7 +4145,7 @@ > "public class X {}"); > Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar"); > if (standardXOutputFile.exists()) { >- standardXOutputFile.delete(); >+ Util.delete(standardXOutputFile); > } > } catch (IOException e) { > fail("could not create jar file"); >@@ -4197,7 +4197,7 @@ > "public class X {}"); > Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar"); > if (standardXOutputFile.exists()) { >- standardXOutputFile.delete(); >+ Util.delete(standardXOutputFile); > } > } catch (IOException e) { > fail("could not create jar file"); >@@ -4248,7 +4248,7 @@ > "public class X {}"); > Util.zip(sourceDir, OUTPUT_DIR + File.separator + "X.jar"); > if (standardXOutputFile.exists()) { >- standardXOutputFile.delete(); >+ Util.delete(standardXOutputFile); > } > } catch (IOException e) { > fail("could not create jar file"); >Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v >retrieving revision 1.65 >diff -u -r1.65 LookupTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 7 Dec 2006 16:03:36 -0000 1.65 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 20 Dec 2006 15:36:51 -0000 >@@ -1516,7 +1516,7 @@ > }, > "SUCCESS"); > // delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile) >- new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class").delete(); >+ Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class")); > > this.runConformTest( > new String[] { >Index: src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java,v >retrieving revision 1.31 >diff -u -r1.31 DebugEvaluationTest.java >--- src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 3 Oct 2006 15:19:13 -0000 1.31 >+++ src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 20 Dec 2006 15:36:52 -0000 >@@ -156,12 +156,8 @@ > } > public void removeTempClass(String className) { > resetEnv(); // needed to reinitialize the caches >- File sourceFile = new File(SOURCE_DIRECTORY + File.separator + className + ".java"); >- sourceFile.delete(); >- >- File binaryFile = new File(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class"); >- >- binaryFile.delete(); >+ Util.delete(SOURCE_DIRECTORY + File.separator + className + ".java"); >+ Util.delete(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class"); > } > /*public static Test suite(Class evaluationTestClass) { > junit.framework.TestSuite suite = new junit.framework.TestSuite(); >Index: src/org/eclipse/jdt/core/tests/util/Util.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v >retrieving revision 1.52 >diff -u -r1.52 Util.java >--- src/org/eclipse/jdt/core/tests/util/Util.java 11 Oct 2006 09:15:32 -0000 1.52 >+++ src/org/eclipse/jdt/core/tests/util/Util.java 20 Dec 2006 15:36:52 -0000 >@@ -15,6 +15,9 @@ > import java.util.*; > import java.util.zip.*; > >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.core.tests.compiler.regression.Requestor; > import org.eclipse.jdt.internal.compiler.Compiler; >@@ -27,6 +30,25 @@ > import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; > import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; > public class Util { >+ // Trace for delete operation >+ /* >+ * Maximum time wasted repeating delete operations while running JDT/Core tests. >+ */ >+ private static int DELETE_MAX_TIME = 0; >+ /** >+ * Trace deletion operations while running JDT/Core tests. >+ */ >+ public static boolean DELETE_DEBUG = false; >+ /** >+ * Maximum of time in ms to wait in deletion operation while running JDT/Core tests. >+ * Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000). >+ * <br> >+ * To avoid too many loops while waiting, the ten first ones are done waiting >+ * 10ms before repeating, the ten loops after are done waiting 100ms and >+ * the other loops are done waiting 1s... >+ */ >+ public static int DELETE_MAX_WAIT = 10000; >+ > private static final boolean DEBUG = false; > /** > * Initially, output directory was located in System.getProperty("user.home")+"\comptest". >@@ -37,7 +59,7 @@ > */ > private final static String OUTPUT_DIRECTORY; > /** >- * Let user specify the delay in hours before output directories are removed from file system >+ * Let user specify the delay in hours before output directories are removed from file system > * while starting a new test run. Default value is 2 hours. > * <p> > * Note that this value may be a float and so have time less than one hour. >@@ -90,7 +112,7 @@ > for (int i=0,l=testDirs.length; i<l; i++) { > if (testDirs[i].isDirectory()) { > if ((now - testDirs[i].lastModified()) > delay) { >- rmdir(testDirs[i]); >+ delete(testDirs[i]); > } > } > } >@@ -242,8 +264,10 @@ > try { > in = new FileInputStream(source); > File destFile = new File(dest, source.getName()); >- if (destFile.exists() && !destFile.delete()) { >- throw new IOException(destFile + " is in use"); >+ if (destFile.exists()) { >+ if (!Util.delete(destFile)) { >+ throw new IOException(destFile + " is in use"); >+ } > } > out = new FileOutputStream(destFile); > int bufferLength = 1024; >@@ -316,6 +340,54 @@ > zip(sourcesDir, zipPath); > } > /** >+ * Delete a file or directory and insure that the file is no longer present >+ * on file system. In case of directory, delete all the hierarchy underneath. >+ * >+ * @param file The file or directory to delete >+ * @return true iff the file was really delete, false otherwise >+ */ >+public static boolean delete(File file) { >+ // flush all directory content >+ if (file.isDirectory()) { >+ flushDirectoryContent(file); >+ } >+ // remove file >+ file.delete(); >+ if (isFileDeleted(file)) { >+ return true; >+ } >+ return waitUntilFileDeleted(file); >+} >+/** >+ * Delete a file or directory and insure that the file is no longer present >+ * on file system. In case of directory, delete all the hierarchy underneath. >+ * >+ * @param resource The resource to delete >+ * @return true iff the file was really delete, false otherwise >+ */ >+public static boolean delete(IResource resource) { >+ try { >+ resource.delete(true, null); >+ if (isResourceDeleted(resource)) { >+ return true; >+ } >+ } >+ catch (CoreException e) { >+ // skip >+ } >+ return waitUntilResourceDeleted(resource); >+} >+/** >+ * Delete a file or directory and insure that the file is no longer present >+ * on file system. In case of directory, delete all the hierarchy underneath. >+ * >+ * @param path The path of the file or directory to delete >+ * @return true iff the file was really delete, false otherwise >+ */ >+public static boolean delete(String path) { >+ return delete(new File(path)); >+} >+/** > * Generate a display string from the given String. > * @param inputString the given input string > * >@@ -527,32 +599,14 @@ > writeToFile(displayString, destinationFilePath); > } > /** >- * Delete a directory and all its hierarchy if not empty >- * >- * @param dir The directory to delete >- */ >-public static void rmdir(File dir) { >- // flush all directory content >- flushDirectoryContent(dir); >- // remove dir >- dir.delete(); >-} >-/** > * Flush content of a given directory (leaving it empty), > * no-op if not a directory. > */ > public static void flushDirectoryContent(File dir) { >- if (dir.isDirectory()) { >- String[] files = dir.list(); >- if (files == null) return; >- for (int i = 0, max = files.length; i < max; i++) { >- File current = new File(dir, files[i]); >- if (current.isDirectory()) { >- flushDirectoryContent(current); >- } >- if (!current.delete()) >- System.err.println("Could not delete " + current.getName()); >- } >+ File[] files = dir.listFiles(); >+ if (files == null) return; >+ for (int i = 0, max = files.length; i < max; i++) { >+ delete(files[i]); > } > } > /** >@@ -645,6 +699,81 @@ > public static String getOutputDirectory() { > return OUTPUT_DIRECTORY; > } >+/** >+ * Returns the parent's child file matching the given file or null if not found. >+ * >+ * @param file The searched file in parent >+ * @return The parent's child matching the given file or null if not found. >+ */ >+private static File getParentChildFile(File file) { >+ File parent = file.getParentFile(); >+ if (parent == null || !parent.exists()) return null; >+ File[] files = parent.listFiles(); >+ int length = files==null ? 0 : files.length; >+ if (length > 0) { >+ for (int i=0; i<length; i++) { >+ if (files[i] == file) { >+ return files[i]; >+ } else if (files[i].equals(file)) { >+ return files[i]; >+ } else if (files[i].getPath().equals(file.getPath())) { >+ return files[i]; >+ } >+ } >+ } >+ return null; >+} >+/** >+ * Returns parent's child resource matching the given resource or null if not found. >+ * >+ * @param resource The searched file in parent >+ * @return The parent's child matching the given file or null if not found. >+ */ >+private static IResource getParentChildResource(IResource resource) { >+ IContainer parent = resource.getParent(); >+ if (parent == null || !parent.exists()) return null; >+ try { >+ IResource[] members = parent.members(); >+ int length = members ==null ? 0 : members.length; >+ if (length > 0) { >+ for (int i=0; i<length; i++) { >+ if (members[i] == resource) { >+ return members[i]; >+ } else if (members[i].equals(resource)) { >+ return members[i]; >+ } else if (members[i].getFullPath().equals(resource.getFullPath())) { >+ return members[i]; >+ } >+ } >+ } >+ } >+ catch (CoreException ce) { >+ // skip >+ } >+ return null; >+} >+/** >+ * Returns the test name from stack elements info. >+ * >+ * @return The name of the test currently running >+ */ >+private static String getTestName() { >+ StackTraceElement[] elements = new Exception().getStackTrace(); >+ int idx = 0, length=elements.length; >+ while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { >+ // loop until JDT/Core class appears in the stack >+ } >+ if (idx<length) { >+ StackTraceElement testElement = null; >+ while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { >+ testElement = elements[idx++]; >+ } >+ if (testElement != null) { >+ return testElement.getClassName() + " - " + testElement.getMethodName(); >+ } >+ } >+ return "?"; >+} > public static String indentString(String inputString, int indent) { > if (inputString == null) > return ""; >@@ -663,10 +792,133 @@ > } > return buffer.toString(); > } >+/** >+ * Returns whether a file is really deleted or not. >+ * Does not only rely on {@link File#exists()} method but also >+ * look if it's not in its parent children {@link #getParentChildFile(File)}. >+ * >+ * @param file The file to test if deleted >+ * @return true if the file does not exist and was not found in its parent children. >+ */ >+public static boolean isFileDeleted(File file) { >+ return !file.exists() && getParentChildFile(file) == null; >+} > public static boolean isMacOS() { > return System.getProperty("os.name").indexOf("Mac") != -1; > } > /** >+ * Returns whether a resource is really deleted or not. >+ * Does not only rely on {@link IResource#isAccessible()} method but also >+ * look if it's not in its parent children {@link #getParentChildResource(IResource)}. >+ * >+ * @param resource The resource to test if deleted >+ * @return true if the resource is not accessible and was not found in its parent children. >+ */ >+public static boolean isResourceDeleted(IResource resource) { >+ return !resource.isAccessible() && getParentChildResource(resource) == null; >+} >+/** >+ * Print given file information with specified indentation. >+ * These information are:<ul> >+ * <li>read {@link File#canRead()}</li> >+ * <li>write {@link File#canWrite()}</li> >+ * <li>exists {@link File#exists()}</li> >+ * <li>is file {@link File#isFile()}</li> >+ * <li>is directory {@link File#isDirectory()}</li> >+ * <li>is hidden {@link File#isHidden()}</li> >+ * </ul> >+ * May recurse several level in parents hierarchy. >+ * May also display children, but then will not recusre in parent >+ * hierarchy to avoid infinite loop... >+ * >+ * @param file The file to display information >+ * @param indent Number of tab to print before the information >+ * @param recurse Display also information on <code>recurse</code>th parents in hierarchy. >+ * If negative then display children information instead. >+ */ >+private static void printFileInfo(File file, int indent, int recurse) { >+ String tab = ""; >+ for (int i=0; i<indent; i++) tab+="\t"; >+ System.out.print(tab+"- "+file.getName()+" file info: "); >+ String sep = ""; >+ if (file.canRead()) { >+ System.out.print("read"); >+ sep = ", "; >+ } >+ if (file.canWrite()) { >+ System.out.print(sep+"write"); >+ sep = ", "; >+ } >+ if (file.exists()) { >+ System.out.print(sep+"exist"); >+ sep = ", "; >+ } >+ if (file.isDirectory()) { >+ System.out.print(sep+"dir"); >+ sep = ", "; >+ } >+ if (file.isFile()) { >+ System.out.print(sep+"file"); >+ sep = ", "; >+ } >+ if (file.isHidden()) { >+ System.out.print(sep+"hidden"); >+ sep = ", "; >+ } >+ System.out.println(); >+ File[] files = file.listFiles(); >+ int length = files==null ? 0 : files.length; >+ if (length > 0) { >+ boolean children = recurse < 0; >+ System.out.print(tab+" + children: "); >+ if (children) System.out.println(); >+ for (int i=0; i<length; i++) { >+ if (children) { // display children >+ printFileInfo(files[i], indent+2, -1); >+ } else { >+ if (i>0) System.out.print(", "); >+ System.out.print(files[i].getName()); >+ if (files[i].isDirectory()) System.out.print("[dir]"); >+ else if (files[i].isFile()) System.out.print("[file]"); >+ else System.out.print("[?]"); >+ } >+ } >+ if (!children) System.out.println(); >+ } >+ if (recurse > 0) { >+ File parent = file.getParentFile(); >+ if (parent != null) printFileInfo(parent, indent+1, recurse-1); >+ } >+} >+/** >+ * Print stack trace with only JDT/Core elements. >+ * >+ * @param exception Exception of the stack trace. May be null, then a fake exception is used. >+ * @param indent Number of tab to display before the stack elements to display. >+ */ >+private static void printJdtCoreStackTrace(Exception exception, int indent) { >+ String tab = ""; >+ for (int i=0; i<indent; i++) tab+="\t"; >+ StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace(); >+ int idx = 0, length=elements.length; >+ while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { >+ // loop until JDT/Core class appears in the stack >+ } >+ if (idx<length) { >+ System.out.print(tab+"- stack trace"); >+ if (exception == null) >+ System.out.println(":"); >+ else >+ System.out.println(" for exception "+exception+":"); >+ while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { >+ StackTraceElement testElement = elements[idx++]; >+ System.out.println(tab+" -> "+testElement); >+ } >+ } else { >+ exception.printStackTrace(System.out); >+ } >+} >+/** > * Makes the given path a path using native path separators as returned by File.getPath() > * and trimming any extra slash. > */ >@@ -729,6 +981,157 @@ > } > } > } >+/** >+ * Wait until the file is _really_ deleted on file system. >+ * >+ * @param file Deleted file >+ * @return true if the file was finally deleted, false otherwise >+ */ >+private static boolean waitUntilFileDeleted(File file) { >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println("WARNING in test: "+getTestName()); >+ System.out.println(" - problems occured while deleting "+file); >+ printJdtCoreStackTrace(null, 1); >+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children >+ System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); >+ } >+ int count = 0; >+ int delay = 10; // ms >+ int maxRetry = DELETE_MAX_WAIT / delay; >+ int time = 0; >+ while (count < maxRetry) { >+ try { >+ count++; >+ Thread.sleep(delay); >+ time += delay; >+ if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; >+ if (DELETE_DEBUG) System.out.print('.'); >+ if (file.exists()) { >+ if (file.delete()) { >+ // SUCCESS >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); >+ System.out.println(); >+ } >+ return true; >+ } >+ } >+ if (isFileDeleted(file)) { >+ // SUCCESS >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); >+ System.out.println(); >+ } >+ return true; >+ } >+ // Increment waiting delay exponentially >+ if (count >= 10 && delay <= 100) { >+ count = 1; >+ delay *= 10; >+ maxRetry = DELETE_MAX_WAIT / delay; >+ if ((DELETE_MAX_WAIT%delay) != 0) { >+ maxRetry++; >+ } >+ } >+ } >+ catch (InterruptedException ie) { >+ break; // end loop >+ } >+ } >+ if (!DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println("WARNING in test: "+getTestName()); >+ System.out.println(" - problems occured while deleting "+file); >+ printJdtCoreStackTrace(null, 1); >+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children >+ } >+ System.out.println(); >+ System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); >+ System.out.println(); >+ return false; >+} >+/** >+ * Wait until a resource is _really_ deleted on file system. >+ * >+ * @param resource Deleted resource >+ * @return true if the file was finally deleted, false otherwise >+ */ >+private static boolean waitUntilResourceDeleted(IResource resource) { >+ File file = resource.getLocation().toFile(); >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println("WARNING in test: "+getTestName()); >+ System.out.println(" - problems occured while deleting resource "+resource); >+ printJdtCoreStackTrace(null, 1); >+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children >+ System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); >+ } >+ int count = 0; >+ int delay = 10; // ms >+ int maxRetry = DELETE_MAX_WAIT / delay; >+ int time = 0; >+ while (count < maxRetry) { >+ try { >+ count++; >+ Thread.sleep(delay); >+ time += delay; >+ if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; >+ if (DELETE_DEBUG) System.out.print('.'); >+ if (resource.isAccessible()) { >+ try { >+ resource.delete(true, null); >+ if (isResourceDeleted(resource) && isFileDeleted(file)) { >+ // SUCCESS >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); >+ System.out.println(); >+ } >+ return true; >+ } >+ } >+ catch (CoreException e) { >+ // skip >+ } >+ } >+ if (isResourceDeleted(resource) && isFileDeleted(file)) { >+ // SUCCESS >+ if (DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); >+ System.out.println(); >+ } >+ return true; >+ } >+ // Increment waiting delay exponentially >+ if (count >= 10 && delay <= 100) { >+ count = 1; >+ delay *= 10; >+ maxRetry = DELETE_MAX_WAIT / delay; >+ if ((DELETE_MAX_WAIT%delay) != 0) { >+ maxRetry++; >+ } >+ } >+ } >+ catch (InterruptedException ie) { >+ break; // end loop >+ } >+ } >+ if (!DELETE_DEBUG) { >+ System.out.println(); >+ System.out.println("WARNING in test: "+getTestName()); >+ System.out.println(" - problems occured while deleting resource "+resource); >+ printJdtCoreStackTrace(null, 1); >+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children >+ } >+ System.out.println(); >+ System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); >+ System.out.println(); >+ return false; >+} > public static void writeToFile(String contents, String destinationFilePath) { > File destFile = new File(destinationFilePath); > FileOutputStream output = null; >@@ -752,7 +1155,9 @@ > public static void zip(File rootDir, String zipPath) throws IOException { > ZipOutputStream zip = null; > try { >- zip = new ZipOutputStream(new FileOutputStream(zipPath)); >+ File zipFile = new File(zipPath); >+ if (zipFile.exists()) delete(zipFile); >+ zip = new ZipOutputStream(new FileOutputStream(zipFile)); > zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash > } finally { > if (zip != null) { >@@ -761,20 +1166,19 @@ > } > } > private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { >- String[] list = dir.list(); >- if (list != null) { >- for (int i = 0, length = list.length; i < length; i++) { >- String name = list[i]; >- File file = new File(dir, name); >- if (file.isDirectory()) { >- zip(file, zip, rootPathLength); >- } else { >+ File[] files = dir.listFiles(); >+ if (files != null) { >+ for (int i = 0, length = files.length; i < length; i++) { >+ File file = files[i]; >+ if (file.isFile()) { > String path = file.getPath(); > path = path.substring(rootPathLength); > ZipEntry entry = new ZipEntry(path.replace('\\', '/')); > zip.putNextEntry(entry); > zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); > zip.closeEntry(); >+ } else { >+ zip(file, zip, rootPathLength); > } > } > } >Index: src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java,v >retrieving revision 1.28 >diff -u -r1.28 AbstractCompilerTest.java >--- src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 23 Nov 2006 15:42:33 -0000 1.28 >+++ src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 20 Dec 2006 15:36:52 -0000 >@@ -458,9 +458,8 @@ > } > > // Output files management >- protected IPath >- outputRootDirectoryPath = new Path(Util.getOutputDirectory()), >- outputTestDirectoryPath; >+ protected IPath outputRootDirectoryPath = new Path(Util.getOutputDirectory()); >+ protected File outputTestDirectory; > > /** > * Create a test specific output directory as a subdirectory of >@@ -470,11 +469,9 @@ > * @param suffixPath a valid relative path for the subdirectory > */ > protected void createOutputTestDirectory(String suffixPath) { >- this.outputTestDirectoryPath = >- ((IPath) this.outputRootDirectoryPath.clone()).append(suffixPath); >- File dir = this.outputTestDirectoryPath.toFile(); >- if (!dir.exists()) { >- dir.mkdirs(); >+ this.outputTestDirectory = new File(this.outputRootDirectoryPath.toFile(), suffixPath); >+ if (!this.outputTestDirectory.exists()) { >+ this.outputTestDirectory.mkdirs(); > } > } > /* >@@ -488,15 +485,14 @@ > for (int i = 0, length = testFiles.length; i < length; ) { > String fileName = testFiles[i++]; > String contents = testFiles[i++]; >- IPath filePath = >- ((IPath) this.outputTestDirectoryPath.clone()).append(fileName); >+ File file = new File(this.outputTestDirectory, fileName); > if (fileName.lastIndexOf('/') >= 0) { >- File dir = filePath.removeLastSegments(1).toFile(); >+ File dir = file.getParentFile(); > if (!dir.exists()) { > dir.mkdirs(); > } > } >- Util.writeToFile(contents, filePath.toString()); >+ Util.writeToFile(contents, file.getPath()); > } > } > >Index: src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java,v >retrieving revision 1.11 >diff -u -r1.11 LocalVirtualMachine.java >--- src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java 10 May 2006 18:07:26 -0000 1.11 >+++ src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java 20 Dec 2006 15:36:52 -0000 >@@ -12,6 +12,8 @@ > > import java.io.*; > >+import org.eclipse.jdt.core.tests.util.Util; >+ > /** > * Wrapper around the external process that is running a local VM. > * This allows to kill this process when we exit this vm. >@@ -46,11 +48,11 @@ > this.process.destroy(); > } > } >-/** >+/* > * Cleans up the given directory by removing all the files it contains as well > * but leaving the directory. > * @throws TargetException if the target path could not be cleaned up >- */ >+ * > private void cleanupDirectory(File directory) throws TargetException { > if (!directory.exists()) { > return; >@@ -70,6 +72,7 @@ > } > } > } >+*/ > /** > * Cleans up this context's target path by removing all the files it contains > * but leaving the directory. >@@ -79,11 +82,11 @@ > if (this.evalTargetPath == null) return; > String targetPath = this.evalTargetPath; > if (LocalVMLauncher.TARGET_HAS_FILE_SYSTEM) { >- cleanupDirectory(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY)); >- cleanupDirectory(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY)); >+ Util.delete(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY)); >+ Util.delete(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY)); > File file = new File(targetPath, RuntimeConstants.SUPPORT_ZIP_FILE_NAME); > >- // workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet >+ /* workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet > int count = 10; > for (int i = 0; i < count; i++) { > if (file.delete()) { >@@ -94,11 +97,12 @@ > } catch (InterruptedException e) { > } > } >- if (file.exists()) { >+ */ >+ if (!Util.delete(file)) { > throw new TargetException("Could not delete " + file.getPath()); > } > } else { >- cleanupDirectory(new File(targetPath)); >+ Util.delete(targetPath); > } > } > /** >#P org.eclipse.jdt.core.tests.builder >Index: src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java,v >retrieving revision 1.48 >diff -u -r1.48 TestingEnvironment.java >--- src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 15 Nov 2006 14:11:16 -0000 1.48 >+++ src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java 20 Dec 2006 15:36:54 -0000 >@@ -16,6 +16,7 @@ > > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; >+import org.eclipse.jdt.core.tests.util.Util; > > import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; > import org.eclipse.jdt.internal.core.ClasspathEntry; >@@ -601,35 +602,24 @@ > return (IProject)fProjects.get(projectPath.lastSegment()); > } > >-private File tmpDirectory; >-File getTmpDirectory() { >- if (this.tmpDirectory == null) { >- this.tmpDirectory = new File(System.getProperty("java.io.tmpdir") + >- File.separator + "org.eclipse.jdt.core.builder.tests.tmp"); >- if (this.tmpDirectory.exists() && !this.tmpDirectory.isDirectory()) { >- this.tmpDirectory.delete(); >+ private File tmpDirectory; >+ File getTmpDirectory() { >+ if (this.tmpDirectory == null) { >+ this.tmpDirectory = new File(System.getProperty("java.io.tmpdir") + >+ File.separator + "org.eclipse.jdt.core.builder.tests.tmp"); >+ if (this.tmpDirectory.exists() && !this.tmpDirectory.isDirectory()) { >+ Util.delete(this.tmpDirectory); >+ } >+ this.tmpDirectory.mkdir(); >+ } >+ return this.tmpDirectory; >+ } >+ void deleteTmpDirectory() { >+ if (this.tmpDirectory != null) { >+ Util.delete(this.tmpDirectory); >+ this.tmpDirectory = null; > } >- this.tmpDirectory.mkdir(); > } >- return this.tmpDirectory; >-} >-void deleteTmpDirectory() { >- if (this.tmpDirectory != null) { >- deleteDirectory(this.tmpDirectory); >- this.tmpDirectory = null; >- } >-} >-private void deleteDirectory(File dir) { >- File[] files = dir.listFiles(); >- for (int i = 0 ; i < files.length ; i++) { >- if (files[i].isDirectory()) { >- deleteDirectory(files[i]); >- } else { >- files[i].delete(); >- } >- } >- dir.delete(); >-} > > /** > * Returns the workspace.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 166977
:
55152
|
55199
| 55967 |
55972
|
62475
|
62679