3434 *
3535 * END_COPYRIGHT_BLOCK*/
3636
37- package edu .rice .cs .drjava .model . compiler . descriptors ;
37+ package edu .rice .cs .drjava .model ;
3838
3939import java .io .File ;
4040import java .io .IOException ;
4141import java .io .FileNotFoundException ;
4242import java .util .Set ;
4343import java .util .jar .JarFile ;
44+ import java .util .Collections ;
45+
46+ import edu .rice .cs .drjava .model .JDKToolsLibrary ;
4447import edu .rice .cs .plt .reflect .JavaVersion ;
48+ import edu .rice .cs .plt .reflect .JavaVersion .FullVersion ;
4549import edu .rice .cs .plt .iter .IterUtil ;
4650
47- /** A description of a JDK. */
48- public interface JDKDescriptor {
51+ /** A description of a JDK.
52+ * Put subclasses of JDKDescriptor in the edu.rice.cs.drjava.model.compiler.descriptors package for DrJava
53+ * to find. */
54+ public abstract class JDKDescriptor {
4955 /** Return the name of this JDK.
5056 * @return name */
51- public String getName ();
57+ public abstract String getName ();
5258
5359 /** Packages to shadow when loading a new tools.jar. If we don't shadow these classes, we won't
5460 * be able to load distinct versions for each tools.jar library. These should be verified whenever
@@ -57,35 +63,53 @@ public interface JDKDescriptor {
5763 *
5864 * @return set of packages that need to be shadowed
5965 */
60- public Set <String > getToolsPackages ();
66+ public abstract Set <String > getToolsPackages ();
6167
6268 /** Returns a list of directories that should be searched for tools.jar and classes.jar files.
6369 * @return list of directories to search */
64- public Iterable <File > getSearchDirectories ();
70+ public abstract Iterable <File > getSearchDirectories ();
6571
6672 /** Returns a list of files that should be searched if they contain a compiler.
6773 * @return list of files to search */
68- public Iterable <File > getSearchFiles ();
74+ public abstract Iterable <File > getSearchFiles ();
6975
7076 /** True if this is a compound JDK and needs a fully featured JDK to operate.
7177 * @return true if compound JDK (e.g. NextGen, Mint, Habanero). */
72- public boolean isCompound ();
78+ public abstract boolean isCompound ();
79+
80+ /** True if this is a JDK that can serve as base for a compound JDK.
81+ * @return true if base for a compound JDK (e.g. Sun JDK, OpenJDK, AppleJDK). */
82+ public boolean isBaseForCompound () { return false ; }
7383
7484 /** Return the class name of the compiler adapter.
7585 * @return class name of compiler, or null if no compiler */
76- public String getAdapterForCompiler ();
86+ public abstract String getAdapterForCompiler ();
87+
88+ /** Return the class name of the compiler adapter.
89+ * @param guessedVersion the guessed version of the compiler
90+ * @return class name of compiler, or null if no compiler */
91+ public String getAdapterForCompiler (JavaVersion .FullVersion guessedVersion ) {
92+ return getAdapterForCompiler (); // ignore the version
93+ }
7794
7895 /** Return the class name of the debugger adapter.
7996 * @return class name of debugger, or null if no debugger */
80- public String getAdapterForDebugger ();
97+ public abstract String getAdapterForDebugger ();
98+
99+ /** Return the class name of the debugger adapter.
100+ * @param guessedVersion the guessed version of the compiler
101+ * @return class name of debugger, or null if no debugger */
102+ public String getAdapterForDebugger (JavaVersion .FullVersion guessedVersion ) {
103+ return getAdapterForDebugger (); // ignore version
104+ }
81105
82106 /** Return true if the file (jar file or directory) contains the compiler.
83107 * @return true if the file contains the compiler */
84- public boolean containsCompiler (File f );
108+ public abstract boolean containsCompiler (File f );
85109
86110 /** Return the minimum Java version required to use this JDK.
87111 * @return minimum version */
88- public JavaVersion getMinimumMajorVersion ();
112+ public abstract JavaVersion getMinimumMajorVersion ();
89113
90114 /** Return the list of additional files required to use the compiler.
91115 * The compiler was found in the specified file. This method may have to search the user's hard drive, e.g.
@@ -105,7 +129,52 @@ public interface JDKDescriptor {
105129 *
106130 * @param compiler location where the compiler was fund
107131 * @return list of additional files that need to be available */
108- public Iterable <File > getAdditionalCompilerFiles (File compiler ) throws FileNotFoundException ;
132+ public abstract Iterable <File > getAdditionalCompilerFiles (File compiler ) throws FileNotFoundException ;
133+
134+ /** Return a description of this JDK.
135+ * @param version the specific version of the compiler
136+ * @return description */
137+ public String getDescription (JavaVersion .FullVersion version ) {
138+ return getName () + " library " + version .versionString ();
139+ }
140+
141+ /** Singleton representing a JDK that doesn't have a descriptor. */
142+ public static final JDKDescriptor NONE = new None ();
143+
144+ /** Class for the singleton representing a JDK that doesn't have a descriptor. */
145+ private static final class None extends JDKDescriptor {
146+ public String getName () { return "none" ; }
147+ public String getDescription (JavaVersion .FullVersion version ) {
148+ switch (version .vendor ()) {
149+ case SUN :
150+ return "Sun JDK library " + version .toString ();
151+ case OPENJDK :
152+ return "OpenJDK library " + version .toString ();
153+ case APPLE :
154+ return "Apple JDK library " + version .toString ();
155+ default :
156+ return "JDK library " + version .toString ();
157+ }
158+ }
159+ public Set <String > getToolsPackages () { return Collections .emptySet (); }
160+ public Iterable <File > getSearchDirectories () { return IterUtil .empty (); }
161+ public Iterable <File > getSearchFiles () { return IterUtil .empty (); }
162+ public boolean isCompound () { return false ; }
163+ public boolean isBaseForCompound () { return true ; }
164+ public String getAdapterForCompiler () { return "" ; }
165+ public String getAdapterForCompiler (JavaVersion .FullVersion guessedVersion ) {
166+ return JDKToolsLibrary .adapterForCompiler (guessedVersion );
167+ }
168+ public String getAdapterForDebugger () { return "" ; }
169+ public String adapterForDebugger (JavaVersion .FullVersion guessedVersion ) {
170+ return JDKToolsLibrary .adapterForCompiler (guessedVersion );
171+ }
172+ public boolean containsCompiler (File f ) { return true ; }
173+ public JavaVersion getMinimumMajorVersion () { return JavaVersion .JAVA_1_1 ; }
174+ public Iterable <File > getAdditionalCompilerFiles (File compiler ) throws FileNotFoundException {
175+ return IterUtil .empty ();
176+ }
177+ }
109178
110179 /** Utilities for JDK descriptors. */
111180 public static class Util {
0 commit comments