@@ -114,7 +114,6 @@ public class JarJDKToolsLibrary extends JDKToolsLibrary {
114114 "org.relaxng" ,
115115 });
116116 }
117-
118117
119118 private final File _location ;
120119 private final List <File > _bootClassPath ; // may be null (i.e. compiler's internal behavior)
@@ -387,41 +386,52 @@ protected static LinkedHashMap<File,Set<JDKDescriptor>> getDefaultSearchRoots()
387386
388387 String javaHome = System .getProperty ("java.home" );
389388 String envJavaHome = null ;
389+ String envJava7Home = null ;
390390 String programFiles = null ;
391391 String systemDrive = null ;
392392 if (JavaVersion .CURRENT .supports (JavaVersion .JAVA_5 )) {
393393 // System.getenv is deprecated under 1.3 and 1.4, and may throw a java.lang.Error (!),
394394 // which we'd rather not have to catch
395395 envJavaHome = System .getenv ("JAVA_HOME" );
396+ envJava7Home = System .getenv ("JAVA7_HOME" );
396397 programFiles = System .getenv ("ProgramFiles" );
397398 systemDrive = System .getenv ("SystemDrive" );
398399 }
399400
401+ // unwind out of potential JRE subdirectory
400402 if (javaHome != null ) {
401403 addIfDir (new File (javaHome ), roots );
402404 addIfDir (new File (javaHome , ".." ), roots );
403405 addIfDir (new File (javaHome , "../.." ), roots );
404406 }
407+
408+ // add JAVA environment bindings to roots
405409 if (envJavaHome != null ) {
406410 addIfDir (new File (envJavaHome ), roots );
407- addIfDir (new File (envJavaHome , ".." ), roots );
408- addIfDir (new File (envJavaHome , "../.." ), roots );
411+ }
412+ if (envJava7Home != null ) {
413+ addIfDir (new File (envJava7Home ), roots );
409414 }
410415
416+ // Add ProgramFiles to roots
411417 if (programFiles != null ) {
412418 addIfDir (new File (programFiles , "Java" ), roots );
413419 addIfDir (new File (programFiles ), roots );
414420 }
421+
415422 addIfDir (new File ("/C:/Program Files/Java" ), roots );
416423 addIfDir (new File ("/C:/Program Files" ), roots );
424+
417425 if (systemDrive != null ) {
418426 addIfDir (new File (systemDrive , "Java" ), roots );
419427 addIfDir (new File (systemDrive ), roots );
420428 }
421429 addIfDir (new File ("/C:/Java" ), roots );
422430 addIfDir (new File ("/C:" ), roots );
423431
432+ /* Entries for Mac OS X */
424433 addIfDir (new File ("/System/Library/Frameworks/JavaVM.framework/Versions" ), roots );
434+ addIfDir (new File ("/System/Library/Java/JavaVirtualMachines" ), roots );
425435
426436 addIfDir (new File ("/usr/java" ), roots );
427437 addIfDir (new File ("/usr/j2se" ), roots );
@@ -432,9 +442,11 @@ protected static LinkedHashMap<File,Set<JDKDescriptor>> getDefaultSearchRoots()
432442
433443 /* Entries for Linux java packages */
434444 addIfDir (new File ("/usr/lib/jvm" ), roots );
445+ addIfDir (new File ("/usr/lib/jvm/java-7-oracle" ), roots );
446+ addIfDir (new File ("/usr/lib/jvm/java-7-openjdk" ), roots );
435447 addIfDir (new File ("/usr/lib/jvm/java-6-sun" ), roots );
436- addIfDir (new File ("/usr/lib/jvm/java-1.5.0-sun" ), roots );
437448 addIfDir (new File ("/usr/lib/jvm/java-6-openjdk" ), roots );
449+ addIfDir (new File ("/usr/lib/jvm/java-1.5.0-sun" ), roots );
438450
439451 addIfDir (new File ("/home/javaplt/java/Linux-i686" ), roots );
440452
@@ -449,11 +461,14 @@ protected static void searchRootsForJars(LinkedHashMap<File,Set<JDKDescriptor>>
449461 Predicate <File > subdirFilter = LambdaUtil .or (IOUtil .regexCanonicalCaseFilePredicate ("j2sdk.*" ),
450462 IOUtil .regexCanonicalCaseFilePredicate ("jdk.*" ),
451463 LambdaUtil .or (IOUtil .regexCanonicalCaseFilePredicate ("\\ d+\\ .\\ d+\\ .\\ d+" ),
452- IOUtil .regexCanonicalCaseFilePredicate ("java.*" )));
464+ IOUtil .regexCanonicalCaseFilePredicate ("java- .*" )));
453465 for (Map .Entry <File ,Set <JDKDescriptor >> root : roots .entrySet ()) {
466+ JDKToolsLibrary .msg ("Searching root (for jar files): " + root .getKey ());
454467 for (File subdir : IOUtil .attemptListFilesAsIterable (root .getKey (), subdirFilter )) {
468+ JDKToolsLibrary .msg ("Looking at subdirectory: " + subdir );
455469 addIfFile (new File (subdir , "lib/tools.jar" ), root .getValue (), jars );
456470 addIfFile (new File (subdir , "Classes/classes.jar" ), root .getValue (), jars );
471+ addIfFile (new File (subdir , "Contents/Classes/classes.jar" ), root .getValue (), jars ); // "Contents/" appears as prefix in new OS X paths
457472 }
458473 }
459474 }
@@ -493,8 +508,7 @@ protected static void collectValidResults(GlobalModel model,
493508 /** Get completed compound JDKs by going through the list of compound JDKs and finding full JDKs that
494509 * complete them. */
495510 protected static Map <FullVersion , Iterable <JarJDKToolsLibrary >>
496- getCompletedCompoundResults (GlobalModel model ,
497- Iterable <JarJDKToolsLibrary > collapsed ,
511+ getCompletedCompoundResults (GlobalModel model , Iterable <JarJDKToolsLibrary > collapsed ,
498512 Iterable <JarJDKToolsLibrary > compoundCollapsed ) {
499513 JDKToolsLibrary .msg ("---- Getting Completed Compound Results ----" );
500514
@@ -503,30 +517,30 @@ protected static void collectValidResults(GlobalModel model,
503517
504518 // now we have the JDK libraries in collapsed and the compound libraries in compoundCollapsed
505519 for (JarJDKToolsLibrary compoundLib : compoundCollapsed ) {
506- JDKToolsLibrary .msg ("compoundLib: " + compoundLib );
507- JDKToolsLibrary .msg (" " + compoundLib .location ());
520+ JDKToolsLibrary .msg ("compoundLib: " + compoundLib );
521+ JDKToolsLibrary .msg (" " + compoundLib .location ());
508522 FullVersion compoundVersion = compoundLib .version ();
509523 JarJDKToolsLibrary found = null ;
510524 // try to find a JDK in results that matches compoundVersion exactly, except for vendor
511525 for (JarJDKToolsLibrary javaLib : collapsed ) {
512- if (!javaLib .jdkDescriptor ().isBaseForCompound ()) continue ; // javaLib not suitable as base
513- JDKToolsLibrary .msg (" exact? " + javaLib );
526+ if (! javaLib .jdkDescriptor ().isBaseForCompound ()) continue ; // javaLib not suitable as base
527+ JDKToolsLibrary .msg (" exact? " + javaLib ); // Is exact comparison necessary? It never seems to match.
514528 FullVersion javaVersion = javaLib .version ();
515529 if ((javaVersion .majorVersion ().equals (compoundVersion .majorVersion ())) &&
516- (javaVersion .maintenance ()== compoundVersion .maintenance ()) &&
517- (javaVersion .update ()== compoundVersion .update ()) &&
518- (javaVersion .release ()== compoundVersion .release ()) &&
530+ (javaVersion .maintenance () == compoundVersion .maintenance ()) &&
531+ (javaVersion .update () == compoundVersion .update ()) &&
532+ (javaVersion .release () == compoundVersion .release ()) &&
519533 (javaVersion .supports (compoundLib .jdkDescriptor ().getMinimumMajorVersion ()))) {
520534 JDKToolsLibrary .msg (" found" );
521535 found = javaLib ;
522536 break ;
523537 }
524538 }
525539 // if we didn't find one, take the best JDK that matches the major version
526- if (found == null ) {
540+ if (found == null ) {
527541 for (JarJDKToolsLibrary javaLib : collapsed ) {
528- if (!javaLib .jdkDescriptor ().isBaseForCompound ()) continue ; // javaLib not suitable as base
529- JDKToolsLibrary .msg (" major? " + javaLib );
542+ if (! javaLib .jdkDescriptor ().isBaseForCompound ()) continue ; // javaLib not suitable as base
543+ JDKToolsLibrary .msg (" major? " + javaLib );
530544 FullVersion javaVersion = javaLib .version ();
531545 if (javaVersion .majorVersion ().equals (compoundVersion .majorVersion ()) &&
532546 javaVersion .supports (compoundLib .jdkDescriptor ().getMinimumMajorVersion ())) {
@@ -537,11 +551,11 @@ protected static void collectValidResults(GlobalModel model,
537551 }
538552 }
539553 // if we found a JDK, then create a new compound library
540- if (found != null ) {
554+ if (found != null ) {
541555 JarJDKToolsLibrary lib = makeFromFile (compoundLib .location (), model , compoundLib .jdkDescriptor (),
542556 found .bootClassPath ());
543557 if (lib .isValid ()) {
544- JDKToolsLibrary .msg (" ==> " + lib .version ());
558+ JDKToolsLibrary .msg (" based on version " + lib .version ());
545559 FullVersion v = lib .version ();
546560 if (completedResults .containsKey (v )) {
547561 completedResults .put (v , IterUtil .compose (lib , completedResults .get (v )));
@@ -595,21 +609,27 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
595609 collectValidResults (model , jars , results , compoundResults );
596610
597611 // We store everything in reverse order, since that's the natural order of the versions
598- Iterable <JarJDKToolsLibrary > collapsed = IterUtil .reverse (IterUtil .collapse (results .values ()));
612+ Iterable <JarJDKToolsLibrary > collapsed = IterUtil .reverse (IterUtil .collapse (results .values ())); // Are versions in results subsequently ignored?
613+
614+ JDKToolsLibrary .msg ("***** Found the following base libraries *****" );
615+ for (JarJDKToolsLibrary lib : collapsed ) {
616+ JDKToolsLibrary .msg (" Base library: " + lib );
617+ }
618+
599619 Iterable <JarJDKToolsLibrary > compoundCollapsed = IterUtil .reverse (IterUtil .collapse (compoundResults .values ()));
600620
601- // Get completed compound JDKs by going through the list of compound JDKs and finding full JDKs that
602- // complete them
621+ // Get completed compound JDKs by going through the list of compound JDKs and finding full JDKs that complete them
603622 Map <FullVersion , Iterable <JarJDKToolsLibrary >> completedResults =
604623 getCompletedCompoundResults (model , collapsed , compoundCollapsed );
605-
606- JDKToolsLibrary .msg ("Result:" );
607- Iterable <JarJDKToolsLibrary > result = IterUtil .
608- compose (collapsed ,IterUtil .reverse (IterUtil .collapse (completedResults .values ())));
609- for (JarJDKToolsLibrary lib : result ) {
610- JDKToolsLibrary .msg ("Found library: " +lib );
624+
625+ JDKToolsLibrary .msg ("***** Found the following completed compound libraries *****" );
626+ for (JarJDKToolsLibrary lib : IterUtil .collapse (completedResults .values ())) {
627+ JDKToolsLibrary .msg (" Compound library: " + lib );
611628 }
612629
630+ Iterable <JarJDKToolsLibrary > result =
631+ IterUtil .compose (collapsed , IterUtil .reverse (IterUtil .collapse (completedResults .values ())));
632+
613633 return result ;
614634 }
615635
@@ -644,8 +664,7 @@ private static void addIfFile(File f, JDKDescriptor c, Map<? super File,Set<JDKD
644664 }
645665
646666 /** Add a canonicalized {@code f} to the given set if it is an existing file */
647- private static void addIfFile (File f , Set <JDKDescriptor > cs ,
648- Map <? super File ,Set <JDKDescriptor >> map ) {
667+ private static void addIfFile (File f , Set <JDKDescriptor > cs , Map <? super File ,Set <JDKDescriptor >> map ) {
649668 f = IOUtil .attemptCanonicalFile (f );
650669 if (IOUtil .attemptIsFile (f )) {
651670 Set <JDKDescriptor > set = map .get (f );
@@ -678,8 +697,8 @@ private static Iterable<JDKDescriptor> searchForJDKDescriptors() {
678697 while (entries .hasMoreElements ()) {
679698 JarEntry je = entries .nextElement ();
680699 String name = je .getName ();
681- if (name .startsWith ("edu/rice/cs/drjava/model/compiler/descriptors/" ) &&
682- name . endsWith ( ".class" ) && name .indexOf ('$' ) < 0 ) {
700+ if (name .startsWith ("edu/rice/cs/drjava/model/compiler/descriptors/" ) && name . endsWith ( ".class" ) &&
701+ ( name .indexOf ('$' ) < 0 ) ) {
683702 descriptors = attemptToLoadDescriptor (descriptors , name );
684703 }
685704 }
0 commit comments