buildframework/helium/sf/java/sysdef/src/com/nokia/helium/sysdef/ant/taskdefs/AbstractSydefTask.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    15 *
    15 *
    16 */
    16 */
    17 package com.nokia.helium.sysdef.ant.taskdefs;
    17 package com.nokia.helium.sysdef.ant.taskdefs;
    18 
    18 
    19 import java.io.File;
    19 import java.io.File;
       
    20 import java.io.FileNotFoundException;
    20 import java.io.FileOutputStream;
    21 import java.io.FileOutputStream;
    21 import java.io.IOException;
    22 import java.io.IOException;
    22 import java.io.FileNotFoundException;
       
    23 import java.util.Map;
    23 import java.util.Map;
    24 
    24 
    25 import javax.xml.transform.ErrorListener;
    25 import javax.xml.transform.ErrorListener;
    26 import javax.xml.transform.Transformer;
    26 import javax.xml.transform.Transformer;
       
    27 import javax.xml.transform.TransformerConfigurationException;
    27 import javax.xml.transform.TransformerException;
    28 import javax.xml.transform.TransformerException;
    28 import javax.xml.transform.TransformerFactory;
    29 import javax.xml.transform.TransformerFactory;
    29 import javax.xml.transform.stream.StreamResult;
    30 import javax.xml.transform.stream.StreamResult;
    30 import javax.xml.transform.stream.StreamSource;
    31 import javax.xml.transform.stream.StreamSource;
    31 import javax.xml.transform.TransformerConfigurationException;
       
    32 
    32 
    33 import org.apache.tools.ant.BuildException;
    33 import org.apache.tools.ant.BuildException;
    34 import org.apache.tools.ant.Project;
    34 import org.apache.tools.ant.Project;
    35 import org.apache.tools.ant.Task;
    35 import org.apache.tools.ant.Task;
    36 
    36 
    43 public abstract class AbstractSydefTask extends Task implements ErrorListener {
    43 public abstract class AbstractSydefTask extends Task implements ErrorListener {
    44 
    44 
    45     private File srcFile;
    45     private File srcFile;
    46     private File destFile;
    46     private File destFile;
    47     private File epocroot;
    47     private File epocroot;
    48     private boolean failOnError = true;
    48     private boolean failOnError = true;  // Error should not fail by default.
       
    49     private boolean failOnWarning; // Warning should not fail by default.
    49     
    50     
    50     /**
    51     /**
    51      * Get the source file.
    52      * Get the source file.
    52      * @return
    53      * @return
    53      */
    54      */
   115     public boolean isFailOnError() {
   116     public boolean isFailOnError() {
   116         return failOnError;
   117         return failOnError;
   117     }
   118     }
   118 
   119 
   119     /**
   120     /**
   120      * Defines if the file should fail on error.
   121      * Shall we fail the build on warning.
       
   122      * @return is the task should fail on warning.
       
   123      */
       
   124     public boolean isFailOnWarning() {
       
   125         return failOnWarning;
       
   126     }
       
   127 
       
   128     /**
       
   129      * Defines if the task should fail on error.
   121      * @param failonerror
   130      * @param failonerror
   122      * @ant.not-required Default is true.
   131      * @ant.not-required Default is true.
   123      */
   132      */
   124     public void setFailOnError(boolean failonerror) {
   133     public void setFailOnError(boolean failonerror) {
   125         this.failOnError = failonerror;
   134         this.failOnError = failonerror;
       
   135     }
       
   136 
       
   137     /**
       
   138      * Defines if the task should fail on warning.
       
   139      * @param failonerror
       
   140      * @ant.not-required Default is true.
       
   141      */
       
   142     public void setFailOnWarning(boolean failOnWarning) {
       
   143         this.failOnWarning = failOnWarning;
   126     }
   144     }
   127 
   145 
   128     /**
   146     /**
   129      * This method should be defined by the implementing class
   147      * This method should be defined by the implementing class
   130      * to define the location of the XSLT file.
   148      * to define the location of the XSLT file.
   131      * @return the XSLT file location.
   149      * @return the XSLT file location.
   132      */
   150      */
   133     abstract File getXsl();
   151     protected abstract File getXsl();
   134     
   152     
   135     /**
   153     /**
   136      * Check if required attribute have been configured correctly.
   154      * Check if required attribute have been configured correctly.
   137      * If not the method will raise a BuildException.
   155      * If not the method will raise a BuildException.
   138      */
   156      */
   265      * Reports errors to the Ant logging system of throw the exception if the task
   283      * Reports errors to the Ant logging system of throw the exception if the task
   266      * is set to failonerror.
   284      * is set to failonerror.
   267      */
   285      */
   268     @Override
   286     @Override
   269     public void warning(TransformerException message) throws TransformerException {
   287     public void warning(TransformerException message) throws TransformerException {
   270         if (this.isFailOnError()) {
   288         if (this.isFailOnWarning()) {
   271             throw message;
   289             throw message;
   272         } else {
   290         } else {
   273             log("WARNING: " + message.getMessageAndLocation(), Project.MSG_WARN);
   291             log("WARNING: " + message.getMessageAndLocation(), Project.MSG_WARN);
   274         }
   292         }
   275     }
   293     }