buildframework/helium/tools/quality/validate-policy.ant.xml
changeset 1 be27ed110b50
child 179 d8ac696cc51f
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!-- 
       
     3 ============================================================================ 
       
     4 Name        : validate-policy.ant.xml 
       
     5 Part of     : Helium 
       
     6 
       
     7 Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     8 All rights reserved.
       
     9 This component and the accompanying materials are made available
       
    10 under the terms of the License "Eclipse Public License v1.0"
       
    11 which accompanies this distribution, and is available
       
    12 at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
    13 
       
    14 Initial Contributors:
       
    15 Nokia Corporation - initial contribution.
       
    16 
       
    17 Contributors:
       
    18 
       
    19 Description:
       
    20 
       
    21 ============================================================================
       
    22 -->
       
    23 <project name="quality.validate-policy" xmlns:hlm="http://www.nokia.com/helium">
       
    24     <description>
       
    25     Policy file validation.
       
    26     </description>
       
    27 
       
    28     <property name="validate.policy.log" location="${build.log.dir}/${build.id}_validate-policy.summary.xml" />
       
    29     <property name="validate.policy.log.xml" location="${build.log.dir}/${build.id}_validate-policy.log.xml" />
       
    30     <property name="validate.policy.csv" location="${helium.dir}/tests/minibuilds/compile/distribution.policy.extended_for_sf.id_status.csv" />
       
    31     <property name="validate.policy.ignoreroot" value="false" />
       
    32     <property name="validate.policy.pattern" value="distribution.policy.s60,distribution.policy" />
       
    33 
       
    34     <!-- Default path settings for policy validation. -->
       
    35     <path id="reference.policy.path.list">
       
    36         <pathelement path="${build.drive}/s60" />
       
    37     </path>
       
    38 
       
    39     <!--
       
    40     This task scan the directory provided by the path element, and valitate the content of the 
       
    41     Distribution.policy.S60 file using some default rules. IDs could also be validate using a CSV input file.
       
    42     'ignoreroot' specifies to ignore the toplevel directory.
       
    43     
       
    44     e.g.
       
    45     <pre>
       
    46       <hlm:validatePolicyMacro output="${validate.policy.log}"
       
    47           ids="${validate.policy.csv}"
       
    48           ignoreroot="${validate.policy.ignoreroot}">
       
    49           <path refid="reference.policy.path.list"/>
       
    50       </hlm:validatePolicyMacro>
       
    51     </pre>
       
    52   -->
       
    53     <scriptdef name="validatePolicyMacro" language="jython" uri="http://www.nokia.com/helium">
       
    54         <attribute name="output" />
       
    55         <attribute name="ignoreroot" />
       
    56         <attribute name="ids" />
       
    57         <attribute name="pattern" />
       
    58         <element name="path" type="path" />
       
    59         <![CDATA[
       
    60 import integration.quality
       
    61 import os
       
    62 ignoreroot = False
       
    63 if (attributes.get('ignoreroot') != None) and (str(attributes.get('ignoreroot')).lower() == "true"):
       
    64     self.log("Ignoring root path.")
       
    65     ignoreroot = True
       
    66 
       
    67 output = None
       
    68 if attributes.get('output') is not None:
       
    69     self.log("Creating %s" % str(attributes.get('output')))
       
    70     output = open(str(attributes.get('output')), "w+")
       
    71     output.write("<?xml version=\"1.0\"?>\n<policyvalidation>\n")
       
    72 components_per_file = {}
       
    73 
       
    74 pattern = ['distribution.policy.s60']
       
    75 if attributes.get('pattern') != None:
       
    76     pattern = str(attributes.get('pattern')).split(',')
       
    77 
       
    78 validator = integration.quality.PolicyValidator(pattern, ignoreroot=ignoreroot)
       
    79 
       
    80 if attributes.get('ids') is not None:
       
    81     self.log("Loading policy ids from: %s" % str(attributes.get('ids')))
       
    82     if not os.path.exists(str(attributes.get('ids'))):
       
    83         self.log("ERROR: Could not find: %s" % str(attributes.get('ids')), project.MSG_ERR)
       
    84     else:
       
    85         for result in validator.load_policy_ids(str(attributes.get('ids'))):
       
    86             self.log(str("%s: - %s - %s" % (result[0], result[1], result[2])), project.MSG_ERR)
       
    87             if output is not None:
       
    88                 output.write("    <error type=\"%s\" message=\"%s\" value=\"%s\"/>\n" % (result[0], result[1], result[2]))
       
    89 
       
    90 for eid in range(elements.get("path").size()):
       
    91     iterator = elements.get("path").get(int(eid)).iterator()
       
    92     while iterator.hasNext():
       
    93         path = str(iterator.next())
       
    94         self.log("Scanning " + path)
       
    95         for result in validator.validate(path):
       
    96             self.log("%s: %s" % (result[0], result[1]), project.MSG_ERR)
       
    97             if output is not None:
       
    98                 output.write("    <error type=\"%s\" message=\"%s\" value=\"%s\"/>\n" % (result[0], result[1], result[2]))
       
    99     
       
   100 if output is not None:
       
   101     output.write("</policyvalidation>\n")
       
   102     output.close()
       
   103     ]]>
       
   104   </scriptdef>
       
   105 
       
   106     <!--
       
   107     Parse all the path defined by 'reference.policy.path.list' and check all policy files.
       
   108     It generates an XML log defined by property 'validate.policy.log'.
       
   109   -->
       
   110     <target name="integration-validate-policy">
       
   111         <mkdir dir="${build.log.dir}"/>
       
   112         <hlm:validatePolicyMacro output="${validate.policy.log}" ids="${validate.policy.csv}" ignoreroot="${validate.policy.ignoreroot}" pattern="${validate.policy.pattern}">
       
   113             <path refid="reference.policy.path.list" />
       
   114         </hlm:validatePolicyMacro>
       
   115         <hlm:metadatarecord database="${metadata.dbfile}">
       
   116             <hlm:policymetadatainput>
       
   117                 <fileset casesensitive="false" file="${validate.policy.log}/" />
       
   118             </hlm:policymetadatainput>
       
   119         </hlm:metadatarecord>
       
   120         <hlm:generateBuildStatus file="${build.id}_validate_policy.log" />
       
   121     </target>
       
   122 
       
   123     <!--
       
   124     Render the policy validation xml file ('validate.policy.log') into an text output.
       
   125   -->
       
   126     <target name="render-validate-policy" depends="integration-validate-policy">
       
   127         <if>
       
   128             <not>
       
   129                 <istrue value="${metadata.enable}" />
       
   130             </not>
       
   131             <then>
       
   132                 <fmpp sourceFile="${helium.dir}/tools/common/templates/integration/validate-policy.log.ftl" outputFile="${build.log.dir}/${build.id}_validate-policy.log">
       
   133                     <freemarkerLinks expandProperties="yes">
       
   134                       macro: ${helium.dir}/tools/common/templates/macro
       
   135                   </freemarkerLinks>
       
   136                     <data expandProperties="yes">
       
   137                       doc: xml(${validate.policy.log})
       
   138                       ant: antProperties()
       
   139                     </data>
       
   140                 </fmpp>
       
   141                 <fmpp sourceFile="${helium.dir}/tools/common/templates/integration/validate-policy.log.xml.ftl" outputFile="${validate.policy.log.xml}">
       
   142                     <freemarkerLinks expandProperties="yes">
       
   143                       macro: ${helium.dir}/tools/common/templates/macro
       
   144                   </freemarkerLinks>
       
   145                     <data expandProperties="yes">
       
   146                       doc: xml(${validate.policy.log})
       
   147                       ant: antProperties()
       
   148                     </data>
       
   149                 </fmpp>
       
   150             </then>
       
   151             <else>
       
   152                 <!-- Todo: check and if required convert as metadata template -->
       
   153             </else>
       
   154         </if>
       
   155     </target>
       
   156 
       
   157     <!-- Target that will apply regular IDO validation rules on Helium. -->
       
   158     <target name="validate-helium-policy">
       
   159         <hlm:validatePolicyMacro>
       
   160             <path>
       
   161                 <pathelement path="${helium.dir}/" />
       
   162             </path>
       
   163         </hlm:validatePolicyMacro>
       
   164     </target>
       
   165 
       
   166     <!--
       
   167       Internal target that set an intermediate property to disable policy validation execution.
       
   168     -->
       
   169     <target name="ido-validate-policy-skip">
       
   170         <if>
       
   171             <istrue value="${skip.policy-validation}"/>
       
   172             <then>
       
   173                 <property name="do.skip.policy-validation" value="1"/>
       
   174             </then>
       
   175         </if>
       
   176     </target>
       
   177     
       
   178     <!-- Policy validation target for IDO. Only detected ADO will get scanned. -->    
       
   179     <target name="ido-validate-policy" depends="ido-create-ado-mapping,ido-validate-policy-skip" unless="do.skip.policy-validation">
       
   180         <hlm:iniKeys2Path ini="${ado.quality.mapping.file}" pathid="reference.policy.path.list"/>
       
   181         <runtarget target="render-validate-policy" />
       
   182     </target>
       
   183 
       
   184 </project>