Skip to content

Commit 4858950

Browse files
author
rcartwright
committed
This commit is hopefully close to a working framework for compiling scala programs. The scala compiler will not load because the
loader cannot find the file scala.tools.nsc.reporters.ConsoleReporter.java, which is in a jar file on the class path. I don't understand what is going wrong. The following files were modified or added (in some cases only trivial formatting changes were made): M platform/classes/base-jdk7/edu/rice/cs/drjava/model/compiler/Javac170Compiler$1.class M platform/classes/base-jdk7/edu/rice/cs/drjava/model/compiler/Javac170Compiler.class M platform/src-scala/edu/rice/cs/drjava/model/compiler/descriptors/ScalaDescriptor.java AM platform/src-scala/edu/rice/cs/drjava/model/compiler/ScalaCompiler.java M platform/src-jdk7/edu/rice/cs/drjava/model/compiler/Javac170Compiler.java M drjava/lib/platform.jar M drjava/src/edu/rice/cs/drjava/model/JDKToolsLibrary.java M drjava/src/edu/rice/cs/drjava/model/compiler/DefaultCompilerModel.java M drjava/src/edu/rice/cs/drjava/model/JarJDKToolsLibrary.java M drjava/src/edu/rice/cs/drjava/model/DefaultGlobalModel.java M drjava/src/edu/rice/cs/util/swing/Utilities.java git-svn-id: file:///tmp/test-svn/branches/drscala@5485 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent cb3f1fc commit 4858950

11 files changed

Lines changed: 430 additions & 44 deletions

File tree

drjava/lib/platform.jar

-38 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ private Iterable<JDKToolsLibrary> findLibraries() {
375375
else { JarJDKToolsLibrary.msg("\tduplicate"); }
376376
}
377377

378-
Utilities.show("compiler results = " + results.values());
378+
JarJDKToolsLibrary.msg("compiler results = " + results.values());
379379
return IterUtil.reverse(results.values());
380380
}
381381

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,18 @@ protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor,
9494
public JavadocModel javadoc() { return _javadoc; }
9595

9696
public boolean isValid() {
97-
return
97+
boolean result =
9898
_compiler instanceof ScalaCompiler || /* This is an ugly hack. TODO: refactor compiler adapters framework */
9999
_compiler.isAvailable() || _debugger.isAvailable() || _javadoc.isAvailable();
100+
JDKToolsLibrary.msg("Invoking isValid() for " + _compiler.getClass() + " returned " + result);
101+
return result;
100102
}
101103

102104
public String toString() { return _jdkDescriptor.getDescription(_version); }
103105

