buildframework/helium/tools/preparation/bom/bom.ant.xml
branchfix
changeset 395 5ad27ebafc22
parent 217 0f5e3a7fb6af
child 587 85df38eb4012
equal deleted inserted replaced
394:b6f8d38305f2 395:5ad27ebafc22
    18 
    18 
    19 Description:
    19 Description:
    20 
    20 
    21 ============================================================================
    21 ============================================================================
    22 -->
    22 -->
       
    23 <!--* @package preparation -->
    23 <project name="preparation.bom" xmlns:hlm="http://www.nokia.com/helium">    
    24 <project name="preparation.bom" xmlns:hlm="http://www.nokia.com/helium">    
    24     <description>
    25     <description>
    25     Creates a Bill-Of-Materials record based on the Synergy inputs.
    26     Creates a Bill-Of-Materials record based on the Synergy inputs.
    26     </description>
    27     </description>
    27     
    28     
       
    29     <!-- Your synergy work area directory (Set as the parent of the helium dir by default).
       
    30     @type string
       
    31     -->
    28     <property name="create.bom.workarea.root" value="."/> 
    32     <property name="create.bom.workarea.root" value="."/> 
    29     
    33     
    30     <!-- The target create-bom creates a Bill-Of-Material based on the Synergy project 
    34     <!-- The target create-bom creates a Bill-Of-Material based on the SCM project 
    31     The target can be run in the project's root directory or the directory can be given by
    35     The target can be run in the project's root directory or the directory can be given by
    32     setting the property create.bom.workarea.root. The IDO builds are expected to set it to their 
    36     setting the property create.bom.workarea.root. The IDO builds are expected to set it to their 
    33     projects work area directory. -->
    37     projects work area directory. -->
    34     <target name="create-bom" depends="get-ccm-password,old-bom-log,ccm-prepare-input,prep-prepare-input" if="prep.delivery.file">
    38     <target name="create-bom" depends="get-ccm-password,old-bom-log,ccm-prepare-input,prep-prepare-input">
    35         <if>
    39         <hlm:startSpecificLogMacro name="${prep.log.dir}/${build.id}_bom.log" regexp="${ccm.user.password}" phase="prep"/>
    36             <isset property="run.ccm"/>
    40         <hlm:python>
    37             <then>
       
    38                 <hlm:startSpecificLogMacro name="${build.log.dir}/${build.id}_bom.log" regexp="${ccm.user.password}"/>
       
    39                 <hlm:python>
       
    40 import os
    41 import os
    41 import build.model
    42 import build.model
    42 import configuration
    43 import configuration
    43 import nokia.nokiaccm
    44 import nokia.nokiaccm
    44 import ccm.extra
    45 import ccm.extra
    46 import sys
    47 import sys
    47 import traceback
    48 import traceback
    48 
    49 
    49 session = None
    50 session = None
    50 try:
    51 try:
       
    52     runccm = ant.get_property(r'${run.ccm}')
    51     database = ant.get_property(r'${ccm.database}')
    53     database = ant.get_property(r'${ccm.database}')
    52     username = ant.get_property(r'${ccm.user.login}')
    54     username = ant.get_property(r'${ccm.user.login}')
    53     password = ant.get_property(r'${ccm.user.password}')
    55     password = ant.get_property(r'${ccm.user.password}')
    54     engine = ant.get_property(r'${ccm.engine.host}')
    56     engine = ant.get_property(r'${ccm.engine.host}')
    55     dbpath = ant.get_property(r'${ccm.database.path}')
    57     dbpath = ant.get_property(r'${ccm.database.path}')
    56     waroot = ant.get_property(r'${create.bom.workarea.root}')
    58     waroot = ant.get_property(r'${create.bom.workarea.root}')
    57     buildid = ant.get_property(r'${build.id}')
    59     buildid = ant.get_property(r'${build.id}')
    58     buildlogdir = ant.get_property(r'${build.log.dir}')
    60     buildlogdir = ant.get_property(r'${build.log.dir}')
    59     cache = None
    61     deliveryfile = ant.get_property(r'${prep.delivery.conf.parsed}')
    60     if ant.get_property(r'${ccm.cache.xml}') is not None:
    62     oldbom = ant.get_property(r'${old.bom.log}')
    61         cache = str(ant.get_property(r'${ccm.cache.xml}'))
    63     bom = None
    62     provider = ccm.extra.CachedSessionProvider(opener=nokia.nokiaccm.open_session, cache=cache)
    64     bomfilename = r"%s/%s_bom.xml" % (buildlogdir, buildid)
       
    65     if runccm and deliveryfile:
       
    66         cache = None
       
    67         if ant.get_property(r'${ccm.cache.xml}') is not None:
       
    68             cache = str(ant.get_property(r'${ccm.cache.xml}'))
       
    69         provider = ccm.extra.CachedSessionProvider(opener=nokia.nokiaccm.open_session, cache=cache)
       
    70             
       
    71         configBuilder = configuration.NestedConfigurationBuilder(open(deliveryfile, 'r'))
       
    72         configSet = configBuilder.getConfiguration()
       
    73         for config in configSet.getConfigurations():
       
    74             waroot = config['dir']
       
    75             print "Found wa for project %s" % waroot
       
    76                         
       
    77         if database != None:
       
    78             session = provider.get(username, password, database=database)
       
    79         else:
       
    80             session = provider.get(username, password, engine, dbpath)
       
    81             
       
    82         ccmproject =  ccm.extra.get_toplevel_project(session, waroot)
    63         
    83         
    64     configBuilder = configuration.NestedConfigurationBuilder(open(ant.get_property(r'${prep.delivery.conf.parsed}'), 'r'))
    84         config_data = {'delivery': deliveryfile, 'prep.xml': ant.get_property(r'${prep.config.file.parsed}'), 'build.id': buildid, 'ccm.database': database, 'symbian_rel_week': ant.get_property(r'${symbian.version.week}'), 'symbian_rel_ver': ant.get_property(r'${symbian.version}'), 'symbian_rel_year': ant.get_property(r'${symbian.version.year}'), 's60_version': ant.get_property(r'${s60.version}'), 's60_release': ant.get_property(r'${s60.release}'), 'currentRelease.xml': ant.get_property(r'${build.drive}') + "/currentRelease.xml"}
    65     configSet = configBuilder.getConfiguration()
    85         config = configuration.Configuration(config_data)
    66     for config in configSet.getConfigurations():
       
    67         waroot = config['dir']
       
    68         print "Found wa for project %s" % waroot
       
    69                     
       
    70     if database != None:
       
    71         session = provider.get(username, password, database=database)
       
    72     else:
       
    73         session = provider.get(username, password, engine, dbpath)
       
    74         
    86         
    75     ccmproject =  ccm.extra.get_toplevel_project(session, waroot)
    87         # let's only support the new spec model!
    76     
    88         bom = build.model.SynergyBOM(config, ccmproject, username=username, password=password, provider=provider)
    77     config_data = {'delivery': ant.get_property(r'${prep.delivery.conf.parsed}'), 'prep.xml': ant.get_property(r'${prep.config.file.parsed}'), 'build.id': buildid, 'ccm.database': database, 'symbian_rel_week': ant.get_property(r'${symbian.version.week}'), 'symbian_rel_ver': ant.get_property(r'${symbian.version}'), 'symbian_rel_year': ant.get_property(r'${symbian.version.year}'), 's60_version': ant.get_property(r'${s60.version}'), 's60_release': ant.get_property(r'${s60.release}'), 'currentRelease.xml': ant.get_property(r'${build.drive}') + "/currentRelease.xml"}
    89         
    78     config = configuration.Configuration(config_data)
    90         xml_writer = build.model.BOMXMLWriter(bom)
    79     
    91         xml_writer.write(bomfilename)
    80     bom = None
    92     if not bom and os.path.exists(bomfilename):
    81     # let's only support the new spec model!
    93         config_data = {'prep.xml': ant.get_property(r'${prep.config.file.parsed}'), 'build.id': buildid, 'symbian_rel_week': ant.get_property(r'${symbian.version.week}'), 'symbian_rel_ver': ant.get_property(r'${symbian.version}'), 'symbian_rel_year': ant.get_property(r'${symbian.version.year}'), 's60_version': ant.get_property(r'${s60.version}'), 's60_release': ant.get_property(r'${s60.release}'), 'currentRelease.xml': ant.get_property(r'${build.drive}') + "/currentRelease.xml"}
    82     bom = build.model.BOM(config, ccmproject, username=username, password=password, provider=provider)
    94         config = configuration.Configuration(config_data)
    83     
    95         bom = build.model.SimpleBOM(config, bomfilename)
    84     xml_writer = build.model.BOMXMLWriter(bom)
    96     if os.path.exists(oldbom):
    85     xml_writer.write(r"%s/%s_bom.xml" % (buildlogdir, buildid))
    97         xml_delta_writer = build.model.BOMDeltaXMLWriter(bom, oldbom)
    86     
       
    87     if os.path.exists(ant.get_property(r'${old.bom.log}')):
       
    88         xml_delta_writer = build.model.BOMDeltaXMLWriter(bom, ant.get_property(r'${old.bom.log}'))
       
    89         xml_delta_writer.write(buildlogdir + "/" + buildid + "_bom_delta.xml")
    98         xml_delta_writer.write(buildlogdir + "/" + buildid + "_bom_delta.xml")
    90         delta_bom_content_validity = xml_delta_writer.validate_delta_bom_contents(buildlogdir + "/" + buildid + "_bom_delta.xml", "%s/%s_bom.xml" % (buildlogdir, buildid), ant.get_property(r'${old.bom.log}'))
    99         delta_bom_content_validity = xml_delta_writer.validate_delta_bom_contents(buildlogdir + "/" + buildid + "_bom_delta.xml", bomfilename, oldbom)
    91         if((delta_bom_content_validity == False) and (ant.get_property(r'${hlm.enable.asserts}') is not None)):
   100         if((delta_bom_content_validity == False) and (ant.get_property(r'${hlm.enable.asserts}') is not None)):
    92             print 'Bom delta contents are not matching'
   101             print 'Bom delta contents are not matching'
    93             raise Exception
   102             raise Exception
    94         elif((delta_bom_content_validity == True) or (delta_bom_content_validity == None)):
   103         elif((delta_bom_content_validity == True) or (delta_bom_content_validity == None)):
    95             print 'Bom delta contents are matching.'
   104             print 'Bom delta contents are matching.'
    96         elif(delta_bom_content_validity == False):
   105         elif(delta_bom_content_validity == False):
    97             print 'Bom delta contents are not matching.'
   106             print 'Bom delta contents are not matching.'
    98     else:
   107     else:
    99         print 'Old BOM log cannot be found, skipping BOM delta creation.'
   108         print 'Old BOM log cannot be found ' + oldbom + ', skipping BOM delta creation.'
   100     bom.close()
   109     if runccm:
   101     session.close()
   110         bom.close()
       
   111     if session:
       
   112         session.close()
   102 except Exception, ex:
   113 except Exception, ex:
   103     print 'Caught exception in BOM: ' + str(ex)
   114     print 'Caught exception in BOM: ' + str(ex)
   104     traceback.print_exc()
   115     traceback.print_exc()
   105                 </hlm:python>
   116         </hlm:python>
   106             
   117         <if>
       
   118             <available file="${build.log.dir}/${build.id}_bom.xml"/>
       
   119             <then>
       
   120                 <echo>${build.log.dir}</echo>
       
   121                 <xmltask source="${build.log.dir}/${build.id}_bom.xml" dest="${build.log.dir}/${build.id}_bom.xml" outputter="simple">
       
   122                     <replace path="//bom/build/text()" withText="${build.id}"/>
       
   123                 </xmltask>
       
   124                 <fmpp sourceRoot="${helium.dir}/tools/preparation/bom"
       
   125                       outputRoot="${prep.log.dir}" includes="bom.html.*,bom.txt.*" removeExtensions="ftl">
       
   126                     <freemarkerLinks expandProperties="yes">
       
   127                         macro: ${helium.dir}/tools/common/templates/macro
       
   128                     </freemarkerLinks>
       
   129                     <data expandProperties="yes">
       
   130                         doc: xml(${build.log.dir}/${build.id}_bom.xml)                
       
   131                     </data>
       
   132                 </fmpp>
       
   133                 
       
   134                 <move file="${prep.log.dir}/bom.html" tofile="${build.log.dir}/${build.id}_bom.html"/>
       
   135                 <move file="${prep.log.dir}/bom.txt" tofile="${prep.log.dir}/${build.id}_bom.txt"/>
       
   136 
       
   137                 <!-- Transform bom data into the diamonds xml format: 
       
   138                      * BOM folders are flattened into tasks.
       
   139                      * Schema version is extracted from the appropriate FMPP template. -->
       
   140                 <fmpp sourcefile="${helium.dir}/tools/common/templates/diamonds/diamonds_header.ftl" 
       
   141                       outputfile="${build.temp.dir}/diamonds_header.xml" quiet="true"/>
       
   142                 <loadfile srcfile="${build.temp.dir}/diamonds_header.xml" property="diamonds.schema.xml">
       
   143                     <filterchain>
       
   144                         <linecontains>
       
   145                             <contains value="schema"/>
       
   146                         </linecontains>
       
   147                     </filterchain>
       
   148                 </loadfile>                
       
   149                 <mkdir dir="${diamonds.build.output.dir}" />
       
   150                 <xmltask source="${build.log.dir}/${build.id}_bom.xml" dest="${diamonds.build.output.dir}/create-bom.xml">           
       
   151                     <insert path="bom/content" xml="${diamonds.schema.xml}" position="before"/>
       
   152                     <remove path="bom/content/project/folder/name"/>
       
   153                     <remove path="bom/build"/>
       
   154                     <rename path="bom" to="diamonds-build"/>
       
   155                 </xmltask>                
       
   156                 <delete file="${build.temp.dir}/diamonds_header.xml"/>
       
   157                 <replace file="${diamonds.build.output.dir}/create-bom.xml" token="&lt;folder&gt;" value="&lt;!-- &lt;folder&gt; --&gt;"/>
       
   158                 <replace file="${diamonds.build.output.dir}/create-bom.xml" token="&lt;/folder&gt;" value="&lt;!-- &lt;/folder&gt; --&gt;"/>
       
   159                 <xmltask source="${diamonds.build.output.dir}/create-bom.xml" dest="${diamonds.build.output.dir}/create-bom.xml"
       
   160                          outputter="simple">
       
   161                     <remove path="//comment()"/>
       
   162                 </xmltask>
       
   163              
       
   164                 <hlm:assertFileExists file="${diamonds.build.output.dir}/create-bom.xml"/>
       
   165                 <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom.html"/>
       
   166                 <hlm:assertFileExists file="${prep.log.dir}/${build.id}_bom.txt"/>
       
   167                 
       
   168                 <runtarget target="collect-task-owner-email"/>
       
   169             </then>
       
   170             <else>
       
   171                 <echo>WARNING: ${build.log.dir}/${build.id}_bom.xml file not found.</echo>
       
   172             </else>
       
   173         </if>
       
   174         
       
   175         <if>
       
   176             <available file="${old.bom.log}"/>
       
   177             <then>
       
   178                 <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom_delta.xml"/>
       
   179                 <fmpp sourceRoot="${helium.dir}/tools/preparation/bom"
       
   180                       outputRoot="${prep.log.dir}" includes="bom_delta.*" removeExtensions="ftl">
       
   181                     <freemarkerLinks expandProperties="yes">
       
   182                         macro: ${helium.dir}/tools/common/templates/macro
       
   183                     </freemarkerLinks>
       
   184                     <data expandProperties="yes">
       
   185                         doc: xml(${build.log.dir}/${build.id}_bom_delta.xml)                
       
   186                     </data>
       
   187                 </fmpp>
       
   188                                 
       
   189                 <move file="${prep.log.dir}/bom_delta.html" tofile="${build.log.dir}/${build.id}_bom_delta.html"/>
       
   190                 <move file="${prep.log.dir}/bom_delta.txt" tofile="${prep.log.dir}/${build.id}_bom_delta.txt"/>
       
   191                 
       
   192                 <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom_delta.html"/>
       
   193             </then>
       
   194         </if>
       
   195         <hlm:stopSpecificLogMacro name="${prep.log.dir}/${build.id}_bom.log" phase="prep"/>
       
   196     </target>
       
   197     
       
   198     <!-- The target create-task-owner-email creates a property task.owners.email which will contain
       
   199     the list of task owners email IDs seperated by comma, the newly created property can be used thereafter
       
   200     to send emails.
       
   201     This target is automatically called by create-bom target. @scope private-->
       
   202     <target name="collect-task-owner-email">
       
   203         <if>
       
   204             <available file="${build.log.dir}/${build.id}_bom_delta.xml"/>
       
   205             <then>
       
   206                 <xmltask source="${build.log.dir}/${build.id}_bom_delta.xml" dest="${build.log.dir}/${build.id}_bom_delta.xml"> 
       
   207                     <call path="/bomDelta/content/task">
       
   208                         <param name="task.delta" path="text()"/>
       
   209                         <actions>
       
   210                             <var name="task.delta" value="@{task.delta}"/>
       
   211                             <propertyregex property="delta.task.id" input="${task.delta}" regexp="^([^:]+):\s*" select="\1"/>
       
   212                             <xmltask source="${build.log.dir}/${build.id}_bom.xml" dest="${build.log.dir}/${build.id}_bom.xml"> 
       
   213                                 <call path="/bom/content/project/folder/task/owner/text()[../../id[.='${delta.task.id}']]" >
       
   214                                     <param name="task.owner" path="."/>
       
   215                                     <actions>
       
   216                                         <var name="task.owner" value="@{task.owner}"/>
       
   217                                         <if>
       
   218                                             <and>
       
   219                                                 <isset property="task.owners"/>
       
   220                                             </and>
       
   221                                             <then>
       
   222                                                 <var name="task.owners" value="${task.owners},${task.owner}"/>
       
   223                                             </then>
       
   224                                             <else>
       
   225                                                 <var name="task.owners" value="${task.owner}"/>
       
   226                                             </else>
       
   227                                         </if>
       
   228                                     </actions>
       
   229                                 </call>
       
   230                             </xmltask>
       
   231                         </actions>
       
   232                     </call>
       
   233                 </xmltask> 
       
   234             </then>
       
   235             <else>
   107                 <if>
   236                 <if>
   108                     <available file="${build.log.dir}/${build.id}_bom.xml"/>
   237                     <available file="${build.log.dir}/${build.id}_bom.xml"/>
   109                     <then>
   238                     <then>
   110                         <echo>${build.log.dir}</echo>
   239                         <xmltask source="${build.log.dir}/${build.id}_bom.xml" dest="${build.log.dir}/${build.id}_bom.xml"> 
   111                         <fmpp sourceRoot="${helium.dir}/tools/preparation/bom"
   240                             <call path="/bom/content/project/folder/task/owner">
   112                               outputRoot="${build.log.dir}" includes="bom.html.*,bom.txt.*" removeExtensions="ftl">
   241                                 <param name="task.owner" path="text()"/>
   113                             <freemarkerLinks expandProperties="yes">
   242                                 <actions>
   114                                 macro: ${helium.dir}/tools/common/templates/macro
   243                                     <var name="task.owner" value="@{task.owner}"/>
   115                             </freemarkerLinks>
   244                                     <if>
   116                             <data expandProperties="yes">
   245                                         <and>
   117                                 doc: xml(${build.log.dir}/${build.id}_bom.xml)                
   246                                             <isset property="task.owners"/>
   118                             </data>
   247                                         </and>
   119                         </fmpp>
   248                                         <then>
   120                         
   249                                             <var name="task.owners" value="${task.owners},${task.owner}"/>
   121                         <move file="${build.log.dir}/bom.html" tofile="${build.log.dir}/${build.id}_bom.html"/>
   250                                         </then>
   122                         <move file="${build.log.dir}/bom.txt" tofile="${build.log.dir}/${build.id}_bom.txt"/>
   251                                         <else>
   123         
   252                                             <var name="task.owners" value="${task.owner}"/>
   124                         <!-- Transform bom data into the diamonds xml format: 
   253                                         </else>
   125                              * BOM folders are flattened into tasks.
   254                                     </if>
   126                              * Schema version is extracted from the appropriate FMPP template. -->
   255                                 </actions>
   127                         <fmpp sourcefile="${helium.dir}/tools/common/templates/diamonds/diamonds_header.ftl" 
   256                             </call>
   128                               outputfile="${build.temp.dir}/diamonds_header.xml" quiet="true"/>
   257                         </xmltask> 
   129                         <loadfile srcfile="${build.temp.dir}/diamonds_header.xml" property="diamonds.schema.xml">
   258                     </then>
   130                             <filterchain>
   259                 </if>
   131                                 <linecontains>
   260             </else>
   132                                     <contains value="schema"/>
   261         </if>
   133                                 </linecontains>
   262         <sortlist property="task.owners" override="true" value="${task.owners}"/>
   134                             </filterchain>
   263         <propertyregex property="task.owners" override="true" input="${task.owners}" regexp="([^,]+),.*\1" replace="\1" global='true'/>
   135                         </loadfile>                
   264         <for list="${task.owners}" delimiter="," param="task.owner" >
   136                         <xmltask source="${build.log.dir}/${build.id}_bom.xml" dest="${build.log.dir}/create-bom.xml">           
   265             <sequential>
   137                             <insert path="bom/content" xml="${diamonds.schema.xml}" position="before"/>
   266                 <var name="task.owner" value="@{task.owner}"/>
   138                             <remove path="bom/content/project/folder/name"/>
   267                 <hlm:ldap url="${email.ldap.server}" rootdn="${email.ldap.rootdn}" filter="uid=${task.owner}" outputproperty="task.owner.email" key="mail"/>
   139                             <remove path="bom/build"/>
   268                 <if>
   140                             <rename path="bom" to="diamonds-build"/>
   269                     <and>
   141                         </xmltask>                
   270                         <isset property="task.owners.email"/>
   142                         <delete file="${build.temp.dir}/diamonds_header.xml"/>
   271                     </and>
   143                         <replace file="${build.log.dir}/create-bom.xml" token="&lt;folder&gt;" value="&lt;!-- &lt;folder&gt; --&gt;"/>
   272                     <then>
   144                         <replace file="${build.log.dir}/create-bom.xml" token="&lt;/folder&gt;" value="&lt;!-- &lt;/folder&gt; --&gt;"/>
   273                         <var name="task.owners.email" value="${task.owners.email},${task.owner.email}"/>
   145                         <xmltask source="${build.log.dir}/create-bom.xml" dest="${build.log.dir}/create-bom.xml"
       
   146                                  outputter="simple">
       
   147                             <remove path="//comment()"/>
       
   148                         </xmltask>
       
   149                      
       
   150                         <hlm:assertFileExists file="${build.log.dir}/create-bom.xml"/>
       
   151                         <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom.html"/>
       
   152                         <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom.txt"/>
       
   153                     </then>
   274                     </then>
   154                     <else>
   275                     <else>
   155                         <echo>WARNING: ${build.log.dir}/${build.id}_bom.xml file not found.</echo>
   276                         <var name="task.owners.email" value="${task.owner.email}"/>
   156                     </else>
   277                     </else>
   157                 </if>
   278                 </if>
   158                 
   279             </sequential>
   159                 <if>
   280         </for>
   160                     <isset property="old.bom.log.present"/>
       
   161                     <then>
       
   162                         <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom_delta.xml"/>
       
   163                         <fmpp sourceRoot="${helium.dir}/tools/preparation/bom"
       
   164                               outputRoot="${build.log.dir}" includes="bom_delta.*" removeExtensions="ftl">
       
   165                             <freemarkerLinks expandProperties="yes">
       
   166                                 macro: ${helium.dir}/tools/common/templates/macro
       
   167                             </freemarkerLinks>
       
   168                             <data expandProperties="yes">
       
   169                                 doc: xml(${build.log.dir}/${build.id}_bom_delta.xml)                
       
   170                             </data>
       
   171                         </fmpp>
       
   172                                         
       
   173                         <move file="${build.log.dir}/bom_delta.html" tofile="${build.log.dir}/${build.id}_bom_delta.html"/>
       
   174                         <move file="${build.log.dir}/bom_delta.txt" tofile="${build.log.dir}/${build.id}_bom_delta.txt"/>
       
   175                         
       
   176                         <hlm:assertFileExists file="${build.log.dir}/${build.id}_bom_delta.html"/>
       
   177                     </then>
       
   178                 </if>
       
   179                 <hlm:stopSpecificLogMacro name="${build.log.dir}/${build.id}_bom.log"/>
       
   180             </then>
       
   181         </if>
       
   182     </target>
   281     </target>
   183 
   282 
   184     <!-- Calculates the previous build number based on the current one. -->
       
   185     <target name="previous-build-number" unless="previous.build.number">
       
   186         <script language="jython" setbeans="false">
       
   187 import ant
       
   188 from com.nokia.ant.util import Helper
       
   189 buildnum = Helper.getProperty(project, "build.number")
       
   190 pbuildnum = ant.get_previous_build_number(buildnum)
       
   191 if pbuildnum != None:
       
   192     project.setProperty("previous.build.number", pbuildnum)
       
   193         </script>
       
   194         <echo>Previous build number = ${previous.build.number}</echo>
       
   195     </target>
       
   196     
       
   197     
       
   198     <!-- Finds the path to the last usable XML BOM log for creating a BOM delta. --> 
   283     <!-- Finds the path to the last usable XML BOM log for creating a BOM delta. --> 
   199     <target name="old-bom-log" unless="old.bom.log" depends="previous-build-number">
   284     <target name="old-bom-log" unless="old.bom.log">
   200         <property name="bom.log" value="${publish.dir}/logs/${build.id}_bom.xml"/>
   285         <!-- Publish dir location of the old bom log.
       
   286         @type string
       
   287         -->
       
   288         <property name="old.bom.log.publish.dir" value="${publish.dir}" />
       
   289         <!-- Location of XML BOM log.
       
   290         @type string
       
   291         @scope private
       
   292         -->
       
   293         <property name="bom.log" value="${old.bom.log.publish.dir}/logs/${build.id}_bom.xml"/>
   201         <script language="jython" setbeans="false">
   294         <script language="jython" setbeans="false">
   202 import re
   295 import re
   203 try:
   296 import ant
   204     buildnumber = project.getProperty("build.number")
   297 import os
   205     pbuildnumber = project.getProperty("previous.build.number")
   298 from com.nokia.ant.util import Helper
   206     bomlog = project.getProperty("bom.log")
   299 
   207     old_bom_log = re.sub(r'\.(%s)([\/_])' % buildnumber, r'.' + pbuildnumber + r'\2', bomlog)
   300 previousbuildnumber = 1
   208     project.setProperty("old.bom.log", old_bom_log)
   301 buildnumber = Helper.getProperty(project, "build.number")
   209 except ValueError:
   302 bomlog = project.getProperty("bom.log")
   210     # Do nothing - old BOM cannot be calulated
   303 while(previousbuildnumber > 0 and previousbuildnumber != ''):
   211     self.log("Old BOM cannot be found")
   304     previousbuildnumber = ant.get_previous_build_number(buildnumber)
       
   305     try:
       
   306         old_bom_log = re.sub(r'\.(%s)([\/_])' % project.getProperty("build.number"), r'.' + previousbuildnumber + r'\2', bomlog)
       
   307         if os.path.exists(old_bom_log):
       
   308             break
       
   309     except ValueError:
       
   310         self.log("Old BOM cannot be found")
       
   311     buildnumber = previousbuildnumber
       
   312 project.setProperty("old.bom.log", old_bom_log)
   212         </script>
   313         </script>
   213         <echo>Previous BOM log: ${old.bom.log}</echo>
   314         <echo>Previous BOM log: ${old.bom.log}</echo>
   214         <available file="${old.bom.log}" property="old.bom.log.present"/>
   315         <available file="${old.bom.log}" property="old.bom.log.present"/>
   215         <if>
       
   216             <isset property="old.bom.log.present"/>
       
   217             <then>
       
   218                 <hlm:assertFileExists file="${old.bom.log}"/>
       
   219             </then>
       
   220         </if>
       
   221         <echo>Previous BOM log present: ${old.bom.log.present}</echo>
   316         <echo>Previous BOM log present: ${old.bom.log.present}</echo>
   222     </target>
   317     </target>
   223     
   318     
   224 </project>
   319 </project>