Skip to content

Commit b35a353

Browse files
author
mgricken
committed
Working on refactored compiler adapters.
git-svn-id: file:///tmp/test-svn/branches/drjava-compilers@5290 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 601a464 commit b35a353

File tree

9 files changed

+112
-60
lines changed

9 files changed

+112
-60
lines changed

drjava/lib/platform.jar

405 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
@@ -259,7 +259,7 @@ private Iterable<JDKToolsLibrary> findLibraries() {
259259

260260
File configTools = DrJava.getConfig().getSetting(JAVAC_LOCATION);
261261
if (configTools != FileOps.NULL_FILE) {
262-
JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this);
262+
JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this, null);
263263
if (fromConfig.isValid()) {
264264
JarJDKToolsLibrary.msg("From config: "+fromConfig);
265265
results.put(coarsenVersion(fromConfig.version()), fromConfig);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected static String adapterForCompiler(JavaVersion.FullVersion version) {
9595
case JAVA_6: {
9696
switch (version.vendor()) {
9797
case OPENJDK: return "edu.rice.cs.drjava.model.compiler.Javac160OpenJDKCompiler";
98-
case COMPOUND: return "edu.rice.cs.drjava.model.compiler.MintCompiler";
98+
case COMPOUND: return null;
9999
default: return "edu.rice.cs.drjava.model.compiler.Javac160Compiler";
100100
}
101101
}

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

Lines changed: 106 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.File;
4040
import java.util.Set;
4141
import java.util.LinkedHashSet;
42+
import java.util.LinkedHashMap;
4243
import java.util.Arrays;
4344
import java.util.List;
4445
import java.util.ArrayList;
@@ -125,12 +126,15 @@ public class JarJDKToolsLibrary extends JDKToolsLibrary {
125126

126127
private final File _location;
127128
private final List<File> _bootClassPath; // may be null (i.e. compiler's internal behavior)
129+
private final CompoundJDKDescriptor _jdkDescriptor; // may be null
128130

129-
private JarJDKToolsLibrary(File location, FullVersion version, CompilerInterface compiler, Debugger debugger,
131+
private JarJDKToolsLibrary(File location, FullVersion version, CompoundJDKDescriptor desc,
132+
CompilerInterface compiler, Debugger debugger,
130133
JavadocModel javadoc, List<File> bootClassPath) {
131134
super(version, compiler, debugger, javadoc);
132135
_location = location;
133136
_bootClassPath = bootClassPath;
137+
_jdkDescriptor = desc;
134138
}
135139

136140
public File location() { return _location; }
@@ -139,30 +143,44 @@ public List<File> bootClassPath() { // may be null
139143
else return null;
140144
}
141145

146+
public CompoundJDKDescriptor getJDKDescriptor() { return _jdkDescriptor; }
147+
142148
public String toString() { return super.toString() + " at " + _location + ", boot classpath: " + bootClassPath(); }
143149

144150
/** Create a JarJDKToolsLibrary from a specific {@code "tools.jar"} or {@code "classes.jar"} file. */
145-
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model) {
146-
return makeFromFile(f, model, new ArrayList<File>());
151+
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, CompoundJDKDescriptor desc) {
152+
return makeFromFile(f, model, desc, new ArrayList<File>());
147153
}
148154

149155
/** Create a JarJDKToolsLibrary from a specific {@code "tools.jar"} or {@code "classes.jar"} file. */
150-
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, List<File> additionalBootClassPath) {
151-
FullVersion version = guessVersion(f);
152-
// JDKToolsLibrary.msg("makeFromFile: "+f+" --> "+version);
156+
public static JarJDKToolsLibrary makeFromFile(File f, GlobalModel model, CompoundJDKDescriptor desc,
157+
List<File> additionalBootClassPath) {
153158
CompilerInterface compiler = NoCompilerAvailable.ONLY;
154159
Debugger debugger = NoDebuggerAvailable.ONLY;
155160
JavadocModel javadoc = new NoJavadocAvailable(model);
156161

162+
FullVersion version = guessVersion(f);
163+
JDKToolsLibrary.msg("makeFromFile: "+f+" --> "+version);
164+
JDKToolsLibrary.msg("\tdesc = "+desc);
165+
166+
boolean isSupported = JavaVersion.CURRENT.supports(version.majorVersion());
167+
if (desc!=null) {
168+
isSupported |= JavaVersion.CURRENT.supports(desc.getMinimumMajorVersion());
169+
}
170+
157171
// We can't execute code that was possibly compiled for a later Java API version.
158172
List<File> bootClassPath = null;
159-
if (JavaVersion.CURRENT.supports(version.majorVersion())) {
173+
if (isSupported) {
160174
// block tools.jar classes, so that references don't point to a different version of the classes
161175
ClassLoader loader =
162176
new ShadowingClassLoader(JarJDKToolsLibrary.class.getClassLoader(), true, TOOLS_PACKAGES, true);
163177
Iterable<File> path = IterUtil.singleton(IOUtil.attemptAbsoluteFile(f));
164178

165179
String compilerAdapter = adapterForCompiler(version);
180+
if (desc!=null) {
181+
compilerAdapter = desc.getAdapterForCompiler();
182+
}
183+
166184
if (compilerAdapter != null) {
167185

168186
// determine boot class path
@@ -201,6 +219,9 @@ else if (f.getName().equals("tools.jar")) {
201219
}
202220

203221
String debuggerAdapter = adapterForDebugger(version);
222+
if (desc!=null) {
223+
debuggerAdapter = desc.getAdapterForDebugger();
224+
}
204225
String debuggerPackage = "edu.rice.cs.drjava.model.debug.jpda";
205226
if (debuggerAdapter != null) {
206227
try {
@@ -226,7 +247,7 @@ else if (f.getName().equals("tools.jar")) {
226247

227248
}
228249

229-
return new JarJDKToolsLibrary(f, version, compiler, debugger, javadoc, bootClassPath);
250+
return new JarJDKToolsLibrary(f, version, desc, compiler, debugger, javadoc, bootClassPath);
230251
}
231252

232253
private static FullVersion guessVersion(File f) {
@@ -363,74 +384,76 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
363384
/* roots is a list of possible parent directories of Java installations; we want to eliminate duplicates &
364385
* remember insertion order
365386
*/
366-
LinkedHashSet<File> roots = new LinkedHashSet<File>();
387+
LinkedHashMap<File,Set<CompoundJDKDescriptor>> roots = new LinkedHashMap<File,Set<CompoundJDKDescriptor>>();
367388

368389
if (javaHome != null) {
369-
addIfDir(new File(javaHome), roots);
370-
addIfDir(new File(javaHome, ".."), roots);
371-
addIfDir(new File(javaHome, "../.."), roots);
390+
addIfDir(new File(javaHome), null, roots);
391+
addIfDir(new File(javaHome, ".."), null, roots);
392+
addIfDir(new File(javaHome, "../.."), null, roots);
372393
}
373394
if (envJavaHome != null) {
374-
addIfDir(new File(envJavaHome), roots);
375-
addIfDir(new File(envJavaHome, ".."), roots);
376-
addIfDir(new File(envJavaHome, "../.."), roots);
395+
addIfDir(new File(envJavaHome), null, roots);
396+
addIfDir(new File(envJavaHome, ".."), null, roots);
397+
addIfDir(new File(envJavaHome, "../.."), null, roots);
377398
}
378399

379400
if (programFiles != null) {
380-
addIfDir(new File(programFiles, "Java"), roots);
381-
addIfDir(new File(programFiles), roots);
401+
addIfDir(new File(programFiles, "Java"), null, roots);
402+
addIfDir(new File(programFiles), null, roots);
382403
}
383-
addIfDir(new File("/C:/Program Files/Java"), roots);
384-
addIfDir(new File("/C:/Program Files"), roots);
404+
addIfDir(new File("/C:/Program Files/Java"), null, roots);
405+
addIfDir(new File("/C:/Program Files"), null, roots);
385406
if (systemDrive != null) {
386-
addIfDir(new File(systemDrive, "Java"), roots);
387-
addIfDir(new File(systemDrive), roots);
407+
addIfDir(new File(systemDrive, "Java"), null, roots);
408+
addIfDir(new File(systemDrive), null, roots);
388409
}
389-
addIfDir(new File("/C:/Java"), roots);
390-
addIfDir(new File("/C:"), roots);
410+
addIfDir(new File("/C:/Java"), null, roots);
411+
addIfDir(new File("/C:"), null, roots);
391412

392-
addIfDir(new File("/System/Library/Frameworks/JavaVM.framework/Versions"), roots);
413+
addIfDir(new File("/System/Library/Frameworks/JavaVM.framework/Versions"), null, roots);
393414

394-
addIfDir(new File("/usr/java"), roots);
395-
addIfDir(new File("/usr/j2se"), roots);
396-
addIfDir(new File("/usr"), roots);
397-
addIfDir(new File("/usr/local/java"), roots);
398-
addIfDir(new File("/usr/local/j2se"), roots);
399-
addIfDir(new File("/usr/local"), roots);
415+
addIfDir(new File("/usr/java"), null, roots);
416+
addIfDir(new File("/usr/j2se"), null, roots);
417+
addIfDir(new File("/usr"), null, roots);
418+
addIfDir(new File("/usr/local/java"), null, roots);
419+
addIfDir(new File("/usr/local/j2se"), null, roots);
420+
addIfDir(new File("/usr/local"), null, roots);
400421

401422
/* Entries for Linux java packages */
402-
addIfDir(new File("/usr/lib/jvm"), roots);
403-
addIfDir(new File("/usr/lib/jvm/java-6-sun"), roots);
404-
addIfDir(new File("/usr/lib/jvm/java-1.5.0-sun"), roots);
405-
addIfDir(new File("/usr/lib/jvm/java-6-openjdk"), roots);
423+
addIfDir(new File("/usr/lib/jvm"), null, roots);
424+
addIfDir(new File("/usr/lib/jvm/java-6-sun"), null, roots);
425+
addIfDir(new File("/usr/lib/jvm/java-1.5.0-sun"), null, roots);
426+
addIfDir(new File("/usr/lib/jvm/java-6-openjdk"), null, roots);
406427

407-
addIfDir(new File("/home/javaplt/java/Linux-i686"), roots);
428+
addIfDir(new File("/home/javaplt/java/Linux-i686"), null, roots);
408429

409430
/* jars is a list of possible tools.jar (or classes.jar) files; we want to eliminate duplicates &
410431
* remember insertion order
411432
*/
412-
LinkedHashSet<File> jars = new LinkedHashSet<File>();
413-
addIfFile(edu.rice.cs.util.FileOps.getDrJavaFile(), jars); // drjava.jar file itself; check if it's a combined Mint/DrJava jar
433+
LinkedHashMap<File,Set<CompoundJDKDescriptor>> jars = new LinkedHashMap<File,Set<CompoundJDKDescriptor>>();
434+
// drjava.jar file itself; check if it's a combined Mint/DrJava jar
435+
addIfFile(edu.rice.cs.util.FileOps.getDrJavaFile(), (CompoundJDKDescriptor)null, jars);
414436

415437
// Search for all compound JDK descriptors in the drjava.jar file
416438
Iterable<CompoundJDKDescriptor> descriptors = searchForCompoundJDKDescriptors();
417439
for(CompoundJDKDescriptor desc: descriptors) {
418440
// add the specific search directories and files
419-
for(File f: desc.getSearchDirectories()) { addIfDir(f, roots); }
420-
for(File f: desc.getSearchFiles()) { addIfFile(f, jars); }
441+
for(File f: desc.getSearchDirectories()) { addIfDir(f, desc, roots); }
442+
for(File f: desc.getSearchFiles()) { addIfFile(f, desc, jars); }
421443
// add to the set of packages that need to be shadowed
422444
TOOLS_PACKAGES.addAll(desc.getToolsPackages());
423445
}
424446

425-
// matches: starts with "j2sdk", starts with "jdk", has form "[number].[number].[number]" (OS X), starts with "java-" (Linux)
447+
// matches: starts with "j2sdk", starts with "jdk", has form "[number].[number].[number]" (OS X), or
448+
// starts with "java-" (Linux)
426449
Predicate<File> subdirFilter = LambdaUtil.or(IOUtil.regexCanonicalCaseFilePredicate("j2sdk.*"),
427450
IOUtil.regexCanonicalCaseFilePredicate("jdk.*"),
428451
LambdaUtil.or(IOUtil.regexCanonicalCaseFilePredicate("\\d+\\.\\d+\\.\\d+"),
429452
IOUtil.regexCanonicalCaseFilePredicate("java.*")));
430-
for (File root : roots) {
431-
for (File subdir : IOUtil.attemptListFilesAsIterable(root, subdirFilter)) {
432-
addIfFile(new File(subdir, "lib/tools.jar"), jars);
433-
addIfFile(new File(subdir, "Classes/classes.jar"), jars);
453+
for (Map.Entry<File,Set<CompoundJDKDescriptor>> root : roots.entrySet()) {
454+
for (File subdir : IOUtil.attemptListFilesAsIterable(root.getKey(), subdirFilter)) {
455+
addIfFile(new File(subdir, "lib/tools.jar"), root.getValue(), jars);
456+
addIfFile(new File(subdir, "Classes/classes.jar"), root.getValue(), jars);
434457
}
435458
}
436459

@@ -460,15 +483,17 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
460483
Map<FullVersion, Iterable<JarJDKToolsLibrary>> compoundResults =
461484
new TreeMap<FullVersion, Iterable<JarJDKToolsLibrary>>();
462485

463-
for (File jar : jars) {
464-
JarJDKToolsLibrary lib = makeFromFile(jar, model);
465-
if (lib.isValid()) {
466-
FullVersion v = lib.version();
467-
Map<FullVersion, Iterable<JarJDKToolsLibrary>> mapToAddTo = results;
468-
if (v.vendor().equals(JavaVersion.VendorType.COMPOUND)) { mapToAddTo = compoundResults; }
469-
470-
if (mapToAddTo.containsKey(v)) { mapToAddTo.put(v, IterUtil.compose(lib, mapToAddTo.get(v))); }
471-
else { mapToAddTo.put(v, IterUtil.singleton(lib)); }
486+
for (Map.Entry<File,Set<CompoundJDKDescriptor>> jar : jars.entrySet()) {
487+
for (CompoundJDKDescriptor desc : jar.getValue()) {
488+
JarJDKToolsLibrary lib = makeFromFile(jar.getKey(), model, desc);
489+
if (lib.isValid()) {
490+
FullVersion v = lib.version();
491+
Map<FullVersion, Iterable<JarJDKToolsLibrary>> mapToAddTo = results;
492+
if (v.vendor().equals(JavaVersion.VendorType.COMPOUND)) { mapToAddTo = compoundResults; }
493+
494+
if (mapToAddTo.containsKey(v)) { mapToAddTo.put(v, IterUtil.compose(lib, mapToAddTo.get(v))); }
495+
else { mapToAddTo.put(v, IterUtil.singleton(lib)); }
496+
}
472497
}
473498
}
474499

@@ -510,7 +535,8 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
510535
}
511536
// if we found a JDK, then create a new compound library
512537
if (found!=null) {
513-
JarJDKToolsLibrary lib = makeFromFile(compoundLib.location(), model, found.bootClassPath());
538+
JarJDKToolsLibrary lib = makeFromFile(compoundLib.location(), model, compoundLib.getJDKDescriptor(),
539+
found.bootClassPath());
514540
if (lib.isValid()) {
515541
JDKToolsLibrary.msg("\t==> "+lib.version());
516542
FullVersion v = lib.version();
@@ -529,16 +555,38 @@ public static Iterable<JarJDKToolsLibrary> search(GlobalModel model) {
529555
}
530556

531557
/** Add a canonicalized {@code f} to the given set if it is an existing directory or link */
532-
private static void addIfDir(File f, Set<? super File> set) {
558+
private static void addIfDir(File f, CompoundJDKDescriptor c, Map<? super File, Set<CompoundJDKDescriptor>> map) {
533559
f = IOUtil.attemptCanonicalFile(f);
534-
if (IOUtil.attemptIsDirectory(f)) { set.add(f); JDKToolsLibrary.msg("Dir added: "+f); }
560+
if (IOUtil.attemptIsDirectory(f)) {
561+
Set<CompoundJDKDescriptor> set = map.get(f);
562+
if (set==null) {
563+
set = new LinkedHashSet<CompoundJDKDescriptor>();
564+
map.put(f, set);
565+
}
566+
set.add(c);
567+
JDKToolsLibrary.msg("Dir added: "+f);
568+
}
535569
else { JDKToolsLibrary.msg("Dir not added: "+f); }
536570
}
537571

538572
/** Add a canonicalized {@code f} to the given set if it is an existing file */
539-
private static void addIfFile(File f, Set<? super File> set) {
573+
private static void addIfFile(File f, CompoundJDKDescriptor c, Map<? super File,Set<CompoundJDKDescriptor>> map) {
574+
addIfFile(f, Collections.singleton(c), map);
575+
}
576+
577+
/** Add a canonicalized {@code f} to the given set if it is an existing file */
578+
private static void addIfFile(File f, Set<CompoundJDKDescriptor> cs,
579+
Map<? super File,Set<CompoundJDKDescriptor>> map) {
540580
f = IOUtil.attemptCanonicalFile(f);
541-
if (IOUtil.attemptIsFile(f)) { set.add(f); JDKToolsLibrary.msg("File added: "+f); }
581+
if (IOUtil.attemptIsFile(f)) {
582+
Set<CompoundJDKDescriptor> set = map.get(f);
583+
if (set==null) {
584+
set = new LinkedHashSet<CompoundJDKDescriptor>();
585+
map.put(f, set);
586+
}
587+
set.addAll(cs);
588+
JDKToolsLibrary.msg("File added: "+f);
589+
}
542590
else { JDKToolsLibrary.msg("File not added: "+f); }
543591
}
544592

Binary file not shown.
Binary file not shown.
Binary file not shown.

platform/src-mint/edu/rice/cs/drjava/model/compiler/descriptors/Mint2Descriptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ public String value(String java_version, String java_runtime_name, String java_v
9999
}
100100
};
101101
}
102+
103+
public String toString() { return getClass().getSimpleName()+" --> "+getAdapterForCompiler(); }
102104
}

platform/src-mint/edu/rice/cs/drjava/model/compiler/descriptors/MintDescriptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,6 @@ public String value(String java_version, String java_runtime_name, String java_v
119119
}
120120
};
121121
}
122+
123+
public String toString() { return getClass().getSimpleName()+" --> "+getAdapterForCompiler(); }
122124
}

0 commit comments

Comments
 (0)