Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 239   Methods: 22
NCLOC: 105   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
JDKDescriptor.java 0% 24.5% 45.5% 26.5%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.model;
 38   
 39    import java.io.File;
 40    import java.io.IOException;
 41    import java.io.FileNotFoundException;
 42    import java.util.Set;
 43    import java.util.jar.JarFile;
 44    import java.util.Collections;
 45   
 46    import edu.rice.cs.drjava.model.JDKToolsLibrary;
 47    import edu.rice.cs.plt.reflect.JavaVersion;
 48    import edu.rice.cs.plt.reflect.JavaVersion.FullVersion;
 49    import edu.rice.cs.plt.iter.IterUtil;
 50   
 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 {
 55    /** Return the name of this JDK.
 56    * @return name */
 57    public abstract String getName();
 58   
 59    /** Packages to shadow when loading a new tools.jar. If we don't shadow these classes, we won't
 60    * be able to load distinct versions for each tools.jar library. These should be verified whenever
 61    * a new Java version is released. (We can't just shadow *everything* because some classes, at
 62    * least in OS X's classes.jar, can only be loaded by the JVM.)
 63    *
 64    * @return set of packages that need to be shadowed
 65    */
 66    public abstract Set<String> getToolsPackages();
 67   
 68    /** Returns a list of directories that should be searched for tools.jar and classes.jar files.
 69    * @return list of directories to search */
 70    public abstract Iterable<File> getSearchDirectories();
 71   
 72    /** Returns a list of files that should be searched if they contain a compiler.
 73    * @return list of files to search */
 74    public abstract Iterable<File> getSearchFiles();
 75   
 76    /** True if this is a compound JDK and needs a fully featured JDK to operate.
 77    * @return true if compound JDK (e.g. NextGen, Mint, Habanero). */
 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  0 public boolean isBaseForCompound() { return false; }
 83   
 84    /** Return the class name of the compiler adapter.
 85    * @return class name of compiler, or null if no compiler */
 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  0 public String getAdapterForCompiler(JavaVersion.FullVersion guessedVersion) {
 92  0 return getAdapterForCompiler(); // ignore the version
 93    }
 94   
 95    /** Return the class name of the debugger adapter.
 96    * @return class name of debugger, or null if no debugger */
 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  0 public String getAdapterForDebugger(JavaVersion.FullVersion guessedVersion) {
 103  0 return getAdapterForDebugger(); // ignore version
 104    }
 105   
 106    /** Return true if the file (jar file or directory) contains the compiler.
 107    * @return true if the file contains the compiler */
 108    public abstract boolean containsCompiler(File f);
 109   
 110    /** Return the guessed version for the compiler in the specified file (jar file or directory).
 111    * Note that this is the Java version that this compiler is compatible to, not the internal compiler version.
 112    * For full (non-compound) JDKs, this is equal to the version, i.e. JDK6 should guess Java 6.0.
 113    * For compound JDKs, this is equal to the version of the full JDK that the compound JDK needs, i.e.
 114    * if a version of the HJ compiler requires JDK6, it should guess JDK6.
 115    * @return guessed version */
 116  2826 public JavaVersion.FullVersion guessVersion(File f) {
 117  2826 return edu.rice.cs.drjava.model.JarJDKToolsLibrary.guessVersion(f, this);
 118    }
 119   
 120    /** Return the minimum Java version required to use this JDK.
 121    * @return minimum version */
 122    public abstract JavaVersion getMinimumMajorVersion();
 123   
 124    /** Return the list of additional files required to use the compiler.
 125    * The compiler was found in the specified file. This method may have to search the user's hard drive, e.g.
 126    * by looking relative to compiler.getParentFile(), by checking environment variables, or by looking in
 127    * certain OS-specific directories.
 128    *
 129    * // for example:
 130    * public Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException {
 131    * File parent = compiler.getParentFile();
 132    * File nextgen2orgjar = new File(parent, "nextgen2org.jar");
 133    * if (!Util.exists(nextgen2orgjar,
 134    * "org/apache/bcel/classfile/Node.class")) {
 135    * throw new FileNotFoundException("org/apache/bcel/classfile/Node.class");
 136    * }
 137    * return IterUtil.singleton(nextgen2orgjar);
 138    * }
 139    *
 140    * @param compiler location where the compiler was fund
 141    * @return list of additional files that need to be available */
 142    public abstract Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException;
 143   
 144    /** Return a description of this JDK.
 145    * @param version the specific version of the compiler
 146    * @return description */
 147  0 public String getDescription(JavaVersion.FullVersion version) {
 148  0 return getName() + " library " + version.versionString();
 149    }
 150   
 151  5652 public String toString() {
 152  5652 return this.getClass().getName()+": "+getName();
 153    }
 154   
 155    /** Singleton representing a JDK that doesn't have a descriptor. */
 156    public static final JDKDescriptor NONE = new None();
 157   
 158    /** Class for the singleton representing a JDK that doesn't have a descriptor. */
 159    private static final class None extends JDKDescriptor {
 160  5652 public String getName() { return "none"; }
 161  5181 public String getDescription(JavaVersion.FullVersion version) {
 162  5181 switch(version.vendor()) {
 163  5181 case ORACLE:
 164  5181 return "Oracle JDK library " + version.toString();
 165  0 case OPENJDK:
 166  0 return "OpenJDK library " + version.toString();
 167  0 case APPLE:
 168  0 return "Apple JDK library " + version.toString();
 169  0 default:
 170  0 return "JDK library " + version.toString();
 171    }
 172    }
 173  0 public Set<String> getToolsPackages() { return Collections.emptySet(); }
 174  0 public Iterable<File> getSearchDirectories() { return IterUtil.empty(); }
 175  0 public Iterable<File> getSearchFiles() { return IterUtil.empty(); }
 176  5338 public boolean isCompound() { return false; }
 177  0 public boolean isBaseForCompound() { return true; }
 178  0 public String getAdapterForCompiler() { return ""; }
 179  2826 public String getAdapterForCompiler(JavaVersion.FullVersion guessedVersion) {
 180  2826 return JDKToolsLibrary.adapterForCompiler(guessedVersion);
 181    }
 182  0 public String getAdapterForDebugger() { return ""; }
 183  2826 public String getAdapterForDebugger(JavaVersion.FullVersion guessedVersion) {
 184  2826 return JDKToolsLibrary.adapterForDebugger(guessedVersion);
 185    }
 186  2826 public boolean containsCompiler(File f) { return true; }
 187  2826 public JavaVersion getMinimumMajorVersion() { return JavaVersion.JAVA_1_1; }
 188  2826 public Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException {
 189  2826 return IterUtil.empty();
 190    }
 191    }
 192   
 193    /** Utilities for JDK descriptors. */
 194    public static class Util {
 195    /** Return true if the file names exist in the specified file, which can either be a directory or jar file.
 196    * @param jarOrDir jar file or directory
 197    * @param fileNames file names that need to exist
 198    * @return true if all file names are found */
 199  0 public static boolean exists(File jarOrDir, String... fileNames) {
 200  0 if (jarOrDir.isFile()) {
 201  0 try {
 202  0 JarFile jf = new JarFile(jarOrDir);
 203  0 for(String fn: fileNames) {
 204  0 if (jf.getJarEntry(fn)==null) return false;
 205    }
 206  0 return true;
 207    }
 208  0 catch(IOException ioe) { return false; }
 209    }
 210  0 else if (jarOrDir.isDirectory()) {
 211  0 for(String fn: fileNames) {
 212  0 if (!(new File(jarOrDir,fn).exists())) return false;
 213    }
 214  0 return true;
 215    }
 216  0 return false;
 217    }
 218   
 219    /** Return the first of the file names that exists in the specified directory.
 220    * Throws FileNotFoundException if none of them exists.
 221    * @param jarOrDir jar file or directory
 222    * @param fileNames file names that need to exist
 223    * @return file name if found, or null
 224    * @throws FileNotFoundException if none of them exists.*/
 225  0 public static File oneOf(File dir, String... fileNames) throws FileNotFoundException {
 226  0 if (dir.isDirectory()) {
 227  0 for(String fn: fileNames) {
 228  0 File f = new File(dir,fn);
 229  0 if (f.exists()) return f;
 230    }
 231  0 throw new FileNotFoundException("None of "+IterUtil.toString(IterUtil.make(fileNames), "", ", ", "")+
 232    " found in "+dir);
 233   
 234    }
 235  0 throw new FileNotFoundException(dir+" is not a directory");
 236   
 237    }
 238    }
 239    }