Lines 15-20
Link Here
|
15 |
import java.util.*; |
15 |
import java.util.*; |
16 |
import java.util.zip.*; |
16 |
import java.util.zip.*; |
17 |
|
17 |
|
|
|
18 |
import org.eclipse.core.resources.IContainer; |
19 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.jdt.core.compiler.IProblem; |
21 |
import org.eclipse.jdt.core.compiler.IProblem; |
19 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
22 |
import org.eclipse.jdt.core.tests.compiler.regression.Requestor; |
20 |
import org.eclipse.jdt.internal.compiler.Compiler; |
23 |
import org.eclipse.jdt.internal.compiler.Compiler; |
Lines 27-32
Link Here
|
27 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
30 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; |
28 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
31 |
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
29 |
public class Util { |
32 |
public class Util { |
|
|
33 |
// Trace for delete operation |
34 |
/* |
35 |
* Maximum time wasted repeating delete operations while running JDT/Core tests. |
36 |
*/ |
37 |
private static int DELETE_MAX_TIME = 0; |
38 |
/** |
39 |
* Trace deletion operations while running JDT/Core tests. |
40 |
*/ |
41 |
public static boolean DELETE_DEBUG = false; |
42 |
/** |
43 |
* Maximum of time in ms to wait in deletion operation while running JDT/Core tests. |
44 |
* Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000). |
45 |
* <br> |
46 |
* To avoid too many loops while waiting, the ten first ones are done waiting |
47 |
* 10ms before repeating, the ten loops after are done waiting 100ms and |
48 |
* the other loops are done waiting 1s... |
49 |
*/ |
50 |
public static int DELETE_MAX_WAIT = 10000; |
51 |
|
30 |
private static final boolean DEBUG = false; |
52 |
private static final boolean DEBUG = false; |
31 |
/** |
53 |
/** |
32 |
* Initially, output directory was located in System.getProperty("user.home")+"\comptest". |
54 |
* Initially, output directory was located in System.getProperty("user.home")+"\comptest". |
Lines 37-43
Link Here
|
37 |
*/ |
59 |
*/ |
38 |
private final static String OUTPUT_DIRECTORY; |
60 |
private final static String OUTPUT_DIRECTORY; |
39 |
/** |
61 |
/** |
40 |
* Let user specify the delay in hours before output directories are removed from file system |
62 |
* Let user specify the delay in hours before output directories are removed from file system |
41 |
* while starting a new test run. Default value is 2 hours. |
63 |
* while starting a new test run. Default value is 2 hours. |
42 |
* <p> |
64 |
* <p> |
43 |
* Note that this value may be a float and so have time less than one hour. |
65 |
* Note that this value may be a float and so have time less than one hour. |
Lines 90-96
Link Here
|
90 |
for (int i=0,l=testDirs.length; i<l; i++) { |
112 |
for (int i=0,l=testDirs.length; i<l; i++) { |
91 |
if (testDirs[i].isDirectory()) { |
113 |
if (testDirs[i].isDirectory()) { |
92 |
if ((now - testDirs[i].lastModified()) > delay) { |
114 |
if ((now - testDirs[i].lastModified()) > delay) { |
93 |
rmdir(testDirs[i]); |
115 |
delete(testDirs[i]); |
94 |
} |
116 |
} |
95 |
} |
117 |
} |
96 |
} |
118 |
} |
Lines 242-249
Link Here
|
242 |
try { |
264 |
try { |
243 |
in = new FileInputStream(source); |
265 |
in = new FileInputStream(source); |
244 |
File destFile = new File(dest, source.getName()); |
266 |
File destFile = new File(dest, source.getName()); |
245 |
if (destFile.exists() && !destFile.delete()) { |
267 |
if (destFile.exists()) { |
246 |
throw new IOException(destFile + " is in use"); |
268 |
if (!Util.delete(destFile)) { |
|
|
269 |
throw new IOException(destFile + " is in use"); |
270 |
} |
247 |
} |
271 |
} |
248 |
out = new FileOutputStream(destFile); |
272 |
out = new FileOutputStream(destFile); |
249 |
int bufferLength = 1024; |
273 |
int bufferLength = 1024; |
Lines 316-321
Link Here
|
316 |
zip(sourcesDir, zipPath); |
340 |
zip(sourcesDir, zipPath); |
317 |
} |
341 |
} |
318 |
/** |
342 |
/** |
|
|
343 |
* Delete a file or directory and insure that the file is no longer present |
344 |
* on file system. In case of directory, delete all the hierarchy underneath. |
345 |
* |
346 |
* @param file The file or directory to delete |
347 |
* @return true iff the file was really delete, false otherwise |
348 |
*/ |
349 |
public static boolean delete(File file) { |
350 |
// flush all directory content |
351 |
if (file.isDirectory()) { |
352 |
flushDirectoryContent(file); |
353 |
} |
354 |
// remove file |
355 |
file.delete(); |
356 |
if (isFileDeleted(file)) { |
357 |
return true; |
358 |
} |
359 |
return waitUntilFileDeleted(file); |
360 |
} |
361 |
/** |
362 |
* Delete a file or directory and insure that the file is no longer present |
363 |
* on file system. In case of directory, delete all the hierarchy underneath. |
364 |
* |
365 |
* @param resource The resource to delete |
366 |
* @return true iff the file was really delete, false otherwise |
367 |
*/ |
368 |
public static boolean delete(IResource resource) { |
369 |
try { |
370 |
resource.delete(true, null); |
371 |
if (isResourceDeleted(resource)) { |
372 |
return true; |
373 |
} |
374 |
} |
375 |
catch (CoreException e) { |
376 |
// skip |
377 |
} |
378 |
return waitUntilResourceDeleted(resource); |
379 |
} |
380 |
/** |
381 |
* Delete a file or directory and insure that the file is no longer present |
382 |
* on file system. In case of directory, delete all the hierarchy underneath. |
383 |
* |
384 |
* @param path The path of the file or directory to delete |
385 |
* @return true iff the file was really delete, false otherwise |
386 |
*/ |
387 |
public static boolean delete(String path) { |
388 |
return delete(new File(path)); |
389 |
} |
390 |
/** |
319 |
* Generate a display string from the given String. |
391 |
* Generate a display string from the given String. |
320 |
* @param inputString the given input string |
392 |
* @param inputString the given input string |
321 |
* |
393 |
* |
Lines 527-558
Link Here
|
527 |
writeToFile(displayString, destinationFilePath); |
599 |
writeToFile(displayString, destinationFilePath); |
528 |
} |
600 |
} |
529 |
/** |
601 |
/** |
530 |
* Delete a directory and all its hierarchy if not empty |
|
|
531 |
* |
532 |
* @param dir The directory to delete |
533 |
*/ |
534 |
public static void rmdir(File dir) { |
535 |
// flush all directory content |
536 |
flushDirectoryContent(dir); |
537 |
// remove dir |
538 |
dir.delete(); |
539 |
} |
540 |
/** |
541 |
* Flush content of a given directory (leaving it empty), |
602 |
* Flush content of a given directory (leaving it empty), |
542 |
* no-op if not a directory. |
603 |
* no-op if not a directory. |
543 |
*/ |
604 |
*/ |
544 |
public static void flushDirectoryContent(File dir) { |
605 |
public static void flushDirectoryContent(File dir) { |
545 |
if (dir.isDirectory()) { |
606 |
File[] files = dir.listFiles(); |
546 |
String[] files = dir.list(); |
607 |
if (files == null) return; |
547 |
if (files == null) return; |
608 |
for (int i = 0, max = files.length; i < max; i++) { |
548 |
for (int i = 0, max = files.length; i < max; i++) { |
609 |
delete(files[i]); |
549 |
File current = new File(dir, files[i]); |
|
|
550 |
if (current.isDirectory()) { |
551 |
flushDirectoryContent(current); |
552 |
} |
553 |
if (!current.delete()) |
554 |
System.err.println("Could not delete " + current.getName()); |
555 |
} |
556 |
} |
610 |
} |
557 |
} |
611 |
} |
558 |
/** |
612 |
/** |
Lines 645-650
Link Here
|
645 |
public static String getOutputDirectory() { |
699 |
public static String getOutputDirectory() { |
646 |
return OUTPUT_DIRECTORY; |
700 |
return OUTPUT_DIRECTORY; |
647 |
} |
701 |
} |
|
|
702 |
/** |
703 |
* Returns the parent's child file matching the given file or null if not found. |
704 |
* |
705 |
* @param file The searched file in parent |
706 |
* @return The parent's child matching the given file or null if not found. |
707 |
*/ |
708 |
private static File getParentChildFile(File file) { |
709 |
File parent = file.getParentFile(); |
710 |
if (parent == null || !parent.exists()) return null; |
711 |
File[] files = parent.listFiles(); |
712 |
int length = files==null ? 0 : files.length; |
713 |
if (length > 0) { |
714 |
for (int i=0; i<length; i++) { |
715 |
if (files[i] == file) { |
716 |
return files[i]; |
717 |
} else if (files[i].equals(file)) { |
718 |
return files[i]; |
719 |
} else if (files[i].getPath().equals(file.getPath())) { |
720 |
return files[i]; |
721 |
} |
722 |
} |
723 |
} |
724 |
return null; |
725 |
} |
726 |
/** |
727 |
* Returns parent's child resource matching the given resource or null if not found. |
728 |
* |
729 |
* @param resource The searched file in parent |
730 |
* @return The parent's child matching the given file or null if not found. |
731 |
*/ |
732 |
private static IResource getParentChildResource(IResource resource) { |
733 |
IContainer parent = resource.getParent(); |
734 |
if (parent == null || !parent.exists()) return null; |
735 |
try { |
736 |
IResource[] members = parent.members(); |
737 |
int length = members ==null ? 0 : members.length; |
738 |
if (length > 0) { |
739 |
for (int i=0; i<length; i++) { |
740 |
if (members[i] == resource) { |
741 |
return members[i]; |
742 |
} else if (members[i].equals(resource)) { |
743 |
return members[i]; |
744 |
} else if (members[i].getFullPath().equals(resource.getFullPath())) { |
745 |
return members[i]; |
746 |
} |
747 |
} |
748 |
} |
749 |
} |
750 |
catch (CoreException ce) { |
751 |
// skip |
752 |
} |
753 |
return null; |
754 |
} |
755 |
/** |
756 |
* Returns the test name from stack elements info. |
757 |
* |
758 |
* @return The name of the test currently running |
759 |
*/ |
760 |
private static String getTestName() { |
761 |
StackTraceElement[] elements = new Exception().getStackTrace(); |
762 |
int idx = 0, length=elements.length; |
763 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
764 |
// loop until JDT/Core class appears in the stack |
765 |
} |
766 |
if (idx<length) { |
767 |
StackTraceElement testElement = null; |
768 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
769 |
testElement = elements[idx++]; |
770 |
} |
771 |
if (testElement != null) { |
772 |
return testElement.getClassName() + " - " + testElement.getMethodName(); |
773 |
} |
774 |
} |
775 |
return "?"; |
776 |
} |
648 |
public static String indentString(String inputString, int indent) { |
777 |
public static String indentString(String inputString, int indent) { |
649 |
if (inputString == null) |
778 |
if (inputString == null) |
650 |
return ""; |
779 |
return ""; |
Lines 663-672
Link Here
|
663 |
} |
792 |
} |
664 |
return buffer.toString(); |
793 |
return buffer.toString(); |
665 |
} |
794 |
} |
|
|
795 |
/** |
796 |
* Returns whether a file is really deleted or not. |
797 |
* Does not only rely on {@link File#exists()} method but also |
798 |
* look if it's not in its parent children {@link #getParentChildFile(File)}. |
799 |
* |
800 |
* @param file The file to test if deleted |
801 |
* @return true if the file does not exist and was not found in its parent children. |
802 |
*/ |
803 |
public static boolean isFileDeleted(File file) { |
804 |
return !file.exists() && getParentChildFile(file) == null; |
805 |
} |
666 |
public static boolean isMacOS() { |
806 |
public static boolean isMacOS() { |
667 |
return System.getProperty("os.name").indexOf("Mac") != -1; |
807 |
return System.getProperty("os.name").indexOf("Mac") != -1; |
668 |
} |
808 |
} |
669 |
/** |
809 |
/** |
|
|
810 |
* Returns whether a resource is really deleted or not. |
811 |
* Does not only rely on {@link IResource#isAccessible()} method but also |
812 |
* look if it's not in its parent children {@link #getParentChildResource(IResource)}. |
813 |
* |
814 |
* @param resource The resource to test if deleted |
815 |
* @return true if the resource is not accessible and was not found in its parent children. |
816 |
*/ |
817 |
public static boolean isResourceDeleted(IResource resource) { |
818 |
return !resource.isAccessible() && getParentChildResource(resource) == null; |
819 |
} |
820 |
/** |
821 |
* Print given file information with specified indentation. |
822 |
* These information are:<ul> |
823 |
* <li>read {@link File#canRead()}</li> |
824 |
* <li>write {@link File#canWrite()}</li> |
825 |
* <li>exists {@link File#exists()}</li> |
826 |
* <li>is file {@link File#isFile()}</li> |
827 |
* <li>is directory {@link File#isDirectory()}</li> |
828 |
* <li>is hidden {@link File#isHidden()}</li> |
829 |
* </ul> |
830 |
* May recurse several level in parents hierarchy. |
831 |
* May also display children, but then will not recusre in parent |
832 |
* hierarchy to avoid infinite loop... |
833 |
* |
834 |
* @param file The file to display information |
835 |
* @param indent Number of tab to print before the information |
836 |
* @param recurse Display also information on <code>recurse</code>th parents in hierarchy. |
837 |
* If negative then display children information instead. |
838 |
*/ |
839 |
private static void printFileInfo(File file, int indent, int recurse) { |
840 |
String tab = ""; |
841 |
for (int i=0; i<indent; i++) tab+="\t"; |
842 |
System.out.print(tab+"- "+file.getName()+" file info: "); |
843 |
String sep = ""; |
844 |
if (file.canRead()) { |
845 |
System.out.print("read"); |
846 |
sep = ", "; |
847 |
} |
848 |
if (file.canWrite()) { |
849 |
System.out.print(sep+"write"); |
850 |
sep = ", "; |
851 |
} |
852 |
if (file.exists()) { |
853 |
System.out.print(sep+"exist"); |
854 |
sep = ", "; |
855 |
} |
856 |
if (file.isDirectory()) { |
857 |
System.out.print(sep+"dir"); |
858 |
sep = ", "; |
859 |
} |
860 |
if (file.isFile()) { |
861 |
System.out.print(sep+"file"); |
862 |
sep = ", "; |
863 |
} |
864 |
if (file.isHidden()) { |
865 |
System.out.print(sep+"hidden"); |
866 |
sep = ", "; |
867 |
} |
868 |
System.out.println(); |
869 |
File[] files = file.listFiles(); |
870 |
int length = files==null ? 0 : files.length; |
871 |
if (length > 0) { |
872 |
boolean children = recurse < 0; |
873 |
System.out.print(tab+" + children: "); |
874 |
if (children) System.out.println(); |
875 |
for (int i=0; i<length; i++) { |
876 |
if (children) { // display children |
877 |
printFileInfo(files[i], indent+2, -1); |
878 |
} else { |
879 |
if (i>0) System.out.print(", "); |
880 |
System.out.print(files[i].getName()); |
881 |
if (files[i].isDirectory()) System.out.print("[dir]"); |
882 |
else if (files[i].isFile()) System.out.print("[file]"); |
883 |
else System.out.print("[?]"); |
884 |
} |
885 |
} |
886 |
if (!children) System.out.println(); |
887 |
} |
888 |
if (recurse > 0) { |
889 |
File parent = file.getParentFile(); |
890 |
if (parent != null) printFileInfo(parent, indent+1, recurse-1); |
891 |
} |
892 |
} |
893 |
/** |
894 |
* Print stack trace with only JDT/Core elements. |
895 |
* |
896 |
* @param exception Exception of the stack trace. May be null, then a fake exception is used. |
897 |
* @param indent Number of tab to display before the stack elements to display. |
898 |
*/ |
899 |
private static void printJdtCoreStackTrace(Exception exception, int indent) { |
900 |
String tab = ""; |
901 |
for (int i=0; i<indent; i++) tab+="\t"; |
902 |
StackTraceElement[] elements = (exception==null?new Exception():exception).getStackTrace(); |
903 |
int idx = 0, length=elements.length; |
904 |
while (idx<length && !elements[idx++].getClassName().startsWith("org.eclipse.jdt")) { |
905 |
// loop until JDT/Core class appears in the stack |
906 |
} |
907 |
if (idx<length) { |
908 |
System.out.print(tab+"- stack trace"); |
909 |
if (exception == null) |
910 |
System.out.println(":"); |
911 |
else |
912 |
System.out.println(" for exception "+exception+":"); |
913 |
while (idx<length && elements[idx].getClassName().startsWith("org.eclipse.jdt")) { |
914 |
StackTraceElement testElement = elements[idx++]; |
915 |
System.out.println(tab+" -> "+testElement); |
916 |
} |
917 |
} else { |
918 |
exception.printStackTrace(System.out); |
919 |
} |
920 |
} |
921 |
/** |
670 |
* Makes the given path a path using native path separators as returned by File.getPath() |
922 |
* Makes the given path a path using native path separators as returned by File.getPath() |
671 |
* and trimming any extra slash. |
923 |
* and trimming any extra slash. |
672 |
*/ |
924 |
*/ |
Lines 729-734
Link Here
|
729 |
} |
981 |
} |
730 |
} |
982 |
} |
731 |
} |
983 |
} |
|
|
984 |
/** |
985 |
* Wait until the file is _really_ deleted on file system. |
986 |
* |
987 |
* @param file Deleted file |
988 |
* @return true if the file was finally deleted, false otherwise |
989 |
*/ |
990 |
private static boolean waitUntilFileDeleted(File file) { |
991 |
if (DELETE_DEBUG) { |
992 |
System.out.println(); |
993 |
System.out.println("WARNING in test: "+getTestName()); |
994 |
System.out.println(" - problems occured while deleting "+file); |
995 |
printJdtCoreStackTrace(null, 1); |
996 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
997 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
998 |
} |
999 |
int count = 0; |
1000 |
int delay = 10; // ms |
1001 |
int maxRetry = DELETE_MAX_WAIT / delay; |
1002 |
int time = 0; |
1003 |
while (count < maxRetry) { |
1004 |
try { |
1005 |
count++; |
1006 |
Thread.sleep(delay); |
1007 |
time += delay; |
1008 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
1009 |
if (DELETE_DEBUG) System.out.print('.'); |
1010 |
if (file.exists()) { |
1011 |
if (file.delete()) { |
1012 |
// SUCCESS |
1013 |
if (DELETE_DEBUG) { |
1014 |
System.out.println(); |
1015 |
System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1016 |
System.out.println(); |
1017 |
} |
1018 |
return true; |
1019 |
} |
1020 |
} |
1021 |
if (isFileDeleted(file)) { |
1022 |
// SUCCESS |
1023 |
if (DELETE_DEBUG) { |
1024 |
System.out.println(); |
1025 |
System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1026 |
System.out.println(); |
1027 |
} |
1028 |
return true; |
1029 |
} |
1030 |
// Increment waiting delay exponentially |
1031 |
if (count >= 10 && delay <= 100) { |
1032 |
count = 1; |
1033 |
delay *= 10; |
1034 |
maxRetry = DELETE_MAX_WAIT / delay; |
1035 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
1036 |
maxRetry++; |
1037 |
} |
1038 |
} |
1039 |
} |
1040 |
catch (InterruptedException ie) { |
1041 |
break; // end loop |
1042 |
} |
1043 |
} |
1044 |
if (!DELETE_DEBUG) { |
1045 |
System.out.println(); |
1046 |
System.out.println("WARNING in test: "+getTestName()); |
1047 |
System.out.println(" - problems occured while deleting "+file); |
1048 |
printJdtCoreStackTrace(null, 1); |
1049 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1050 |
} |
1051 |
System.out.println(); |
1052 |
System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1053 |
System.out.println(); |
1054 |
return false; |
1055 |
} |
1056 |
/** |
1057 |
* Wait until a resource is _really_ deleted on file system. |
1058 |
* |
1059 |
* @param resource Deleted resource |
1060 |
* @return true if the file was finally deleted, false otherwise |
1061 |
*/ |
1062 |
private static boolean waitUntilResourceDeleted(IResource resource) { |
1063 |
File file = resource.getLocation().toFile(); |
1064 |
if (DELETE_DEBUG) { |
1065 |
System.out.println(); |
1066 |
System.out.println("WARNING in test: "+getTestName()); |
1067 |
System.out.println(" - problems occured while deleting resource "+resource); |
1068 |
printJdtCoreStackTrace(null, 1); |
1069 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1070 |
System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); |
1071 |
} |
1072 |
int count = 0; |
1073 |
int delay = 10; // ms |
1074 |
int maxRetry = DELETE_MAX_WAIT / delay; |
1075 |
int time = 0; |
1076 |
while (count < maxRetry) { |
1077 |
try { |
1078 |
count++; |
1079 |
Thread.sleep(delay); |
1080 |
time += delay; |
1081 |
if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; |
1082 |
if (DELETE_DEBUG) System.out.print('.'); |
1083 |
if (resource.isAccessible()) { |
1084 |
try { |
1085 |
resource.delete(true, null); |
1086 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1087 |
// SUCCESS |
1088 |
if (DELETE_DEBUG) { |
1089 |
System.out.println(); |
1090 |
System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1091 |
System.out.println(); |
1092 |
} |
1093 |
return true; |
1094 |
} |
1095 |
} |
1096 |
catch (CoreException e) { |
1097 |
// skip |
1098 |
} |
1099 |
} |
1100 |
if (isResourceDeleted(resource) && isFileDeleted(file)) { |
1101 |
// SUCCESS |
1102 |
if (DELETE_DEBUG) { |
1103 |
System.out.println(); |
1104 |
System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); |
1105 |
System.out.println(); |
1106 |
} |
1107 |
return true; |
1108 |
} |
1109 |
// Increment waiting delay exponentially |
1110 |
if (count >= 10 && delay <= 100) { |
1111 |
count = 1; |
1112 |
delay *= 10; |
1113 |
maxRetry = DELETE_MAX_WAIT / delay; |
1114 |
if ((DELETE_MAX_WAIT%delay) != 0) { |
1115 |
maxRetry++; |
1116 |
} |
1117 |
} |
1118 |
} |
1119 |
catch (InterruptedException ie) { |
1120 |
break; // end loop |
1121 |
} |
1122 |
} |
1123 |
if (!DELETE_DEBUG) { |
1124 |
System.out.println(); |
1125 |
System.out.println("WARNING in test: "+getTestName()); |
1126 |
System.out.println(" - problems occured while deleting resource "+resource); |
1127 |
printJdtCoreStackTrace(null, 1); |
1128 |
printFileInfo(file.getParentFile(), 1, -1); // display parent with its children |
1129 |
} |
1130 |
System.out.println(); |
1131 |
System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); |
1132 |
System.out.println(); |
1133 |
return false; |
1134 |
} |
732 |
public static void writeToFile(String contents, String destinationFilePath) { |
1135 |
public static void writeToFile(String contents, String destinationFilePath) { |
733 |
File destFile = new File(destinationFilePath); |
1136 |
File destFile = new File(destinationFilePath); |
734 |
FileOutputStream output = null; |
1137 |
FileOutputStream output = null; |
Lines 752-758
Link Here
|
752 |
public static void zip(File rootDir, String zipPath) throws IOException { |
1155 |
public static void zip(File rootDir, String zipPath) throws IOException { |
753 |
ZipOutputStream zip = null; |
1156 |
ZipOutputStream zip = null; |
754 |
try { |
1157 |
try { |
755 |
zip = new ZipOutputStream(new FileOutputStream(zipPath)); |
1158 |
File zipFile = new File(zipPath); |
|
|
1159 |
if (zipFile.exists()) delete(zipFile); |
1160 |
zip = new ZipOutputStream(new FileOutputStream(zipFile)); |
756 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
1161 |
zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash |
757 |
} finally { |
1162 |
} finally { |
758 |
if (zip != null) { |
1163 |
if (zip != null) { |
Lines 761-780
Link Here
|
761 |
} |
1166 |
} |
762 |
} |
1167 |
} |
763 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
1168 |
private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { |
764 |
String[] list = dir.list(); |
1169 |
File[] files = dir.listFiles(); |
765 |
if (list != null) { |
1170 |
if (files != null) { |
766 |
for (int i = 0, length = list.length; i < length; i++) { |
1171 |
for (int i = 0, length = files.length; i < length; i++) { |
767 |
String name = list[i]; |
1172 |
File file = files[i]; |
768 |
File file = new File(dir, name); |
1173 |
if (file.isFile()) { |
769 |
if (file.isDirectory()) { |
|
|
770 |
zip(file, zip, rootPathLength); |
771 |
} else { |
772 |
String path = file.getPath(); |
1174 |
String path = file.getPath(); |
773 |
path = path.substring(rootPathLength); |
1175 |
path = path.substring(rootPathLength); |
774 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
1176 |
ZipEntry entry = new ZipEntry(path.replace('\\', '/')); |
775 |
zip.putNextEntry(entry); |
1177 |
zip.putNextEntry(entry); |
776 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
1178 |
zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); |
777 |
zip.closeEntry(); |
1179 |
zip.closeEntry(); |
|
|
1180 |
} else { |
1181 |
zip(file, zip, rootPathLength); |
778 |
} |
1182 |
} |
779 |
} |
1183 |
} |
780 |
} |
1184 |
} |