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 55972 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.2.2
v17.txt (text/plain), 58.01 KB, created by
Frederic Fusier
on 2006-12-20 11:19:32 EST
(
hide
)
Description:
Proposed patch for 3.2.2
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2006-12-20 11:19:32 EST
Size:
58.01 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests >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.288 >diff -u -r1.288 NegativeTest.java >--- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 10 Apr 2006 19:02:50 -0000 1.288 >+++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java 20 Dec 2006 13:26:27 -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 { >@@ -15355,7 +15356,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[] { >@@ -15403,7 +15404,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[] { >@@ -15453,7 +15454,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[] { >@@ -15649,7 +15650,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.32 >diff -u -r1.32 JavaModelRegressionTestSetup.java >--- Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java 29 Mar 2006 05:07:12 -0000 1.32 >+++ Eclipse Java Tests Model/src/org/eclipse/jdt/tests/core/JavaModelRegressionTestSetup.java 20 Dec 2006 13:26:27 -0000 >@@ -32,6 +32,7 @@ > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; > import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.tests.util.Util; > > public class JavaModelRegressionTestSetup extends TestSetup { > public static JavaModelRegressionTestSetup CURRENT_TEST_SETUP = null; >@@ -234,9 +235,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: plugin.xml >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/plugin.xml,v >retrieving revision 1.21.2.1 >diff -u -r1.21.2.1 plugin.xml >--- plugin.xml 2 Jul 2006 10:12:08 -0000 1.21.2.1 >+++ plugin.xml 20 Dec 2006 13:26:23 -0000 >@@ -3,8 +3,9 @@ > <plugin > id="org.eclipse.jdt.core.tests" > name="%pluginName" >- provider-name = "%providerName" >- version="3.2.1"> >+ version="3.2.1" >+ provider-name="%providerName" >+ class="org.eclipse.jdt.core.tests.JDTCoreTestsPlugin"> > > <runtime> > <library name="jdtcoretests.jar"> >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.model >Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v >retrieving revision 1.98.4.7 >diff -u -r1.98.4.7 ReconcilerTests.java >--- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 15 Nov 2006 10:01:19 -0000 1.98.4.7 >+++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 20 Dec 2006 13:37:31 -0000 >@@ -871,8 +871,7 @@ > * @test Ensures that changing an internal jar and refreshing takes the change into account > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621" > */ >-// TODO (frederic) put back when issue on Linux and Mac/OS will be fixed >-public void _testChangeInternalJar() throws CoreException, IOException { >+public void testChangeInternalJar() throws CoreException, IOException { > IJavaProject project = getJavaProject("Reconciler"); > String jarName = "b162621.jar"; > try { >@@ -884,6 +883,14 @@ > }; > addLibrary(project, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4); > >+ // Wait a little bit to be sure file system is aware of zip file creation >+ try { >+ Thread.sleep(1000); >+ } >+ catch (InterruptedException ie) { >+ // skip >+ } >+ > // Set working copy content with no error > setUpWorkingCopy("/Reconciler/src/test/Test.java", > "package test;\n" + >@@ -932,6 +939,13 @@ > }, jarPath, "1.4"); > project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); > >+ try { >+ Thread.sleep(1000); >+ } >+ catch (InterruptedException ie) { >+ // skip >+ } >+ > // Verify that error is gone > this.problemRequestor.initialize(contents.toCharArray()); > this.workingCopy.reconcile(ICompilationUnit.NO_AST, true, null, null); >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.67.4.2 >diff -u -r1.67.4.2 JavaProjectTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 6 Sep 2006 10:18:31 -0000 1.67.4.2 >+++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 20 Dec 2006 13:37:30 -0000 >@@ -812,13 +812,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); >@@ -851,13 +845,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 13:37:31 -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.8 >diff -u -r1.8 AbstractJavadocCompletionModelTest.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java 31 May 2006 15:08:42 -0000 1.8 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavadocCompletionModelTest.java 20 Dec 2006 13:37:30 -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.flushDirectoryContent(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.55.4.4 >diff -u -r1.55.4.4 TypeHierarchyTests.java >--- src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 6 Oct 2006 09:18:35 -0000 1.55.4.4 >+++ src/org/eclipse/jdt/core/tests/model/TypeHierarchyTests.java 20 Dec 2006 13:37:31 -0000 >@@ -439,9 +439,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/CompletionTests2.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java,v >retrieving revision 1.28.4.2 >diff -u -r1.28.4.2 CompletionTests2.java >--- src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 15 Nov 2006 10:01:19 -0000 1.28.4.2 >+++ src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 20 Dec 2006 13:37:30 -0000 >@@ -2252,8 +2252,7 @@ > * @test Ensures that changing an internal jar and refreshing takes the change into account > * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162621" > */ >-// TODO (frederic) put back when issue on Linux and Mac/OS will be fixed >-public void _testChangeInternalJar() throws CoreException, IOException { >+public void testChangeInternalJar() throws CoreException, IOException { > IJavaProject currentProject = getJavaProject("Completion"); > String jarName = "b162621.jar"; > try { >@@ -2268,6 +2267,14 @@ > }; > addLibrary(currentProject, jarName, "b162621_src.zip", pathAndContents, JavaCore.VERSION_1_4); > >+ // Wait a little bit to be sure file system is aware of zip file creation >+ try { >+ Thread.sleep(1000); >+ } >+ catch (InterruptedException ie) { >+ // skip >+ } >+ > // Create compilation unit in which completion occurs > String path = "/Completion/src/test/Test.java"; > String source = "package test;\n" + >@@ -2306,6 +2313,13 @@ > }, jarPath, "1.4"); > currentProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); > >+ try { >+ Thread.sleep(1000); >+ } >+ catch (InterruptedException ie) { >+ // skip >+ } >+ > // second completion > requestor = new CompletionTestsRequestor2(); > unit.codeComplete(cursorLocation, requestor); >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.152 >diff -u -r1.152 JavaSearchTests.java >--- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 18 Apr 2006 16:28:01 -0000 1.152 >+++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 20 Dec 2006 13:37:31 -0000 >@@ -21,6 +21,7 @@ > import org.eclipse.jdt.core.*; > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.core.search.*; >+import org.eclipse.jdt.core.tests.util.Util; > import org.eclipse.jdt.internal.core.JavaModelStatus; > import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; > >@@ -2073,7 +2074,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.166.2.2 >diff -u -r1.166.2.2 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 23 Oct 2006 20:44:43 -0000 1.166.2.2 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 20 Dec 2006 13:37:30 -0000 >@@ -1145,29 +1145,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)); >@@ -1200,44 +1183,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; > } > } > /** >@@ -1685,8 +1635,10 @@ > IProject project = javaProject.getProject(); > String projectPath = '/' + project.getName() + '/'; > removeLibraryEntry(javaProject, new Path(projectPath + jarName)); >- project.getFile(jarName).delete(false, null); >- project.getFile(sourceZipName).delete(false, null); >+ org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(jarName)); >+ if (sourceZipName != null && sourceZipName.length() != 0) { >+ org.eclipse.jdt.core.tests.util.Util.delete(project.getFile(sourceZipName)); >+ } > } > protected void removeLibraryEntry(IJavaProject project, Path path) throws JavaModelException { > IClasspathEntry[] entries = project.getRawClasspath(); >#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.33.4.2 >diff -u -r1.33.4.2 FullSourceWorkspaceTests.java >--- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 20 Oct 2006 14:11:35 -0000 1.33.4.2 >+++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceTests.java 20 Dec 2006 13:37:34 -0000 >@@ -89,7 +89,7 @@ > // protected final static String JUNIT_PROJECT_NAME = "junit"; > // protected static IJavaProject JUNIT_PROJECT; > >- // Compilaiton variable >+ // Compilation variable > public static final String COMPILER_OUTPUT_DIR; > static { > String outputDir = null; >@@ -836,28 +836,6 @@ > this.scenarioComment.append(warnings); > } > >- /** >- * Delete a directory from file system. >- * @param directory >- */ >- protected void cleanupDirectory(File directory) { >- if (!directory.isDirectory() || !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()); //$NON-NLS-1$ >- } >- } >- if (!directory.delete()) >- System.out.println("Could not delete directory " + directory.getPath()); //$NON-NLS-1$ >- } >- > /* > * Clear given options > */ >@@ -925,7 +903,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 +935,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.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.37 >diff -u -r1.37 JavadocTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 30 Mar 2006 15:26:50 -0000 1.37 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java 20 Dec 2006 13:37:35 -0000 >@@ -365,11 +365,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 { >@@ -411,7 +411,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 >@@ -442,7 +442,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"); >@@ -548,7 +548,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.62 >diff -u -r1.62 AbstractRegressionTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 26 Apr 2006 09:17:16 -0000 1.62 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 20 Dec 2006 13:37:35 -0000 >@@ -259,7 +259,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]); > } > } > } >@@ -269,7 +269,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]); > } > } > } >@@ -883,7 +883,6 @@ > File outputDir = new File(OUTPUT_DIR); > if (outputDir.exists()) { > Util.flushDirectoryContent(outputDir); >- outputDir.delete(); > } > super.tearDown(); > if (RUN_JAVAC) { >@@ -978,29 +977,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()); >- } >- >- /* > * Write given source test files in current output sub-directory. > * Use test name for this sub-directory name (ie. test001, test002, etc...) > */ >@@ -1051,7 +1027,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 >@@ -1082,7 +1058,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"); >@@ -1147,7 +1123,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(); >@@ -1216,7 +1192,7 @@ > } > finally { > // Clean up written file(s) >- cleanupDirectory(outputTestDirectoryPath.toFile()); >+ Util.delete(outputTestDirectory); > } > } > >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.60.2.4 >diff -u -r1.60.2.4 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 9 Nov 2006 00:42:19 -0000 1.60.2.4 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 20 Dec 2006 13:37:35 -0000 >@@ -1682,7 +1682,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 >@@ -2280,11 +2280,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"); > } > >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.56.2.6 >diff -u -r1.56.2.6 LookupTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 6 Oct 2006 09:18:17 -0000 1.56.2.6 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 20 Dec 2006 13:37:36 -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.30 >diff -u -r1.30 DebugEvaluationTest.java >--- src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 29 Mar 2006 03:52:03 -0000 1.30 >+++ src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java 20 Dec 2006 13:37:36 -0000 >@@ -155,12 +155,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.45.4.1 >diff -u -r1.45.4.1 Util.java >--- src/org/eclipse/jdt/core/tests/util/Util.java 2 Jul 2006 10:15:23 -0000 1.45.4.1 >+++ src/org/eclipse/jdt/core/tests/util/Util.java 20 Dec 2006 13:37:36 -0000 >@@ -25,6 +25,9 @@ > import java.util.zip.ZipInputStream; > import java.util.zip.ZipOutputStream; > >+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; >@@ -37,8 +40,101 @@ > 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; >- public static String OUTPUT_DIRECTORY = "comptest"; >+ >+ // Output directory initialization >+ /** >+ * Initially, output directory was located in System.getProperty("user.home")+"\comptest". >+ * To allow user to run several compiler tests at the same time, main output directory >+ * is now located in a sub-directory of "comptest" which name is "run."+<code>System.currentMilliseconds</code>. >+ * >+ * @see #DELAY_BEFORE_CLEAN_PREVIOUS >+ */ >+ private final static String OUTPUT_DIRECTORY; >+ /** >+ * 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. >+ * If value is 0 or negative, then all previous run directories will be removed... >+ * >+ * @see #OUTPUT_DIRECTORY >+ */ >+ private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay"); >+ /* >+ * Static initializer to clean directories created while running previous test suites. >+ */ >+ static { >+ // Get delay for cleaning sub-directories >+ long millisecondsPerHour = 1000L * 3600L; >+ long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours >+ try { >+ if (DELAY_BEFORE_CLEAN_PREVIOUS != null) { >+ float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS); >+ delay = (int) (millisecondsPerHour * hours); >+ } >+ } >+ catch (NumberFormatException nfe) { >+ // use default >+ } >+ >+ // Get output directory root from system properties >+ String container = System.getProperty("jdt.test.output_directory"); >+ if (container == null){ >+ container = System.getProperty("user.home"); >+ } >+ if (container == null) { >+ container = "."; // use current directory >+ } >+ >+ // Get file for root directory >+ if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') { >+ container = Character.toUpperCase(container.charAt(0)) + container.substring(1); >+ } >+ File dir = new File(new File(container), "comptest"); >+ >+ // If root directory already exists, clean it >+ if (dir.exists()) { >+ long now = System.currentTimeMillis(); >+ if ((now - dir.lastModified()) > delay) { >+ // remove all directory content >+ flushDirectoryContent(dir); >+ } else { >+ // remove only old sub-dirs >+ File[] testDirs = dir.listFiles(); >+ for (int i=0,l=testDirs.length; i<l; i++) { >+ if (testDirs[i].isDirectory()) { >+ if ((now - testDirs[i].lastModified()) > delay) { >+ delete(testDirs[i]); >+ } >+ } >+ } >+ } >+ } >+ >+ // Computed test run directory name based on current time >+ File dateDir = new File(dir, "run."+System.currentTimeMillis()); >+ OUTPUT_DIRECTORY = dateDir.getPath(); >+ } > > public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { > problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); >@@ -158,8 +254,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 (!delete(destFile)) { >+ throw new IOException(destFile + " is in use"); >+ } > } > out = new FileOutputStream(destFile); > int bufferLength = 1024; >@@ -231,6 +329,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 > * >@@ -446,17 +592,10 @@ > * 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]); > } > } > /** >@@ -547,11 +686,82 @@ > * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] > */ > public static String getOutputDirectory() { >- String container = System.getProperty("user.home"); >- if (container == null){ >- return null; >+ 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 toNativePath(container) + File.separator + OUTPUT_DIRECTORY; >+ 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) >@@ -571,10 +781,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. > */ >@@ -637,6 +970,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; >@@ -660,7 +1144,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) { >@@ -669,20 +1155,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.25 >diff -u -r1.25 AbstractCompilerTest.java >--- src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 30 Mar 2006 15:26:50 -0000 1.25 >+++ src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java 20 Dec 2006 13:37:36 -0000 >@@ -416,9 +416,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 >@@ -428,11 +427,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(); > } > } > /* >@@ -446,15 +443,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 13:37:36 -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); > } > } > /**
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