1 25 26 package net.sourceforge.cobertura.instrument; 27 28 import java.util.Collection ; 29 import java.util.HashSet ; 30 31 import net.sourceforge.cobertura.util.RegexUtil; 32 33 43 public class ClassPattern 44 { 45 46 private Collection includeClassesRegexes = new HashSet (); 47 48 private Collection excludeClassesRegexes = new HashSet (); 49 50 private static final String WEBINF_CLASSES = "WEB-INF/classes/"; 51 52 58 boolean isSpecified() 59 { 60 return includeClassesRegexes.size() > 0; 61 } 62 63 75 boolean matches(String filename) 76 { 77 boolean matches = true; 78 79 if (isSpecified()) 80 { 81 matches = false; 82 if (filename.endsWith(".class")) 84 { 85 filename = filename.substring(0, filename.length() - 6); 86 } 87 filename = filename.replace('\\', '/'); 88 89 filename = removeAnyWebInfClassesString(filename); 90 91 filename = filename.replace('/', '.'); 92 if (RegexUtil.matches(includeClassesRegexes, filename)) 93 { 94 matches = true; 95 } 96 if (matches && RegexUtil.matches(excludeClassesRegexes, filename)) 97 { 98 matches = false; 99 } 100 } 101 return matches; 102 } 103 104 private String removeAnyWebInfClassesString(String filename) 105 { 106 if (filename.startsWith(WEBINF_CLASSES)) 107 { 108 filename = filename.substring(WEBINF_CLASSES.length()); 109 } 110 return filename; 111 } 112 113 118 void addIncludeClassesRegex(String regex) 119 { 120 RegexUtil.addRegex(includeClassesRegexes, regex); 121 } 122 123 128 void addExcludeClassesRegex(String regex) 129 { 130 RegexUtil.addRegex(excludeClassesRegexes, regex); 131 } 132 133 } 134 | Popular Tags |