Lines 19-24
Link Here
|
19 |
import java.util.zip.ZipInputStream; |
19 |
import java.util.zip.ZipInputStream; |
20 |
import java.util.zip.ZipOutputStream; |
20 |
import java.util.zip.ZipOutputStream; |
21 |
|
21 |
|
|
|
22 |
import org.eclipse.core.resources.IContainer; |
23 |
import org.eclipse.core.resources.IResource; |
24 |
import org.eclipse.core.runtime.CoreException; |
22 |
import org.eclipse.jdt.core.compiler.IProblem; |
25 |
import org.eclipse.jdt.core.compiler.IProblem; |
23 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
26 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
24 |
import org.eclipse.jdt.internal.compiler.Compiler; |
27 |
import org.eclipse.jdt.internal.compiler.Compiler; |
Lines 31-37
Link Here
|
31 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
34 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
32 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
35 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
33 |
public class Util { |
36 |
public class Util { |
34 |
public static String OUTPUT_DIRECTORY = "comptest"; |
37 |
// Trace for delete operation |
|
|
38 |
/* |
39 |
* Maximum time wasted repeating delete operations while running JDT/Core tests. |
40 |
*/ |
41 |
private static int DELETE_MAX_TIME = 0; |
42 |
/** |
43 |
* Trace deletion operations while running JDT/Core tests. |
44 |
*/ |
45 |
public static boolean DELETE_DEBUG = false; |
46 |
/** |
47 |
* Maximum of time in ms to wait in deletion operation while running JDT/Core tests. |
48 |
* Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000). |
49 |
* <br> |
50 |
* To avoid too many loops while waiting, the ten first ones are done waiting |
51 |
* 10ms before repeating, the ten loops after are done waiting 100ms and |
52 |
* the other loops are done waiting 1s... |
53 |
*/ |
54 |
public static int DELETE_MAX_WAIT = 10000; |
55 |
|
56 |
// Output directory initialization |
57 |
/** |
58 |
* Initially, output directory was located in System.getProperty("user.home")+"\comptest". |
59 |
* To allow user to run several compiler tests at the same time, main output directory |
60 |
* is now located in a sub-directory of "comptest" which name is "run."+<code>System.currentMilliseconds</code>. |
61 |
* |
62 |
* @see #DELAY_BEFORE_CLEAN_PREVIOUS |
63 |
*/ |
64 |
private final static String OUTPUT_DIRECTORY; |
65 |
/** |
66 |
* Let user specify the delay in hours before output directories are removed from file system |
67 |
* while starting a new test run. Default value is 2 hours. |
68 |
* <p> |
69 |
* Note that this value may be a float and so have time less than one hour. |
70 |
* If value is 0 or negative, then all previous run directories will be removed... |
71 |
* |
72 |
* @see #OUTPUT_DIRECTORY |
73 |
*/ |
74 |
private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay"); |
75 |
/* |
76 |
* Static initializer to clean directories created while running previous test suites. |
77 |
*/ |
78 |
static { |
79 |
// Get delay for cleaning sub-directories |
80 |
long millisecondsPerHour = 1000L * 3600L; |
81 |
long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours |
82 |
try { |
83 |
if (DELAY_BEFORE_CLEAN_PREVIOUS != null) { |
84 |
float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS); |
85 |
delay = (int) (millisecondsPerHour * hours); |
86 |
} |
87 |
} |
88 |
catch (NumberFormatException nfe) { |
89 |
// use default |
90 |
} |
91 |
|
92 |
// Get output directory root from system properties |
93 |
String container = System.getProperty("jdt.test.output_directory"); |
94 |
if (container == null){ |
95 |
container = System.getProperty("user.home"); |
96 |
} |
97 |
if (container == null) { |
98 |
container = "."; // use current directory |
99 |
} |
100 |
|
101 |
// Get file for root directory |
102 |
if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') { |
103 |
container = Character.toUpperCase(container.charAt(0)) + container.substring(1); |
104 |
} |
105 |
File dir = new File(new File(container), "comptest"); |
106 |
|
107 |
// If root directory already exists, clean it |
108 |
if (dir.exists()) { |
109 |
long now = System.currentTimeMillis(); |
110 |
if ((now - dir.lastModified()) > delay) { |
111 |
// remove all directory content |
112 |
flushDirectoryContent(dir); |
113 |
} else { |
114 |
// remove only old sub-dirs |
115 |
File[] testDirs = dir.listFiles(); |
116 |
for (int i=0,l=testDirs.length; i<l; i++) { |
117 |
if (testDirs[i].isDirectory()) { |
118 |
if ((now - testDirs[i].lastModified()) > delay) { |
119 |
delete(testDirs[i]); |
120 |
} |
121 |
} |
122 |
} |
123 |
} |
124 |
} |
125 |
|
126 |
// Computed test run directory name based on current time |
127 |
File dateDir = new File(dir, "run."+System.currentTimeMillis()); |
128 |
OUTPUT_DIRECTORY = dateDir.getPath(); |
129 |
} |
35 |
|
130 |
|
36 |
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { |
131 |
public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { |
37 |
problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); |
132 |
problems.append(problemCount + (problem.isError() ? ". ERROR" : ". WARNING")); |
Lines 146-153
Link Here
|
146 |
try { |
241 |
try { |
147 |
in = new FileInputStream(source); |
242 |
in = new FileInputStream(source); |
148 |
File destFile = new File(dest, source.getName()); |
243 |
File destFile = new File(dest, source.getName()); |
149 |
if (destFile.exists() && !destFile.delete()) { |
244 |
if (destFile.exists()) { |
150 |
throw new IOException(destFile + " is in use"); |
245 |
if (!delete(destFile)) { |
|
|
246 |
throw new IOException(destFile + " is in use"); |
247 |
} |
151 |
} |
248 |
} |
152 |
out = new FileOutputStream(destFile); |
249 |
out = new FileOutputStream(destFile); |
153 |
int bufferLength = 1024; |
250 |
int bufferLength = 1024; |
Lines 218-223
Link Here
|
218 |
zip(sourcesDir, zipPath); |
315 |
zip(sourcesDir, zipPath); |
219 |
} |
316 |
} |
220 |
/** |
317 |
/** |
|
|
318 |
* Delete a file or directory and insure that the file is no longer present |
319 |
* on file system. In case of directory, delete all the hierarchy underneath. |
320 |
* |
321 |
* @param file The file or directory to delete |
322 |
* @return true iff the file was really delete, false otherwise |
323 |
*/ |
324 |
public static boolean delete(File file) { |
325 |
// flush all directory content |
326 |
if (file.isDirectory()) { |
327 |
flushDirectoryContent(file); |
328 |
} |
329 |
// remove file |
330 |
file.delete(); |
331 |
if (isFileDeleted(file)) { |
332 |
return true; |
333 |
} |
334 |
return waitUntilFileDeleted(file); |
335 |
} |
336 |
/** |
337 |
* Delete a file or directory and insure that the file is no longer present |
338 |
* on file system. In case of directory, delete all the hierarchy underneath. |
339 |
* |
340 |
* @param resource The resource to delete |
341 |
* @return true iff the file was really delete, false otherwise |
342 |
*/ |
343 |
public static boolean delete(IResource resource) { |
344 |
try { |
345 |
resource.delete(true, null); |
346 |
if (isResourceDeleted(resource)) { |
347 |
return true; |
348 |
} |
349 |
} |
350 |
catch (CoreException e) { |
351 |
// skip |
352 |
} |
353 |
return waitUntilResourceDeleted(resource); |
354 |
} |
355 |
/** |
356 |
* Delete a file or directory and insure that the file is no longer present |
357 |
* on file system. In case of directory, delete all the hierarchy underneath. |
358 |
* |
359 |
* @param path The path of the file or directory to delete |
360 |
* @return true iff the file was really delete, false otherwise |
361 |
*/ |
362 |
public static boolean delete(String path) { |
363 |
return delete(new File(path)); |
364 |
} |
365 |
/** |
221 |
* Generate a display string from the given String. |
366 |
* Generate a display string from the given String. |
222 |
* @param inputString the given input string |
367 |
* @param inputString the given input string |
223 |
* |
368 |
* |
Lines 433-448
Link Here
|
433 |
* no-op if not a directory. |
578 |
* no-op if not a directory. |
434 |
*/ |
579 |
*/ |
435 |
public static void flushDirectoryContent(File dir) { |
580 |
public static void flushDirectoryContent(File dir) { |
436 |
if (dir.isDirectory()) { |
581 |
File[] files = dir.listFiles(); |
437 |
String[] files = dir.list(); |
582 |
if (files == null) return; |
438 |
if (files == null) return; |
583 |
for (int i = 0, max = files.length; i < max; i++) { |
439 |
for (int i = 0, max = files.length; i < max; i++) { |
584 |
delete(files[i]); |
440 |
File current = new File(dir, files[i]); |
|
|
441 |
if (current.isDirectory()) { |
442 |
flushDirectoryContent(current); |
443 |
} |
444 |
current.delete(); |
445 |
} |
446 |
} |
585 |
} |
447 |
} |
586 |
} |
448 |
/** |
587 |
/** |
Lines 499-509
Link Here
|
499 |
* Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] |
638 |
* Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] |
500 |
*/ |
639 |
*/ |
501 |
public static String getOutputDirectory() { |
640 |
public static String getOutputDirectory() { |
502 |
String container = System.getProperty("user.home"); |
641 |
return OUTPUT_DIRECTORY; |
503 |
if (container == null){ |
642 |
} |
504 |
return null; |
643 |
/** |
|
|
644 |
* Returns the parent's child file matching the given file or null if not found. |
645 |
* |
646 |
* @param file The searched file in parent |
647 |
* @return The parent's child matching the given file or null if not found. |
648 |
*/ |
649 |
private static File getParentChildFile(File file) { |
650 |
File parent = file.getParentFile(); |
651 |
if (parent == null || !parent.exists()) return null; |
652 |
File[] files = parent.listFiles(); |
653 |
int length = files==null ? 0 : files.length; |
654 |
if (length > 0) { |
655 |
for (int i=0; i<length; i++) { |
656 |
if (files[i] == file) { |
657 |
return files[i]; |
658 |
} else if (files[i].equals(file)) { |
659 |
return files[i]; |
660 |
} else if (files[i].getPath().equals(file.getPath())) { |
661 |
return files[i]; |
662 |
} |
663 |
} |
505 |
} |
664 |
} |
506 |
return toNativePath(container) + File.separator + OUTPUT_DIRECTORY; |
665 |
return null; |
|
|
666 |
} |
667 |
/** |
668 |
* Returns parent's child resource matching the given resource or null if not found. |
669 |
* |
670 |
* @param resource The searched file in parent |
671 |
* @return The parent's child matching the given file or null if not found. |
672 |
*/ |
673 |
private static IResource getParentChildResource(IResource resource) { |
674 |
IContainer parent = resource.getParent(); |
675 |
if (parent == null || !parent.exists()) return null; |
676 |
try { |
677 |
IResource[] members = parent.members(); |
678 |
int length = members ==null ? 0 : members.length; |
679 |
if (length > 0) { |
680 |
for (int i=0; i<length; i++) { |
681 |
if (members[i] == resource) { |
682 |
return members[i]; |
683 |
} else if (members[i].equals(resource)) { |
684 |
return members[i]; |
685 |
} else if (members[i].getFullPath().equals(resource.getFullPath())) { |
686 |
return members[i]; |
687 |
} |
688 |
} |
689 |
} |
690 |
} |
691 |
catch (CoreException ce) { |
692 |
// skip |
693 |
} |
694 |
return null; |
695 |
} |
696 |
/** |
697 |
* Returns the test name from stack elements info. |
698 |
* |
699 |
* @return The name of the test currently running |
700 |
*/ |
701 |
private static String getTestName() { |
702 |
StackTraceElement[] elements = new Exception().getStackTrace(); |
703 |
int idx = 0, length=elements.length; |
704 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
705 |
// loop until JDT/Core class appears in the stack |
706 |
} |
707 |
if (idx<length) { |
708 |
StackTraceElement testElement = null; |
709 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
710 |
testElement = elements[idx++]; |
711 |
} |
712 |
if (testElement != null) { |
713 |
return testElement.getClassName() + " - " + testElement.getMethodName(); |
714 |
} |
715 |
} |
716 |
return "?"; |
507 |
} |
717 |
} |
508 |
/** |
718 |
/** |
509 |
* Returns the next available port number on the local host. |
719 |
* Returns the next available port number on the local host. |
Lines 545-550
Link Here
|
545 |
return buffer.toString(); |
755 |
return buffer.toString(); |
546 |
} |
756 |
} |
547 |
/** |
757 |
/** |
|
|
758 |
* Returns whether a file is really deleted or not. |
759 |
* Does not only rely on {@link File#exists()} method but also |
760 |
* look if it's not in its parent children {@link #getParentChildFile(File)}. |
761 |
* |
762 |
* @param file The file to test if deleted |
763 |
* @return true if the file does not exist and was not found in its parent children. |
764 |
*/ |
765 |
public static boolean isFileDeleted(File file) { |
766 |
return !file.exists() && getParentChildFile(file) == null; |
767 |
} |
768 |
public static boolean isMacOS() { |
769 |
return System.getProperty("os.name").indexOf("Mac") != -1; |
770 |
} |
771 |
/** |
772 |
* Returns whether a resource is really deleted or not. |
773 |
* Does not only rely on {@link IResource#isAccessible()} method but also |
774 |
* look if it's not in its parent children {@link #getParentChildResource(IResource)}. |
775 |
* |
776 |
* @param resource The resource to test if deleted |
777 |
* @return true if the resource is not accessible and was not found in its parent children. |
778 |
*/ |
779 |
public static boolean isResourceDeleted(IResource resource) { |
780 |
return !resource.isAccessible() && getParentChildResource(resource) == null; |
781 |
} |
782 |
/** |
783 |
* Print given file information with specified indentation. |
784 |
* These information are:<ul> |
785 |
* <li>read {@link File#canRead()}</li> |
786 |
* <li>write {@link File#canWrite()}</li> |
787 |
* <li>exists {@link File#exists()}</li> |
788 |
* <li>is file {@link File#isFile()}</li> |
789 |
* <li>is directory {@link File#isDirectory()}</li> |
790 |
* <li>is hidden {@link File#isHidden()}</li> |
791 |
* </ul> |
792 |
* May recurse several level in parents hierarchy. |
793 |
* May also display children, but then will not recusre in parent |
794 |
* hierarchy to avoid infinite loop... |
795 |
* |
796 |
* @param file The file to display information |
797 |
* @param indent Number of tab to print before the information |
798 |
* @param recurse Display also information on <code>recurse</code>th parents in hierarchy. |
799 |
* If negative then display children information instead. |
800 |
*/ |
801 |
private static void printFileInfo(File file, int indent, int recurse) { |
802 |
String tab = ""; |
803 |
for (int i=0; i<indent; i++) tab+="\t"; |
804 |
System.out.print(tab+"- "+file.getName()+" file info: "); |
805 |
String sep = ""; |
806 |
if (file.canRead()) { |
807 |
System.out.print("read"); |
808 |
sep = ", "; |
809 |
} |
810 |
if (file.canWrite()) { |
811 |
System.out.print(sep+"write"); |
812 |
sep = ", "; |
813 |
} |
814 |
if (file.exists()) { |
815 |
System.out.print(sep+"exist"); |
816 |
sep = ", "; |
817 |
} |
818 |
if (file.isDirectory()) { |
819 |
System.out.print(sep+"dir"); |
820 |
sep = ", "; |
821 |
} |
822 |
if (file.isFile()) { |
823 |
System.out.print(sep+"file"); |
824 |
sep = ", "; |
825 |
} |
826 |
if (file.isHidden()) { |
827 |
System.out.print(sep+"hidden"); |
828 |
sep = ", "; |
829 |
} |
830 |
System.out.println(); |
831 |
File[] files = file.listFiles(); |
832 |
int length = files==null ? 0 : files.length; |
833 |
if (length > 0) { |
834 |
boolean children = recurse < 0; |
835 |
System.out.print(tab+" + children: "); |
836 |
if (children) System.out.println(); |
837 |
for (int i=0; i<length; i++) { |
838 |
if (children) { // display children |
839 |
printFileInfo(files[i], indent+2, -1); |
840 |
} else { |
841 |
if (i>0) System.out.print(", "); |
842 |
System.out.print(files[i].getName()); |
843 |
if (files[i].isDirectory()) System.out.print("[dir]"); |
844 |
else if (files[i].isFile()) System.out.print("[file]"); |
845 |
else System.out.print("[?]"); |
846 |
} |
847 |
} |
848 |
if (!children) System.out.println(); |
849 |
} |
850 |
if (recurse > 0) { |
851 |
File parent = file.getParentFile(); |
852 |
if (parent != null) printFileInfo(parent, indent+1, recurse-1); |
853 |
} |
854 |
} |
855 |
/** |
856 |
* Print stack trace with only JDT/Core elements. |
857 |
* |
858 |
* @param exception Exception of the stack trace. May be null, then a fake exception is used. |
859 |
* @param indent Number of tab to display before the stack elements to display. |
860 |
*/ |
861 |
private static void printJdtCoreStackTrace(Exception exception, int indent) { |
862 |
String tab = ""; |
863 |
for (int i=0; i<indent; i++) tab+="\t"; |
864 |
StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace(); |
865 |
int idx = 0, length=elements.length; |
866 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
867 |
// loop until JDT/Core class appears in the stack |
868 |
} |
869 |
if (idx<length) { |
870 |
System.out.print(tab+"- stack trace"); |
871 |
if (exception == null) |
872 |
System.out.println(":"); |
873 |
else |
874 |
System.out.println(" for exception "+exception+":"); |
875 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
876 |
StackTraceElement testElement = elements[idx++]; |
877 |
System.out.println(tab+" -> "+testElement); |
878 |
} |
879 |
} else { |
880 |
exception.printStackTrace(System.out); |
881 |
} |
882 |
} |
883 |
/** |
548 |
* Makes the given path a path using native path separators as returned by File.getPath() |
884 |
* Makes the given path a path using native path separators as returned by File.getPath() |
549 |
* and trimming any extra slash. |
885 |
* and trimming any extra slash. |
550 |
*/ |
886 |
*/ |
Lines 607-612
Link Here
|
607 |
} |
943 |
} |
608 |
} |
944 |
} |
609 |
} |
945 |
} |
|
|
946 |
/** |
947 |
* Wait until the file is _really_ deleted on file system. |
948 |
* |
949 |
* @param file Deleted file |
950 |
* @return true if the file was finally deleted, false otherwise |
951 |
*/ |
952 |
private static boolean waitUntilFileDeleted(File file) { |
953 |
if (DELETE_DEBUG) { |
954 |
System.out.println(); |
955 |
System.out.println("WARNING in test: "+getTestName()); |
956 |
System.out.println(" - problems occured while deleting "+file); |
957 |
printJdtCoreStackTrace(null, 1); |
958 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
959 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
960 |
} |
961 |
int count = 0; |
962 |
int delay = 10; // ms |
963 |
int maxRetry = DELETE_MAX_WAIT / delay; |
964 |
int time = 0; |
965 |
while (count < maxRetry) { |
966 |
try { |
967 |
count++; |
968 |
Thread.sleep(delay); |
969 |
time += delay; |
970 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
971 |
if (DELETE_DEBUG) System.out.print('.'); |
972 |
if (file.exists()) { |
973 |
if (file.delete()) { |
974 |
// SUCCESS |
975 |
if (DELETE_DEBUG) { |
976 |
System.out.println(); |
977 |
System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
978 |
System.out.println(); |
979 |
} |
980 |
return true; |
981 |
} |
982 |
} |
983 |
if (isFileDeleted(file)) { |
984 |
// SUCCESS |
985 |
if (DELETE_DEBUG) { |
986 |
System.out.println(); |
987 |
System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
988 |
System.out.println(); |
989 |
} |
990 |
return true; |
991 |
} |
992 |
// Increment waiting delay exponentially |
993 |
if (count >= 10 && delay <= 100) { |
994 |
count = 1; |
995 |
delay *= 10; |
996 |
maxRetry = DELETE_MAX_WAIT / delay; |
997 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
998 |
maxRetry++; |
999 |
} |
1000 |
} |
1001 |
} |
1002 |
catch (InterruptedException ie) { |
1003 |
break; // end loop |
1004 |
} |
1005 |
} |
1006 |
if (!DELETE_DEBUG) { |
1007 |
System.out.println(); |
1008 |
System.out.println("WARNING in test: "+getTestName()); |
1009 |
System.out.println(" - problems occured while deleting "+file); |
1010 |
printJdtCoreStackTrace(null, 1); |
1011 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1012 |
} |
1013 |
System.out.println(); |
1014 |
System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1015 |
System.out.println(); |
1016 |
return false; |
1017 |
} |
1018 |
/** |
1019 |
* Wait until a resource is _really_ deleted on file system. |
1020 |
* |
1021 |
* @param resource Deleted resource |
1022 |
* @return true if the file was finally deleted, false otherwise |
1023 |
*/ |
1024 |
private static boolean waitUntilResourceDeleted(IResource resource) { |
1025 |
File file = resource.getLocation().toFile(); |
1026 |
if (DELETE_DEBUG) { |
1027 |
System.out.println(); |
1028 |
System.out.println("WARNING in test: "+getTestName()); |
1029 |
System.out.println(" - problems occured while deleting resource "+resource); |
1030 |
printJdtCoreStackTrace(null, 1); |
1031 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1032 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
1033 |
} |
1034 |
int count = 0; |
1035 |
int delay = 10; // ms |
1036 |
int maxRetry = DELETE_MAX_WAIT / delay; |
1037 |
int time = 0; |
1038 |
while (count < maxRetry) { |
1039 |
try { |
1040 |
count++; |
1041 |
Thread.sleep(delay); |
1042 |
time += delay; |
1043 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
1044 |
if (DELETE_DEBUG) System.out.print('.'); |
1045 |
if (resource.isAccessible()) { |
1046 |
try { |
1047 |
resource.delete(true, null); |
1048 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1049 |
// SUCCESS |
1050 |
if (DELETE_DEBUG) { |
1051 |
System.out.println(); |
1052 |
System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1053 |
System.out.println(); |
1054 |
} |
1055 |
return true; |
1056 |
} |
1057 |
} |
1058 |
catch (CoreException e) { |
1059 |
// skip |
1060 |
} |
1061 |
} |
1062 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1063 |
// SUCCESS |
1064 |
if (DELETE_DEBUG) { |
1065 |
System.out.println(); |
1066 |
System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1067 |
System.out.println(); |
1068 |
} |
1069 |
return true; |
1070 |
} |
1071 |
// Increment waiting delay exponentially |
1072 |
if (count >= 10 && delay <= 100) { |
1073 |
count = 1; |
1074 |
delay *= 10; |
1075 |
maxRetry = DELETE_MAX_WAIT / delay; |
1076 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
1077 |
maxRetry++; |
1078 |
} |
1079 |
} |
1080 |
} |
1081 |
catch (InterruptedException ie) { |
1082 |
break; // end loop |
1083 |
} |
1084 |
} |
1085 |
if (!DELETE_DEBUG) { |
1086 |
System.out.println(); |
1087 |
System.out.println("WARNING in test: "+getTestName()); |
1088 |
System.out.println(" - problems occured while deleting resource "+resource); |
1089 |
printJdtCoreStackTrace(null, 1); |
1090 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1091 |
} |
1092 |
System.out.println(); |
1093 |
System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1094 |
System.out.println(); |
1095 |
return false; |
1096 |
} |
610 |
public static void writeToFile(String contents, String destinationFilePath) { |
1097 |
public static void writeToFile(String contents, String destinationFilePath) { |
611 |
File destFile = new File(destinationFilePath); |
1098 |
File destFile = new File(destinationFilePath); |
612 |
FileOutputStream output = null; |
1099 |
FileOutputStream output = null; |
Lines 630-636
Link Here
|
630 |
public static void zip(File rootDir, String zipPath) throws IOException { |
1117 |
public static void zip(File rootDir, String zipPath) throws IOException { |
631 |
ZipOutputStream zip = null; |
1118 |
ZipOutputStream zip = null; |
632 |
try { |
1119 |
try { |
633 |
zip = new ZipOutputStream(new FileOutputStream(zipPath)); |
1120 |
File zipFile = new File(zipPath); |
|
|
1121 |
if (zipFile.exists()) delete(zipFile); |
1122 |
zip = new ZipOutputStream(new FileOutputStream(zipFile)); |
634 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
1123 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
635 |
} finally { |
1124 |
} finally { |
636 |
if (zip != null) { |
1125 |
if (zip != null) { |
Lines 639-658
Link Here
|
639 |
} |
1128 |
} |
640 |
} |
1129 |
} |
641 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
1130 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
642 |
String[] list = dir.list(); |
1131 |
File[] files = dir.listFiles(); |
643 |
if (list != null) { |
1132 |
if (files != null) { |
644 |
for (int i = 0, length = list.length; i < length; i++) { |
1133 |
for (int i = 0, length = files.length; i < length; i++) { |
645 |
String name = list[i]; |
1134 |
File file = files[i]; |
646 |
File file = new File(dir, name); |
1135 |
if (file.isFile()) { |
647 |
if (file.isDirectory()) { |
|
|
648 |
zip(file, zip, rootPathLength); |
649 |
} else { |
650 |
String path = file.getPath(); |
1136 |
String path = file.getPath(); |
651 |
path = path.substring(rootPathLength); |
1137 |
path = path.substring(rootPathLength); |
652 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
1138 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
653 |
zip.putNextEntry(entry); |
1139 |
zip.putNextEntry(entry); |
654 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
1140 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
655 |
zip.closeEntry(); |
1141 |
zip.closeEntry(); |
|
|
1142 |
} else { |
1143 |
zip(file, zip, rootPathLength); |
656 |
} |
1144 |
} |
657 |
} |
1145 |
} |
658 |
} |
1146 |
} |