Lines 25-30
Link Here
|
25 |
import java.util.zip.ZipInputStream; |
25 |
import java.util.zip.ZipInputStream; |
26 |
import java.util.zip.ZipOutputStream; |
26 |
import java.util.zip.ZipOutputStream; |
27 |
|
27 |
|
|
|
28 |
import org.eclipse.core.resources.IContainer; |
29 |
import org.eclipse.core.resources.IResource; |
30 |
import org.eclipse.core.runtime.CoreException; |
28 |
import org.eclipse.jdt.core.compiler.IProblem; |
31 |
import org.eclipse.jdt.core.compiler.IProblem; |
29 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
32 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
30 |
import org.eclipse.jdt.internal.compiler.Compiler; |
33 |
import org.eclipse.jdt.internal.compiler.Compiler; |
Lines 37-44
Link Here
|
37 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
40 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
38 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
41 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
39 |
public class Util { |
42 |
public class Util { |
|
|
43 |
// Trace for delete operation |
44 |
/* |
45 |
* Maximum time wasted repeating delete operations while running JDT/Core tests. |
46 |
*/ |
47 |
private static int DELETE_MAX_TIME = 0; |
48 |
/** |
49 |
* Trace deletion operations while running JDT/Core tests. |
50 |
*/ |
51 |
public static boolean DELETE_DEBUG = false; |
52 |
/** |
53 |
* Maximum of time in ms to wait in deletion operation while running JDT/Core tests. |
54 |
* Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000). |
55 |
* <br> |
56 |
* To avoid too many loops while waiting, the ten first ones are done waiting |
57 |
* 10ms before repeating, the ten loops after are done waiting 100ms and |
58 |
* the other loops are done waiting 1s... |
59 |
*/ |
60 |
public static int DELETE_MAX_WAIT = 10000; |
61 |
|
40 |
private static final boolean DEBUG = false; |
62 |
private static final boolean DEBUG = false; |
41 |
public static String OUTPUT_DIRECTORY = "comptest"; |
63 |
|
|
|
64 |
// Output directory initialization |
65 |
/** |
66 |
* Initially, output directory was located in System.getProperty("user.home")+"\comptest". |
67 |
* To allow user to run several compiler tests at the same time, main output directory |
68 |
* is now located in a sub-directory of "comptest" which name is "run."+<code>System.currentMilliseconds</code>. |
69 |
* |
70 |
* @see #DELAY_BEFORE_CLEAN_PREVIOUS |
71 |
*/ |
72 |
private final static String OUTPUT_DIRECTORY; |
73 |
/** |
74 |
* Let user specify the delay in hours before output directories are removed from file system |
75 |
* while starting a new test run. Default value is 2 hours. |
76 |
* <p> |
77 |
* Note that this value may be a float and so have time less than one hour. |
78 |
* If value is 0 or negative, then all previous run directories will be removed... |
79 |
* |
80 |
* @see #OUTPUT_DIRECTORY |
81 |
*/ |
82 |
private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay"); |
83 |
/* |
84 |
* Static initializer to clean directories created while running previous test suites. |
85 |
*/ |
86 |
static { |
87 |
// Get delay for cleaning sub-directories |
88 |
long millisecondsPerHour = 1000L * 3600L; |
89 |
long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours |
90 |
try { |
91 |
if (DELAY_BEFORE_CLEAN_PREVIOUS != null) { |
92 |
float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS); |
93 |
delay = (int) (millisecondsPerHour * hours); |
94 |
} |
95 |
} |
96 |
catch (NumberFormatException nfe) { |
97 |
// use default |
98 |
} |
99 |
|
100 |
// Get output directory root from system properties |
101 |
String container = System.getProperty("jdt.test.output_directory"); |
102 |
if (container == null){ |
103 |
container = System.getProperty("user.home"); |
104 |
} |
105 |
if (container == null) { |
106 |
container = "."; // use current directory |
107 |
} |
108 |
|
109 |
// Get file for root directory |
110 |
if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') { |
111 |
container = Character.toUpperCase(container.charAt(0)) + container.substring(1); |
112 |
} |
113 |
File dir = new File(new File(container), "comptest"); |
114 |
|
115 |
// If root directory already exists, clean it |
116 |
if (dir.exists()) { |
117 |
long now = System.currentTimeMillis(); |
118 |
if ((now - dir.lastModified()) > delay) { |
119 |
// remove all directory content |
120 |
flushDirectoryContent(dir); |
121 |
} else { |
122 |
// remove only old sub-dirs |
123 |
File[] testDirs = dir.listFiles(); |
124 |
for (int i=0,l=testDirs.length; i<l; i++) { |
125 |
if (testDirs[i].isDirectory()) { |
126 |
if ((now - testDirs[i].lastModified()) > delay) { |
127 |
delete(testDirs[i]); |
128 |
} |
129 |
} |
130 |
} |
131 |
} |
132 |
} |
133 |
|
134 |
// Computed test run directory name based on current time |
135 |
File dateDir = new File(dir, "run."+System.currentTimeMillis()); |
136 |
OUTPUT_DIRECTORY = dateDir.getPath(); |
137 |
} |
42 |
|
138 |
|
43 |
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { |
139 |
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { |
44 |
problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); |
140 |
problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); |
Lines 158-165
Link Here
|
158 |
try { |
254 |
try { |
159 |
in = new FileInputStream(source); |
255 |
in = new FileInputStream(source); |
160 |
File destFile = new File(dest, source.getName()); |
256 |
File destFile = new File(dest, source.getName()); |
161 |
if (destFile.exists() && !destFile.delete()) { |
257 |
if (destFile.exists()) { |
162 |
throw new IOException(destFile + " is in use"); |
258 |
if (!delete(destFile)) { |
|
|
259 |
throw new IOException(destFile + " is in use"); |
260 |
} |
163 |
} |
261 |
} |
164 |
out = new FileOutputStream(destFile); |
262 |
out = new FileOutputStream(destFile); |
165 |
int bufferLength = 1024; |
263 |
int bufferLength = 1024; |
Lines 231-236
Link Here
|
231 |
zip(sourcesDir, zipPath); |
329 |
zip(sourcesDir, zipPath); |
232 |
} |
330 |
} |
233 |
/** |
331 |
/** |
|
|
332 |
* Delete a file or directory and insure that the file is no longer present |
333 |
* on file system. In case of directory, delete all the hierarchy underneath. |
334 |
* |
335 |
* @param file The file or directory to delete |
336 |
* @return true iff the file was really delete, false otherwise |
337 |
*/ |
338 |
public static boolean delete(File file) { |
339 |
// flush all directory content |
340 |
if (file.isDirectory()) { |
341 |
flushDirectoryContent(file); |
342 |
} |
343 |
// remove file |
344 |
file.delete(); |
345 |
if (isFileDeleted(file)) { |
346 |
return true; |
347 |
} |
348 |
return waitUntilFileDeleted(file); |
349 |
} |
350 |
/** |
351 |
* Delete a file or directory and insure that the file is no longer present |
352 |
* on file system. In case of directory, delete all the hierarchy underneath. |
353 |
* |
354 |
* @param resource The resource to delete |
355 |
* @return true iff the file was really delete, false otherwise |
356 |
*/ |
357 |
public static boolean delete(IResource resource) { |
358 |
try { |
359 |
resource.delete(true, null); |
360 |
if (isResourceDeleted(resource)) { |
361 |
return true; |
362 |
} |
363 |
} |
364 |
catch (CoreException e) { |
365 |
// skip |
366 |
} |
367 |
return waitUntilResourceDeleted(resource); |
368 |
} |
369 |
/** |
370 |
* Delete a file or directory and insure that the file is no longer present |
371 |
* on file system. In case of directory, delete all the hierarchy underneath. |
372 |
* |
373 |
* @param path The path of the file or directory to delete |
374 |
* @return true iff the file was really delete, false otherwise |
375 |
*/ |
376 |
public static boolean delete(String path) { |
377 |
return delete(new File(path)); |
378 |
} |
379 |
/** |
234 |
* Generate a display string from the given String. |
380 |
* Generate a display string from the given String. |
235 |
* @param inputString the given input string |
381 |
* @param inputString the given input string |
236 |
* |
382 |
* |
Lines 446-462
Link Here
|
446 |
* no-op if not a directory. |
592 |
* no-op if not a directory. |
447 |
*/ |
593 |
*/ |
448 |
public static void flushDirectoryContent(File dir) { |
594 |
public static void flushDirectoryContent(File dir) { |
449 |
if (dir.isDirectory()) { |
595 |
File[] files = dir.listFiles(); |
450 |
String[] files = dir.list(); |
596 |
if (files == null) return; |
451 |
if (files == null) return; |
597 |
for (int i = 0, max = files.length; i < max; i++) { |
452 |
for (int i = 0, max = files.length; i < max; i++) { |
598 |
delete(files[i]); |
453 |
File current = new File(dir, files[i]); |
|
|
454 |
if (current.isDirectory()) { |
455 |
flushDirectoryContent(current); |
456 |
} |
457 |
if (!current.delete()) |
458 |
System.err.println("Could not delete " + current.getName()); |
459 |
} |
460 |
} |
599 |
} |
461 |
} |
600 |
} |
462 |
/** |
601 |
/** |
Lines 547-557
Link Here
|
547 |
* Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] |
686 |
* Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] |
548 |
*/ |
687 |
*/ |
549 |
public static String getOutputDirectory() { |
688 |
public static String getOutputDirectory() { |
550 |
String container = System.getProperty("user.home"); |
689 |
return OUTPUT_DIRECTORY; |
551 |
if (container == null){ |
690 |
} |
552 |
return null; |
691 |
/** |
|
|
692 |
* Returns the parent's child file matching the given file or null if not found. |
693 |
* |
694 |
* @param file The searched file in parent |
695 |
* @return The parent's child matching the given file or null if not found. |
696 |
*/ |
697 |
private static File getParentChildFile(File file) { |
698 |
File parent = file.getParentFile(); |
699 |
if (parent == null || !parent.exists()) return null; |
700 |
File[] files = parent.listFiles(); |
701 |
int length = files==null ? 0 : files.length; |
702 |
if (length > 0) { |
703 |
for (int i=0; i<length; i++) { |
704 |
if (files[i] == file) { |
705 |
return files[i]; |
706 |
} else if (files[i].equals(file)) { |
707 |
return files[i]; |
708 |
} else if (files[i].getPath().equals(file.getPath())) { |
709 |
return files[i]; |
710 |
} |
711 |
} |
712 |
} |
713 |
return null; |
714 |
} |
715 |
/** |
716 |
* Returns parent's child resource matching the given resource or null if not found. |
717 |
* |
718 |
* @param resource The searched file in parent |
719 |
* @return The parent's child matching the given file or null if not found. |
720 |
*/ |
721 |
private static IResource getParentChildResource(IResource resource) { |
722 |
IContainer parent = resource.getParent(); |
723 |
if (parent == null || !parent.exists()) return null; |
724 |
try { |
725 |
IResource[] members = parent.members(); |
726 |
int length = members ==null ? 0 : members.length; |
727 |
if (length > 0) { |
728 |
for (int i=0; i<length; i++) { |
729 |
if (members[i] == resource) { |
730 |
return members[i]; |
731 |
} else if (members[i].equals(resource)) { |
732 |
return members[i]; |
733 |
} else if (members[i].getFullPath().equals(resource.getFullPath())) { |
734 |
return members[i]; |
735 |
} |
736 |
} |
737 |
} |
738 |
} |
739 |
catch (CoreException ce) { |
740 |
// skip |
553 |
} |
741 |
} |
554 |
return toNativePath(container) + File.separator + OUTPUT_DIRECTORY; |
742 |
return null; |
|
|
743 |
} |
744 |
/** |
745 |
* Returns the test name from stack elements info. |
746 |
* |
747 |
* @return The name of the test currently running |
748 |
*/ |
749 |
private static String getTestName() { |
750 |
StackTraceElement[] elements = new Exception().getStackTrace(); |
751 |
int idx = 0, length=elements.length; |
752 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
753 |
// loop until JDT/Core class appears in the stack |
754 |
} |
755 |
if (idx<length) { |
756 |
StackTraceElement testElement = null; |
757 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
758 |
testElement = elements[idx++]; |
759 |
} |
760 |
if (testElement != null) { |
761 |
return testElement.getClassName() + " - " + testElement.getMethodName(); |
762 |
} |
763 |
} |
764 |
return "?"; |
555 |
} |
765 |
} |
556 |
public static String indentString(String inputString, int indent) { |
766 |
public static String indentString(String inputString, int indent) { |
557 |
if (inputString == null) |
767 |
if (inputString == null) |
Lines 571-580
Link Here
|
571 |
} |
781 |
} |
572 |
return buffer.toString(); |
782 |
return buffer.toString(); |
573 |
} |
783 |
} |
|
|
784 |
/** |
785 |
* Returns whether a file is really deleted or not. |
786 |
* Does not only rely on {@link File#exists()} method but also |
787 |
* look if it's not in its parent children {@link #getParentChildFile(File)}. |
788 |
* |
789 |
* @param file The file to test if deleted |
790 |
* @return true if the file does not exist and was not found in its parent children. |
791 |
*/ |
792 |
public static boolean isFileDeleted(File file) { |
793 |
return !file.exists() && getParentChildFile(file) == null; |
794 |
} |
574 |
public static boolean isMacOS() { |
795 |
public static boolean isMacOS() { |
575 |
return System.getProperty("os.name").indexOf("Mac") != -1; |
796 |
return System.getProperty("os.name").indexOf("Mac") != -1; |
576 |
} |
797 |
} |
577 |
/** |
798 |
/** |
|
|
799 |
* Returns whether a resource is really deleted or not. |
800 |
* Does not only rely on {@link IResource#isAccessible()} method but also |
801 |
* look if it's not in its parent children {@link #getParentChildResource(IResource)}. |
802 |
* |
803 |
* @param resource The resource to test if deleted |
804 |
* @return true if the resource is not accessible and was not found in its parent children. |
805 |
*/ |
806 |
public static boolean isResourceDeleted(IResource resource) { |
807 |
return !resource.isAccessible() && getParentChildResource(resource) == null; |
808 |
} |
809 |
/** |
810 |
* Print given file information with specified indentation. |
811 |
* These information are:<ul> |
812 |
* <li>read {@link File#canRead()}</li> |
813 |
* <li>write {@link File#canWrite()}</li> |
814 |
* <li>exists {@link File#exists()}</li> |
815 |
* <li>is file {@link File#isFile()}</li> |
816 |
* <li>is directory {@link File#isDirectory()}</li> |
817 |
* <li>is hidden {@link File#isHidden()}</li> |
818 |
* </ul> |
819 |
* May recurse several level in parents hierarchy. |
820 |
* May also display children, but then will not recusre in parent |
821 |
* hierarchy to avoid infinite loop... |
822 |
* |
823 |
* @param file The file to display information |
824 |
* @param indent Number of tab to print before the information |
825 |
* @param recurse Display also information on <code>recurse</code>th parents in hierarchy. |
826 |
* If negative then display children information instead. |
827 |
*/ |
828 |
private static void printFileInfo(File file, int indent, int recurse) { |
829 |
String tab = ""; |
830 |
for (int i=0; i<indent; i++) tab+="\t"; |
831 |
System.out.print(tab+"- "+file.getName()+" file info: "); |
832 |
String sep = ""; |
833 |
if (file.canRead()) { |
834 |
System.out.print("read"); |
835 |
sep = ", "; |
836 |
} |
837 |
if (file.canWrite()) { |
838 |
System.out.print(sep+"write"); |
839 |
sep = ", "; |
840 |
} |
841 |
if (file.exists()) { |
842 |
System.out.print(sep+"exist"); |
843 |
sep = ", "; |
844 |
} |
845 |
if (file.isDirectory()) { |
846 |
System.out.print(sep+"dir"); |
847 |
sep = ", "; |
848 |
} |
849 |
if (file.isFile()) { |
850 |
System.out.print(sep+"file"); |
851 |
sep = ", "; |
852 |
} |
853 |
if (file.isHidden()) { |
854 |
System.out.print(sep+"hidden"); |
855 |
sep = ", "; |
856 |
} |
857 |
System.out.println(); |
858 |
File[] files = file.listFiles(); |
859 |
int length = files==null ? 0 : files.length; |
860 |
if (length > 0) { |
861 |
boolean children = recurse < 0; |
862 |
System.out.print(tab+" + children: "); |
863 |
if (children) System.out.println(); |
864 |
for (int i=0; i<length; i++) { |
865 |
if (children) { // display children |
866 |
printFileInfo(files[i], indent+2, -1); |
867 |
} else { |
868 |
if (i>0) System.out.print(", "); |
869 |
System.out.print(files[i].getName()); |
870 |
if (files[i].isDirectory()) System.out.print("[dir]"); |
871 |
else if (files[i].isFile()) System.out.print("[file]"); |
872 |
else System.out.print("[?]"); |
873 |
} |
874 |
} |
875 |
if (!children) System.out.println(); |
876 |
} |
877 |
if (recurse > 0) { |
878 |
File parent = file.getParentFile(); |
879 |
if (parent != null) printFileInfo(parent, indent+1, recurse-1); |
880 |
} |
881 |
} |
882 |
/** |
883 |
* Print stack trace with only JDT/Core elements. |
884 |
* |
885 |
* @param exception Exception of the stack trace. May be null, then a fake exception is used. |
886 |
* @param indent Number of tab to display before the stack elements to display. |
887 |
*/ |
888 |
private static void printJdtCoreStackTrace(Exception exception, int indent) { |
889 |
String tab = ""; |
890 |
for (int i=0; i<indent; i++) tab+="\t"; |
891 |
StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace(); |
892 |
int idx = 0, length=elements.length; |
893 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
894 |
// loop until JDT/Core class appears in the stack |
895 |
} |
896 |
if (idx<length) { |
897 |
System.out.print(tab+"- stack trace"); |
898 |
if (exception == null) |
899 |
System.out.println(":"); |
900 |
else |
901 |
System.out.println(" for exception "+exception+":"); |
902 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
903 |
StackTraceElement testElement = elements[idx++]; |
904 |
System.out.println(tab+" -> "+testElement); |
905 |
} |
906 |
} else { |
907 |
exception.printStackTrace(System.out); |
908 |
} |
909 |
} |
910 |
/** |
578 |
* Makes the given path a path using native path separators as returned by File.getPath() |
911 |
* Makes the given path a path using native path separators as returned by File.getPath() |
579 |
* and trimming any extra slash. |
912 |
* and trimming any extra slash. |
580 |
*/ |
913 |
*/ |
Lines 637-642
Link Here
|
637 |
} |
970 |
} |
638 |
} |
971 |
} |
639 |
} |
972 |
} |
|
|
973 |
/** |
974 |
* Wait until the file is _really_ deleted on file system. |
975 |
* |
976 |
* @param file Deleted file |
977 |
* @return true if the file was finally deleted, false otherwise |
978 |
*/ |
979 |
private static boolean waitUntilFileDeleted(File file) { |
980 |
if (DELETE_DEBUG) { |
981 |
System.out.println(); |
982 |
System.out.println("WARNING in test: "+getTestName()); |
983 |
System.out.println(" - problems occured while deleting "+file); |
984 |
printJdtCoreStackTrace(null, 1); |
985 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
986 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
987 |
} |
988 |
int count = 0; |
989 |
int delay = 10; // ms |
990 |
int maxRetry = DELETE_MAX_WAIT / delay; |
991 |
int time = 0; |
992 |
while (count < maxRetry) { |
993 |
try { |
994 |
count++; |
995 |
Thread.sleep(delay); |
996 |
time += delay; |
997 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
998 |
if (DELETE_DEBUG) System.out.print('.'); |
999 |
if (file.exists()) { |
1000 |
if (file.delete()) { |
1001 |
// SUCCESS |
1002 |
if (DELETE_DEBUG) { |
1003 |
System.out.println(); |
1004 |
System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1005 |
System.out.println(); |
1006 |
} |
1007 |
return true; |
1008 |
} |
1009 |
} |
1010 |
if (isFileDeleted(file)) { |
1011 |
// SUCCESS |
1012 |
if (DELETE_DEBUG) { |
1013 |
System.out.println(); |
1014 |
System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1015 |
System.out.println(); |
1016 |
} |
1017 |
return true; |
1018 |
} |
1019 |
// Increment waiting delay exponentially |
1020 |
if (count >= 10 && delay <= 100) { |
1021 |
count = 1; |
1022 |
delay *= 10; |
1023 |
maxRetry = DELETE_MAX_WAIT / delay; |
1024 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
1025 |
maxRetry++; |
1026 |
} |
1027 |
} |
1028 |
} |
1029 |
catch (InterruptedException ie) { |
1030 |
break; // end loop |
1031 |
} |
1032 |
} |
1033 |
if (!DELETE_DEBUG) { |
1034 |
System.out.println(); |
1035 |
System.out.println("WARNING in test: "+getTestName()); |
1036 |
System.out.println(" - problems occured while deleting "+file); |
1037 |
printJdtCoreStackTrace(null, 1); |
1038 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1039 |
} |
1040 |
System.out.println(); |
1041 |
System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1042 |
System.out.println(); |
1043 |
return false; |
1044 |
} |
1045 |
/** |
1046 |
* Wait until a resource is _really_ deleted on file system. |
1047 |
* |
1048 |
* @param resource Deleted resource |
1049 |
* @return true if the file was finally deleted, false otherwise |
1050 |
*/ |
1051 |
private static boolean waitUntilResourceDeleted(IResource resource) { |
1052 |
File file = resource.getLocation().toFile(); |
1053 |
if (DELETE_DEBUG) { |
1054 |
System.out.println(); |
1055 |
System.out.println("WARNING in test: "+getTestName()); |
1056 |
System.out.println(" - problems occured while deleting resource "+resource); |
1057 |
printJdtCoreStackTrace(null, 1); |
1058 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1059 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
1060 |
} |
1061 |
int count = 0; |
1062 |
int delay = 10; // ms |
1063 |
int maxRetry = DELETE_MAX_WAIT / delay; |
1064 |
int time = 0; |
1065 |
while (count < maxRetry) { |
1066 |
try { |
1067 |
count++; |
1068 |
Thread.sleep(delay); |
1069 |
time += delay; |
1070 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
1071 |
if (DELETE_DEBUG) System.out.print('.'); |
1072 |
if (resource.isAccessible()) { |
1073 |
try { |
1074 |
resource.delete(true, null); |
1075 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1076 |
// SUCCESS |
1077 |
if (DELETE_DEBUG) { |
1078 |
System.out.println(); |
1079 |
System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1080 |
System.out.println(); |
1081 |
} |
1082 |
return true; |
1083 |
} |
1084 |
} |
1085 |
catch (CoreException e) { |
1086 |
// skip |
1087 |
} |
1088 |
} |
1089 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1090 |
// SUCCESS |
1091 |
if (DELETE_DEBUG) { |
1092 |
System.out.println(); |
1093 |
System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1094 |
System.out.println(); |
1095 |
} |
1096 |
return true; |
1097 |
} |
1098 |
// Increment waiting delay exponentially |
1099 |
if (count >= 10 && delay <= 100) { |
1100 |
count = 1; |
1101 |
delay *= 10; |
1102 |
maxRetry = DELETE_MAX_WAIT / delay; |
1103 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
1104 |
maxRetry++; |
1105 |
} |
1106 |
} |
1107 |
} |
1108 |
catch (InterruptedException ie) { |
1109 |
break; // end loop |
1110 |
} |
1111 |
} |
1112 |
if (!DELETE_DEBUG) { |
1113 |
System.out.println(); |
1114 |
System.out.println("WARNING in test: "+getTestName()); |
1115 |
System.out.println(" - problems occured while deleting resource "+resource); |
1116 |
printJdtCoreStackTrace(null, 1); |
1117 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1118 |
} |
1119 |
System.out.println(); |
1120 |
System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1121 |
System.out.println(); |
1122 |
return false; |
1123 |
} |
640 |
public static void writeToFile(String contents, String destinationFilePath) { |
1124 |
public static void writeToFile(String contents, String destinationFilePath) { |
641 |
File destFile = new File(destinationFilePath); |
1125 |
File destFile = new File(destinationFilePath); |
642 |
FileOutputStream output = null; |
1126 |
FileOutputStream output = null; |
Lines 660-666
Link Here
|
660 |
public static void zip(File rootDir, String zipPath) throws IOException { |
1144 |
public static void zip(File rootDir, String zipPath) throws IOException { |
661 |
ZipOutputStream zip = null; |
1145 |
ZipOutputStream zip = null; |
662 |
try { |
1146 |
try { |
663 |
zip = new ZipOutputStream(new FileOutputStream(zipPath)); |
1147 |
File zipFile = new File(zipPath); |
|
|
1148 |
if (zipFile.exists()) delete(zipFile); |
1149 |
zip = new ZipOutputStream(new FileOutputStream(zipFile)); |
664 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
1150 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
665 |
} finally { |
1151 |
} finally { |
666 |
if (zip != null) { |
1152 |
if (zip != null) { |
Lines 669-688
Link Here
|
669 |
} |
1155 |
} |
670 |
} |
1156 |
} |
671 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
1157 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
672 |
String[] list = dir.list(); |
1158 |
File[] files = dir.listFiles(); |
673 |
if (list != null) { |
1159 |
if (files != null) { |
674 |
for (int i = 0, length = list.length; i < length; i++) { |
1160 |
for (int i = 0, length = files.length; i < length; i++) { |
675 |
String name = list[i]; |
1161 |
File file = files[i]; |
676 |
File file = new File(dir, name); |
1162 |
if (file.isFile()) { |
677 |
if (file.isDirectory()) { |
|
|
678 |
zip(file, zip, rootPathLength); |
679 |
} else { |
680 |
String path = file.getPath(); |
1163 |
String path = file.getPath(); |
681 |
path = path.substring(rootPathLength); |
1164 |
path = path.substring(rootPathLength); |
682 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
1165 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
683 |
zip.putNextEntry(entry); |
1166 |
zip.putNextEntry(entry); |
684 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
1167 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
685 |
zip.closeEntry(); |
1168 |
zip.closeEntry(); |
|
|
1169 |
} else { |
1170 |
zip(file, zip, rootPathLength); |
686 |
} |
1171 |
} |
687 |
} |
1172 |
} |
688 |
} |
1173 |
} |