Clover coverage report - DrJava Test Coverage (drjava-20110828-r5448)
Coverage timestamp: Sun Aug 28 2011 03:13:33 CDT
file stats: LOC: 161   Methods: 16
NCLOC: 76   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassPathManager.java - 74.3% 56.2% 68.6%
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.repl.newjvm;
 38   
 39    import java.io.File;
 40    import java.util.LinkedList;
 41    import java.lang.ClassLoader;
 42    import edu.rice.cs.plt.io.IOUtil;
 43    import edu.rice.cs.plt.iter.IterUtil;
 44    import edu.rice.cs.plt.lambda.Lambda;
 45    import edu.rice.cs.plt.reflect.PathClassLoader;
 46   
 47    import static edu.rice.cs.plt.debug.DebugUtil.error;
 48    import static edu.rice.cs.plt.debug.DebugUtil.debug;
 49   
 50    /**
 51    * Maintains a dynamic class path, allowing entries to be incrementally added in the appropriate
 52    * place in the list. This class is used in the interpreter JVM, and may be accessed concurrently.
 53    */
 54    public class ClassPathManager implements Lambda<ClassLoader, ClassLoader> {
 55   
 56    // For thread safety, all accesses to these lists are synchronized on this, and when they are made available
 57    // to others (via getters or in the class loader), a snapshot is used.
 58   
 59    private final LinkedList<File> _projectCP; /* The custom project class path. */
 60    private final LinkedList<File> _buildCP; /* The build directory. */
 61    private final LinkedList<File> _projectFilesCP; /* The open project files. */
 62    private final LinkedList<File> _externalFilesCP; /* The open external files. */
 63    private final LinkedList<File> _extraCP; /* The extra preferences class path. */
 64    // these can be accessed concurrently:
 65   
 66    private final Iterable<File> _fullPath;
 67   
 68  206 public ClassPathManager(Iterable<File> builtInCP) {
 69  206 _projectCP = new LinkedList<File>();
 70  206 _buildCP = new LinkedList<File>();
 71  206 _projectFilesCP = new LinkedList<File>();
 72  206 _externalFilesCP = new LinkedList<File>();
 73  206 _extraCP = new LinkedList<File>();
 74    // conversions to SizedIterables are necessary to support 1.4 compatibility
 75  206 Iterable<Iterable<File>> allPaths =
 76    IterUtil.<Iterable<File>>make(IterUtil.asSizedIterable(_projectCP),
 77    IterUtil.asSizedIterable(_buildCP),
 78    IterUtil.asSizedIterable(_projectFilesCP),
 79    IterUtil.asSizedIterable(_externalFilesCP),
 80    IterUtil.asSizedIterable(_extraCP),
 81    IterUtil.snapshot(builtInCP));
 82    // lazily map the lists to their snapshots -- the snapshot code executes every time
 83    // _fullPath is traversed
 84  206 _fullPath = IterUtil.collapse(IterUtil.map(allPaths, _makeSafeSnapshot));
 85  206 updateProperty();
 86    }
 87   
 88    public static final String INTERACTIONS_CLASS_PATH_PROPERTY = "edu.rice.cs.drjava.interactions.class.path";
 89   
 90  869 protected void updateProperty() {
 91  869 System.setProperty(INTERACTIONS_CLASS_PATH_PROPERTY,IOUtil.pathToString(_fullPath));
 92    }
 93   
 94    private final Lambda<Iterable<File>, Iterable<File>> _makeSafeSnapshot =
 95    new Lambda<Iterable<File>, Iterable<File>>() {
 96  14124 public Iterable<File> value(Iterable<File> arg) {
 97  14124 synchronized(ClassPathManager.this) { return IterUtil.snapshot(arg); }
 98    }
 99    };
 100   
 101    /** Adds the entry to the front of the project classpath
 102    * (this is the classpath specified in project properties)
 103    */
 104  0 public synchronized void addProjectCP(File f) { _projectCP.addFirst(f); updateProperty(); }
 105   
 106  0 public synchronized Iterable<File> getProjectCP() { return IterUtil.snapshot(_projectCP); }
 107   
 108    /** Adds the entry to the front of the build classpath. */
 109  30 public synchronized void addBuildDirectoryCP(File f) {
 110  30 _buildCP.remove(f); // eliminate duplicates
 111  30 _buildCP.addFirst(f);
 112  30 updateProperty();
 113    }
 114   
 115  0 public synchronized Iterable<File> getBuildDirectoryCP() { return IterUtil.snapshot(_buildCP); }
 116   
 117    /** Adds the entry to the front of the project files classpath (this is the classpath for all open project files). */
 118  182 public synchronized void addProjectFilesCP(File f) {
 119  182 _projectFilesCP.remove(f); // eliminate duplicates
 120  182 _projectFilesCP.addFirst(f);
 121  182 updateProperty();
 122    }
 123   
 124  0 public synchronized Iterable<File> getProjectFilesCP() { return IterUtil.snapshot(_projectFilesCP); }
 125   
 126    /** Adds new entry containing f to the front of the external classpath. */
 127  225 public synchronized void addExternalFilesCP(File f) {
 128  225 _externalFilesCP.remove(f); // eliminate duplicates
 129  225 _externalFilesCP.addFirst(f);
 130  225 updateProperty();
 131    }
 132   
 133  0 public synchronized Iterable<File> getExternalFilesCP() { return IterUtil.snapshot(_externalFilesCP); }
 134   
 135    /** Adds the entry to the front of the extra classpath. */
 136  2 public synchronized void addExtraCP(File f) {
 137  2 _extraCP.remove(f); // eliminate duplicates
 138  2 _extraCP.addFirst(f);
 139  2 updateProperty();
 140    }
 141   
 142  0 public Iterable<File> getExtraCP() { return IterUtil.snapshot(_extraCP); }
 143   
 144    /** Create a new class loader based on the given path. The loader's path is dynamically updated
 145    * as changes are made in the ClassPathManager. Each loader returned by this method will
 146    * have its own set of loaded classes, and will only share those classes that are loaded
 147    * by a common parent.
 148    * @param parent The parent class loader. May be {@code null}, signifying the bootstrap
 149    * class loader.
 150    */
 151  224 public synchronized ClassLoader makeClassLoader(ClassLoader parent) {
 152  224 updateProperty();
 153  224 return new PathClassLoader(parent, _fullPath);
 154    }
 155   
 156    /** Lambda value method */
 157  18 public ClassLoader value(ClassLoader parent) { return makeClassLoader(parent); }
 158   
 159    /** Get a dynamic view of the full class path. */
 160  0 public synchronized Iterable<File> getClassPath() { updateProperty(); return _fullPath; }
 161    }