buildframework/helium/tools/relnotes/relnotes.ant.xml
author Zheng Shen <zheng.shen@nokia.com>
Tue, 20 Jul 2010 15:02:28 +0800
changeset 617 3a747a240983
parent 587 85df38eb4012
child 628 7c4a911dc066
permissions -rw-r--r--
ROM Tools 12.2.0.4 Postlinker 2.2.5 Revert package_definition.xml to changeset 360bd6b35136

<?xml version="1.0" encoding="UTF-8"?>
<!-- 
============================================================================ 
Name        : relnotes.ant.xml 
Part of     : Helium 

Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved.
This component and the accompanying materials are made available
under the terms of the License "Eclipse Public License v1.0"
which accompanies this distribution, and is available
at the URL "http://www.eclipse.org/legal/epl-v10.html".

Initial Contributors:
Nokia Corporation - initial contribution.

Contributors:

Description:

============================================================================
-->
<!--* @package releases -->
<project name="relnotes" default="release-notes" xmlns:hlm="http://www.nokia.com/helium">
    <description>
    Generates a release note by modifying a template (that you can edit yourself) with
    values from the build and Synergy.
    
    * Modifies a RTF template with values from build
    * Adds table of errors and warnings
    * Generates list of baselines, projects and tasks used
    </description>
    
    <!--* @property product.printname
    A printable name for a product used in release notes.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property product.type
    Project ID in release notes.
    @type string
    @editable required
    @scope public
    -->
    
    <!--* @property relnotes.config.dir
    Defines the directory that contains release notes creation configuration files.
    @type string
    @editable required
    @scope public
    -->

    <!-- Defines the directory that will contain the output of release notes creation.
    @type string
    @scope private
    -->
    <property name="releasenotes.output.dir" value="${build.output.dir}/relnotes"/>
    <!-- Defines the logo image file which will be used in release notes.
    @type string
    @scope private
    -->
    <property name="releasenotes.logo" value="${relnotes.config.dir}/logo.png"/>
    <!-- Property file with customer values
    @type string
    @scope private
    -->
    <property name="releasenotes.props" value="${relnotes.config.dir}/relnotes.properties"/>
    <!-- Temp file
    @type string
    @scope private
    -->
    <property name="releasenotes.temp.props" value="${temp.build.dir}/relnotes.properties"/>
    <!-- Temp file
    @type string
    @scope private
    -->
    <property name="releasenotes.temp.props2" value="${temp.build.dir}/relnotes2.properties"/>
    <!-- Defines the name of the release note template used.
    @type string
    @scope private
    -->
    <property name="releasenotes.template" value="${relnotes.config.dir}/template.rtf"/>
    <!-- Location of output rtf file
    @type string
    @scope private
    -->
    <property name="releasenotes.output" value="${releasenotes.output.dir}/${build.id}_relnotes.rtf"/>
    <!-- Temp file
    @type string
    @scope private
    -->
    <property name="releasenotes.temp.errors" value="${temp.build.dir}/errors.csv"/>
    <!-- Temp file
    @type string
    @scope private
    -->
    <property name="releasenotes.temp.output" value="${temp.build.dir}/tempDocument.rtf"/>
    <!-- Location of scan2log HTML file
    @type string
    @scope private
    -->
    <property name="releasenotes.scan2log" value="${build.log.dir}/${build.id}.${product.family}_scan2.html"/>
    
    <import file="${relnotes.config.dir}/relnotes_properties.ant.xml" optional="true"/>
    
    <!-- @scope private -->
    <target name="release-notes-variant-configuration" depends="imaker-merge-rom-xml">
        <script language="jython" setbeans="false">
tagnames = ""
for product in project.getProperty("product.list").split(","):
    tagnames += "Type%sVariantTableHere\n" %  product 
project.setProperty("variant.product.tagnames", tagnames)
        </script>
        <replace file="${releasenotes.output}" token="TypeVariantTableHere" value="${variant.product.tagnames}" summary="true"/>
        <for list="${product.list}" delimiter="," param="product.name" >
            <sequential>            
                <exec executable="python" failonerror="${failonerror}">
                    <arg line="-m getVariantConfiguration"/>
                    <arg value="@{product.name}"/>
                    <arg value="${rombuild.config.file.parsed}"/>
                    <arg value="${temp.build.dir}/variant_@{product.name}.csv"/>
                </exec>
                <hlm:python>
