Skip to content

Commit 1b2ad6f

Browse files
author
rcartwright
committed
This revision contains code modifications in JarJDKToolsLibrary
intended to find more Java/Scala compilers, particularly on Mac OS X. It also turns off logging except in JarJDKToolsLibrary. This commit got mangled by a conflict so subsequent cleanup may be necessary. The following files were modified: M drjava/src/edu/rice/cs/drjava/model/JarJDKToolsLibrary.java M drjava/src/edu/rice/cs/drjava/model/GlobalModelTestCase.java M drjava/src/edu/rice/cs/drjava/model/GlobalModelCompileErrorsTest.java M drjava/src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java M drjava/src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java M drjava/src/edu/rice/cs/drjava/model/JDKDescriptor.java 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/AbstractGlobalModel.java M drjava/src/edu/rice/cs/drjava/ui/JUnitPanel.java git-svn-id: file:///tmp/test-svn/branches/drscala@5537 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent b795036 commit 1b2ad6f

File tree

10 files changed

+313
-296
lines changed

10 files changed

+313
-296
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
*/
165165
public class AbstractGlobalModel implements SingleDisplayModel, OptionConstants, DocumentIterator {
166166

167-
public static final Log _log = new Log("GlobalModel.txt", true);
167+
public static final Log _log = new Log("GlobalModel.txt", false);
168168

169169
/** A document cache that manages how many unmodified documents are open at once. */
170170
protected DocumentCache _cache;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
public final class GlobalModelCompileErrorsTest extends GlobalModelTestCase {
5858

59-
public static final Log _log = new Log("GlobalModel.txt", true);
59+
public static final Log _log = new Log("GlobalModel.txt", false);
6060

6161
private static final String FOO_MISSING_CLOSE_TEXT = "class DrScalaTestFoo {\n\n";
6262
private static final String BAR_MISSING_DECLARATION_KEYWORD = "class DrScalaTestBar { zz }";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
*/
7676
public abstract class GlobalModelTestCase extends MultiThreadedTestCase {
7777

78-
public static final Log _log = new Log("GlobalModel.txt", true);
78+
public static final Log _log = new Log("GlobalModel.txt", false);
7979

8080
protected volatile DefaultGlobalModel _model;
8181
protected volatile InteractionsController _interactionsController;

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

Lines changed: 239 additions & 239 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ public class JDKToolsLibrary {
7676
private final JavadocModel _javadoc;
7777
private final JDKDescriptor _jdkDescriptor; // JDKDescriptor.NONE if none
7878

79-
protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor,
80-
CompilerInterface compiler, Debugger debugger,
81-
JavadocModel javadoc) {
79+
protected JDKToolsLibrary(FullVersion version, JDKDescriptor jdkDescriptor, CompilerInterface compiler,
80+
Debugger debugger, JavadocModel javadoc) {
8281
assert jdkDescriptor != null;
8382
_version = version;
8483
_compiler = compiler;

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

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
public class DefaultCompilerModel implements CompilerModel {
7777

7878
/** for logging debug info */
79-
private static edu.rice.cs.util.Log _log = new edu.rice.cs.util.Log("GlobalModel.txt", true);
79+
private static edu.rice.cs.util.Log _log = new edu.rice.cs.util.Log("GlobalModel.txt", false);
8080

8181
/** The available compilers */
8282
private final List<CompilerInterface> _compilers;

drjava/src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
*/
6969
public class DefinitionsDocument extends AbstractDJDocument implements Finalizable<DefinitionsDocument> {
7070

71-
public static final Log _log = new Log("GlobalModel.txt", true);
71+
public static final Log _log = new Log("GlobalModel.txt", false);
7272
private static final int NO_COMMENT_OFFSET = 0;
7373
private static final int WING_COMMENT_OFFSET = 2;
7474

drjava/src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
public class DefaultJUnitModel implements JUnitModel, JUnitModelCallback {
9494

9595
/** log for use in debugging */
96-
private static Log _log = new Log("GlobalModel.txt", true);
96+
private static Log _log = new Log("GlobalModel.txt", false);
9797

9898
/** Manages listeners to this model. */
9999
private final JUnitEventNotifier _notifier = new JUnitEventNotifier();

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import edu.rice.cs.util.UnexpectedException;
4444
import edu.rice.cs.util.swing.BorderlessScrollPane;
4545
import edu.rice.cs.util.swing.RightClickMouseAdapter;
46+
import edu.rice.cs.util.swing.Utilities;
4647

4748
import javax.swing.*;
4849
import javax.swing.border.EmptyBorder;
@@ -87,10 +88,10 @@ private static final SimpleAttributeSet _getTestFailAttributes() {
8788
private static final String TEST_OUT_OF_SYNC =
8889
"The documents being tested have been modified and should be recompiled!\n";
8990

90-
protected JUnitErrorListPane _errorListPane;
91+
protected volatile JUnitErrorListPane _errorListPane;
9192
private final MainFrame _mainFrame; // only used in assert statements
92-
private int _testCount;
93-
private boolean _testsSuccessful;
93+
private volatile int _testCount;
94+
private volatile boolean _testsSuccessful;
9495

9596
private volatile JUnitProgressBar _progressBar;
9697

@@ -194,15 +195,12 @@ public void progressStep(boolean successful) {
194195
public void testStarted(String className, String testName) { }
195196

196197
private void _displayStackTrace (JUnitError e) {
197-
_errorLabel.setText((e.isWarning() ? "Error: " : "Failure: ") +
198-
e.message());
198+
_errorLabel.setText((e.isWarning() ? "Error: " : "Failure: ") + e.message());
199199
_fileLabel.setText("File: " + (new File(e.fileName())).getName());
200-
if (!e.testName().equals("")) {
200+
if (!e.testName().equals(""))
201201
_testLabel.setText("Test: " + e.testName());
202-
}
203-
else {
202+
else
204203
_testLabel.setText("");
205-
}
206204
_stackTextArea.setText(e.toString());
207205
_stackTextArea.setCaretPosition(0);
208206
_frame.setPopupLoc(_stackFrame);
@@ -211,9 +209,9 @@ private void _displayStackTrace (JUnitError e) {
211209

212210
/** A pane to show JUnit errors. It acts like a listbox (clicking selects an item) but items can each wrap, etc. */
213211
public class JUnitErrorListPane extends ErrorPanel.ErrorListPane {
214-
private JPopupMenu _popMenu;
215-
private String _runningTestName;
216-
private boolean _warnedOutOfSync;
212+
private volatile JPopupMenu _popMenu;
213+
private volatile String _runningTestName;
214+
private volatile boolean _warnedOutOfSync;
217215
private static final String JUNIT_WARNING = "junit.framework.TestSuite$1.warning";
218216

219217
/** Maps any test names in the currently running suite to the position that they appear in the list pane. */
@@ -522,7 +520,7 @@ private boolean _selectError(MouseEvent e) {
522520
* Adapted from JUnit code.
523521
*/
524522
static class JUnitProgressBar extends JProgressBar {
525-
private boolean _hasError = false;
523+
private volatile boolean _hasError = false;
526524

527525
public JUnitProgressBar() {
528526
super();
@@ -544,15 +542,16 @@ public void reset() {
544542
setValue(0);
545543
}
546544

547-
public void start(int total) {
545+
public void start(final int total) {
548546
setMaximum(total);
549547
reset();
550548
}
551549

552-
public void step(int value, boolean successful) {
550+
public void step(final int value, final boolean successful) {
553551
setValue(value);
554-
if (!_hasError && !successful) {
552+
if (! _hasError && ! successful) {
555553
_hasError= true;
554+
// Utilities.show(Thread.currentThread().getStackTrace()));
556555
setForeground(getStatusColor());
557556
}
558557
}

0 commit comments

Comments
 (0)