Skip to content

Commit 5e4fade

Browse files
author
mgricken
committed
Working on refactored compiler adapters.
git-svn-id: file:///tmp/test-svn/branches/drjava-compilers@5302 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent b121ed2 commit 5e4fade

File tree

6 files changed

+48
-20
lines changed

6 files changed

+48
-20
lines changed

drjava/lib/platform.jar

17 Bytes
Binary file not shown.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,15 @@ private Iterable<JDKToolsLibrary> findLibraries() {
285285
Iterable<JarJDKToolsLibrary> fromSearch = JarJDKToolsLibrary.search(this);
286286
for (JDKToolsLibrary t : fromSearch) {
287287
JavaVersion.FullVersion tVersion = t.version();
288-
if (!results.containsKey(coarsenVersion(tVersion))) {
289-
JarJDKToolsLibrary.msg("From search: "+t);
290-
results.put(coarsenVersion(tVersion), t);
288+
JarJDKToolsLibrary.msg("From search: "+t);
289+
JavaVersion.FullVersion coarsenedVersion = coarsenVersion(tVersion);
290+
JarJDKToolsLibrary.msg("\ttVersion: "+tVersion+" "+tVersion.vendor());
291+
JarJDKToolsLibrary.msg("\tcoarsenedVersion: "+coarsenedVersion+" "+coarsenedVersion.vendor());
292+
if (!results.containsKey(coarsenedVersion)) {
293+
JarJDKToolsLibrary.msg("\tadded");
294+
results.put(coarsenedVersion, t);
291295
}
292-
else { JarJDKToolsLibrary.msg("From search: duplicate "+t); }
296+
else { JarJDKToolsLibrary.msg("\tduplicate"); }
293297
}
294298

295299
return IterUtil.reverse(results.values());

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import edu.rice.cs.drjava.model.javadoc.JavadocModel;
5555
import edu.rice.cs.drjava.model.javadoc.NoJavadocAvailable;
5656
import edu.rice.cs.drjava.model.javadoc.DefaultJavadocModel;
57+
import edu.rice.cs.drjava.model.compiler.descriptors.JDKDescriptor;
5758

5859
/**
5960
* Provides dynamic access to the interface of a JDK's tools.jar classes. This level of indirection
@@ -67,17 +68,22 @@ public class JDKToolsLibrary {
6768
private final CompilerInterface _compiler;
6869
private final Debugger _debugger;
6970
private final JavadocModel _javadoc;
71+
private final JDKDescriptor _jdkDescriptor; // may be null
7072

71-
protected JDKToolsLibrary(FullVersion version, CompilerInterface compiler, Debugger debugger,
73+
protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor,
74+
CompilerInterface compiler, Debugger debugger,
7275
JavadocModel javadoc) {
7376
_version = version;
7477
_compiler = compiler;
7578
_debugger = debugger;
7679
_javadoc = javadoc;
80+
_jdkDescriptor = jdkDescriptor;
7781
}
7882

7983
public FullVersion version() { return _version; }
8084

85+
public JDKDescriptor jdkDescriptor() { return _jdkDescriptor; }
86+
8187
public CompilerInterface compiler() { return _compiler; }
8288

8389
public Debugger debugger() { return _debugger; }
@@ -88,7 +94,23 @@ public boolean isValid() {
8894
return _compiler.isAvailable() || _debugger.isAvailable() || _javadoc.isAvailable();
8995
}
9096

91-
public String toString() { return "JDK library " + _version.versionString(); }
97+
public String toString() {
98+
if (_jdkDescriptor==null) {
99+
switch(_version.vendor()) {
100+
case SUN:
101+
return "Sun JDK library " + _version.versionString();
102+
case OPENJDK:
103+
return "OpenJDK library " + _version.versionString();
104+
case APPLE:
105+
return "Apple JDK library " + _version.versionString();
106+
default:
107+
return "JDK library " + _version.versionString();
108+
}
109+
}
110+
else {
111+
return _jdkDescriptor.getName() + " library " + _version.versionString();
112+
}
113+
}
92114

93115
protected static String adapterForCompiler(JavaVersion.FullVersion version) {
94116
switch (version.majorVersion()) {
@@ -165,7 +187,7 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
165187
if (compiler!=NoCompilerAvailable.ONLY) {
166188
// if we have found a compiler, add it
167189
msg(" compiler found");
168-
list.add(new JDKToolsLibrary(version, compiler, debugger, javadoc));
190+
list.add(new JDKToolsLibrary(version, null, compiler, debugger, javadoc));
169191
}
170192

171193
if (JavaVersion.JAVA_6.compareTo(version.majorVersion())>=0) {
@@ -180,15 +202,15 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
180202
if (compiler!=NoCompilerAvailable.ONLY) {
181203
// if we have found a compiler, add it
182204
msg(" compiler found");
183-
list.add(new JDKToolsLibrary(eclipseVersion, compiler, debugger, javadoc));
205+
list.add(new JDKToolsLibrary(eclipseVersion, null, compiler, debugger, javadoc));
184206
}
185207
}
186208
msg(" compilers found: "+list.size());
187209

188210
if (list.size()==0) {
189211
// no compiler found, i.e. compiler == NoCompilerAvailable.ONLY
190212
msg(" no compilers found, adding NoCompilerAvailable library");
191-
list.add(new JDKToolsLibrary(version, NoCompilerAvailable.ONLY, debugger, javadoc));
213+
list.add(new JDKToolsLibrary(version, null, NoCompilerAvailable.ONLY, debugger, javadoc));
192214
}
193215

194216
return list;

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,13 @@ public class JarJDKToolsLibrary extends JDKToolsLibrary {
127127

128128
private final File _location;
129129
private final List<File> _bootClassPath; // may be null (i.e. compiler's internal behavior)
130-
private final JDKDescriptor _jdkDescriptor; // may be null
131130

132-
private JarJDKToolsLibrary(File location, FullVersion version, JDKDescriptor desc,
131+
private JarJDKToolsLibrary(File location, FullVersion version, JDKDescriptor jdkDescriptor,
133132
CompilerInterface compiler, Debugger debugger,
134133
JavadocModel javadoc, List<File> bootClassPath) {
135-
super(version, compiler, debugger, javadoc);
134+
super(version, jdkDescriptor, compiler, debugger, javadoc);
136135
_location = location;
137136
_bootClassPath = bootClassPath;
138-
_jdkDescriptor = desc;
139137
}
140138

141139
public File location() { return _location; }
@@ -144,9 +142,9 @@ public List<File> bootClassPath() { // may be null
144142
else return null;
145143
}
146144

147-
public JDKDescriptor getJDKDescriptor() { return _jdkDescriptor; }
148-
149-
public String toString() { return super.toString() + " at " + _location + ", boot classpath: " + bootClassPath(); }
145+
public String toString() {
146+
return super.toString() + " at " + _location + ", boot classpath: " + bootClassPath();
147+
}
150148

151149
/** Create a JarJDKToolsLibrary from a specific {@code "tools.jar"} or {@code "classes.jar"} file. */
152150
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, JDKDescriptor desc) {
@@ -251,7 +249,7 @@ else if (f.getName().equals("tools.jar")) {
251249
return new JarJDKToolsLibrary(f, version, desc, compiler, debugger, javadoc, bootClassPath);
252250
}
253251

254-
private static FullVersion guessVersion(File f) {
252+
public static FullVersion guessVersion(File f) {
255253
FullVersion result = null;
256254

257255
// We could start with f.getParentFile(), but this simplifies the logic
@@ -317,8 +315,11 @@ else if (name.matches("\\d+\\.\\d+\\.\\d+")) {
317315
JarFile jf = null;
318316
try {
319317
jf = new JarFile(f);
320-
if (jf.getJarEntry("com/sun/tools/javac/util/JavacFileManager.class")!=null) {
321-
// NOTE: this may cause Sun's Java 7 to also be recognized as openjdk
318+
/* if (jf.getJarEntry("com/sun/tools/javac/file/JavacFileManager.class")!=null) {
319+
// NOTE: this may cause OpenJDK 7 to also be recognized as sun
320+
vendor = "sun";
321+
}
322+
else */ if (jf.getJarEntry("com/sun/tools/javac/util/JavacFileManager.class")!=null) {
322323
vendor = "openjdk";
323324
}
324325
else if (jf.getJarEntry("com/sun/tools/javac/util/DefaultFileManager.class")!=null) {
@@ -527,7 +528,7 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
527528
}
528529
// if we found a JDK, then create a new compound library
529530
if (found!=null) {
530-
JarJDKToolsLibrary lib = makeFromFile(compoundLib.location(), model, compoundLib.getJDKDescriptor(),
531+
JarJDKToolsLibrary lib = makeFromFile(compoundLib.location(), model, compoundLib.jdkDescriptor(),
531532
found.bootClassPath());
532533
if (lib.isValid()) {
533534
JDKToolsLibrary.msg("\t==> "+lib.version());
Binary file not shown.

platform/src-mint/edu/rice/cs/drjava/model/compiler/descriptors/Mint2Descriptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public Set<String> getToolsPackages() {
8585
public Iterable<File> getSearchDirectories() { return IterUtil.asIterable(new File[0]); }
8686
public Iterable<File> getSearchFiles() {
8787
Iterable<File> files = IterUtil.asIterable(new File[] {
88+
new File("/home/mgricken/research/Mint/java-mint/trunk/langtools/dist/lib/classes.jar"),
8889
new File("/Users/mgricken/Documents/Research/Mint/java-mint/trunk/langtools/dist/lib/classes.jar"),
8990
new File("/D:/Documents/Research/Mint/java-mint/trunk/langtools/dist/lib/classes.jar")
9091
});

0 commit comments

Comments
 (0)