import ant
import rtfutils
rn = rtfutils.RTFUtils(ant.get_property(r'${releasenotes.output}'))
rn.rtftable(ant.get_property(r'${temp.build.dir}/variant_@{product.name}.csv'), ant.get_property(r'${releasenotes.temp.output}'), ant.get_property(r'Type@{product.name}VariantTableHere'))
                </hlm:python>
  
                <delete file="${releasenotes.output}"/>
                <move file="${releasenotes.temp.output}" tofile="${releasenotes.output}"/>
            </sequential>
        </for>
    </target>
    
    <!-- Create error list in release notes
    @scope private    
    -->
    <target name="release-notes-error-summary">
        <fmpp sourceFile="${helium.dir}/tools/relnotes/templates/errors.csv.ftl"
                     outputfile="${releasenotes.temp.errors}">
            <freemarkerLinks expandProperties="yes">
                macro: ${helium.dir}/tools/common/templates/macro
            </freemarkerLinks>
            <data expandProperties="yes">
                dbPath: ${metadata.dbfile}
                ant: antProperties()
            </data>
        </fmpp>
        <hlm:python>
import ant
import rtfutils
rn = rtfutils.RTFUtils(ant.get_property(r'${releasenotes.output}'))
rn.rtftable(ant.get_property(r'${releasenotes.temp.errors}'), ant.get_property(r'${releasenotes.temp.output}'), 'TypeErrorTableSummaryHere')
        </hlm:python>
        <delete file="${releasenotes.output}"/>
        <move file="${releasenotes.temp.output}" tofile="${releasenotes.output}"/>
    </target>
    
    <!--  Add logo to release notes. @scope private -->
    <target name="release-notes-logo">
        <hlm:python>
import ant
import rtfutils
rn = rtfutils.RTFUtils(ant.get_property(r'${releasenotes.output}'))
rn.rtfimage(ant.get_property(r'${releasenotes.logo}'), ant.get_property(r'${releasenotes.temp.output}'), 'AddProductImageHere')
        </hlm:python>
        <move file="${releasenotes.temp.output}" tofile="${releasenotes.output}"/>
    </target>
    
    <!-- Find project and baseline of what is running helium
    @scope private    
    -->
    <target name="release-notes-getcmprojectname">
        <if>
            <istrue value="${ccm.enabled}" />
            <then>
                <script language="jython" setbeans="false">
import ccm.extra
import traceback
import os
import logging
import ccmutil

#logging.basicConfig(level=logging.DEBUG)
session = None
try:
    database = project.getProperty('ccm.database')
    username = project.getProperty('ccm.user.login')
    password = project.getProperty('ccm.user.password')
    engine = project.getProperty('ccm.engine.host')
    dbpath = project.getProperty('ccm.database.path')     
    waroot = project.getProperty('create.bom.workarea.root')
    
    session = ccmutil.get_session(database, username, password, engine, dbpath)
    cmproject = ccm.extra.get_toplevel_project(session, waroot)
    
    if cmproject == None:
        print 'Error: ' + waroot + ' must be a synergy project and still be in database'
    else:
        project.setProperty("ccm.toplevel.project", str(cmproject))
    session.close()
except Exception, ex:
    print 'Caught exception: ' + str(ex)
    traceback.print_exc()
    if session:
        session.close()
                </script>
                <hlm:python outputproperty="ccm.toplevel.baseline">
import traceback
import ant
import logging
import ccmutil
logging.disable(logging.INFO)
session = None
try:
    database = ant.get_property(r'${ccm.database}')
    username = ant.get_property(r'${ccm.user.login}')
    password = ant.get_property(r'${ccm.user.password}')
    engine = ant.get_property(r'${ccm.engine.host}')
    dbpath = ant.get_property(r'${ccm.database.path}')
    session = ccmutil.get_session(database, username, password, engine, dbpath)
    cmproject = session.create(ant.get_property(r'${ccm.toplevel.project}'))
    print cmproject.baseline
    session.close()
except Exception, ex:
    print 'Caught exception: ' + str(ex)
    traceback.print_exc()
    if session:
        session.close()
                </hlm:python>
            </then>
        </if>
    </target>
    
    <!--
    Look 'startsWith' and find complete CM name
    Output property: '{startsWith}.project'.
        
    @scope private
    -->
    <macrodef name="releaseNotesGetProjectName" uri="http://www.nokia.com/helium">
        <attribute name="startsWith" />
        <sequential>
            <if>
                <available file="${build.log.dir}/${build.id}_bom.xml" />
                <then>
                    <hlm:python outputproperty="@{startsWith}.project">
