|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.model.compiler; |
|
38 |
| |
|
39 |
| import java.util.List; |
|
40 |
| import java.util.ArrayList; |
|
41 |
| import java.util.LinkedList; |
|
42 |
| import java.util.Iterator; |
|
43 |
| import java.io.File; |
|
44 |
| import java.io.IOException; |
|
45 |
| import java.io.FilenameFilter; |
|
46 |
| import java.io.FileFilter; |
|
47 |
| import java.io.InputStream; |
|
48 |
| import java.io.FileOutputStream; |
|
49 |
| import edu.rice.cs.plt.io.IOUtil; |
|
50 |
| import edu.rice.cs.drjava.config.OptionConstants; |
|
51 |
| import edu.rice.cs.drjava.DrJava; |
|
52 |
| import edu.rice.cs.drjava.model.DJError; |
|
53 |
| import edu.rice.cs.util.ArgumentTokenizer; |
|
54 |
| import edu.rice.cs.plt.reflect.JavaVersion; |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| public abstract class Javac160FilteringCompiler extends JavacCompiler { |
|
61 |
| protected final boolean _filterExe; |
|
62 |
| protected final File _tempJUnit; |
|
63 |
| protected static final String PREFIX = "drjava-junit"; |
|
64 |
| protected static final String SUFFIX = ".jar"; |
|
65 |
| |
|
66 |
1413
| protected Javac160FilteringCompiler(JavaVersion.FullVersion version,
|
|
67 |
| String location, |
|
68 |
| List<? extends File> defaultBootClassPath) { |
|
69 |
1413
| super(version, location, defaultBootClassPath);
|
|
70 |
| |
|
71 |
1413
| _filterExe = version.compareTo(JavaVersion.parseFullVersion("1.6.0_04")) >= 0;
|
|
72 |
1413
| File tempJUnit = null;
|
|
73 |
1413
| if (_filterExe) {
|
|
74 |
| |
|
75 |
| |
|
76 |
1099
| try {
|
|
77 |
| |
|
78 |
| |
|
79 |
1099
| InputStream is = Javac160FilteringCompiler.class.getResourceAsStream("/junit.jar");
|
|
80 |
1099
| if (is!=null) {
|
|
81 |
| |
|
82 |
0
| tempJUnit = edu.rice.cs.plt.io.IOUtil.createAndMarkTempFile(PREFIX,SUFFIX);
|
|
83 |
0
| FileOutputStream fos = new FileOutputStream(tempJUnit);
|
|
84 |
0
| int size = edu.rice.cs.plt.io.IOUtil.copyInputStream(is,fos);
|
|
85 |
| |
|
86 |
| } |
|
87 |
| else { |
|
88 |
| |
|
89 |
1099
| if (tempJUnit!=null) {
|
|
90 |
0
| tempJUnit.delete();
|
|
91 |
0
| tempJUnit = null;
|
|
92 |
| } |
|
93 |
| } |
|
94 |
| } |
|
95 |
| catch(IOException ioe) { |
|
96 |
0
| if (tempJUnit!=null) {
|
|
97 |
0
| tempJUnit.delete();
|
|
98 |
0
| tempJUnit = null;
|
|
99 |
| } |
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
1099
| Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
|
104 |
514
| public void run() {
|
|
105 |
579
| try {
|
|
106 |
579
| File temp = File.createTempFile(PREFIX, SUFFIX);
|
|
107 |
372
| IOUtil.attemptDelete(temp);
|
|
108 |
330
| File[] toDelete = temp.getParentFile().listFiles(new FilenameFilter() {
|
|
109 |
73458
| public boolean accept(File dir, String name) {
|
|
110 |
91305
| if ((!name.startsWith(PREFIX)) || (!name.endsWith(SUFFIX))) return false;
|
|
111 |
538
| String rest = name.substring(PREFIX.length(), name.length()-SUFFIX.length());
|
|
112 |
538
| try {
|
|
113 |
538
| Integer i = new Integer(rest);
|
|
114 |
| |
|
115 |
0
| return true;
|
|
116 |
| } |
|
117 |
| catch(NumberFormatException e) { } |
|
118 |
538
| return false;
|
|
119 |
| } |
|
120 |
| }); |
|
121 |
240
| for(File f: toDelete) {
|
|
122 |
0
| f.delete();
|
|
123 |
| } |
|
124 |
| } |
|
125 |
| catch(IOException ioe) { } |
|
126 |
| } |
|
127 |
| })); |
|
128 |
| } |
|
129 |
1413
| _tempJUnit = tempJUnit;
|
|
130 |
| } |
|
131 |
| |
|
132 |
55
| protected java.util.List<File> getFilteredClassPath(java.util.List<? extends File> classPath) {
|
|
133 |
55
| java.util.List<File> filteredClassPath = null;
|
|
134 |
55
| if (classPath!=null) {
|
|
135 |
55
| filteredClassPath = new LinkedList<File>(classPath);
|
|
136 |
| |
|
137 |
55
| if (_filterExe) {
|
|
138 |
55
| FileFilter filter = IOUtil.extensionFilePredicate("exe");
|
|
139 |
55
| Iterator<? extends File> i = filteredClassPath.iterator();
|
|
140 |
55
| while (i.hasNext()) {
|
|
141 |
0
| if (filter.accept(i.next())) { i.remove(); }
|
|
142 |
| } |
|
143 |
0
| if (_tempJUnit!=null) { filteredClassPath.add(_tempJUnit); }
|
|
144 |
| } |
|
145 |
| } |
|
146 |
55
| return filteredClassPath;
|
|
147 |
| } |
|
148 |
| } |