1 18 19 package alt.jiapi; 20 21 import java.util.Collections ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Set ; 26 import java.util.TreeSet ; 27 28 import org.apache.log4j.Category; 29 30 44 public class InstrumentationDescriptor { 45 private static Category log = Runtime.getLogCategory(InstrumentationDescriptor.class); 46 47 50 private boolean debugLoader = false; 51 52 55 private List instrumentors = Collections.synchronizedList(new ArrayList ()); 56 57 60 private Set inclusionRules = new TreeSet (Collections.reverseOrder()); 61 62 65 private Set exclusionRules = new TreeSet (Collections.reverseOrder()); 66 67 public InstrumentationDescriptor() { 68 } 71 72 78 public void addInstrumentor(Instrumentor instrumentor) { 79 instrumentors.add(instrumentor); 80 } 81 82 87 public List getInstrumentors() { 88 return instrumentors; 89 } 90 91 112 public void addInclusionRule(String rule) throws JiapiException { 113 inclusionRules.add(new Rule(rule)); 114 } 115 116 120 public Set getInclusionsRules() { 121 return inclusionRules; 122 } 123 124 135 public void addExclusionRule(String rule) throws JiapiException { 136 exclusionRules.add(new Rule(rule)); 137 } 138 139 143 public Set getExclusionsRules() { 144 return exclusionRules; 145 } 146 147 154 public boolean match(String className) { 155 log.debug("Matching rules to " + className); 156 157 Rule exclusionRule = null; 158 Rule inclusionRule = null; 159 160 for (Iterator i = inclusionRules.iterator(); i.hasNext(); ) { 162 Rule rule = (Rule) i.next(); 163 if (rule.match(className)) { 164 166 inclusionRule = rule; 167 break; 168 } 169 } 170 171 if (inclusionRule == null) { 174 log.debug("Excluding: " + className + " cause: no match"); 175 176 return false; 177 } 178 179 for (Iterator i = exclusionRules.iterator(); i.hasNext(); ) { 181 Rule rule = (Rule) i.next(); 182 if (rule.match(className)) { 183 exclusionRule = rule; 184 break; 185 } 186 } 187 188 if (exclusionRule == null) { 191 log.debug("Including: " + className + " cause: " + inclusionRule + 192 ", no exclusion rule"); 193 194 return true; 195 } 196 197 if (inclusionRule.isMoreSignificant(exclusionRule)) { 201 log.debug("Including: " + className + " cause:\n include " + 202 inclusionRule + " is more significant than " + 203 exclusionRule); 204 205 return true; 206 } 207 else { 208 log.debug("Excluding: " + className + " cause:\n excluding " + 209 exclusionRule + " is more significant than " + 210 inclusionRule); 211 212 return false; 213 } 214 215 } 216 217 public String toString() { 218 return inclusionRules.toString() + ", " + exclusionRules.toString(); 219 } 220 } 221 222 | Popular Tags |