buildframework/helium/tools/common/common.antlib.xml
changeset 2 39c28ec933dd
equal deleted inserted replaced
1:820b22e13ff1 2:39c28ec933dd
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : common.antlib.xml 
       
     5 Part of     : Helium 
       
     6 
       
     7 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 All rights reserved.
       
     9 This component and the accompanying materials are made available
       
    10 under the terms of the License "Eclipse Public License v1.0"
       
    11 which accompanies this distribution, and is available
       
    12 at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 
       
    14 Initial Contributors:
       
    15 Nokia Corporation - initial contribution.
       
    16 
       
    17 Contributors:
       
    18 
       
    19 Description:
       
    20 
       
    21 ============================================================================
       
    22 -->
       
    23 <!--* @package framework -->
       
    24 <antlib xmlns:au="org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
       
    25     
       
    26     
       
    27     <!-- Macro to execute bldmake command. To be removed if not used. -->
       
    28     <macrodef name="bldmakeBldfilesMacro" uri="http://www.nokia.com/helium">
       
    29         <attribute name="dir"/>
       
    30         <sequential>
       
    31             <exec executable="${build.drive}/epoc32/tools/bldmake.bat" dir="@{dir}" failonerror="${failonerror}">
       
    32                 <arg value="bldfiles"/>
       
    33                 <arg value="-k"/>
       
    34             </exec>
       
    35         </sequential>
       
    36     </macrodef>
       
    37 
       
    38 
       
    39     <!-- Macro to execute abld command. Once used in rombuild.ant.xml. -->
       
    40     <macrodef name="abldMacro" uri="http://www.nokia.com/helium">
       
    41         <attribute name="dir"/>
       
    42         <attribute name="command"/>
       
    43         <attribute name="platform"/>
       
    44         <sequential>
       
    45             <exec executable="@{dir}/abld.bat" dir="@{dir}" failonerror="${failonerror}">
       
    46                 <arg value="@{command}"/>
       
    47                 <arg value="@{platform}"/>
       
    48                 <arg value="-k"/>
       
    49             </exec>
       
    50         </sequential>
       
    51     </macrodef>
       
    52 
       
    53     <!--
       
    54         This macro generate a file that contains a list of path from a path structure:
       
    55         <pre>
       
    56         <hlm:pathToFileListMacro file="output.lst">
       
    57             <path>
       
    58                 <pathelement path="${helium.dir}"/>
       
    59             </path>
       
    60         </hlm:pathToFileListMacro> 
       
    61         </pre>
       
    62     -->
       
    63     <scriptdef name="pathToFileListMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
    64         <attribute name="file"/>
       
    65         <element name="path" type="path"/>
       
    66         <![CDATA[
       
    67     import java.io.FileWriter;
       
    68     FileWriter out = new FileWriter(attributes.get("file"));
       
    69     paths = elements.get("path");
       
    70     for (int i = 0 ; i < paths.size() ; i++) {
       
    71         String[] files = paths.get(i).list();
       
    72         for (int l = 0; l < files.length ; l++) {
       
    73             out.write(files[l] + "\n");
       
    74         }
       
    75     }
       
    76 out.close();
       
    77 ]]>   
       
    78     </scriptdef>
       
    79 
       
    80     
       
    81    
       
    82     <!-- This Macro is a wrapper to command line tool 
       
    83         Currently supported command line tools are
       
    84         configuration tool and
       
    85         sbs tool
       
    86         Usage: 
       
    87             name - name of the tool:
       
    88             toolvarset - reference id for variables to be passed to the tool
       
    89         <pre>
       
    90         <hlm:toolMacro name="configuration">
       
    91             <hlm:toolvarset refid="cnftool.conf.50"/>
       
    92         </hlm:toolMacro>
       
    93         </pre>
       
    94     -->
       
    95     <scriptdef name="toolMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
    96         <element name="toolvarset" classname="com.nokia.helium.core.ant.types.VariableSet"/>
       
    97         <attribute name="name"/>
       
    98 <![CDATA[
       
    99 import com.nokia.ant.util.ToolsProcess;
       
   100 import com.nokia.tools.*;
       
   101 import com.nokia.helium.core.ant.types.VariableSet;
       
   102 import org.apache.tools.ant.types.Reference;
       
   103     Reference ref;
       
   104     java.lang.String toolName = attributes.get("name");
       
   105     confTool =  ToolsProcess.getTool(toolName);
       
   106     varSets = elements.get("toolvarset");
       
   107     for (i = 0; i < varSets.size(); ++i) {
       
   108         try {
       
   109             varSet = (VariableSet)varSets.get(i);
       
   110             if (varSet.isReference()) {
       
   111                 varSet = varSet.getRefid().getReferencedObject(project);
       
   112             }
       
   113             confTool.execute(varSet,project);
       
   114         } catch (Exception e) {
       
   115             self.log("Error: " + e);
       
   116             //self.log("Tool Argument Validation failure");
       
   117             throw e;
       
   118         }
       
   119   }
       
   120 ]]>
       
   121     </scriptdef>
       
   122     
       
   123     <!-- ConE tool macro to run the command for each argument -->
       
   124     <scriptdef name="conEToolMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
   125         <element name="arg" classname="com.nokia.ant.types.Variable"/>
       
   126         <attribute name="name"/>
       
   127 <![CDATA[
       
   128 import com.nokia.ant.util.ToolsProcess;
       
   129 import com.nokia.tools.*;
       
   130 import com.nokia.ant.types.Variable;
       
   131     conETool =  ToolsProcess.getTool("ConE");
       
   132     vars = elements.get("arg");
       
   133     for (i = 0; i < vars.size(); ++i) {
       
   134         try {
       
   135             var = (Variable)vars.get(i);
       
   136             conETool.storeVariables(var.getName(), var.getValue());
       
   137         } catch (Exception e) {
       
   138             self.log("Error: " + e);
       
   139             //self.log("Tool Argument Validation failure");
       
   140             throw e;
       
   141         }
       
   142   }
       
   143   conETool.execute(project);
       
   144 ]]>
       
   145     </scriptdef>
       
   146     
       
   147     
       
   148     <!-- This macro will read the line from file which matches the regexp -->
       
   149     <scriptdef name="grepMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
   150         <attribute name="filename"/>
       
   151         <attribute name="output"/>
       
   152         <attribute name="regexp"/>
       
   153 <![CDATA[
       
   154 import java.util.*;
       
   155 import java.io.*;
       
   156 import java.util.regex.Matcher;
       
   157 import java.util.regex.Pattern;
       
   158 
       
   159 if (attributes.get("filename") == null ||  attributes.get("output") == null || attributes.get("regexp") == null)
       
   160     throw new BuildException("Filename/output/regexp attribute is not set for readLineMacro");
       
   161     
       
   162 String search = attributes.get("regexp");
       
   163 String output = "";
       
   164 pattern = Pattern.compile(search);
       
   165 
       
   166 BufferedReader input =  new BufferedReader(new FileReader(attributes.get("filename")));
       
   167 try {
       
   168         String line = null;
       
   169         Matcher match = null;
       
   170         while (( line = input.readLine()) != null) {
       
   171              match = pattern.matcher(line);
       
   172             if (match.find()) {
       
   173                 //self.log("Line containg " + search + " is = " + line + " returned vaue = " + match.group(1));
       
   174                 int checkIndex = output.indexOf(match.group(1), 0);
       
   175                 if (checkIndex == -1 ) {
       
   176                    output = output + match.group(1) + ",";
       
   177                 }
       
   178             }
       
   179         }
       
   180     } catch (IOException ex) {
       
   181       ex.printStackTrace();
       
   182     }
       
   183     project.setNewProperty(attributes.get("output") , output);
       
   184 
       
   185 ]]>
       
   186     </scriptdef>
       
   187 
       
   188     <!-- This task allow to dump the content of a text file to the shell. -->
       
   189     <scriptdef name="echoFileMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
   190         <attribute name="file"/>
       
   191         <![CDATA[        
       
   192         //Open the file for reading
       
   193          try {
       
   194             java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(attributes.get("file")));
       
   195             while ((thisLine = in.readLine()) != null) { // while loop begins here
       
   196                  self.log(thisLine);
       
   197             } // end while 
       
   198         } catch (java.io.IOException e) {
       
   199             self.log("Error: " + e);
       
   200             throw e;
       
   201         }        
       
   202         ]]>
       
   203     </scriptdef>
       
   204     
       
   205     <!-- This task create the herder information in the symbian log file -->
       
   206     <scriptdef name="symbianLogHeaderMacro" language="jython" uri="http://www.nokia.com/helium">
       
   207         <attribute name="config"/>
       
   208         <attribute name="command"/>
       
   209         <attribute name="dir"/>
       
   210 import log2xml
       
   211 log2xml.symbian_log_header(self, attributes.get('config'), attributes.get('command'), attributes.get('dir'))
       
   212     </scriptdef>
       
   213 
       
   214     <!-- This task create the footer information in the symbian log file -->
       
   215     <scriptdef name="symbianLogFooterMacro" language="jython" uri="http://www.nokia.com/helium">
       
   216 import log2xml
       
   217 log2xml.symbian_log_footer(self)
       
   218     </scriptdef>
       
   219 
       
   220 
       
   221     
       
   222     <!-- A generic assert macro similar to AntUnit "assertTrue". -->
       
   223     <macrodef name="assert" uri="http://www.nokia.com/helium">
       
   224         <attribute name="message" default="Value is not true."/>
       
   225         <element name="condition" implicit="yes"/>
       
   226         <sequential>
       
   227             <if>
       
   228                 <isset property="hlm.enable.asserts"/>
       
   229                 <then>
       
   230                     <au:assertTrue message="@{message}">
       
   231                         <condition/>
       
   232                     </au:assertTrue>
       
   233                 </then>
       
   234                 <else>
       
   235                     <trycatch property="assert.try">
       
   236                         <try>
       
   237                             <au:assertTrue message="@{message}">
       
   238                                 <condition/>
       
   239                             </au:assertTrue>
       
   240                         </try>
       
   241                         <catch>
       
   242                             <echo message="Warning: @{message}"/>
       
   243                             <hlm:hlmassertmessage assertName="hlm:assert" message="Warning: @{message}"/>
       
   244                         </catch>
       
   245                     </trycatch>
       
   246                 </else>
       
   247             </if>
       
   248         </sequential>
       
   249     </macrodef>
       
   250     
       
   251     
       
   252     <!-- A generic assert macro similar to AntUnit "assertFileExists". -->
       
   253     <macrodef name="assertFileExists" uri="http://www.nokia.com/helium">
       
   254         <attribute name="file"/>
       
   255         <attribute name="message" default="@{file} does not exists."/>
       
   256         <sequential>
       
   257             <if>
       
   258                 <isset property="hlm.enable.asserts"/>
       
   259                 <then>
       
   260                     <au:assertFileExists file="@{file}" message="Warning: @{message}"/>
       
   261                 </then>
       
   262                 <else>
       
   263                     <trycatch property="assert.try">
       
   264                         <try>
       
   265                             <au:assertFileExists file="@{file}" message="Warning: @{message}"/>                                
       
   266                         </try>
       
   267                         <catch>
       
   268                             <echo message="Warning: @{message}"/>
       
   269                             <hlm:hlmassertmessage assertName="hlm:assertFileExists" message="Warning: @{message}"/>
       
   270                         </catch>
       
   271                     </trycatch>
       
   272                 </else>
       
   273             </if>
       
   274         </sequential>
       
   275     </macrodef>
       
   276 
       
   277     <!-- A generic assert macro similar to AntUnit "assertPropertySet". -->
       
   278     <macrodef name="assertPropertySet" uri="http://www.nokia.com/helium">
       
   279         <attribute name="property"/>
       
   280         <attribute name="message" default="@{property} is not set."/>
       
   281         <sequential>
       
   282             <if>
       
   283                 <isset property="hlm.enable.asserts"/>
       
   284                 <then>
       
   285                     <au:assertPropertySet name="@{property}" message="@{message}"/>
       
   286                 </then>
       
   287                 <else>
       
   288                     <trycatch property="assert.try">
       
   289                         <try>
       
   290                             <au:assertPropertySet name="@{property}" message="@{message}"/>
       
   291                         </try>
       
   292                         <catch>
       
   293                             <echo message="Warning: @{message}"/>
       
   294                             <hlm:hlmassertmessage assertName="hlm:assertPropertySet" message="Warning: @{message}"/>
       
   295                         </catch>
       
   296                     </trycatch>
       
   297                 </else>
       
   298             </if>
       
   299         </sequential>
       
   300     </macrodef>
       
   301 
       
   302 
       
   303     
       
   304     <!-- Script definition to collect target dependencies -->
       
   305     <scriptdef name="dependencies" language="jython" uri="http://www.nokia.com/helium">
       
   306         <attribute name="target"/>
       
   307         <attribute name="format"/>
       
   308 parsedTargets = []
       
   309 targetList = []
       
   310 
       
   311 def collectTargetDependencies(targetName, indent):    
       
   312     targetObject = project.getTargets().get(targetName)
       
   313     if targetObject is None :
       
   314         print  "Target '" + targetName + "' not found."   
       
   315     else :
       
   316         dependenciesEnum = targetObject.getDependencies()
       
   317         while dependenciesEnum.hasMoreElements():
       
   318             dependency = dependenciesEnum.nextElement()
       
   319             if dependency not in parsedTargets:
       
   320                 collectTargetDependencies(dependency, indent + 1)
       
   321                 parsedTargets.append(dependency)
       
   322                 targetList.append((dependency, indent))
       
   323 
       
   324 target = str(attributes.get('target'))
       
   325 
       
   326 collectTargetDependencies(target, 1)
       
   327 targetList.append((target, 0))
       
   328     
       
   329 format = str(attributes.get('format'))
       
   330 
       
   331 if format == 'nested':    
       
   332     for target, indent in targetList:        
       
   333         indentString = ''.join(['   ' for x in range(indent)])
       
   334         print indentString + str(target)
       
   335 elif format == 'executable':
       
   336     print "Top level targets:\n"
       
   337     print ''.join([str(target) + ' ' for target, indent in targetList[:-1] if indent == 1])
       
   338     print "\n\nAll targets in sequence:\n"
       
   339     print ''.join([str(target) + ' ' for target, indent in targetList[:-1]])
       
   340     </scriptdef>
       
   341     
       
   342     
       
   343     <!-- This new task allows to save a reference to a file. -->
       
   344     <scriptdef name="referenceToFileMacro" language="jython" uri="http://www.nokia.com/helium">
       
   345         <attribute name="refid"/>
       
   346         <attribute name="output"/>
       
   347     <![CDATA[
       
   348 from java.io import FileWriter
       
   349 
       
   350 refid = str(attributes.get("refid"))
       
   351 output = str(attributes.get("output"))
       
   352 
       
   353 if refid == None:
       
   354     raise Exception("'refid' attribute must be defined!")    
       
   355 if output == None:
       
   356     raise Exception("'output' attribute must be defined!")
       
   357     
       
   358 self.log("Creating %s using %s" % (output, refid))
       
   359 
       
   360 reference = project.getReference(refid)
       
   361 if reference == None:
       
   362     raise Exception("Unknown reference '%s'" % refid)
       
   363 output = FileWriter(output)
       
   364 i = reference.iterator()
       
   365 while i.hasNext():
       
   366     path = i.next().toString()
       
   367     self.log(path)
       
   368     output.write(path + "\n")
       
   369 output.close()
       
   370     ]]></scriptdef>
       
   371     
       
   372     <!-- Reads password from .netrc file for a specific type of service. -->
       
   373     <scriptdef name="netrcPasswordMacro" language="jython" uri="http://www.nokia.com/helium">
       
   374         <attribute name="output-prop"/>
       
   375         <attribute name="result-prop"/>
       
   376         <attribute name="type"/>
       
   377         <![CDATA[
       
   378 import netrc
       
   379 import os
       
   380 result = "0"
       
   381 try:
       
   382     netrc_file = netrc.netrc()
       
   383     self.log("Type: %s" % str(attributes.get("type")))
       
   384     netrc_info = netrc_file.authenticators(str(attributes.get("type")))
       
   385     if netrc_info == None:
       
   386         raise Exception("No entry found for Type: %s" % str(attributes.get("type")))
       
   387     (n_username, n_account, n_password) = netrc_info
       
   388     if attributes.get('output-prop') != None:
       
   389         project.setProperty(str(attributes.get('output-prop')), str(n_password))
       
   390 except Exception, e:
       
   391     result = "-1"
       
   392     print "Warning: %s" % e
       
   393 if attributes.get('result-prop') != None:
       
   394     project.setProperty(str(attributes.get('result-prop')), str(result))
       
   395         ]]>
       
   396     </scriptdef>
       
   397 
       
   398     <!-- Reads user name from .netrc file for a specific type of service. -->
       
   399     <scriptdef name="netrcUsernameMacro" language="jython" uri="http://www.nokia.com/helium">
       
   400         <attribute name="output-prop"/>
       
   401         <attribute name="result-prop"/>
       
   402         <attribute name="type"/>
       
   403         <![CDATA[
       
   404 import netrc
       
   405 import os
       
   406 result = "0"
       
   407 try:
       
   408     netrc_file = netrc.netrc()
       
   409     self.log("Type: %s" % str(attributes.get("type")))
       
   410     netrc_info = netrc_file.authenticators(str(attributes.get("type")))
       
   411     if netrc_info == None:
       
   412         raise Exception("No entry found for Type: %s" % str(attributes.get("type")))
       
   413     (n_username, n_account, n_password) = netrc_info
       
   414     if attributes.get('output-prop') != None:
       
   415         project.setProperty(str(attributes.get('output-prop')), str(n_username))
       
   416 except Exception, e:
       
   417     result = "-1"
       
   418     print "Warning: %s" % e
       
   419 if attributes.get('result-prop') != None:
       
   420     project.setProperty(str(attributes.get('result-prop')), str(result))
       
   421         ]]>
       
   422     </scriptdef>
       
   423      
       
   424     <!-- Check availability of synergy. -->   
       
   425     <scriptdef  name="ccmAvailableMacro" language="jython" uri="http://www.nokia.com/helium">
       
   426         <attribute name="resultproperty"/>
       
   427         <![CDATA[
       
   428 import nokia.nokiaccm
       
   429 import logging
       
   430 import ccm.extra
       
   431 
       
   432 logging.basicConfig(level=logging.INFO)
       
   433 
       
   434 session = None
       
   435 result = "0"
       
   436 cache = None
       
   437 if project.getProperty("ccm.cache.xml")is not None:
       
   438     cache = str(project.getProperty("ccm.cache.xml"))
       
   439 try:
       
   440     database = project.getProperty('ccm.database')
       
   441     
       
   442     if project.getProperty('ccm.user.login') == None :
       
   443         raise Exception("'ccm.user.login' property is not defined")
       
   444         
       
   445     username = project.getProperty('ccm.user.login')
       
   446     
       
   447     if project.getProperty('ccm.user.password') == None :
       
   448         raise Exception("'ccm.user.password' property is not defined")
       
   449         
       
   450     password = project.getProperty('ccm.user.password')
       
   451     
       
   452     
       
   453     engine = project.getProperty('ccm.engine.host')
       
   454     dbpath = project.getProperty('ccm.database.path')
       
   455     provider = ccm.extra.CachedSessionProvider(opener=nokia.nokiaccm.open_session, cache=cache)
       
   456     if database != None:
       
   457         session = provider.get(username, password, database=database, reuse=False)
       
   458     else:
       
   459         session = provider.get(username, password, engine, dbpath, reuse=False)
       
   460     session.close()
       
   461     provider.close()
       
   462 except Exception, e:
       
   463     print "ERROR: %s" % e
       
   464     if str(e).find("access denied") != -1:
       
   465         result = "-2"
       
   466     else:
       
   467         result = "-1"
       
   468 self.log("Result: %s" % attributes.get('resultproperty'))
       
   469 project.setProperty(str(attributes.get('resultproperty')), str(result))
       
   470         ]]>
       
   471      </scriptdef>
       
   472 
       
   473     <macrodef name="signalMacro" uri="http://www.nokia.com/helium">
       
   474         <attribute name="logfile"/>
       
   475         <attribute name="phase" default=""/>
       
   476         <attribute name="signal.input" />
       
   477         <attribute name="skip.count" default="false" />
       
   478         <attribute name="result" default="not-set"/>
       
   479         <sequential>
       
   480             <var name="signal.errors.total" value="" unset="true"/>
       
   481             <var name="base.signal.log.file" value="" unset="true"/>
       
   482             <basename property="base.signal.log.file" file="@{logfile}"/>
       
   483             <if>
       
   484                 <isfalse value="@{skip.count}" />
       
   485                 <then>
       
   486                     <hlm:metadataCountSeverity severity="error" 
       
   487                         log="@{logfile}"
       
   488                         db="${metadata.dbfile}" property="signal.errors.total"/>
       
   489                 </then>
       
   490                 <else>
       
   491                     <if>
       
   492                         <equals arg1="@{result}" arg2="not-set"/>
       
   493                         <then>
       
   494                             <fail message="result parameter is missing for signa macro" />
       
   495                         </then>
       
   496                     </if>
       
   497                     <var name="signal.errors.total" value="@{result}" />
       
   498                 </else>
       
   499             </if>
       
   500             <if>
       
   501                 <isset property="@{phase}.log.dir" />
       
   502                 <then>
       
   503                     <var name="signal.log.dir" value="" unset="true"/>
       
   504                     <property name="signal.log.dir" value="${@{phase}.log.dir}"/>
       
   505                     <echo>signal.log.dir = ${signal.log.dir}</echo>
       
   506                 </then>
       
   507                 <else>
       
   508                     <var name="signal.log.dir" value="" unset="true"/>
       
   509                     <property name="signal.log.dir" value="${build.log.dir}"/>
       
   510                 </else>
       
   511             </if>
       
   512             <hlm:generateBuildStatus output-dir="${build.signal.status.dir}/" 
       
   513                 file="${base.signal.log.file}" />
       
   514             <!-- signal for errors -->
       
   515             <hlm:signal name="@{signal.input}" result="${signal.errors.total}" >
       
   516                 <signalNotifierInput>
       
   517                     <signalInput refid="@{signal.input}" />
       
   518                     <notifierInput>
       
   519                         <fileset casesensitive="false" dir="${build.log.dir}" >
       
   520                             <include name="**/${base.signal.log.file}*" />
       
   521                         </fileset>
       
   522                     </notifierInput>
       
   523                 </signalNotifierInput>
       
   524             </hlm:signal>
       
   525         </sequential>
       
   526     </macrodef>
       
   527 
       
   528     <!-- A simple test macro -->
       
   529     <macrodef name="fooMacro" uri="http://www.nokia.com/helium">
       
   530         <sequential>
       
   531             <echo>foo</echo>
       
   532             <runtarget target="hello"/>
       
   533         </sequential>
       
   534     </macrodef>
       
   535     
       
   536     
       
   537     <!-- Asserts that two XML resources are logically equal.
       
   538     
       
   539     This looks at the XML content rather than just diffing the strings. -->
       
   540     <scriptdef name="assertXmlEqual" language="jython" uri="http://www.nokia.com/helium">
       
   541         <attribute name="control"/>
       
   542         <attribute name="test"/>
       
   543         <attribute name="failonerror"/>
       
   544         <![CDATA[
       
   545 import logging
       
   546 
       
   547 import java.io
       
   548 import org.custommonkey.xmlunit
       
   549 
       
   550 control_id = str(attributes.get('control'))
       
   551 test_id = str(attributes.get('test'))
       
   552 
       
   553 control_resource = project.getReference(control_id)
       
   554 test_resource = project.getReference(test_id)
       
   555 control_reader = java.io.InputStreamReader(control_resource.getInputStream())
       
   556 test_reader = java.io.InputStreamReader(test_resource.getInputStream())
       
   557 
       
   558 org.custommonkey.xmlunit.XMLUnit.setIgnoreWhitespace(True)
       
   559 org.custommonkey.xmlunit.XMLUnit.setIgnoreComments(True)
       
   560 diff = org.custommonkey.xmlunit.Diff(control_reader, test_reader)
       
   561 detailed_diff = org.custommonkey.xmlunit.DetailedDiff(diff)
       
   562 differences = detailed_diff.getAllDifferences()
       
   563 print 'Differences total = ' + str(differences.size())
       
   564 for diff in differences.toArray():
       
   565     print logging.warning(diff.toString())
       
   566 
       
   567 try:
       
   568     control_reader = java.io.InputStreamReader(control_resource.getInputStream())
       
   569     test_reader = java.io.InputStreamReader(test_resource.getInputStream())
       
   570     org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(control_reader, test_reader)
       
   571     print 'XML is similar'
       
   572 except Exception, e:
       
   573     print 'XML is NOT similar!'
       
   574     failonerror = str(attributes.get('failonerror'))
       
   575     if failonerror == 'true' or failonerror == 'None':
       
   576         raise e
       
   577         ]]>
       
   578     </scriptdef>
       
   579     
       
   580     <!-- unsubst task, will unsubst a given drive. -->
       
   581     <scriptdef name="unsubst" language="jython" uri="http://www.nokia.com/helium">
       
   582         <attribute name="drive"/>
       
   583         <attribute name="failonerror"/>
       
   584 """ internal.codescanner.drive """
       
   585 import fileutils
       
   586 self.setTaskName('unsubst')
       
   587 drive = attributes.get('drive')
       
   588 failonerror = attributes.get('failonerror')
       
   589 if (failonerror == None or str(failonerror) == "true"):
       
   590     failonerror = True
       
   591 else:
       
   592     failonerror = False
       
   593 if drive == None or len(str(drive)) != 2:
       
   594     raise Exception("'drive' attribute is missing or invalid. " + str(drive))
       
   595 drive = str(drive)
       
   596 try:
       
   597     self.log(str("Unsubsting %s..." % drive))
       
   598     fileutils.unsubst(drive)
       
   599 except Exception, e:
       
   600     if failonerror:
       
   601         raise e
       
   602     else:
       
   603         self.log(str("Error: %s" % e))
       
   604     </scriptdef>
       
   605     
       
   606     <!-- Touches the files in the paths given. -->
       
   607     <scriptdef name="touch" language="jython" uri="http://www.nokia.com/helium">
       
   608         <element name="path" type="path"/>
       
   609         <![CDATA[
       
   610 import fileutils
       
   611 for id in range(elements.get("path").size()):
       
   612     iterator = elements.get("path").get(int(id)).iterator()
       
   613     while iterator.hasNext():
       
   614         path = str(iterator.next())
       
   615         fileutils.touch(path)
       
   616         ]]>
       
   617     </scriptdef>
       
   618     
       
   619 </antlib>