buildframework/helium/tools/common/common.antlib.xml
changeset 217 0f5e3a7fb6af
parent 179 d8ac696cc51f
child 587 85df38eb4012
equal deleted inserted replaced
181:59bb7c4d6172 217:0f5e3a7fb6af
    18 
    18 
    19 Description:
    19 Description:
    20 
    20 
    21 ============================================================================
    21 ============================================================================
    22 -->
    22 -->
       
    23 <!--* @package framework -->
    23 <antlib xmlns:au="org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
    24 <antlib xmlns:au="org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
    24     
    25     
    25     
    26     
    26     <!-- Macro to execute bldmake command. To be removed if not used. -->
    27     <!-- Macro to execute bldmake command. To be removed if not used. -->
    27     <macrodef name="bldmakeBldfilesMacro" uri="http://www.nokia.com/helium">
    28     <macrodef name="bldmakeBldfilesMacro" uri="http://www.nokia.com/helium">
   168         Matcher match = null;
   169         Matcher match = null;
   169         while (( line = input.readLine()) != null) {
   170         while (( line = input.readLine()) != null) {
   170              match = pattern.matcher(line);
   171              match = pattern.matcher(line);
   171             if (match.find()) {
   172             if (match.find()) {
   172                 //self.log("Line containg " + search + " is = " + line + " returned vaue = " + match.group(1));
   173                 //self.log("Line containg " + search + " is = " + line + " returned vaue = " + match.group(1));
   173                 output = output + match.group(1) + ",";
   174                 int checkIndex = output.indexOf(match.group(1), 0);
       
   175                 if (checkIndex == -1 ) {
       
   176                    output = output + match.group(1) + ",";
       
   177                 }
   174             }
   178             }
   175         }
   179         }
   176     } catch (IOException ex) {
   180     } catch (IOException ex) {
   177       ex.printStackTrace();
   181       ex.printStackTrace();
   178     }
   182     }
   212 import log2xml
   216 import log2xml
   213 log2xml.symbian_log_footer(self)
   217 log2xml.symbian_log_footer(self)
   214     </scriptdef>
   218     </scriptdef>
   215 
   219 
   216 
   220 
   217     <!-- Macro to record content to a separate log file without recording in the main log. -->
       
   218     <macrodef name="recordStartMacro" uri="http://www.nokia.com/helium">
       
   219         <attribute name="name"/>
       
   220         <attribute name="emacsmode" default="false"/>
       
   221         <sequential>
       
   222             <if>
       
   223                 <available file="${build.log.dir}" type="dir"/>
       
   224                 <then>
       
   225                     <hlm:record name="${build.log.dir}/@{name}" action="start" append="true" emacsmode="@{emacsmode}" loglevel="${ant.loglevel}"/>
       
   226                 </then>
       
   227             </if>
       
   228         </sequential>
       
   229     </macrodef>
       
   230 
       
   231 
       
   232     <!-- Macro to stop recording content to a separate log file without recording in the main log. -->
       
   233     <macrodef name="recordStopMacro" uri="http://www.nokia.com/helium">
       
   234         <attribute name="name"/>
       
   235         <sequential>
       
   236             <if>
       
   237                 <available file="${build.log.dir}/@{name}"/>
       
   238                 <then>
       
   239                     <hlm:record name="${build.log.dir}/@{name}" action="stop" append="true"/>
       
   240                 </then>
       
   241             </if>
       
   242         </sequential>
       
   243     </macrodef>
       
   244 
       
   245     
       
   246     <!--Macro to stop recording to the main log file (if present) and record to
       
   247         a separate log file that is filtered after logging is stopped. -->
       
   248     <macrodef name="filterRecordStartMacro" uri="http://www.nokia.com/helium">
       
   249         <attribute name="pattern" default=""/>
       
   250         <attribute name="category" default=""/>
       
   251         <sequential>
       
   252             <hlm:record name="${build.cache.log.dir}/temp_ant_build.log" action="start" loglevel="${ant.loglevel}">
       
   253                 <hlm:recordfilter category="@{category}" regexp="@{pattern}" />
       
   254             </hlm:record>
       
   255         </sequential>
       
   256     </macrodef>
       
   257     
       
   258 
       
   259     <!--Macro to stop recording the seperate filtered log file, filter the passwords
       
   260     and start recording in main log file -->
       
   261     <macrodef name="filterRecordStopMacro" uri="http://www.nokia.com/helium">
       
   262         <attribute name="log" default="${build.log}"/>
       
   263         <attribute name="append" default="true"/>
       
   264         <sequential>
       
   265             <hlm:record name="${build.cache.log.dir}/temp_ant_build.log" action="stop"/>                    
       
   266             <concat destfile="@{log}" append="@{append}">
       
   267                 <filelist dir="${build.cache.log.dir}" files="temp_ant_build.log"/>                        
       
   268             </concat>
       
   269             <delete file="${build.cache.log.dir}/temp_ant_build.log" failonerror="false"/>
       
   270             <echo>End of filtering @{log} for passwords</echo>
       
   271         </sequential>
       
   272     </macrodef>
       
   273     
       
   274     
   221     
   275     <!-- A generic assert macro similar to AntUnit "assertTrue". -->
   222     <!-- A generic assert macro similar to AntUnit "assertTrue". -->
   276     <macrodef name="assert" uri="http://www.nokia.com/helium">
   223     <macrodef name="assert" uri="http://www.nokia.com/helium">
   277         <attribute name="message" default="Value is not true."/>
   224         <attribute name="message" default="Value is not true."/>
   278         <element name="condition" implicit="yes"/>
   225         <element name="condition" implicit="yes"/>
   521 self.log("Result: %s" % attributes.get('resultproperty'))
   468 self.log("Result: %s" % attributes.get('resultproperty'))
   522 project.setProperty(str(attributes.get('resultproperty')), str(result))
   469 project.setProperty(str(attributes.get('resultproperty')), str(result))
   523         ]]>
   470         ]]>
   524      </scriptdef>
   471      </scriptdef>
   525 
   472 
   526     <!-- Extract logs from text file and process error/warnings/components name etc
       
   527     into xml file.
       
   528     <deprecated>Please consider using the metadata framework.</deprecated>
       
   529     -->
       
   530     <scriptdef name="logextract" language="jython"  uri="http://www.nokia.com/helium">
       
   531         <attribute name="file" />
       
   532         <attribute name="outputfile" />
       
   533         <element name="fileset" type="fileset"/>
       
   534         <element name="logfilterset" classname="com.nokia.ant.types.LogFilterSet"/>
       
   535         <![CDATA[
       
   536 import os.path
       
   537 import log2xml
       
   538 import java.io
       
   539 
       
   540 def convertFile(inputfile, outputfile, config):
       
   541     if (outputfile != None):
       
   542         print "output file not none"
       
   543         print "output file: %s" % outputfile
       
   544         targetfile = str(outputfile)
       
   545     else:
       
   546         #print "output file: %s" % outputfile
       
   547         targetfile = "%s.xml" % inputfile
       
   548         #print "targetFile %s" % targetfile
       
   549     if not os.path.exists(targetfile) or \
       
   550        (os.path.exists(targetfile) and os.path.getmtime(inputfile) > os.path.getmtime(targetfile)):
       
   551         self.getProject().log("Converting %s..." % inputfile)
       
   552         log2xml.convert(inputfile, targetfile, False, config)
       
   553     else:
       
   554         self.getProject().log("Extracted log is uptodate: %s" % inputfile)
       
   555         
       
   556 config = log2xml.DEFAULT_CONFIGURATION
       
   557 logfilterset = elements.get("logfilterset")
       
   558 if logfilterset != None and logfilterset.size() > 0:
       
   559     # if any logfilterset are dfined then
       
   560     # it override the default configuration
       
   561     config = {}
       
   562     for filtersetid in range(logfilterset.size()):
       
   563         filterset = logfilterset.get(filtersetid)
       
   564         if filterset.isReference():
       
   565             filterset = filterset.getRefid().getReferencedObject(project)
       
   566         filters = filterset.getFilters()
       
   567         for filterid in range(filters.size()):
       
   568             if not filters.get(filterid).getCategory() in config:
       
   569                 config[filters.get(filterid).getCategory()] = []
       
   570             config[filters.get(filterid).getCategory()].append(str(filters.get(filterid).getRegex()))
       
   571 
       
   572 fileset = elements.get("fileset")
       
   573 outputfile = attributes.get("outputfile")
       
   574 if fileset != None and fileset.size() > 0:
       
   575     for filesetid in range(fileset.size()):
       
   576         dirscanner = fileset.get(filesetid).getDirectoryScanner(project)
       
   577         for filename in dirscanner.getIncludedFiles():
       
   578             inputfile = str(java.io.File(dirscanner.getBasedir(), str(filename)).getAbsolutePath())
       
   579             convertFile(inputfile, outputfile, config)
       
   580 elif attributes.get("file") != None:
       
   581     inputfile = str(java.io.File(str(attributes.get("file"))).getAbsolutePath())
       
   582     convertFile(inputfile, outputfile, config)
       
   583 else:
       
   584     self.log("No input specified.")
       
   585         ]]>
       
   586     </scriptdef>
       
   587     
       
   588     
       
   589     <!--Macro to stop recording to the main log file (if present) and record to
       
   590         a separate log file into a temporary location (doesn't need the build aread to work). -->
       
   591     <macrodef name="tempRecordStartMacro" uri="http://www.nokia.com/helium">
       
   592         <attribute name="name"/>
       
   593         <sequential>
       
   594             <mkdir dir="${build.cache.log.dir}"/>
       
   595             <hlm:record name="${build.cache.log.dir}/@{name}" action="start" loglevel="${ant.loglevel}"/>
       
   596         </sequential>
       
   597     </macrodef>
       
   598 
       
   599 
       
   600     <!--Macro to restart  the main log file (if present) and stop recording to
       
   601         a separate log file into a temporary location the file is next xml summarized 
       
   602         and potentially copied to the build area (if exists). Else those files will get copied during the 
       
   603         build area preparation. -->
       
   604     <macrodef name="tempRecordStopMacro" uri="http://www.nokia.com/helium">
       
   605         <attribute name="name"/>
       
   606         <attribute name="phase" default=""/>
       
   607         <attribute name="database" default="${metadata.dbfile}"/>
       
   608         <attribute name="filterref" default="filterset.temprecord"/>
       
   609         <sequential>
       
   610             <mkdir dir="${build.cache.log.dir}"/>
       
   611             <mkdir dir="${build.log.dir}"/>
       
   612             <mkdir dir="${build.cache.log.dir}/signals"/>
       
   613             <hlm:record name="${build.cache.log.dir}/@{name}" action="stop" loglevel="${ant.loglevel}"/>
       
   614             <!--Temporary solution, the logextract in general 
       
   615                 needs to be handled in a better way (not all logs needs to be processed,
       
   616                 logextract / counting errors could be merged and logextract should be
       
   617                 executed on a need basis and not to process for all stopmacro.-->
       
   618             <!-- Todo: metadata: replace logextract -->
       
   619             <hlm:metadatarecord database="@{database}">
       
   620                 <hlm:antmetadatainput>
       
   621                     <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   622                     <metadatafilterset refid="@{filterref}" />
       
   623                 </hlm:antmetadatainput>
       
   624             </hlm:metadatarecord>
       
   625             <hlm:generateBuildStatus dbfile="@{database}" output-dir="${build.cache.log.dir}/signals" file="@{name}" />
       
   626             <if>
       
   627                 <isset property="@{phase}.log.dir" />
       
   628                 <then>
       
   629                     <mkdir dir="${@{phase}.log.dir}"/>
       
   630                     <copy todir="${@{phase}.log.dir}" failonerror="false">
       
   631                         <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   632                     </copy>
       
   633                 </then>
       
   634                 <else>
       
   635                     <copy todir="${build.log.dir}" failonerror="false">
       
   636                         <fileset casesensitive="false" file="${build.cache.log.dir}/@{name}" />
       
   637                     </copy>
       
   638                 </else>
       
   639             </if>            
       
   640             <copy todir="${build.signal.status.dir}" failonerror="false">
       
   641                 <fileset casesensitive="false" dir="${build.cache.log.dir}/signals" />
       
   642             </copy>
       
   643         </sequential>
       
   644     </macrodef>
       
   645     
       
   646 
       
   647     <macrodef name="signalMacro" uri="http://www.nokia.com/helium">
   473     <macrodef name="signalMacro" uri="http://www.nokia.com/helium">
   648         <attribute name="logfile"/>
   474         <attribute name="logfile"/>
   649         <attribute name="phase" default=""/>
   475         <attribute name="phase" default=""/>
   650         <attribute name="signal.input" />
   476         <attribute name="signal.input" />
   651         <attribute name="skip.count" default="false" />
   477         <attribute name="skip.count" default="false" />
   652         <attribute name="result" default="not-set"/>
   478         <attribute name="result" default="not-set"/>
   653         <sequential>
   479         <sequential>
   654             <var name="signal.errors.total" value="" unset="true"/>
   480             <var name="signal.errors.total" value="" unset="true"/>
   655             <var name="base.signal.log.file" value="" unset="true"/>
   481             <var name="base.signal.log.file" value="" unset="true"/>
   656             <basename property="base.signal.log.file" file="@{logfile}" suffix=".log"/>
   482             <basename property="base.signal.log.file" file="@{logfile}"/>
   657             <if>
   483             <if>
   658                 <isfalse value="@{skip.count}" />
   484                 <isfalse value="@{skip.count}" />
   659                 <then>
   485                 <then>
   660                     <hlm:metadataCountSeverity severity="error" 
   486                     <hlm:metadataCountSeverity severity="error" 
   661                         log="@{logfile}"
   487                         log="@{logfile}"
   688             <!-- signal for errors -->
   514             <!-- signal for errors -->
   689             <hlm:signal name="@{signal.input}" result="${signal.errors.total}" >
   515             <hlm:signal name="@{signal.input}" result="${signal.errors.total}" >
   690                 <signalNotifierInput>
   516                 <signalNotifierInput>
   691                     <signalInput refid="@{signal.input}" />
   517                     <signalInput refid="@{signal.input}" />
   692                     <notifierInput>
   518                     <notifierInput>
   693                         <fileset dir="${build.log.dir}" >
   519                         <fileset casesensitive="false" dir="${build.log.dir}" >
   694                             <include name="**/${base.signal.log.file}*" />
   520                             <include name="**/${base.signal.log.file}*" />
   695                         </fileset>
   521                         </fileset>
   696                     </notifierInput>
   522                     </notifierInput>
   697                 </signalNotifierInput>
   523                 </signalNotifierInput>
   698             </hlm:signal>
   524             </hlm:signal>
   699         </sequential>
       
   700     </macrodef>
       
   701 
       
   702     <!-- Macro to start logging to a separate log file.
       
   703     
       
   704     This will stop logging to the main ant_build log file until stopSpecificLogMacro
       
   705     is called. -->
       
   706     <macrodef name="startSpecificLogMacro">
       
   707         <attribute name="name"/>
       
   708         <attribute name="regexp" default=""/>
       
   709         <attribute name="backup" default="false"/>
       
   710         <attribute name="phase" default=""/>
       
   711         
       
   712         <sequential>
       
   713             <if>
       
   714                 <isset property="@{phase}.log.dir" />
       
   715                 <then>
       
   716                     <mkdir dir="${@{phase}.log.dir}"/>
       
   717                 </then>
       
   718             </if> 
       
   719             <mkdir dir="@{name}/.."/>
       
   720             <hlm:record name="@{name}" action="start" loglevel="verbose" >
       
   721                 <hlm:recordfilter category="@{phase}" regexp="@{regexp}" />
       
   722             </hlm:record>
       
   723         </sequential>
       
   724     </macrodef>
       
   725 
       
   726 
       
   727     <!--Macro to restart  the main log file (if present) and stop recording to
       
   728         a separate log file. -->
       
   729     <macrodef name="stopSpecificLogMacro">
       
   730         <attribute name="name"/>
       
   731         <attribute name="phase" default=""/>
       
   732         <sequential>
       
   733             <hlm:record name="@{name}" action="stop" loglevel="verbose"/>
       
   734         </sequential>
       
   735     </macrodef>
       
   736 
       
   737     <!-- Temp BMD macro -->
       
   738     <macrodef name="bmdLogExtractMacro" uri="http://www.nokia.com/helium">
       
   739         <attribute name="log"/>
       
   740         <attribute name="metadatafilterset" default="common"/>
       
   741         <sequential>
       
   742             <hlm:metadatarecord database="${metadata.dbfile}">
       
   743                 <hlm:textmetadatainput>
       
   744                     <fileset casesensitive="false" file="@{log}"/>
       
   745                     <metadatafilterset refid="@{metadatafilterset}" />
       
   746                 </hlm:textmetadatainput>
       
   747             </hlm:metadatarecord>
       
   748             <!-- todo: check to add for usage and add genbuildstatus macro -->
       
   749             <basename property="log.name" file="@{log}"/>
       
   750             <fmpp sourceFile="${helium.dir}/tools/common/templates/db2xml.xml.ftl"
       
   751                          outputfile="@{log}.xml">
       
   752                 <data expandProperties="yes">
       
   753                     dbPath: ${metadata.dbfile}
       
   754                     log: ${log.name}
       
   755                     ant: antProperties()
       
   756                 </data>
       
   757             </fmpp>
       
   758         </sequential>
   525         </sequential>
   759     </macrodef>
   526     </macrodef>
   760 
   527 
   761     <!-- A simple test macro -->
   528     <!-- A simple test macro -->
   762     <macrodef name="fooMacro" uri="http://www.nokia.com/helium">
   529     <macrodef name="fooMacro" uri="http://www.nokia.com/helium">