Skip to content

Commit 0de85ca

Browse files
author
mgricken
committed
Working on pluggable compound compiler adapters.
git-svn-id: file:///tmp/test-svn/branches/drjava-compilers@5276 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent c1c33f1 commit 0de85ca

File tree

25 files changed

+782
-531
lines changed

25 files changed

+782
-531
lines changed

drjava/lib/platform.jar

-3.25 KB
Binary file not shown.

drjava/lib/plt.jar

3.65 KB
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/JDKToolsLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected static String adapterForCompiler(JavaVersion.FullVersion version) {
9595
case JAVA_6: {
9696
switch (version.vendor()) {
9797
case OPENJDK: return "edu.rice.cs.drjava.model.compiler.Javac160OpenJDKCompiler";
98-
case MINT: return "edu.rice.cs.drjava.model.compiler.MintCompiler";
98+
case COMPOUND: return "edu.rice.cs.drjava.model.compiler.MintCompiler";
9999
default: return "edu.rice.cs.drjava.model.compiler.Javac160Compiler";
100100
}
101101
}

drjava/src/edu/rice/cs/drjava/model/JarJDKToolsLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
446446
if (lib.isValid()) {
447447
FullVersion v = lib.version();
448448
Map<FullVersion, Iterable<JarJDKToolsLibrary>> mapToAddTo = results;
449-
if (v.vendor().equals(JavaVersion.VendorType.MINT)) { mapToAddTo = mintResults; }
449+
if (v.vendor().equals(JavaVersion.VendorType.COMPOUND)) { mapToAddTo = mintResults; }
450450

451451
if (mapToAddTo.containsKey(v)) { mapToAddTo.put(v, IterUtil.compose(lib, mapToAddTo.get(v))); }
452452
else { mapToAddTo.put(v, IterUtil.singleton(lib)); }
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
* This software is Open Source Initiative approved Open Source Software.
30+
* Open Source Initative Approved is a trademark of the Open Source Initiative.
31+
*
32+
* This file is part of DrJava. Download the current version of this project
33+
* from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
34+
*
35+
* END_COPYRIGHT_BLOCK*/
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+
/** An abstract parent for all javac-based compiler interfaces that may need to filter .exe files from the
57+
* classpath, i.e. javac from JDKs 1.6.0_04 or newer.
58+
* @version $Id$
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+
protected Javac160FilteringCompiler(JavaVersion.FullVersion version,
67+
String location,
68+
List<? extends File> defaultBootClassPath) {
69+
super(version, location, defaultBootClassPath);
70+
71+
_filterExe = version.compareTo(JavaVersion.parseFullVersion("1.6.0_04")) >= 0;
72+
File tempJUnit = null;
73+
if (_filterExe) {
74+
// if we need to filter out exe files from the classpath, we also need to
75+
// extract junit.jar and create a temporary file
76+
try {
77+
// edu.rice.cs.util.Log LOG = new edu.rice.cs.util.Log("jdk160.txt",true);
78+
// LOG.log("Filtering exe files from classpath.");
79+
InputStream is = Javac160FilteringCompiler.class.getResourceAsStream("/junit.jar");
80+
if (is!=null) {
81+
// LOG.log("\tjunit.jar found");
82+
tempJUnit = edu.rice.cs.plt.io.IOUtil.createAndMarkTempFile(PREFIX,SUFFIX);
83+
FileOutputStream fos = new FileOutputStream(tempJUnit);
84+
int size = edu.rice.cs.plt.io.IOUtil.copyInputStream(is,fos);
85+
// LOG.log("\t"+size+" bytes written to "+tempJUnit.getAbsolutePath());
86+
}
87+
else {
88+
// LOG.log("\tjunit.jar not found");
89+
if (tempJUnit!=null) {
90+
tempJUnit.delete();
91+
tempJUnit = null;
92+
}
93+
}
94+
}
95+
catch(IOException ioe) {
96+
if (tempJUnit!=null) {
97+
tempJUnit.delete();
98+
tempJUnit = null;
99+
}
100+
}
101+
// sometimes this file may be left behind, so create a shutdown hook
102+
// that deletes temporary files matching our pattern
103+
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
104+
public void run() {
105+
try {
106+
File temp = File.createTempFile(PREFIX, SUFFIX);
107+
IOUtil.attemptDelete(temp);
108+
File[] toDelete = temp.getParentFile().listFiles(new FilenameFilter() {
109+
public boolean accept(File dir, String name) {
110+
if ((!name.startsWith(PREFIX)) || (!name.endsWith(SUFFIX))) return false;
111+
String rest = name.substring(PREFIX.length(), name.length()-SUFFIX.length());
112+
try {
113+
Integer i = new Integer(rest);
114+
// we could create an integer from the rest, this is one of our temporary files
115+
return true;
116+
}
117+
catch(NumberFormatException e) { /* couldn't convert, ignore this file */ }
118+
return false;
119+
}
120+
});
121+
for(File f: toDelete) {
122+
f.delete();
123+
}
124+
}
125+
catch(IOException ioe) { /* could not delete temporary files, ignore */ }
126+
}
127+
}));
128+
}
129+
_tempJUnit = tempJUnit;
130+
}
131+
132+
protected java.util.List<File> getFilteredClassPath(java.util.List<? extends File> classPath) {
133+
java.util.List<File> filteredClassPath = null;
134+
if (classPath!=null) {
135+
filteredClassPath = new LinkedList<File>(classPath);
136+
137+
if (_filterExe) {
138+
FileFilter filter = IOUtil.extensionFilePredicate("exe");
139+
Iterator<? extends File> i = filteredClassPath.iterator();
140+
while (i.hasNext()) {
141+
if (filter.accept(i.next())) { i.remove(); }
142+
}
143+
if (_tempJUnit!=null) { filteredClassPath.add(_tempJUnit); }
144+
}
145+
}
146+
return filteredClassPath;
147+
}
148+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
* This software is Open Source Initiative approved Open Source Software.
30+
* Open Source Initative Approved is a trademark of the Open Source Initiative.
31+
*
32+
* This file is part of DrJava. Download the current version of this project
33+
* from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
34+
*
35+
* END_COPYRIGHT_BLOCK*/
36+
37+
package edu.rice.cs.drjava.model.compiler.descriptors;
38+
39+
import java.io.File;
40+
import edu.rice.cs.plt.lambda.Lambda3;
41+
import edu.rice.cs.plt.reflect.JavaVersion;
42+
43+
/** A description of a compound JDK like Mint. */
44+
public interface CompoundJDKDescriptor {
45+
46+
/** Packages to shadow when loading a new tools.jar. If we don't shadow these classes, we won't
47+
* be able to load distinct versions for each tools.jar library. These should be verified whenever
48+
* a new Java version is released. (We can't just shadow *everything* because some classes, at
49+
* least in OS X's classes.jar, can only be loaded by the JVM.)
50+
*/
51+
public Iterable<String> getToolsPackages();
52+
53+
public Iterable<File> getSearchDirectories();
54+
public Iterable<File> getSearchFiles();
55+
56+
public String getAdapterForCompiler();
57+
public String getAdapterForDebugger();
58+
59+
public JavaVersion getMinimumMajorVersion();
60+
61+
public Lambda3<String,String,String,String> getDetector();
62+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)