Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 117   Methods: 13
NCLOC: 66   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
RecursiveFileListProperty.java 66.7% 67.6% 92.3% 73.2%
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 java.util.HashSet;
 40    import java.util.List;
 41    import java.util.ArrayList;
 42    import java.io.*;
 43    import edu.rice.cs.util.StringOps;
 44    import edu.rice.cs.plt.text.TextUtil;
 45   
 46    /** Class representing a lazy lists of files that are found recursively inside a start directory.
 47    * @version $Id: RecursiveFileListProperty.java 5175 2010-01-20 08:46:32Z mgricken $
 48    */
 49    public class RecursiveFileListProperty extends FileListProperty {
 50    /** Start directory. */
 51    protected String _start;
 52    /** Create an recursive file list property. */
 53  84 public RecursiveFileListProperty(String name, String sep, String dir, String start, String help) {
 54  84 super(name, sep, dir, help);
 55  84 _start = start;
 56  84 resetAttributes();
 57    }
 58   
 59    public static class RegexFilter implements FileFilter {
 60    protected String _regex;
 61  2 public RegexFilter(String regex) {
 62  2 _regex = regex;
 63    }
 64  5 public boolean accept(File pathname) {
 65  5 return pathname.getName().matches(_regex);
 66    }
 67    }
 68    public static class FileMaskFilter extends RegexFilter {
 69    private HashSet<File> _include = new HashSet<File>();
 70    private HashSet<File> _exclude = new HashSet<File>();
 71  1 public FileMaskFilter(String mask) {
 72  1 super(TextUtil.regexEscape(mask)
 73    .replaceAll("\\\\\\*",".*") // turn \* into .*
 74    .replaceAll("\\\\\\?",".")); // turn \? into .
 75    }
 76  5 public boolean accept(File pathname) {
 77  1 if (_include.contains(pathname)) { return true; }
 78  1 if (_exclude.contains(pathname)) { return false; }
 79  3 return super.accept(pathname);
 80    }
 81  1 public void addIncludedFile(File f) { _include.add(f); }
 82  1 public void removeIncludedFile(File f) { _include.remove(f); }
 83  1 public void clearIncludedFile() { _include.clear(); }
 84  1 public void addExcludedFile(File f) { _exclude.add(f); }
 85  1 public void removeExcludedFile(File f) { _exclude.remove(f); }
 86  1 public void clearExcludedFile() { _exclude.clear(); }
 87    }
 88   
 89    /** Abstract factory method specifying the list.
 90    * @param pm PropertyMaps used for substitution when replacing variables */
 91  0 protected List<File> getList(PropertyMaps pm) {
 92  0 FileMaskFilter fFilter = new FileMaskFilter(_attributes.get("filter"));
 93  0 FileMaskFilter fDirFilter = new FileMaskFilter(_attributes.get("dirfilter"));
 94  0 String start = StringOps.replaceVariables(_attributes.get("dir"), pm, PropertyMaps.GET_CURRENT);
 95  0 start = StringOps.unescapeFileName(start);
 96  0 File fStart = new File(start);
 97    // if the specified starting point is a directory, allow that directory
 98  0 if (fStart.isDirectory()) { fDirFilter.addIncludedFile(fStart); }
 99  0 Iterable<File> it = edu.rice.cs.plt.io.IOUtil.listFilesRecursively(fStart, fFilter, fDirFilter);
 100    // StringBuilder sb = new StringBuilder(); // not used
 101  0 ArrayList<File> l = new ArrayList<File>();
 102  0 for(File f: it) { l.add(f); }
 103  0 return l;
 104    }
 105   
 106    /** Reset the attributes. */
 107  138 public void resetAttributes() {
 108  138 _attributes.clear();
 109  138 _attributes.put("sep", _sep);
 110  138 _attributes.put("rel", _dir);
 111  138 _attributes.put("dir", _start);
 112  138 _attributes.put("filter", "*");
 113  138 _attributes.put("dirfilter", "*");
 114  138 _attributes.put("squote", null);
 115  138 _attributes.put("dquote", null);
 116    }
 117    }