1 20 package net.sf.clirr.ant; 21 22 import net.sf.clirr.core.ClassFilter; 23 24 import java.util.List ; 25 import java.io.File ; 26 27 import org.apache.bcel.classfile.JavaClass; 28 import org.apache.tools.ant.types.selectors.SelectorUtils; 29 import org.apache.tools.ant.types.PatternSet; 30 import org.apache.tools.ant.Project; 31 32 37 class PatternSetFilter implements ClassFilter 38 { 39 private final Project project; 40 private final List patternSets; 41 42 43 48 public PatternSetFilter(Project project, List patternSets) 49 { 50 this.project = project; 51 this.patternSets = patternSets; 52 } 53 54 55 public boolean isSelected(JavaClass clazz) 56 { 57 String className = clazz.getClassName(); 60 String name = className.replace('.', File.separatorChar); 61 62 63 if (patternSets == null || patternSets.isEmpty()) 64 { 65 return true; 66 } 67 68 boolean included = false; 69 for (int i = 0; i < patternSets.size(); i++) 70 { 71 PatternSet p = (PatternSet) patternSets.get(i); 72 p.getIncludePatterns(project); 73 74 String [] incls = p.getIncludePatterns(project); 75 if (incls == null || incls.length == 0) 76 { 77 incls = new String [] {"**"}; 79 } 80 81 for (int w = 0; w < incls.length; w++) 82 { 83 String pattern = incls[w].replace('/', File.separatorChar) 84 .replace('\\', File.separatorChar); 85 if (pattern.endsWith(File.separator)) 86 { 87 pattern += "**"; 88 } 89 90 included = SelectorUtils.matchPath(pattern, name); 91 if (included) 92 { 93 break; 94 } 95 } 96 97 if (!included) 98 { 99 break; 100 } 101 102 103 String [] excls = p.getExcludePatterns(project); 104 if (excls != null) 105 { 106 for (int w = 0; w < excls.length; w++) 107 { 108 String pattern = excls[w] 109 .replace('/', File.separatorChar) 110 .replace('\\', File.separatorChar); 111 if (pattern.endsWith(File.separator)) 112 { 113 pattern += "**"; 114 } 115 included = !(SelectorUtils.matchPath(pattern, name)); 116 if (!included) 117 { 118 break; 119 } 120 } 121 } 122 } 123 project.log("included " + className + " = " + included, Project.MSG_VERBOSE); 124 return included; 125 } 126 } 127 | Popular Tags |