Skip to content

Commit 99a07c4

Browse files
committed
This revision eliminates loading the compiler from the runtime class
path if other compilers can be loaded. The runtime class path apparently does not include rt.jar which breaks the compile commands when the compiler on the class path is selected. This issue should be investigated more deeply when we have more resources. The following files were modified: modified: drjava/src/edu/rice/cs/drjava/model/DefaultGlobalModel.java modified: drjava/src/edu/rice/cs/drjava/model/JDKToolsLibrary.java modified: drjava/src/edu/rice/cs/drjava/model/JarJDKToolsLibrary.java modified: drjava/src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java modified: drjava/src/edu/rice/cs/drjava/ui/DrJavaErrorHandler.java
1 parent 7980b06 commit 99a07c4

File tree

5 files changed

+66
-55
lines changed

5 files changed

+66
-55
lines changed

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ private Iterable<JDKToolsLibrary> findLibraries() {
333333

334334
File configTools = DrJava.getConfig().getSetting(JAVAC_LOCATION);
335335
if (configTools != FileOps.NULL_FILE) {
336+
// TODO: reference to subclass in next line is a code smell!
336337
JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this, JDKDescriptor.NONE);
337338
if (fromConfig.isValid()) {
338339
JarJDKToolsLibrary.msg("From config: " + fromConfig);
@@ -342,19 +343,6 @@ private Iterable<JDKToolsLibrary> findLibraries() {
342343
}
343344
else { JarJDKToolsLibrary.msg("From config: not set"); }
344345

345-
Iterable<JDKToolsLibrary> allFromRuntime = JDKToolsLibrary.makeFromRuntime(this);
346-
347-
for(JDKToolsLibrary fromRuntime: allFromRuntime) {
348-
if (fromRuntime.isValid()) {
349-
if (!results.containsKey(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime))) {
350-
JarJDKToolsLibrary.msg("From runtime: " + fromRuntime);
351-
results.put(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime), fromRuntime);
352-
}
353-
else { JarJDKToolsLibrary.msg("From runtime: duplicate " + fromRuntime); }
354-
}
355-
else { JarJDKToolsLibrary.msg("From runtime: invalid " + fromRuntime); }
356-
}
357-
358346
Iterable<JarJDKToolsLibrary> fromSearch = JarJDKToolsLibrary.search(this);
359347
for (JDKToolsLibrary t : fromSearch) {
360348
JavaVersion.FullVersion tVersion = t.version();
@@ -365,14 +353,35 @@ private Iterable<JDKToolsLibrary> findLibraries() {
365353
// give a lower priority to built-in compilers
366354
int priority = (edu.rice.cs.util.FileOps.getDrJavaFile().equals(tVersion.location())) ?
367355
LibraryKey.PRIORITY_BUILTIN : LibraryKey.PRIORITY_SEARCH;
368-
if (!results.containsKey(getLibraryKey(priority, t))) {
356+
if (! results.containsKey(getLibraryKey(priority, t))) {
369357
JarJDKToolsLibrary.msg("\tadded");
370358
results.put(getLibraryKey(priority, t), t);
371359
}
372360
else { JarJDKToolsLibrary.msg("\tduplicate"); }
373361
}
374362

375-
return IterUtil.reverse(results.values());
363+
// Only include a runtime compiler/library if the list of results is otherwise empty; in recent versions
364+
// of Java, the runtime classpath sometimes does not include rt.jar for the current version (in the JVM executing
365+
// this code). This is a bit a kludge; it should be fixed in a comprehensive revision of the JDKToolsLibrary code
366+
367+
if (results.isEmpty()) {
368+
Iterable<JDKToolsLibrary> allFromRuntime = JDKToolsLibrary.makeFromRuntime(this);
369+
370+
for(JDKToolsLibrary fromRuntime: allFromRuntime) {
371+
if (fromRuntime.isValid()) {
372+
if (! results.containsKey(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime))) {
373+
JarJDKToolsLibrary.msg("From runtime: " + fromRuntime);
374+
results.put(getLibraryKey(LibraryKey.PRIORITY_RUNTIME, fromRuntime), fromRuntime);
375+
}
376+
else { JarJDKToolsLibrary.msg("From runtime: duplicate " + fromRuntime); }
377+
}
378+
else { JarJDKToolsLibrary.msg("From runtime: invalid " + fromRuntime); }
379+
}
380+
}
381+
382+
Iterable<JDKToolsLibrary> libraries = IterUtil.reverse(results.values());
383+
JarJDKToolsLibrary.msg("Returning libraries: '" + libraries);
384+
return libraries;
376385
}
377386

378387
// public void junitAll() { _state.junitAll(); }

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636

3737
package edu.rice.cs.drjava.model;
3838

39-
import java.util.List;
4039
import java.util.ArrayList;
40+
import java.util.Arrays;
41+
import java.util.List;
4142
import java.io.File;
4243

