Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 207   Methods: 12
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JikesOutputParser.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000,2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs;
 55   
 
 56   
 import java.io.BufferedReader;
 57   
 import java.io.IOException;
 58   
 import java.io.InputStream;
 59   
 import java.io.InputStreamReader;
 60   
 import java.io.OutputStream;
 61   
 import org.apache.tools.ant.Project;
 62   
 import org.apache.tools.ant.Task;
 63   
 
 64   
 /**
 65   
  * Parses output from jikes and
 66   
  * passes errors and warnings
 67   
  * into the right logging channels of Project.
 68   
  *
 69   
  * <p><strong>As of Ant 1.2, this class is considered to be dead code
 70   
  * by the Ant developers and is unmaintained.  Don't use
 71   
  * it.</strong></p>
 72   
  *
 73   
  * @author skanthak@muehlheim.de
 74   
  * @deprecated use Jikes' exit value to detect compilation failure.
 75   
  */
 76   
 public class JikesOutputParser implements ExecuteStreamHandler {
 77   
     protected Task task;
 78   
     protected boolean errorFlag = false; // no errors so far
 79   
     protected int errors;
 80   
     protected int warnings;
 81   
     protected boolean error = false;
 82   
     protected boolean emacsMode;
 83   
     
 84   
     protected BufferedReader br;
 85   
 
 86   
     /**
 87   
      * Ignore.
 88   
      */
 89  0
     public void setProcessInputStream(OutputStream os) {}
 90   
 
 91   
     /**
 92   
      * Ignore.
 93   
      */
 94  0
     public void setProcessErrorStream(InputStream is) {}
 95   
 
 96   
     /**
 97   
      * Set the inputstream
 98   
      */
 99  0
     public void setProcessOutputStream(InputStream is) throws IOException {
 100  0
         br = new BufferedReader(new InputStreamReader(is));
 101   
     }
 102   
 
 103   
     /**
 104   
      * Invokes parseOutput.
 105   
      */
 106  0
     public void start() throws IOException {
 107  0
         parseOutput(br);
 108   
     }
 109   
 
 110   
     /**
 111   
      * Ignore.
 112   
      */
 113  0
     public void stop() {}
 114   
 
 115   
     /**
 116   
      * Construct a new Parser object
 117   
      * @param task - task in whichs context we are called
 118   
      */
 119  0
     protected JikesOutputParser(Task task, boolean emacsMode) {
 120  0
         super();
 121   
 
 122  0
         System.err.println("As of Ant 1.2 released in October 2000, the " 
 123   
             + "JikesOutputParser class");
 124  0
         System.err.println("is considered to be dead code by the Ant " 
 125   
             + "developers and is unmaintained.");
 126  0
         System.err.println("Don\'t use it!");
 127   
 
 128  0
         this.task = task;
 129  0
         this.emacsMode = emacsMode;
 130   
     }
 131   
 
 132   
     /**
 133   
      * Parse the output of a jikes compiler
 134   
      * @param reader - Reader used to read jikes's output
 135   
      */
 136  0
     protected void parseOutput(BufferedReader reader) throws IOException {
 137  0
        if (emacsMode) {
 138  0
            parseEmacsOutput(reader);
 139   
        } else {
 140  0
            parseStandardOutput(reader);
 141   
        }
 142   
     }
 143   
 
 144  0
     private void parseStandardOutput(BufferedReader reader) throws IOException {
 145  0
         String line;
 146  0
         String lower;
 147   
         // We assume, that every output, jike does, stands for an error/warning
 148   
         // XXX 
 149   
         // Is this correct?
 150   
         
 151   
         // TODO:
 152   
         // A warning line, that shows code, which contains a variable
 153   
         // error will cause some trouble. The parser should definitely
 154   
         // be much better.
 155   
 
 156  0
         while ((line = reader.readLine()) != null) {
 157  0
             lower = line.toLowerCase();
 158  0
             if (line.trim().equals("")) {
 159  0
                 continue;
 160   
             }
 161  0
             if (lower.indexOf("error") != -1) {
 162  0
                 setError(true);
 163  0
             } else if (lower.indexOf("warning") != -1) {
 164  0
                 setError(false);
 165   
                    } else {
 166   
                 // If we don't know the type of the line
 167   
                 // and we are in emacs mode, it will be
 168   
                 // an error, because in this mode, jikes won't
 169   
                 // always print "error", but sometimes other
 170   
                 // keywords like "Syntax". We should look for
 171   
                 // all those keywords.
 172  0
                 if (emacsMode) {
 173  0
                     setError(true);
 174   
                 }
 175   
             }
 176  0
             log(line);
 177   
         }
 178   
     }
 179   
 
 180  0
     private void parseEmacsOutput(BufferedReader reader) throws IOException {
 181   
        // This may change, if we add advanced parsing capabilities.
 182  0
        parseStandardOutput(reader);
 183   
     }
 184   
 
 185  0
     private void setError(boolean err) {
 186  0
         error = err;
 187  0
         if (error) {
 188  0
             errorFlag = true;
 189   
         }
 190   
     }
 191   
 
 192  0
     private void log(String line) {
 193  0
        if (!emacsMode) {
 194  0
            task.log("", (error ? Project.MSG_ERR : Project.MSG_WARN));
 195   
        }
 196  0
        task.log(line, (error ? Project.MSG_ERR : Project.MSG_WARN));
 197   
     }
 198   
 
 199   
     /**
 200   
      * Indicate if there were errors during the compile
 201   
      * @return if errors ocured
 202   
      */
 203  0
     protected boolean getErrorFlag() {
 204  0
         return errorFlag;
 205   
     }
 206   
 }
 207