buildframework/helium/sf/java/core/src/com/nokia/helium/core/ant/conditions/XMLLogCondition.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    16  */
    16  */
    17 
    17 
    18 package com.nokia.helium.core.ant.conditions;
    18 package com.nokia.helium.core.ant.conditions;
    19 
    19 
    20 import java.io.File;
    20 import java.io.File;
    21 import org.apache.tools.ant.BuildException;
    21 
    22 import javax.xml.parsers.SAXParser;
    22 import javax.xml.parsers.SAXParser;
    23 import javax.xml.parsers.SAXParserFactory;
    23 import javax.xml.parsers.SAXParserFactory;
    24 import org.xml.sax.*;
    24 
    25 import org.xml.sax.helpers.*;
    25 import org.apache.tools.ant.BuildException;
    26 import com.nokia.helium.core.ant.types.ConditionType;
    26 import org.apache.tools.ant.taskdefs.condition.Condition;
       
    27 import org.apache.tools.ant.types.DataType;
       
    28 import org.xml.sax.Attributes;
       
    29 import org.xml.sax.SAXException;
       
    30 import org.xml.sax.helpers.DefaultHandler;
    27 
    31 
    28 /**
    32 /**
    29  * This class implements a Ant Condition which report true if it finds any
    33  * This class implements a Ant Condition which report true if it finds any
    30  * matching severity inside an XML log.
    34  * matching severity inside an XML log.
    31  * 
    35  * 
    40  * 
    44  * 
    41  * The condition will eval as true if the build_log.log.xml contains any error message in the log.
    45  * The condition will eval as true if the build_log.log.xml contains any error message in the log.
    42  * 
    46  * 
    43  * @ant.type name="hasSeverity" category="Core"
    47  * @ant.type name="hasSeverity" category="Core"
    44  */
    48  */
    45 public class XMLLogCondition extends ConditionType {
    49 public class XMLLogCondition extends DataType implements Condition {
    46 
    50 
    47     // The severity to count
    51     // The severity to count
    48     private String severity;
    52     private String severity;
    49     private String logRegexp;
    53     private String logRegexp;
    50     private File fileName;
    54     private File fileName;
    82         int messageCount = 0;
    86         int messageCount = 0;
    83         if (fileName == null || !fileName.exists()) {
    87         if (fileName == null || !fileName.exists()) {
    84             //this.log("Error: Log file does not exist " + fileName);
    88             //this.log("Error: Log file does not exist " + fileName);
    85             return -1;
    89             return -1;
    86         }
    90         }
    87         if (severity == null)
    91         if (severity == null) {
    88             throw new BuildException("'severity' attribute is not defined");
    92             throw new BuildException("'severity' attribute is not defined");
       
    93         }
    89 
    94 
    90         //this.log("Looking for severity '" + severity + "' under '" + fileName.getAbsolutePath() + "'");
    95         //this.log("Looking for severity '" + severity + "' under '" + fileName.getAbsolutePath() + "'");
    91         SAXParserFactory factory = SAXParserFactory.newInstance();
    96         SAXParserFactory factory = SAXParserFactory.newInstance();
    92         try {
    97         try {
    93             SAXParser saxParser = factory.newSAXParser();
    98             SAXParser saxParser = factory.newSAXParser();