@@ -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 =
0 commit comments