104106
public static String adapterForCompiler(JavaVersion.FullVersion version) {
105107
switch (version.majorVersion()) {
108+
case FUTURE: return "edu.rice.cs.drjava.model.compiler.ScalaCompiler";
106109
case JAVA_7: return "edu.rice.cs.drjava.model.compiler.Javac170Compiler";
107110
case JAVA_6: {
108111
switch (version.vendor()) {
@@ -125,7 +128,9 @@ public static String adapterForDebugger(JavaVersion.FullVersion version) {
125128
}
126129
}
127130

131+
/** Only called in making compilers from runtime? */
128132
protected static CompilerInterface getCompilerInterface(String className, FullVersion version) {
133+
msg("JDKToolsLibrary.getCompilerInterface(" + className + ", " + version + ") called");
129134
if (className != null) {
130135
List<File> bootClassPath = null;
131136
String bootProp = System.getProperty("sun.boot.class.path");
@@ -135,7 +140,7 @@ protected static CompilerInterface getCompilerInterface(String className, FullVe
135140
Class<?>[] sig = { FullVersion.class, String.class, List.class };
136141
Object[] args = { version, "the runtime class path", bootClassPath };
137142
CompilerInterface attempt = (CompilerInterface) ReflectUtil.loadObject(className, sig, args);
138-
msg(" attempt = "+attempt+", isAvailable() = "+attempt.isAvailable());
143+
msg(" attempt = " + attempt + ", isAvailable() = " + attempt.isAvailable());
139144
if (attempt.isAvailable()) { return attempt; }
140145
}
141146
catch (ReflectException e) { /* can't load */ }
@@ -151,9 +156,9 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
151156
FullVersion version = JavaVersion.CURRENT_FULL;
152157

153158
String compilerAdapter = adapterForCompiler(version);
154-
msg("makeFromRuntime: compilerAdapter="+compilerAdapter);
159+
msg("makeFromRuntime: compilerAdapter=" + compilerAdapter);
155160
CompilerInterface compiler = getCompilerInterface(compilerAdapter, version);
156-
msg(" compiler="+compiler.getClass().getName());
161+
msg(" compiler=" + compiler.getClass().getName());
157162

158163
Debugger debugger = NoDebuggerAvailable.ONLY;
159164
String debuggerAdapter = adapterForDebugger(version);
@@ -164,8 +169,8 @@ public static Iterable<JDKToolsLibrary> makeFromRuntime(GlobalModel model) {
164169
msg(" debugger="+attempt.getClass().getName());
165170
if (attempt.isAvailable()) { debugger = attempt; }
166171
}
167-
catch (ReflectException e) { msg(" no debugger, ReflectException "+e); /* can't load */ }
168-
catch (LinkageError e) { msg(" no debugger, LinkageError "+e); /* can't load */ }
172+
catch (ReflectException e) { msg(" no debugger, ReflectException " + e); /* can't load */ }
173+
catch (LinkageError e) { msg(" no debugger, LinkageError " + e); /* can't load */ }
169174
}
170175

171176
JavadocModel javadoc = new NoJavadocAvailable(model);

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

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class JarJDKToolsLibrary extends JDKToolsLibrary {
8888
* least in OS X's classes.jar, can only be loaded by the JVM.)
8989
*/
9090
private static final Set<String> TOOLS_PACKAGES = new HashSet<String>();
91+
private static final Set<String> SCALA_PACKAGES = new HashSet<String>();
9192
static {
9293
Collections.addAll(TOOLS_PACKAGES, new String[] {
9394
// From 1.4 tools.jar:
@@ -117,7 +118,6 @@ public class JarJDKToolsLibrary extends JDKToolsLibrary {
117118
});
118119
}
119120

120-
121121
private final File _location;
122122
private final List<File> _bootClassPath; // may be null (i.e. compiler's internal behavior)
123123

@@ -131,7 +131,7 @@ private JarJDKToolsLibrary(File location, FullVersion version, JDKDescriptor jdk
131131

132132
public File location() { return _location; }
133133
public List<File> bootClassPath() { // may be null
134-
if (_bootClassPath!=null) return new ArrayList<File>(_bootClassPath);
134+
if (_bootClassPath != null) return new ArrayList<File>(_bootClassPath);
135135
else return null;
136136
}
137137

@@ -154,8 +154,10 @@ public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, JDKDesc
154154
JavadocModel javadoc = new NoJavadocAvailable(model);
155155

156156
FullVersion version = desc.guessVersion(f);
157-
JDKToolsLibrary.msg("makeFromFile: "+f+" --> "+version+", vendor: "+version.vendor());
158-
JDKToolsLibrary.msg(" desc = "+desc);
157+
JDKToolsLibrary.msg("makeFromFile: " + f + " --> " + version + ", vendor: " + version.vendor());
158+
JDKToolsLibrary.msg(" desc = " + desc);
159+
boolean isScala = f.toString().contains("scala-compiler");
160+
msg("isScala = " + isScala);
159161

160162
boolean isSupported = JavaVersion.CURRENT.supports(version.majorVersion());
161163
Iterable<File> additionalCompilerFiles = IterUtil.empty();
@@ -165,23 +167,26 @@ public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, JDKDesc
165167
isSupported |= JavaVersion.CURRENT.supports(desc.getMinimumMajorVersion());
166168
try {
167169
additionalCompilerFiles = desc.getAdditionalCompilerFiles(f);
170+
msg("Additional compiler files for " + f + " = " + additionalCompilerFiles);
168171
}
169172
catch(FileNotFoundException fnfe) {
170173
// not all additional compiler files were found
171174
isSupported = false;
172175
}
173-
176+
// msg("additionalCompilerFiles = " + additionalCompilerFiles);
174177
// We can't execute code that was possibly compiled for a later Java API version.
175178
List<File> bootClassPath = null;
176179
if (isSupported) {
180+
ClassLoader currentLoader = JarJDKToolsLibrary.class.getClassLoader();
177181
// block tools.jar classes, so that references don't point to a different version of the classes
178-
ClassLoader loader =
179-
new ShadowingClassLoader(JarJDKToolsLibrary.class.getClassLoader(), true, TOOLS_PACKAGES, true);
182+
ClassLoader loader = isScala ? new ShadowingClassLoader(currentLoader, true, SCALA_PACKAGES, true) :
183+
new ShadowingClassLoader(currentLoader, true, TOOLS_PACKAGES, true);
180184
Iterable<File> path = IterUtil.map(IterUtil.compose(additionalCompilerFiles, f), new Lambda<File,File>() {
181185
public File value(File arg) { return IOUtil.attemptAbsoluteFile(arg); }
182186
});
183187

184188
String compilerAdapter = desc.getAdapterForCompiler(version);
189+
msg("CREATING COMPILER ADAPTER " + compilerAdapter);
185190

186191
if (compilerAdapter != null) {
187192
// determine boot class path
@@ -206,44 +211,47 @@ else if (f.getName().equals("tools.jar")) {
206211
if (jars != null) { bootClassPath.addAll(Arrays.asList(jars)); }
207212
}
208213
else {
209-
// could not determine boot classpath because the file was not named classes.jar or tools.jar
214+
// Could not determine boot classpath because the file was not named classes.jar or tools.jar
210215
// at least put the compiler file itself and the additional compiler files on the boot classpath
211216
bootClassPath.add(f);
212217
for(File acf: additionalCompilerFiles) { bootClassPath.add(acf); };
213218
}
214-
if (additionalBootClassPath!=null) { bootClassPath.addAll(additionalBootClassPath); }
219+
if (additionalBootClassPath != null) { bootClassPath.addAll(additionalBootClassPath); }
215220
if (bootClassPath.isEmpty()) { bootClassPath = null; } // null defers to the compiler's default behavior
216221

217222
try {
218223
Class<?>[] sig = { FullVersion.class, String.class, List.class };
219224
Object[] args = { version, f.toString(), bootClassPath };
220-
// JDKToolsLibrary.msg("classpath for compiler: "+IterUtil.multilineToString(path));
221-
// JDKToolsLibrary.msg("boot classpath for compiler: "+IterUtil.multilineToString(bootClassPath));
222-
CompilerInterface attempt = (CompilerInterface) ReflectUtil.loadLibraryAdapter(loader, path, compilerAdapter,
223-
sig, args);
225+
JDKToolsLibrary.msg("classpath for compiler: " + IterUtil.multilineToString(path));
226+
JDKToolsLibrary.msg("boot classpath for compiler: " + IterUtil.multilineToString(bootClassPath));
227+
msg("loader = " + loader + "; path = " + path + "; compilerAdapter = " + compilerAdapter + "; sig = " +
228+
sig + "; args = " + args);
229+
CompilerInterface attempt =
230+
(CompilerInterface) ReflectUtil.loadLibraryAdapter(loader, path, compilerAdapter, sig, args);
231+
msg("attempt = " + attempt + "; availability = " + attempt.isAvailable());
224232
if (attempt.isAvailable()) { compiler = attempt; }
225233
}
226-
catch (ReflectException e) { /* can't load */ }
227-
catch (LinkageError e) { /* can't load */ }
234+
catch (ReflectException e) { msg("Class loader threw " + e); /* can't load */ }
235+
catch (LinkageError e) { msg("Class loader threw " + e); /* can't load */ }
228236
}
229237

230238
String debuggerAdapter = desc.getAdapterForDebugger(version);
231239
String debuggerPackage = "edu.rice.cs.drjava.model.debug.jpda";
232240
if (debuggerAdapter != null) {
233241
try {
234-
JDKToolsLibrary.msg(" loading debugger: "+debuggerAdapter);
242+
JDKToolsLibrary.msg(" loading debugger: " + debuggerAdapter);
235243
Class<?>[] sig = { GlobalModel.class };
236244
// can't use loadLibraryAdapter because we need to preempt the whole package
237245
ClassLoader debugLoader = new PreemptingClassLoader(new PathClassLoader(loader, path), debuggerPackage);
238246
Debugger attempt = (Debugger) ReflectUtil.loadObject(debugLoader, debuggerAdapter, sig, model);
239-
JDKToolsLibrary.msg(" debugger="+attempt.getClass().getName());
247+
JDKToolsLibrary.msg(" debugger = " + attempt.getClass().getName());
240248
if (attempt.isAvailable()) { debugger = attempt; }
241249
}
242250
catch (ReflectException e) {
243-
JDKToolsLibrary.msg(" no debugger, ReflectException "+e); /* can't load */
251+
JDKToolsLibrary.msg(" no debugger, ReflectException " + e); /* can't load */
244252
}
245253
catch (LinkageError e) {
246-
JDKToolsLibrary.msg(" no debugger, LinkageError "+e); /* can't load */
254+
JDKToolsLibrary.msg(" no debugger, LinkageError " + e); /* can't load */
247255
}
248256
}
249257

@@ -341,9 +349,9 @@ else if (name.matches("\\d+\\.\\d+\\.\\d+")) {
341349
}
342350

343351
if ((result == null) || (result.vendor()==JavaVersion.VendorType.UNKNOWN)) {
344-
if (!forceUnknown) {
345-
if (result.majorVersion().compareTo(JavaVersion.JAVA_6)<0) {
346-
// Java 5 or earlier, assume Sun
352+
if (! forceUnknown) {
353+
if (result.majorVersion().compareTo(JavaVersion.JAVA_6) < 0) {
354+
// Java 5, assume Sun
347355
vendor = "sun";
348356
}
349357
else {
@@ -469,13 +477,13 @@ protected static void collectValidResults(GlobalModel model,
469477
assert desc != null;
470478

471479
boolean containsCompiler = desc.containsCompiler(jar.getKey());
472-
Utilities.show("Checking file " + jar.getKey() + " for " + desc);
473-
JDKToolsLibrary.msg("Checking file "+jar.getKey()+" for "+desc);
474-
JDKToolsLibrary.msg(" "+containsCompiler);
475-
if (!containsCompiler) continue;
480+
// Utilities.show("Checking file " + jar.getKey() + " for " + desc);
481+
JDKToolsLibrary.msg("Checking file " + jar.getKey() + " for " + desc);
482+
JDKToolsLibrary.msg(" " + containsCompiler);
483+
if (! containsCompiler) continue;
476484

477485
JarJDKToolsLibrary lib = makeFromFile(jar.getKey(), model, desc);
478-
Utilities.show("Is file " + lib + " valid? " + lib.isValid());
486+
JDKToolsLibrary.msg("Is file " + lib + " of class " + lib.getClass() + " valid? " + lib.isValid());
479487
if (lib.isValid()) {
480488
FullVersion v = lib.version();
481489
Map<FullVersion, Iterable<JarJDKToolsLibrary>> mapToAddTo = results;
@@ -485,8 +493,8 @@ protected static void collectValidResults(GlobalModel model,
485493
else { mapToAddTo.put(v, IterUtil.singleton(lib)); }
486494
}
487495
else {
488-
JDKToolsLibrary.msg(" library is not valid: compiler="+lib.compiler().isAvailable()+
489-
" debugger="+lib.debugger().isAvailable()+" javadoc="+lib.javadoc().isAvailable());
496+
JDKToolsLibrary.msg(" library is not valid: compiler=" + lib.compiler().isAvailable()+
497+
" debugger=" + lib.debugger().isAvailable() + " javadoc=" + lib.javadoc().isAvailable());
490498
}
491499
}
492500
}
@@ -588,7 +596,7 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
588596
// search for jar files in roots and, if found, transfer them to the jars collection
589597
searchRootsForJars(roots, jars);
590598

591-
Utilities.show("jars list in JarJDKToolsLibrary is: " + jars);
599+
JarJDKToolsLibrary.msg("jars list in JarJDKToolsLibrary is: " + jars);
592600

593601
// check which jars are valid JDKs, and determine if they are compound or full (non-compound) JDKs
594602
Map<FullVersion, Iterable<JarJDKToolsLibrary>> results =

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public DefaultCompilerModel(GlobalModel m, Iterable<? extends CompilerInterface>
128128
_compilerErrorModel = new CompilerErrorModel(new DJError[0], _model);
129129
_LLSTM = new LanguageLevelStackTraceMapper(_model);
130130
}
131-
132-
131+
133132
//--------------------------------- Locking -------------------------------//
134133

135134
/** Returns the lock used to prevent simultaneous compilation and JUnit testing */

drjava/src/edu/rice/cs/util/swing/Utilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static void clearEventQueue(boolean newEvents) {
9191
assert ! EventQueue.isDispatchThread();
9292
final EventQueue q = Toolkit.getDefaultToolkit().getSystemEventQueue();
9393
do {
94-
// it is an error to be in the event queue, so Utilties.invokeAndWait shouldn't be used
94+
// it is an error to be in the event queue, so Utilities.invokeAndWait shouldn't be used
9595
try { EventQueue.invokeAndWait(LambdaUtil.NO_OP); }
9696
catch (Exception e) { throw new UnexpectedException(e); }
9797
} while (newEvents && (null != q.peekEvent()));
Binary file not shown.
Binary file not shown.

platform/src-jdk7/edu/rice/cs/drjava/model/compiler/Javac170Compiler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
// DJError class is not in the same package as this
5555
import edu.rice.cs.drjava.model.DJError;
56+
import edu.rice.cs.util.swing.Utilities;
5657

5758
import edu.rice.cs.plt.reflect.JavaVersion;
5859
import edu.rice.cs.plt.io.IOUtil;
@@ -88,7 +89,7 @@ public boolean isAvailable() {
8889
// if DrJava is started with just the JRE, instead of with the JDK, even if tools.jar is later made available
8990
// to the class loader.
9091
JavaCompiler compiler = (JavaCompiler)(Class.forName("com.sun.tools.javac.api.JavacTool").newInstance());
91-
92+
// Utilities.show("isAvailable() for JDK7.0 is returning " + (compiler != null));
9293
return (compiler != null);
9394
}
9495
catch (Exception e) { return false; }

0 commit comments

Comments
 (0)