import amara
import ant

bomfile = open(r"${build.log.dir}/${build.id}_bom.xml")
bom = amara.parse(bomfile)

for p in bom.bom.content.project:
    if (str(p.name).startswith(ant.get_property(r'@{startsWith}'))):
        print str(p.name)
bomfile.close()
                    </hlm:python>
                </then>
            </if>
        </sequential>
    </macrodef>
    
    <!-- Write projects, baselines and task list for MC and IBUSAL
    @scope private    
    -->
    <target name="release-notes-ccm" depends="get-ccm-password,release-notes-getcmprojectname,create-bom">
        <if>
            <and>
                <istrue value="${ccm.enabled}" />
                <available file="${build.log.dir}/${build.id}_bom.xml" />
            </and>
            <then>
                <hlm:python>
import amara
import ant
import bomtofile
import ccmutil

bomfile = open(r"${build.log.dir}/${build.id}_bom.xml")
bom = amara.parse(bomfile)
password = ant.get_property(r'${ccm.user.password}')
session = ccmutil.get_session(ant.get_property(r'${ccm.database}'), ant.get_property(r'${ccm.user.login}'), password, ant.get_property(r'${ccm.engine.host}'), ant.get_property(r'${ccm.database.path}'))
for p in bom.bom.content.project:
    if p.name == ant.get_property(r'${ccm.toplevel.project}'):
        bomwriter = bomtofile.BOMWriter(session, 'MC', p, ant.get_property(r'${releasenotes.output.dir}'))
        bomwriter.writeprojects()
        bomwriter.writebaselines()
        bomwriter.writetasks()
            
    if (str(p.name).startswith('IBUSAL')):
        bomwriter = bomtofile.BOMWriter(session, 'IBUSAL', p, ant.get_property(r'${releasenotes.output.dir}'))
        bomwriter.writeprojects()
        bomwriter.writetasks()
session.close()
bomfile.close()
                </hlm:python>
            </then>
        </if>
    </target>
    
    <!-- Read BOM and write ICF list
    @scope private
    -->
    <target name="release-notes-icfs" depends="create-bom">
        <exec executable="python" failonerror="${failonerror}">
            <arg line="-m icf2txt"/>
            <arg value="${build.log.dir}/${build.id}_bom.xml"/>            
            <arg value="${releasenotes.output.dir}/icdicf.txt"/>
        </exec>
    </target>
    
    <!-- @scope private -->
    <target name="release-notes-test" if="hlm.enable.asserts">
        <if>
            <istrue value="${ccm.enabled}" />
            <then>
                <hlm:python>
import ccm
#check for ccm session leaks
assert (len(ccm.running_sessions()) == 0)
                </hlm:python>
            </then>
        </if>
    </target>
        
    <!-- 
    Generates a product release note based on a template in config dir
    -->
    <target name="release-notes" description="Generates a product release note based off a template in config dir">        
        <mkdir dir="${releasenotes.output.dir}"/>
        
        <copy file="${releasenotes.props}" tofile="${releasenotes.temp.props}">
            <filterchain>
                <expandproperties/>
            </filterchain>
        </copy>
          
        <hlm:python>
import ant
import rtfutils
rn = rtfutils.RTFUtils(ant.get_property(r'${releasenotes.output}'))
rn.rtfconvert(ant.get_property(r'${releasenotes.temp.props}'), ant.get_property(r'${releasenotes.temp.props2}'))
        </hlm:python>
        
        <property file="${releasenotes.temp.props2}"/>                
        <copy file="${releasenotes.template}" tofile="${releasenotes.output}" overwrite="true"/>

        <antcall target="release-notes-logo" />
        <antcall target="release-notes-error-summary" />
        <antcall target="release-notes-variant-configuration" />
            
        <delete file="${releasenotes.temp.errors}"/>
        <delete file="${releasenotes.temp.output}"/>
        <delete file="${releasenotes.temp.props}"/>
        <delete file="${releasenotes.temp.props2}"/>
        
        <antcall target="release-notes-ccm"/>
        
        <antcall target="release-notes-icfs"/>
    
        <antcall target="release-notes-replace"/>
        
        <antcall target="release-notes-test"/>
    </target>

</project>