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