Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 120   Methods: 7
NCLOC: 64   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FileProperty.java 28.6% 64.1% 71.4% 56.7%
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.config;
 38   
 39    import edu.rice.cs.plt.lambda.Thunk;
 40    import edu.rice.cs.util.StringOps;
 41    import edu.rice.cs.util.FileOps;
 42    import java.util.HashSet;
 43    import java.io.*;
 44   
 45    /** Property that evaluates to a file and that can be inserted as variables in external processes.
 46    * @version $Id: FileProperty.java 5175 2010-01-20 08:46:32Z mgricken $
 47    */
 48    public class FileProperty extends DrJavaProperty {
 49    protected Thunk<File> _getFile;
 50    /** Create an eager file property. */
 51  404 public FileProperty(String name, Thunk<File> getFile, String help) {
 52  404 super(name,help);
 53  404 _getFile = getFile;
 54  404 resetAttributes();
 55    }
 56   
 57    /** Return the value of the property. If it is not current, update first.
 58    * @param pm PropertyMaps used for substitution when replacing variables */
 59  111 public String getCurrent(PropertyMaps pm) {
 60  111 update(pm);
 61  0 if (_value == null) { throw new IllegalArgumentException("DrJavaProperty value is null"); }
 62  111 _isCurrent = true;
 63  111 return _value;
 64    }
 65   
 66    /** Return the value. */
 67  0 public String toString() { return _value; }
 68   
 69    /** Return true if the value is current. */
 70  0 public boolean isCurrent() { return true; }
 71   
 72    /** Mark the value as stale. */
 73  57 public void invalidate() {
 74    // nothing to do, but tell those who are listening
 75  57 invalidateOthers(new HashSet<DrJavaProperty>());
 76    }
 77   
 78    /** Update the value of the property.
 79    * @param pm PropertyMaps used for substitution */
 80  111 public void update(PropertyMaps pm) {
 81  111 String quot = "";
 82  111 String q = _attributes.get("squote");
 83  111 if (q != null) {
 84  0 if (q.toLowerCase().equals("true")) { quot = "'"; }
 85    }
 86  111 q = _attributes.get("dquote");
 87  111 if (q != null) {
 88  0 if (q.toLowerCase().equals("true")) { quot = "\"" + quot; }
 89    }
 90  111 try {
 91  111 File f;
 92  ? if (_getFile == null || (f = _getFile.value()) == null) {
 93  0 _value = "";
 94  0 return;
 95    }
 96  111 if (_attributes.get("rel").equals("/")) {
 97  111 f = f.getAbsoluteFile();
 98  111 try { f = f.getCanonicalFile(); }
 99    catch(IOException ioe) { }
 100  111 _value = edu.rice.cs.util.StringOps.escapeFileName(f.toString());
 101    }
 102    else {
 103  0 File rf = new File(StringOps.unescapeFileName(StringOps.replaceVariables(_attributes.get("rel"),
 104    pm,
 105    PropertyMaps.GET_CURRENT)));
 106  0 String s = FileOps.stringMakeRelativeTo(f,rf);
 107  0 _value = quot+edu.rice.cs.util.StringOps.escapeFileName(s)+quot;
 108    }
 109    }
 110  0 catch(IOException e) { _value = "(Error...)"; }
 111  0 catch(SecurityException e) { _value = "(Error...)"; }
 112    }
 113   
 114  965 public void resetAttributes() {
 115  965 _attributes.clear();
 116  965 _attributes.put("rel", "/");
 117  965 _attributes.put("squote", null);
 118  965 _attributes.put("dquote", null);
 119    }
 120    }