KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > capture > JavadocLogInterpreter


1 /**
2  * $Id: JavadocLogInterpreter.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.capture;
30
31 import java.io.BufferedReader JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.Reader JavaDoc;
34 import java.util.List JavaDoc;
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 /**
44  * Our default Ant &lt;javadoc&gt; output log interpreter. This interpreter does
45  * not work for Maven generated javadoc logs (which have the tool's leading name
46  * field removed). This interpreter only updates the count properties iff there was
47  * at least one problem; it does not set the properties if the log was determined to
48  * be clean.
49  *
50  * @since JWare/AntX 0.5
51  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
52  * @version 0.5
53  * @.safety single
54  * @.group impl,helper
55  * @see InterpretLoggedTask
56  * @.impl This interpreter is used to verify interpret task.
57  **/

58
59 public final class JavadocLogInterpreter implements LogInterpreter
60 {
61     /**
62      * Initializes a new javadoc log interpreter.
63      **/

64     public JavadocLogInterpreter()
65     {
66     }
67  
68  
69     private static final String JavaDoc RE_ERRORS_ = "^ \\[javadoc\\] ([0-9]+) errors.*$";
70     private static final String JavaDoc RE_WARNINGS_ = "^ \\[javadoc\\] ([0-9]+) warnings.*$";
71
72
73     public String JavaDoc interpret(Reader JavaDoc inputr, InterpretParameters config)
74         throws BuildException
75     {
76         String JavaDoc 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             //NB: if we could read backwards this would be basically instantaneous
93
BufferedReader JavaDoc in = new BufferedReader JavaDoc(inputr,512);
94             String JavaDoc line;
95             while ((line=in.readLine())!=null) {
96                 List JavaDoc 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 JavaDoc 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 /* end-of-JavadocLogInterpreter.java */
Popular Tags