4344
import edu.rice.cs.plt.reflect.ReflectUtil;
@@ -57,12 +58,13 @@
5758
import edu.rice.cs.drjava.model.javadoc.DefaultJavadocModel;
5859
import edu.rice.cs.drjava.model.JDKDescriptor;
5960

60-
/**
61-
* Provides dynamic access to the interface of a JDK's tools.jar classes. This level of indirection
62-
* eliminates the need to have specific tools.jar classes available statically (and the resulting need
63-
* to reset the JVM if they are not), and makes it possible to interface with multiple tools.jar
64-
* libraries simultaneously.
65-
*/
61+
import edu.rice.cs.util.Log;
62+
63+
/** Provides dynamic access to the interface of a JDK's tools.jar classes. This level of indirection
64+
* eliminates the need to have specific tools.jar classes available statically (and the resulting need
65+
* to reset the JVM if they are not), and makes it possible to interface with multiple tools.jar
66+
* libraries simultaneously.
67+
*/
6668
public class JDKToolsLibrary {
6769

6870
private final FullVersion _version;
@@ -71,7 +73,7 @@ public class JDKToolsLibrary {
7173
private final JavadocModel _javadoc;
7274
private final JDKDescriptor _jdkDescriptor; // JDKDescriptor.NONE if none
7375

74-
/* package private */ static edu.rice.cs.util.Log _log = new edu.rice.cs.util.Log("JDKToolsLibrary.txt", false);
76+
/* package private */ static Log _log = new Log("JDKToolsLibrary.txt", true);
7577

7678
protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor, CompilerInterface compiler,
7779
Debugger debugger, JavadocModel javadoc) {
@@ -128,6 +130,7 @@ public static String adapterForDebugger(JavaVersion.FullVersion version) {
128130
}
129131

130132
protected static CompilerInterface getCompilerInterface(String className, FullVersion version) {
133+
msg("getCompilerInterface(" + className + ", " + version + ")");
131134
if (className != null) {
132135
List<File> bootClassPath = null;
133136
String bootProp = System.getProperty("sun.boot.class.path");
@@ -138,8 +141,11 @@ protected static CompilerInterface getCompilerInterface(String className, FullVe
138141
Class<?>[] sig = { FullVersion.class, String.class, List.class };
139142
Object[] args = { version, "the runtime class path", bootClassPath };
140143
CompilerInterface attempt = (CompilerInterface) ReflectUtil.loadObject(className, sig, args);
141-
msg(" attempt = " + attempt + ", isAvailable() = " + attempt.isAvailable());
142-
if (attempt.isAvailable()) { return attempt; }
144+
msg("Attempting " + attempt + ", isAvailable() = " + attempt.isAvailable());
145+
if (attempt.isAvailable()) {
146+
msg("In this successful attempt, args were:" + Arrays.toString(args));
147+
return attempt;
148+
}
143149
}
144150
catch (ReflectException e) { /* can't load */ }
145151
catch (LinkageError e) { /* can't load */ }
@@ -148,27 +154,27 @@ protected static CompilerInterface getCompilerInterface(String className, FullVe
148154
}
149155

150156
/** Create a JDKToolsLibrary from the runtime class path (or, more accurately, from the class
151-
* loader that loaded this class.
152-
*/
157+
* loader that loaded this class.
158+
*/
153159
public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
154160
FullVersion version = JavaVersion.CURRENT_FULL;
155161

156162
String compilerAdapter = adapterForCompiler(version);
157-
msg("makeFromRuntime: compilerAdapter="+compilerAdapter);
163+
msg("makeFromRuntime: version = " + version + "; compilerAdapter = " + compilerAdapter);
158164
CompilerInterface compiler = getCompilerInterface(compilerAdapter, version);
159-
msg(" compiler="+compiler.getClass().getName());
165+
msg(" compiler = " + compiler.getClass().getName());
160166

161167
Debugger debugger = NoDebuggerAvailable.ONLY;
162168
String debuggerAdapter = adapterForDebugger(version);
163169
if (debuggerAdapter != null) {
164170
try {
165-
msg(" loading debugger: "+debuggerAdapter);
171+
msg(" loading debugger: " + debuggerAdapter);
166172
Debugger attempt = (Debugger) ReflectUtil.loadObject(debuggerAdapter, new Class<?>[]{GlobalModel.class}, model);
167-
msg(" debugger="+attempt.getClass().getName());
173+
msg(" debugger = " + attempt.getClass().getName());
168174
if (attempt.isAvailable()) { debugger = attempt; }
169175
}
170-
catch (ReflectException e) { msg(" no debugger, ReflectException "+e); /* can't load */ }
171-
catch (LinkageError e) { msg(" no debugger, LinkageError "+e); /* can't load */ }
176+
catch (ReflectException e) { msg(" no debugger, ReflectException " + e); /* can't load */ }
177+
catch (LinkageError e) { msg(" no debugger, LinkageError " + e); /* can't load */ }
172178
}
173179

174180
JavadocModel javadoc = new NoJavadocAvailable(model);
@@ -198,17 +204,6 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
198204
return list;
199205
}
200206

201-
public static final java.io.StringWriter LOG_STRINGWRITER = new java.io.StringWriter();
202-
// protected static final java.io.PrintWriter LOG_PW = new java.io.PrintWriter(LOG_STRINGWRITER);
203-
204-
public static void msg(String s) { _log.log(s);
205-
// try {
206-
// java.io.PrintWriter pw = new java.io.PrintWriter(new java.io.FileWriter(new File(new File(System.getProperty("user.home")),
207-
// "FindCompilers.txt").getAbsolutePath(),true));
208-
// pw.println(s);
209-
//// LOG_PW.println(s);
210-
// pw.close();
211-
// }
212-
// catch(java.io.IOException ioe) { }
213-
}
207+
public static final java.io.StringWriter LOG_STRINGWRITER = new java.io.StringWriter();
208+
public static void msg(String s) { _log.log(s); }
214209
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public String toString() {
137137
return super.toString() + " at " + _location + ", boot classpath: " + bootClassPath();
138138
}
139139

140-
/** Create a JarJDKToolsLibrary from a specific {@code "tools.jar"} or {@code "classes.jar"} file. */
140+
/** Create a JarJDKToolsLibrary from a specific {@code "tools.jar"} or {@code "classes.jar"} file.
141+
* NOTE: Why isn't this method in JDKToolsLibrary? */
141142
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, JDKDescriptor desc) {
142143
return makeFromFile(f, model, desc, new ArrayList<File>());
143144
}

drjava/src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,27 @@
5353
import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
5454
import edu.rice.cs.drjava.model.DrJavaFileUtils;
5555
import edu.rice.cs.drjava.model.definitions.InvalidPackageException;
56-
import edu.rice.cs.plt.io.IOUtil;
57-
import edu.rice.cs.plt.iter.IterUtil;
58-
import edu.rice.cs.plt.collect.CollectUtil;
56+
5957
import edu.rice.cs.util.FileOps;
6058
import edu.rice.cs.util.Log;
6159
import edu.rice.cs.util.UnexpectedException;
60+
import edu.rice.cs.util.swing.ScrollableListDialog;
6261
import edu.rice.cs.util.swing.Utilities;
62+
6363
import edu.rice.cs.javalanglevels.*;
6464
import edu.rice.cs.javalanglevels.parser.*;
6565
import edu.rice.cs.javalanglevels.tree.*;
66-
import edu.rice.cs.util.swing.ScrollableListDialog;
66+
67+
import edu.rice.cs.plt.io.IOUtil;
68+
import edu.rice.cs.plt.iter.IterUtil;
69+
import edu.rice.cs.plt.collect.CollectUtil;
70+
// import edu.rice.cs.plt.tuple.Pair;
71+
// TODO: use the preceding pair class instead of javalanglevels.Pair; must change javalanglevels code as well
6772

6873
import static edu.rice.cs.plt.debug.DebugUtil.debug;
6974

7075
/** Default implementation of the CompilerModel interface. This implementation is used for normal DrJava execution
71-
* (as opposed to testing DrJava). TO DO: convert edu.rice.cs.util.Pair to edu.rice.cs.plt.tuple.Pair; requires
72-
* making the same conversion in javalanglevels.
76+
* (as opposed to testing DrJava).
7377
* @version $Id$
7478
*/
7579
public class DefaultCompilerModel implements CompilerModel {
@@ -344,7 +348,9 @@ private void _compileFiles(List<File> files, File buildDir) throws IOException {
344348

345349
List<? extends File> preprocessedFiles = _compileLanguageLevelsFiles(files, errors, classPath, bootClassPath);
346350

347-
System.err.println("Performed Language Level Translation of " + preprocessedFiles);
351+
System.err.println("Compiler is using classPath = '" + classPath + "; bootClassPath = '" + bootClassPath + "'");
352+
353+
if (preprocessedFiles != null) System.err.println("Performed Language Level Translation of " + preprocessedFiles);
348354
if (errors.isEmpty()) {
349355
CompilerInterface compiler = getActiveCompiler();
350356

drjava/src/edu/rice/cs/drjava/ui/DrJavaErrorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ else if (isSwingBugArrayIndexOufOfBoundsExceptionInCharWidth(thrown)) {
137137
* @return true if this is the Swing bug */
138138
public static boolean isSwingBugArrayIndexOufOfBoundsExceptionInCharWidth(Throwable thrown) {
139139
// only ignore on Sun/Oracle JVMs
140-
if (!edu.rice.cs.plt.reflect.JavaVersion.CURRENT_FULL.vendor().
140+
if (! edu.rice.cs.plt.reflect.JavaVersion.CURRENT_FULL.vendor().
141141
equals(edu.rice.cs.plt.reflect.JavaVersion.VendorType.ORACLE)) return false;
142142

143143
// only ignore if current version is older than 6.0_18 (6.0_18 > JavaVersion.CURRENT_FULL)

0 commit comments

Comments
 (0)