1 17 package org.apache.tools.ant.taskdefs.optional.metamata; 18 19 import java.io.File ; 20 import java.util.Vector ; 21 import org.apache.tools.ant.util.StringUtils; 22 import org.apache.tools.ant.util.regexp.RegexpMatcher; 23 import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; 24 25 37 final class MAuditParser { 38 39 40 41 private static final String AUDIT_PATTERN = "(?:file:)?(.+):(\\d+)\\s*:\\s+(.*)"; 43 44 45 private final RegexpMatcher matcher; 46 47 MAuditParser() { 48 49 matcher = (new RegexpMatcherFactory()).newRegexpMatcher(); 50 matcher.setPattern(AUDIT_PATTERN); 51 } 52 53 60 Violation parseLine(String line) { 61 Vector matches = matcher.getGroups(line); 62 if (matches == null) { 63 return null; 64 } 65 final String file = (String ) matches.elementAt(1); 66 Violation violation = new Violation(); 67 violation.file = file; 68 violation.line = (String ) matches.elementAt(2); 69 violation.error = (String ) matches.elementAt(3); 70 final int pos = file.lastIndexOf(File.separatorChar); 72 if ((pos != -1) && (pos != file.length() - 1)) { 73 String filename = file.substring(pos + 1); 74 violation.error = StringUtils.replace(violation.error, 75 "file:" + file, filename); 76 } 77 return violation; 78 } 79 80 81 static final class Violation { 82 String file; 83 String line; 84 String error; 85 } 86 } 87 | Popular Tags |