buildframework/helium/tools/common/common.antlib.xml
changeset 1 be27ed110b50
child 179 d8ac696cc51f
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     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 <antlib xmlns:au="org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
       
    24     
       
    25     
       
    26     <!-- Macro to execute bldmake command. To be removed if not used. -->
       
    27     <macrodef name="bldmakeBldfilesMacro" uri="http://www.nokia.com/helium">
       
    28         <attribute name="dir"/>
       
    29         <sequential>
       
    30             <exec executable="${build.drive}/epoc32/tools/bldmake.bat" dir="@{dir}" failonerror="${failonerror}">
       
    31                 <arg value="bldfiles"/>
       
    32                 <arg value="-k"/>
       
    33             </exec>
       
    34         </sequential>
       
    35     </macrodef>
       
    36 
       
    37 
       
    38     <!-- Macro to execute abld command. Once used in rombuild.ant.xml. -->
       
    39     <macrodef name="abldMacro" uri="http://www.nokia.com/helium">
       
    40         <attribute name="dir"/>
       
    41         <attribute name="command"/>
       
    42         <attribute name="platform"/>
       
    43         <sequential>
       
    44             <exec executable="@{dir}/abld.bat" dir="@{dir}" failonerror="${failonerror}">
       
    45                 <arg value="@{command}"/>
       
    46                 <arg value="@{platform}"/>
       
    47                 <arg value="-k"/>
       
    48             </exec>
       
    49         </sequential>
       
    50     </macrodef>
       
    51 
       
    52     <!--
       
    53         This macro generate a file that contains a list of path from a path structure:
       
    54         <pre>
       
    55         <hlm:pathToFileListMacro file="output.lst">
       
    56             <path>
       
    57                 <pathelement path="${helium.dir}"/>
       
    58             </path>
       
    59         </hlm:pathToFileListMacro> 
       
    60         </pre>
       
    61     -->
       
    62     <scriptdef name="pathToFileListMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
    63         <attribute name="file"/>
       
    64         <element name="path" type="path"/>
       
    65         <![CDATA[
       
    66     import java.io.FileWriter;
       
    67     FileWriter out = new FileWriter(attributes.get("file"));
       
    68     paths = elements.get("path");
       
    69     for (int i = 0 ; i < paths.size() ; i++) {
       
    70         String[] files = paths.get(i).list();
       
    71         for (int l = 0; l < files.length ; l++) {
       
    72             out.write(files[l] + "\n");
       
    73         }
       
    74     }
       
    75 out.close();
       
    76 ]]>   
       
    77     </scriptdef>
       
    78 
       
    79     
       
    80    
       
    81     <!-- This Macro is a wrapper to command line tool 
       
    82         Currently supported command line tools are
       
    83         configuration tool and
       
    84         sbs tool
       
    85         Usage: 
       
    86             name - name of the tool:
       
    87             toolvarset - reference id for variables to be passed to the tool
       
    88         <pre>
       
    89         <hlm:toolMacro name="configuration">
       
    90             <hlm:toolvarset refid="cnftool.conf.50"/>
       
    91         </hlm:toolMacro>
       
    92         </pre>
       
    93     -->
       
    94     <scriptdef name="toolMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
    95         <element name="toolvarset" classname="com.nokia.ant.types.VariableSet"/>
       
    96         <attribute name="name"/>
       
    97 <![CDATA[
       
    98 import com.nokia.ant.util.ToolsProcess;
       
    99 import com.nokia.tools.*;
       
   100 import com.nokia.ant.types.VariableSet;
       
   101 import org.apache.tools.ant.types.Reference;
       
   102     Reference ref;
       
   103     java.lang.String toolName = attributes.get("name");
       
   104     confTool =  ToolsProcess.getTool(toolName);
       
   105     varSets = elements.get("toolvarset");
       
   106     for (i = 0; i < varSets.size(); ++i) {
       
   107         try {
       
   108             varSet = (VariableSet)varSets.get(i);
       
   109             if (varSet.isReference()) {
       
   110                 varSet = varSet.getRefid().getReferencedObject(project);
       
   111             }
       
   112             confTool.execute(varSet,project);
       
   113         } catch (Exception e) {
       
   114             self.log("Error: " + e);
       
   115             //self.log("Tool Argument Validation failure");
       
   116             throw e;
       
   117         }
       
   118   }
       
   119 ]]>
       
   120     </scriptdef>
       
   121 
       
   122     <!-- This task allow to dump the content of a text file to the shell. -->
       
   123     <scriptdef name="echoFileMacro" language="beanshell" uri="http://www.nokia.com/helium">
       
   124         <attribute name="file"/>
       
   125         <![CDATA[        
       
   126         //Open the file for reading
       
   127          try {
       
   128             java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(attributes.get("file")));
       
   129             while ((thisLine = in.readLine()) != null) { // while loop begins here
       
   130                  self.log(thisLine);
       
   131             } // end while 
       
   132         } catch (java.io.IOException e) {
       
   133             self.log("Error: " + e);
       
   134             throw e;
       
   135         }        
       
   136         ]]>
       
   137     </scriptdef>
       
   138     
       
   139     <!-- This task create the herder information in the symbian log file -->
       
   140     <scriptdef name="symbianLogHeaderMacro" language="jython" uri="http://www.nokia.com/helium">
       
   141         <attribute name="config"/>
       
   142         <attribute name="command"/>
       
   143         <attribute name="dir"/>
       
   144 import log2xml
       
   145 log2xml.symbian_log_header(self, attributes.get('config'), attributes.get('command'), attributes.get('dir'))
       
   146     </scriptdef>
       
   147 
       
   148     <!-- This task create the footer information in the symbian log file -->
       
   149     <scriptdef name="symbianLogFooterMacro" language="jython" uri="http://www.nokia.com/helium">
       
   150 import log2xml
       
   151 log2xml.symbian_log_footer(self)
       
   152     </scriptdef>
       
   153 
       
   154 
       
   155     <!-- Macro to record content to a separate log file without recording in the main log. -->
       
   156     <macrodef name="recordStartMacro" uri="http://www.nokia.com/helium">
       
   157         <attribute name="name"/>
       
   158         <attribute name="emacsmode" default="false"/>
       
   159         <sequential>
       
   160             <if>
       
   161                 <available file="${build.log}"/>
       
   162                 <then>
       
   163                     <record name="${build.log}" action="stop" append="true"/>
       
   164                 </then>
       
   165             </if>
       
   166             <if>
       
   167                 <available file="${build.log.dir}" type="dir"/>
       
   168                 <then>
       
   169                     <record name="${build.log.dir}/@{name}" action="start" append="true" emacsmode="@{emacsmode}"/>
       
   170                 </then>
       
   171             </if>
       
   172         </sequential>
       
   173     </macrodef>
       
   174 
       
   175 
       
   176     <!-- Macro to stop recording content to a separate log file without recording in the main log. -->
       
   177     <macrodef name="recordStopMacro" uri="http://www.nokia.com/helium">
       
   178         <attribute name="name"/>
       
   179         <sequential>
       
   180             <if>
       
   181                 <available file="${build.log.dir}/@{name}"/>
       
   182                 <then>
       
   183                     <record name="${build.log.dir}/@{name}" action="stop" append="true"/>
       
   184                 </then>
       
   185             </if>
       
   186             <if>
       
   187                 <available file="${build.log}"/>
       
   188                 <then>
       
   189                     <record name="${build.log}" action="start" append="true"/>
       
   190                 </then>
       
   191             </if>
       
   192         </sequential>
       
   193     </macrodef>
       
   194 
       
   195     
       
   196     <!--Macro to stop recording to the main log file (if present) and record to
       
   197         a separate log file that is filtered after logging is stopped. -->
       
   198     <macrodef name="filterRecordStartMacro" uri="http://www.nokia.com/helium">
       
   199         <sequential>
       
   200             <if>
       
   201                 <available file="${build.log}"/>
       
   202                 <then>
       
   203                     <record name="${build.log}" action="stop" append="true"/>
       
   204                 </then>
       
   205             </if>
       
   206             <echo>Start of filtering ${build.log} for passwords</echo>
       
   207             <record name="${build.cache.log.dir}/temp_ant_build.log" action="start" loglevel="info"/>
       
   208         </sequential>
       
   209     </macrodef>
       
   210     
       
   211 
       
   212     <!--Macro to stop recording the seperate filtered log file, filter the passwords
       
   213     and start recording in main log file -->
       
   214     <macrodef name="filterRecordStopMacro" uri="http://www.nokia.com/helium">
       
   215         <attribute name="pattern"/>
       
   216         <attribute name="log" default="${build.log}"/>
       
   217         <attribute name="append" default="true"/>
       
   218         <sequential>
       
   219             <record name="${build.cache.log.dir}/temp_ant_build.log" action="stop"/>                    
       
   220             <concat destfile="@{log}" append="@{append}">
       
   221                 <filelist dir="${build.cache.log.dir}" files="temp_ant_build.log"/>                        
       
   222                 <filterchain>
       
   223                     <tokenfilter>
       
   224                         <replaceregex pattern="@{pattern}" replace="****" flags="gi"/>
       
   225                     </tokenfilter>
       
   226                 </filterchain>                        
       
   227             </concat>
       
   228             <delete file="${build.cache.log.dir}/temp_ant_build.log" failonerror="false"/>
       
   229             <if>
       
   230                 <available file="${build.log}"/>
       
   231                 <then>
       
   232                     <record name="${build.log}" action="start" append="true"/>
       
   233                 </then>
       
   234             </if>
       
   235             <echo>End of filtering @{log} for passwords</echo>
       
   236         </sequential>
       
   237     </macrodef>
       
   238     
       
   239     
       
   240     <!-- A generic assert macro similar to AntUnit "assertTrue". -->
       
   241     <macrodef name="assert" uri="http://www.nokia.com/helium">
       
   242         <attribute name="message" default="Value is not true."/>
       
   243         <element name="condition" implicit="yes"/>
       
   244         <sequential>
       
   245             <if>
       
   246                 <isset property="hlm.enable.asserts"/>
       
   247                 <then>
       
   248                     <au:assertTrue message="@{message}">
       
   249                         <condition/>
       
   250                     </au:assertTrue>
       
   251                 </then>
       
   252                 <else>
       
   253                     <trycatch property="assert.try">
       
   254                         <try>
       
   255                             <au:assertTrue message="@{message}">
       
   256                                 <condition/>
       
   257                             </au:assertTrue>
       
   258                         </try>
       
   259                         <catch>
       
   260                             <echo message="Warning: @{message}"/>
       
   261                             <hlm:hlmassertmessage assertName="hlm:assert" message="Warning: @{message}"/>
       
   262                         </catch>
       
   263                     </trycatch>
       
   264                 </else>
       
   265             </if>
       
   266         </sequential>
       
   267     </macrodef>
       
   268     
       
   269     
       
   270     <!-- A generic assert macro similar to AntUnit "assertFileExists". -->
       
   271     <macrodef name="assertFileExists" uri="http://www.nokia.com/helium">
       
   272         <attribute name="file"/>
       
   273         <attribute name="message" default="@{file} does not exists."/>
       
   274         <sequential>
       
   275             <if>
       
   276                 <isset property="hlm.enable.asserts"/>
       
   277                 <then>
       
   278                     <au:assertFileExists file="@{file}" message="Warning: @{message}"/>
       
   279                 </then>
       
   280                 <else>
       
   281                     <trycatch property="assert.try">
       
   282                         <try>
       
   283                             <au:assertFileExists file="@{file}" message="Warning: @{message}"/>                                
       
   284                         </try>
       
   285                         <catch>
       
   286                             <echo message="Warning: @{message}"/>
       
   287                             <hlm:hlmassertmessage assertName="hlm:assertFileExists" message="Warning: @{message}"/>
       
   288                         </catch>
       
   289                     </trycatch>
       
   290                 </else>
       
   291             </if>
       
   292         </sequential>
       
   293     </macrodef>
       
   294 
       
   295     <!-- A generic assert macro similar to AntUnit "assertPropertySet". -->
       
   296     <macrodef name="assertPropertySet" uri="http://www.nokia.com/helium">
       
   297         <attribute name="property"/>
       
   298         <attribute name="message" default="@{property} is not set."/>
       
   299         <sequential>
       
   300             <if>
       
   301                 <isset property="hlm.enable.asserts"/>
       
   302                 <then>
       
   303                     <au:assertPropertySet name="@{property}" message="@{message}"/>
       
   304                 </then>
       
   305                 <else>
       
   306                     <trycatch property="assert.try">
       
   307                         <try>
       
   308                             <au:assertPropertySet name="@{property}" message="@{message}"/>
       
   309                         </try>
       
   310                         <catch>
       
   311                             <echo message="Warning: @{message}"/>
       
   312                             <hlm:hlmassertmessage assertName="hlm:assertPropertySet" message="Warning: @{message}"/>
       
   313                         </catch>
       
   314                     </trycatch>
       
   315                 </else>
       
   316             </if>
       
   317         </sequential>
       
   318     </macrodef>
       
   319 
       
   320 
       
   321     
       
   322     <!-- Script definition to collect target dependencies -->
       
   323     <scriptdef name="dependencies" language="jython" uri="http://www.nokia.com/helium">
       
   324         <attribute name="target"/>
       
   325         <attribute name="format"/>
       
   326 parsedTargets = []
       
   327 targetList = []
       
   328 
       
   329 def collectTargetDependencies(targetName, indent):    
       
   330     targetObject = project.getTargets().get(targetName)
       
   331     if targetObject is None :
       
   332         print  "Target '" + targetName + "' not found."   
       
   333     else :
       
   334         dependenciesEnum = targetObject.getDependencies()
       
   335         while dependenciesEnum.hasMoreElements():
       
   336             dependency = dependenciesEnum.nextElement()
       
   337             if dependency not in parsedTargets:
       
   338                 collectTargetDependencies(dependency, indent + 1)
       
   339                 parsedTargets.append(dependency)
       
   340                 targetList.append((dependency, indent))
       
   341 
       
   342 target = str(attributes.get('target'))
       
   343 
       
   344 collectTargetDependencies(target, 1)
       
   345 targetList.append((target, 0))
       
   346     
       
   347 format = str(attributes.get('format'))
       
   348 
       
   349 if format == 'nested':    
       
   350     for target, indent in targetList:        
       
   351         indentString = ''.join(['   ' for x in range(indent)])
       
   352         print indentString + str(target)
       
   353 elif format == 'executable':
       
   354     print "Top level targets:\n"
       
   355     print ''.join([str(target) + ' ' for target, indent in targetList[:-1] if indent == 1])
       
   356     print "\n\nAll targets in sequence:\n"
       
   357     print ''.join([str(target) + ' ' for target, indent in targetList[:-1]])
       
   358     </scriptdef>
       
   359     
       
   360     
       
   361     <!-- This new task allows to save a reference to a file. -->
       
   362     <scriptdef name="referenceToFileMacro" language="jython" uri="http://www.nokia.com/helium">
       
   363         <attribute name="refid"/>
       
   364         <attribute name="output"/>
       
   365     <![CDATA[
       
   366 from java.io import FileWriter
       
   367 
       
   368 refid = str(attributes.get("refid"))
       
   369 output = str(attributes.get("output"))
       
   370 
       
   371 if refid == None:
       
   372     raise Exception("'refid' attribute must be defined!")    
       
   373 if output == None:
       
   374     raise Exception("'output' attribute must be defined!")
       
   375     
       
   376 self.log("Creating %s using %s" % (output, refid))
       
   377 
       
   378 reference = project.getReference(refid)
       
   379 if reference == None:
       
   380     raise Exception("Unknown reference '%s'" % refid)
       
   381 output = FileWriter(output)
       
   382 i = reference.iterator()
       
   383 while i.hasNext():
       
   384     path = i.next().toString()
       
   385     self.log(path)
       
   386     output.write(path + "\n")
       
   387 output.close()
       
   388     ]]></scriptdef>
       
   389     
       
   390     <!-- Reads password from .netrc file for a specific type of service. -->
       
   391     <scriptdef name="netrcPasswordMacro" language="jython" uri="http://www.nokia.com/helium">
       
   392         <attribute name="output-prop"/>
       
   393         <attribute name="result-prop"/>
       
   394         <attribute name="type"/>
       
   395         <![CDATA[
       
   396 import netrc
       
   397 import os
       
   398 result = "0"
       
   399 try:
       
   400     netrc_file = netrc.netrc()
       
   401     self.log("Type: %s" % str(attributes.get("type")))
       
   402     netrc_info = netrc_file.authenticators(str(attributes.get("type")))
       
   403     if netrc_info == None:
       
   404         raise Exception("No entry found for Type: %s" % str(attributes.get("type")))
       
   405     (n_username, n_account, n_password) = netrc_info
       
   406     if attributes.get('output-prop') != None:
       
   407         self.log("Output: %s" % attributes.get('output-prop'))
       
   408         project.setProperty(str(attributes.get('output-prop')), str(n_password))
       
   409 except Exception, e:
       
   410     result = "-1"
       
   411     print "ERROR: %s" % e
       
   412 if attributes.get('result-prop') != None:
       
   413     self.log("Result: %s" % attributes.get('result-prop'))
       
   414     project.setProperty(str(attributes.get('result-prop')), str(result))
       
   415     self.log("%s: %s" % (attributes.get('result-prop'), project.getProperty(str(attributes.get('result-prop')))))
       
   416         ]]>
       
   417     </scriptdef>
       
   418 
       
   419     <!-- Reads user name from .netrc file for a specific type of service. -->
       
   420     <scriptdef name="netrcUsernameMacro" language="jython" uri="http://www.nokia.com/helium">
       
   421         <attribute name="output-prop"/>
       
   422         <attribute name="result-prop"/>
       
   423         <attribute name="type"/>
       
   424         <![CDATA[
       
   425 import netrc
       
   426 import os
       
   427 result = "0"
       
   428 try:
       
   429     netrc_file = netrc.netrc()
       
   430     self.log("Type: %s" % str(attributes.get("type")))
       
   431     netrc_info = netrc_file.authenticators(str(attributes.get("type")))
       
   432     if netrc_info == None:
       
   433         raise Exception("No entry found for Type: %s" % str(attributes.get("type")))
       
   434     (n_username, n_account, n_password) = netrc_info
       
   435     if attributes.get('output-prop') != None:
       
   436         self.log("Output: %s" % attributes.get('output-prop'))
       
   437         project.setProperty(str(attributes.get('output-prop')), str(n_username))
       
   438 except Exception, e:
       
   439     result = "-1"
       
   440     print "ERROR: %s" % e
       
   441 if attributes.get('result-prop') != None:
       
   442 
       
   443     self.log("Result: %s" % attributes.get('result-prop'))
       
   444     project.setProperty(str(attributes.get('result-prop')), str(result))
       
   445     self.log("%s: %s" % (attributes.get('result-prop'), project.getProperty(str(attributes.get('result-prop')))))
       
   446         ]]>
       
   447     </scriptdef>
       
   448      
       
   449     <!-- Check availability of synergy. -->   
       
   450     <scriptdef  name="ccmAvailableMacro" language="jython" uri="http://www.nokia.com/helium">
       
   451         <attribute name="resultproperty"/>
       
   452         <![CDATA[
       
   453 import nokia.nokiaccm
       
   454 import logging
       
   455 import ccm.extra
       
   456 
       
   457 logging.basicConfig(level=logging.INFO)
       
   458 
       
   459 session = None
       
   460 result = "0"
       
   461 cache = None
       
   462 if project.getProperty("ccm.cache.xml")is not None:
       
   463     cache = str(project.getProperty("ccm.cache.xml"))
       
   464 try:
       
   465     database = project.getProperty('ccm.database')
       
   466     
       
   467     if project.getProperty('ccm.user.login') == None :
       
   468         raise Exception("'ccm.user.login' property is not defined")
       
   469         
       
   470     username = project.getProperty('ccm.user.login')
       
   471     
       
   472     if project.getProperty('ccm.user.password') == None :
       
   473         raise Exception("'ccm.user.password' property is not defined")
       
   474         
       
   475     password = project.getProperty('ccm.user.password')
       
   476     
       
   477     
       
   478     engine = project.getProperty('ccm.engine.host')
       
   479     dbpath = project.getProperty('ccm.database.path')
       
   480     provider = ccm.extra.CachedSessionProvider(opener=nokia.nokiaccm.open_session, cache=cache)
       
   481     if database != None:
       
   482         session = provider.get(username, password, database=database, reuse=False)
       
   483     else:
       
   484         session = provider.get(username, password, engine, dbpath, reuse=False)
       
   485     del(session)
       
   486 except Exception, e:
       
   487     print "ERROR: %s" % e
       
   488     if str(e).find("access denied") != -1:
       
   489         result = "-2"
       
   490     else:
       
   491         result = "-1"
       
   492 self.log("Result: %s" % attributes.get('resultproperty'))
       
   493 project.setProperty(str(attributes.get('resultproperty')), str(result))
       
   494         ]]>
       
   495      </scriptdef>
       
   496 
       
   497     <!-- Extract logs from text file and process error/warnings/components name etc
       
   498     into xml file.-->
       
   499     <scriptdef name="logextract" language="jython"  uri="http://www.nokia.com/helium">
       
   500         <attribute name="file" />
       
   501         <attribute name="outputfile" />
       
   502         <element name="fileset" type="fileset"/>
       
   503         <element name="logfilterset" classname="com.nokia.ant.types.LogFilterSet"/>
       
   504         <![CDATA[
       
   505 import os.path
       
   506 import log2xml
       
   507 import java.io
       
   508 
       
   509 def convertFile(inputfile, outputfile, config):
       
   510     if (outputfile != None):
       
   511         print "output file not none"
       
   512         print "output file: %s" % outputfile
       
   513         targetfile = str(outputfile)
       
   514     else:
       
   515         #print "output file: %s" % outputfile
       
   516         targetfile = "%s.xml" % inputfile
       
   517         #print "targetFile %s" % targetfile
       
   518     if not os.path.exists(targetfile) or \
       
   519        (os.path.exists(targetfile) and os.path.getmtime(inputfile) > os.path.getmtime(targetfile)):
       
   520         self.getProject().log("Converting %s..." % inputfile)
       
   521         log2xml.convert(inputfile, targetfile, False, config)
       
   522     else:
       
   523         self.getProject().log("Extracted log is uptodate: %s" % inputfile)
       
   524         
       
   525 config = log2xml.DEFAULT_CONFIGURATION
       
   526 logfilterset = elements.get("logfilterset")
       
   527 if logfilterset != None and logfilterset.size() > 0:
       
   528     # if any logfilterset are dfined then
       
   529     # it override the default configuration
       
   530     config = {}
       
   531     for filtersetid in range(logfilterset.size()):
       
   532         filterset = logfilterset.get(filtersetid)
       
   533         if filterset.isReference():
       
   534             filterset = filterset.getRefid().getReferencedObject(project)
       
   535         filters = filterset.getFilters()
       
   536         for filterid in range(filters.size()):
       
   537             if not filters.get(filterid).getCategory() in config:
       
   538                 config[filters.get(filterid).getCategory()] = []
       
   539             config[filters.get(filterid).getCategory()].append(str(filters.get(filterid).getRegex()))
       
   540 
       
   541 fileset = elements.get("fileset")
       
   542 outputfile = attributes.get("outputfile")
       
   543 if fileset != None and fileset.size() > 0:
       
   544     for filesetid in range(fileset.size()):
       
   545         dirscanner = fileset.get(filesetid).getDirectoryScanner(project)
       
   546         for filename in dirscanner.getIncludedFiles():
       
   547             inputfile = str(java.io.File(dirscanner.getBasedir(), str(filename)).getAbsolutePath())
       
   548             convertFile(inputfile, outputfile, config)
       
   549 elif attributes.get("file") != None:
       
   550     inputfile = str(java.io.File(str(attributes.get("file"))).getAbsolutePath())
       
   551     convertFile(inputfile, outputfile, config)
       
   552 else:
       
   553     self.log("No input specified.")
       
   554         ]]>
       
   555     </scriptdef>
       
   556     
       
   557     
       
   558     <!--Macro to stop recording to the main log file (if present) and record to
       
   559         a separate log file into a temporary location (doesn't need the build aread to work). -->
       
   560     <macrodef name="tempRecordStartMacro" uri="http://www.nokia.com/helium">
       
   561         <attribute name="name"/>
       
   562         <sequential>
       
   563             <mkdir dir="${build.cache.log.dir}"/>
       
   564             <if>
       
   565                 <available file="${build.log}"/>
       
   566                 <then>
       
   567                     <record name="${build.log}" action="stop" append="true"/>
       
   568                 </then>
       
   569             </if>
       
   570             <record name="${build.cache.log.dir}/@{name}" action="start" loglevel="verbose"/>
       
   571         </sequential>
       
   572     </macrodef>
       
   573 
       
   574 
       
   575     <!--Macro to restart  the main log file (if present) and stop recording to
       
   576         a separate log file into a temporary location the file is next xml summarized 
       
   577         and potentially copied to the build area (if exists). Else those files will get copied during the 
       
   578         build area preparation. -->
       
   579     <macrodef name="tempRecordStopMacro" uri="http://www.nokia.com/helium">
       
   580         <attribute name="name"/>
       
   581         <attribute name="database" default="${metadata.dbfile}"/>
       
   582         <attribute name="filterref" default="filterset.temprecord"/>
       
   583         <sequential>
       
   584             <mkdir dir="${build.cache.log.dir}"/>
       
   585             <mkdir dir="${build.cache.log.dir}/signals"/>
       
   586             <record name="${build.cache.log.dir}/@{name}" action="stop" loglevel="verbose"/>
       
   587             <!--Temporary solution, the logextract in general 
       
   588                 needs to be handled in a better way (not all logs needs to be processed,
       
   589                 logextract / counting errors could be merged and logextract should be
       
   590                 executed on a need basis and not to process for all stopmacro.-->
       
   591             <!-- Todo: metadata: replace logextract -->
       
   592             <hlm:metadatarecord database="@{database}">
       
   593                 <hlm:antmetadatainput>
       
   594                     <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   595                     <metadatafilterset refid="@{filterref}" />
       
   596                 </hlm:antmetadatainput>
       
   597             </hlm:metadatarecord>
       
   598             <hlm:generateBuildStatus dbfile="@{database}" output-dir="${build.cache.log.dir}/signals" file="@{name}" />
       
   599             <copy todir="${build.log.dir}" failonerror="false">
       
   600                 <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   601             </copy>
       
   602             <copy todir="${build.signal.status.dir}" failonerror="false">
       
   603                 <fileset casesensitive="false" dir="${build.cache.log.dir}/signals" />
       
   604             </copy>
       
   605             <if>
       
   606                 <available file="${build.log}"/>
       
   607                 <then>
       
   608                     <record name="${build.log}" action="start" append="true"/>
       
   609                 </then>
       
   610             </if>
       
   611         </sequential>
       
   612     </macrodef>
       
   613     
       
   614 
       
   615     <macrodef name="signalMacro" uri="http://www.nokia.com/helium">
       
   616         <attribute name="logfile"/>
       
   617         <attribute name="signal.input" />
       
   618         <attribute name="skip.count" default="false" />
       
   619         <attribute name="result" default="not-set"/>
       
   620         <sequential>
       
   621             <var name="signal.errors.total" value="" unset="true"/>
       
   622             <var name="base.signal.log.file" value="" unset="true"/>
       
   623             <basename property="base.signal.log.file" file="@{logfile}" suffix=".log"/>
       
   624             <if>
       
   625                 <isfalse value="@{skip.count}" />
       
   626                 <then>
       
   627                     <hlm:metadataCountSeverity severity="error" 
       
   628                         log="@{logfile}"
       
   629                         db="${metadata.dbfile}" property="signal.errors.total"/>
       
   630                 </then>
       
   631                 <else>
       
   632                     <if>
       
   633                         <equals arg1="@{result}" arg2="not-set"/>
       
   634                         <then>
       
   635                             <fail message="result parameter is missing for signa macro" />
       
   636                         </then>
       
   637                     </if>
       
   638                     <var name="signal.errors.total" value="@{result}" />
       
   639                 </else>
       
   640             </if>
       
   641             <hlm:generateBuildStatus output-dir="${build.signal.status.dir}/" 
       
   642                 file="${base.signal.log.file}" />
       
   643             <!-- signal for errors -->
       
   644             <hlm:signal name="@{signal.input}" result="${signal.errors.total}" >
       
   645                 <signalNotifierInput>
       
   646                     <signalInput refid="@{signal.input}" />
       
   647                     <notifierInput file = "${build.signal.status.dir}/${base.signal.log.file}.status.html" />
       
   648                 </signalNotifierInput>
       
   649             </hlm:signal>
       
   650         </sequential>
       
   651     </macrodef>
       
   652 
       
   653     <!-- Macro to start logging to a separate log file.
       
   654     
       
   655     This will stop logging to the main ant_build log file until stopSpecificLogMacro
       
   656     is called. -->
       
   657     <macrodef name="startSpecificLogMacro">
       
   658         <attribute name="name"/>
       
   659         <attribute name="regexp" default=""/>
       
   660         <attribute name="backup" default="false"/>
       
   661         
       
   662         <sequential>
       
   663             <if>
       
   664                 <available file="${build.log}"/>
       
   665                 <then>
       
   666                     <echo>Stopping recording to main Ant build log.</echo>
       
   667                     <record name="${build.log}" action="stop" append="true"/>
       
   668                 </then>
       
   669             </if>
       
   670             <mkdir dir="@{name}/.."/>
       
   671             <hlm:logrecord name="@{name}" action="start" loglevel="verbose" regexp="@{regexp}" backup="@{backup}"/>
       
   672         </sequential>
       
   673     </macrodef>
       
   674 
       
   675 
       
   676     <!--Macro to restart  the main log file (if present) and stop recording to
       
   677         a separate log file. -->
       
   678     <macrodef name="stopSpecificLogMacro">
       
   679         <attribute name="name"/>
       
   680         <sequential>
       
   681             <hlm:logrecord name="@{name}" action="stop" loglevel="verbose"/>
       
   682             <if>
       
   683                 <available file="${build.log}"/>
       
   684                 <then>
       
   685                     <record name="${build.log}" action="start" append="true"/>
       
   686                     <echo>Starting recording to main Ant build log again.</echo>
       
   687                 </then>
       
   688             </if>
       
   689         </sequential>
       
   690     </macrodef>
       
   691 
       
   692     <!-- Temp BMD macro -->
       
   693     <macrodef name="bmdLogExtractMacro" uri="http://www.nokia.com/helium">
       
   694         <attribute name="log"/>
       
   695         <attribute name="metadatafilterset" default="common"/>
       
   696         <sequential>
       
   697             <hlm:metadatarecord database="${metadata.dbfile}">
       
   698                 <hlm:textmetadatainput>
       
   699                     <fileset casesensitive="false" file="@{log}"/>
       
   700                     <metadatafilterset refid="@{metadatafilterset}" />
       
   701                 </hlm:textmetadatainput>
       
   702             </hlm:metadatarecord>
       
   703             <!-- todo: check to add for usage and add genbuildstatus macro -->
       
   704             <basename property="log.name" file="@{log}"/>
       
   705             <fmpp sourceFile="${helium.dir}/tools/common/templates/db2xml.xml.ftl"
       
   706                          outputfile="@{log}.xml">
       
   707                 <data expandProperties="yes">
       
   708                     dbPath: ${metadata.dbfile}
       
   709                     log: ${log.name}
       
   710                     ant: antProperties()
       
   711                 </data>
       
   712             </fmpp>
       
   713         </sequential>
       
   714     </macrodef>
       
   715 
       
   716     <!-- A simple test macro -->
       
   717     <macrodef name="fooMacro" uri="http://www.nokia.com/helium">
       
   718         <sequential>
       
   719             <echo>foo</echo>
       
   720             <runtarget target="hello"/>
       
   721         </sequential>
       
   722     </macrodef>
       
   723     
       
   724     
       
   725     <!-- Asserts that two XML resources are logically equal.
       
   726     
       
   727     This looks at the XML content rather than just diffing the strings. -->
       
   728     <scriptdef name="assertXmlEqual" language="jython" uri="http://www.nokia.com/helium">
       
   729         <attribute name="control"/>
       
   730         <attribute name="test"/>
       
   731         <attribute name="failonerror"/>
       
   732         <![CDATA[
       
   733 import logging
       
   734 
       
   735 import java.io
       
   736 import org.custommonkey.xmlunit
       
   737 
       
   738 control_id = str(attributes.get('control'))
       
   739 test_id = str(attributes.get('test'))
       
   740 
       
   741 control_resource = project.getReference(control_id)
       
   742 test_resource = project.getReference(test_id)
       
   743 control_reader = java.io.InputStreamReader(control_resource.getInputStream())
       
   744 test_reader = java.io.InputStreamReader(test_resource.getInputStream())
       
   745 
       
   746 org.custommonkey.xmlunit.XMLUnit.setIgnoreWhitespace(True)
       
   747 org.custommonkey.xmlunit.XMLUnit.setIgnoreComments(True)
       
   748 diff = org.custommonkey.xmlunit.Diff(control_reader, test_reader)
       
   749 detailed_diff = org.custommonkey.xmlunit.DetailedDiff(diff)
       
   750 differences = detailed_diff.getAllDifferences()
       
   751 print 'Differences total = ' + str(differences.size())
       
   752 for diff in differences.toArray():
       
   753     print logging.warning(diff.toString())
       
   754 
       
   755 try:
       
   756     control_reader = java.io.InputStreamReader(control_resource.getInputStream())
       
   757     test_reader = java.io.InputStreamReader(test_resource.getInputStream())
       
   758     org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(control_reader, test_reader)
       
   759     print 'XML is similar'
       
   760 except Exception, e:
       
   761     print 'XML is NOT similar!'
       
   762     failonerror = str(attributes.get('failonerror'))
       
   763     if failonerror == 'true' or failonerror == 'None':
       
   764         raise e
       
   765         ]]>
       
   766     </scriptdef>
       
   767     
       
   768     <!-- unsubst task, will unsubst a given drive. -->
       
   769     <scriptdef name="unsubst" language="jython" uri="http://www.nokia.com/helium">
       
   770         <attribute name="drive"/>
       
   771         <attribute name="failonerror"/>
       
   772 """ internal.codescanner.drive """
       
   773 import fileutils
       
   774 self.setTaskName('unsubst')
       
   775 drive = attributes.get('drive')
       
   776 failonerror = attributes.get('failonerror')
       
   777 if (failonerror == None or str(failonerror) == "true"):
       
   778     failonerror = True
       
   779 else:
       
   780     failonerror = False
       
   781 if drive == None or len(str(drive)) != 2:
       
   782     raise Exception("'drive' attribute is missing or invalid. " + str(drive))
       
   783 drive = str(drive)
       
   784 try:
       
   785     self.log(str("Unsubsting %s..." % drive))
       
   786     fileutils.unsubst(drive)
       
   787 except Exception, e:
       
   788     if failonerror:
       
   789         raise e
       
   790     else:
       
   791         self.log(str("Error: %s" % e))
       
   792     </scriptdef>
       
   793     
       
   794     <!-- Touches the files in the paths given. -->
       
   795     <scriptdef name="touch" language="jython" uri="http://www.nokia.com/helium">
       
   796         <element name="path" type="path"/>
       
   797         <![CDATA[
       
   798 import fileutils
       
   799 for id in range(elements.get("path").size()):
       
   800     iterator = elements.get("path").get(int(id)).iterator()
       
   801     while iterator.hasNext():
       
   802         path = str(iterator.next())
       
   803         fileutils.touch(path)
       
   804         ]]>
       
   805     </scriptdef>
       
   806     
       
   807 </antlib>