Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 148   Methods: 4
NCLOC: 92   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Javac160FilteringCompiler.java 60% 72.1% 100% 70.1%
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.compiler;
 38   
 39    import java.util.List;
 40    import java.util.ArrayList;
 41    import java.util.LinkedList;
 42    import java.util.Iterator;
 43    import java.io.File;
 44    import java.io.IOException;
 45    import java.io.FilenameFilter;
 46    import java.io.FileFilter;
 47    import java.io.InputStream;
 48    import java.io.FileOutputStream;
 49    import edu.rice.cs.plt.io.IOUtil;
 50    import edu.rice.cs.drjava.config.OptionConstants;
 51    import edu.rice.cs.drjava.DrJava;
 52    import edu.rice.cs.drjava.model.DJError;
 53    import edu.rice.cs.util.ArgumentTokenizer;
 54    import edu.rice.cs.plt.reflect.JavaVersion;
 55   
 56    /** An abstract parent for all javac-based compiler interfaces that may need to filter .exe files from the
 57    * classpath, i.e. javac from JDKs 1.6.0_04 or newer.
 58    * @version $Id$
 59    */
 60    public abstract class Javac160FilteringCompiler extends JavacCompiler {
 61    protected final boolean _filterExe;
 62    protected final File _tempJUnit;
 63    protected static final String PREFIX = "drjava-junit";
 64    protected static final String SUFFIX = ".jar";
 65   
 66  1413 protected Javac160FilteringCompiler(JavaVersion.FullVersion version,
 67    String location,
 68    List<? extends File> defaultBootClassPath) {
 69  1413 super(version, location, defaultBootClassPath);
 70   
 71  1413 _filterExe = version.compareTo(JavaVersion.parseFullVersion("1.6.0_04")) >= 0;
 72  1413 File tempJUnit = null;
 73  1413 if (_filterExe) {
 74    // if we need to filter out exe files from the classpath, we also need to
 75    // extract junit.jar and create a temporary file
 76  1099 try {
 77    // edu.rice.cs.util.Log LOG = new edu.rice.cs.util.Log("jdk160.txt",true);
 78    // LOG.log("Filtering exe files from classpath.");
 79  1099 InputStream is = Javac160FilteringCompiler.class.getResourceAsStream("/junit.jar");
 80  1099 if (is!=null) {
 81    // LOG.log("\tjunit.jar found");
 82  0 tempJUnit = edu.rice.cs.plt.io.IOUtil.createAndMarkTempFile(PREFIX,SUFFIX);
 83  0 FileOutputStream fos = new FileOutputStream(tempJUnit);
 84  0 int size = edu.rice.cs.plt.io.IOUtil.copyInputStream(is,fos);
 85    // LOG.log("\t"+size+" bytes written to "+tempJUnit.getAbsolutePath());
 86    }
 87    else {
 88    // LOG.log("\tjunit.jar not found");
 89  1099 if (tempJUnit!=null) {
 90  0 tempJUnit.delete();
 91  0 tempJUnit = null;
 92    }
 93    }
 94    }
 95    catch(IOException ioe) {
 96  0 if (tempJUnit!=null) {
 97  0 tempJUnit.delete();
 98  0 tempJUnit = null;
 99    }
 100    }
 101    // sometimes this file may be left behind, so create a shutdown hook
 102    // that deletes temporary files matching our pattern
 103  1099 Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
 104  514 public void run() {
 105  579 try {
 106  579 File temp = File.createTempFile(PREFIX, SUFFIX);
 107  372 IOUtil.attemptDelete(temp);
 108  330 File[] toDelete = temp.getParentFile().listFiles(new FilenameFilter() {
 109  73458 public boolean accept(File dir, String name) {
 110  91305 if ((!name.startsWith(PREFIX)) || (!name.endsWith(SUFFIX))) return false;
 111  538 String rest = name.substring(PREFIX.length(), name.length()-SUFFIX.length());
 112  538 try {
 113  538 Integer i = new Integer(rest);
 114    // we could create an integer from the rest, this is one of our temporary files
 115  0 return true;
 116    }
 117    catch(NumberFormatException e) { /* couldn't convert, ignore this file */ }
 118  538 return false;
 119    }
 120    });
 121  240 for(File f: toDelete) {
 122  0 f.delete();
 123    }
 124    }
 125    catch(IOException ioe) { /* could not delete temporary files, ignore */ }
 126    }
 127    }));
 128    }
 129  1413 _tempJUnit = tempJUnit;
 130    }
 131   
 132  55 protected java.util.List<File> getFilteredClassPath(java.util.List<? extends File> classPath) {
 133  55 java.util.List<File> filteredClassPath = null;
 134  55 if (classPath!=null) {
 135  55 filteredClassPath = new LinkedList<File>(classPath);
 136   
 137  55 if (_filterExe) {
 138  55 FileFilter filter = IOUtil.extensionFilePredicate("exe");
 139  55 Iterator<? extends File> i = filteredClassPath.iterator();
 140  55 while (i.hasNext()) {
 141  0 if (filter.accept(i.next())) { i.remove(); }
 142    }
 143  0 if (_tempJUnit!=null) { filteredClassPath.add(_tempJUnit); }
 144    }
 145    }
 146  55 return filteredClassPath;
 147    }
 148    }