1 package net.sourceforge.pmd.util; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.Rule; 5 import net.sourceforge.pmd.RuleSet; 6 import net.sourceforge.pmd.RuleSetFactory; 7 8 import java.util.Collection ; 9 import java.util.Iterator ; 10 import java.util.Set ; 11 12 public class Appendix { 13 14 public static void main(String [] args) throws Exception { 15 RuleSetFactory rsf = new RuleSetFactory(); 16 Iterator i = rsf.getRegisteredRuleSets(); 17 StringBuffer sb = new StringBuffer (); 18 while (i.hasNext()) { 19 RuleSet rs = (RuleSet) i.next(); 20 if (rs.getName().toLowerCase().indexOf(args[0]) == -1) { 21 continue; 22 } 23 sb.append("====================================================================" + PMD.EOL); 24 sb.append(rs.getName() + PMD.EOL); 25 sb.append(rs.getDescription() + PMD.EOL); 26 sb.append("--------------------------------------------------------------------" + PMD.EOL); 27 28 Collection rules = rs.getRules(); 29 for (Iterator j = rules.iterator(); j.hasNext();) { 30 Rule r = (Rule) j.next(); 31 sb.append(r.getName() + ": " + trimCRs(r.getDescription()) + PMD.EOL); 32 sb.append("Example: " + PMD.EOL + trimCRs(r.getExample()) + PMD.EOL); 33 34 if (r.hasProperty("xpath")) { 35 sb.append("XPath expression:" + PMD.EOL); 36 sb.append(trimCRs(r.getProperties().getProperty("xpath"))); 37 } 38 39 Set keys = r.getProperties().keySet(); 40 boolean header = false; 41 for (Iterator k = keys.iterator(); k.hasNext();) { 42 String key = (String ) k.next(); 43 String value = (String ) r.getProperties().getProperty(key); 44 45 if (key.equals("xpath")) { 46 continue; 47 } 48 49 if (!header) { 50 sb.append(PMD.EOL + "Properties:" + PMD.EOL); 51 header = true; 52 } 53 54 sb.append("Name = '" + key + "', value = '" + value + "'" + PMD.EOL); 55 } 56 sb.append(PMD.EOL + "Notes: " + PMD.EOL); 57 sb.append(PMD.EOL + "--------------------------------------------------------------------" + PMD.EOL); 58 } 59 } 60 System.out.println(sb.toString()); 61 } 62 63 private static String trimCRs(String str) { 64 while (str.startsWith(PMD.EOL)) { 65 str = str.substring(1); 66 } 67 while (str.endsWith(PMD.EOL)) { 68 str = str.substring(0, str.length() - 1); 69 } 70 return str; 71 } 72 } 73 | Popular Tags |