1 28 29 package com.idaremedia.antx.capture; 30 31 import java.io.BufferedReader ; 32 import java.io.IOException ; 33 import java.io.Reader ; 34 import java.util.List ; 35 36 import org.apache.tools.ant.BuildException; 37 import org.apache.tools.ant.Project; 38 import org.apache.tools.ant.types.RegularExpression; 39 import org.apache.tools.ant.util.regexp.RegexpMatcher; 40 41 import com.idaremedia.antx.helpers.Tk; 42 43 58 59 public final class JavadocLogInterpreter implements LogInterpreter 60 { 61 64 public JavadocLogInterpreter() 65 { 66 } 67 68 69 private static final String RE_ERRORS_ = "^ \\[javadoc\\] ([0-9]+) errors.*$"; 70 private static final String RE_WARNINGS_ = "^ \\[javadoc\\] ([0-9]+) warnings.*$"; 71 72 73 public String interpret(Reader inputr, InterpretParameters config) 74 throws BuildException 75 { 76 String result = CLEAN; 77 final Project P = config.getProject(); 78 int nErrs = 0; 79 int nWarnings = 0; 80 81 RegularExpression re = new RegularExpression(); 82 re.setProject(P); 83 re.setPattern(RE_ERRORS_); 84 RegexpMatcher errors = re.getRegexp(P); 85 86 re = new RegularExpression(); 87 re.setProject(P); 88 re.setPattern(RE_WARNINGS_); 89 RegexpMatcher warnings = re.getRegexp(P); 90 91 try { 92 BufferedReader in = new BufferedReader (inputr,512); 94 String line; 95 while ((line=in.readLine())!=null) { 96 List gl = errors.getGroups(line); 97 if (gl!=null && gl.size()>=2) { 98 int n = Tk.integerFrom(gl.get(1),Tk.NO_INT); 99 if (n!=Tk.NO_INT) { 100 nErrs = n; 101 } 102 } 103 gl = warnings.getGroups(line); 104 if (gl!=null && gl.size()>=2) { 105 int n = Tk.integerFrom(gl.get(1),Tk.NO_INT); 106 if (n!=Tk.NO_INT) { 107 nWarnings = n; 108 } 109 } 110 } 111 in.close(); 112 } catch(IOException ioX) { 113 throw new BuildException(ioX); 114 } 115 116 if (nErrs!=0) { 117 if (nErrs>config.getMaxErrors()) { 118 result = FAILURE; 119 } else { 120 result = PROBLEM; 121 } 122 } else if (nWarnings!=0) { 123 if (nWarnings>config.getMaxWarnings()) { 124 result = FAILURE; 125 } else { 126 result = PROBLEM; 127 } 128 } 129 130 ResultsHelper.set(config,nErrs,nWarnings,result); 131 return result; 132 } 133 } 134 135 | Popular Tags |