buildframework/helium/tools/common/common.antlib.xml
changeset 628 7c4a911dc066
parent 588 c7c26511138f
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    60     -->
    60     -->
    61     <scriptdef name="pathToFileListMacro" language="beanshell" uri="http://www.nokia.com/helium">
    61     <scriptdef name="pathToFileListMacro" language="beanshell" uri="http://www.nokia.com/helium">
    62         <attribute name="file"/>
    62         <attribute name="file"/>
    63         <element name="path" type="path"/>
    63         <element name="path" type="path"/>
    64         <![CDATA[
    64         <![CDATA[
    65     import java.io.FileWriter;
    65 import java.io.FileWriter;
    66     FileWriter out = new FileWriter(attributes.get("file"));
    66 FileWriter out = new FileWriter(attributes.get("file"));
    67     paths = elements.get("path");
    67 
    68     for (int i = 0 ; i < paths.size() ; i++) {
    68 paths = elements.get("path");
    69         String[] files = paths.get(i).list();
    69 for (int i = 0 ; i < paths.size() ; i++) {
    70         for (int l = 0; l < files.length ; l++) {
    70     String[] files = paths.get(i).list();
    71             out.write(files[l] + "\n");
    71     for (int j = 0; j < files.length ; j++) {
    72         }
    72         out.write(files[j] + "\n");
    73     }
    73     }
       
    74 }
    74 out.close();
    75 out.close();
    75 ]]>   
    76     ]]>   
    76     </scriptdef>
    77     </scriptdef>
    77 
    78 
    78     
    79     
    79    
    80    
    80     <!-- This Macro is a wrapper to command line tool.
    81     <!-- This Macro is a wrapper to command line tool.
    89         </hlm:toolMacro>
    90         </hlm:toolMacro>
    90     -->
    91     -->
    91     <scriptdef name="toolMacro" language="beanshell" uri="http://www.nokia.com/helium">
    92     <scriptdef name="toolMacro" language="beanshell" uri="http://www.nokia.com/helium">
    92         <element name="toolvarset" classname="com.nokia.helium.core.ant.types.VariableSet"/>
    93         <element name="toolvarset" classname="com.nokia.helium.core.ant.types.VariableSet"/>
    93         <attribute name="name"/>
    94         <attribute name="name"/>
    94 <![CDATA[
    95         <![CDATA[
    95 import com.nokia.ant.util.ToolsProcess;
    96 import com.nokia.ant.util.ToolsProcess;
    96 import com.nokia.tools.*;
    97 import com.nokia.tools.*;
    97 import com.nokia.helium.core.ant.types.VariableSet;
    98 import com.nokia.helium.core.ant.types.VariableSet;
    98 import org.apache.tools.ant.types.Reference;
    99 import org.apache.tools.ant.types.Reference;
    99     Reference ref;
   100 
   100     java.lang.String toolName = attributes.get("name");
   101 Reference ref;
   101     confTool =  ToolsProcess.getTool(toolName);
   102 java.lang.String toolName = attributes.get("name");
   102     varSets = elements.get("toolvarset");
   103 confTool =  ToolsProcess.getTool(toolName);
   103     for (i = 0; i < varSets.size(); ++i) {
   104 varSets = elements.get("toolvarset");
   104         try {
   105 for (i = 0; i < varSets.size(); ++i) {
   105             varSet = (VariableSet)varSets.get(i);
   106     try {
   106             if (varSet.isReference()) {
   107         varSet = (VariableSet)varSets.get(i);
   107                 varSet = varSet.getRefid().getReferencedObject(project);
   108         if (varSet.isReference()) {
   108             }
   109             varSet = varSet.getRefid().getReferencedObject(project);
   109             confTool.execute(varSet,project);
       
   110         } catch (BuildException e) {
       
   111             self.log("Error: " + e);
       
   112             //self.log("Tool Argument Validation failure");
       
   113             throw e;
       
   114         }
   110         }
   115   }
   111         confTool.execute(varSet,project);
   116 ]]>
   112     }
       
   113     catch (BuildException e) {
       
   114         self.log("Error: " + e);
       
   115         //self.log("Tool Argument Validation failure");
       
   116         throw e;
       
   117     }
       
   118 }
       
   119     ]]>
   117     </scriptdef>
   120     </scriptdef>
   118     
   121     
   119     <!-- ConE tool macro to run the command for each argument -->
   122     <!-- ConE tool macro to run the command for each argument -->
   120     <scriptdef name="conEToolMacro" language="beanshell" uri="http://www.nokia.com/helium">
   123     <scriptdef name="conEToolMacro" language="beanshell" uri="http://www.nokia.com/helium">
   121         <element name="arg" classname="com.nokia.ant.types.Variable"/>
   124         <element name="arg" classname="com.nokia.helium.core.ant.types.VariableImpl"/>
   122         <attribute name="name"/>
   125         <attribute name="name"/>
   123 <![CDATA[
   126         <![CDATA[
   124 import com.nokia.ant.util.ToolsProcess;
   127 import com.nokia.ant.util.ToolsProcess;
   125 import com.nokia.tools.*;
   128 import com.nokia.tools.*;
   126 import com.nokia.ant.types.Variable;
   129 import com.nokia.helium.core.ant.types.VariableImpl;
   127     conETool =  ToolsProcess.getTool("ConE");
   130 
   128     vars = elements.get("arg");
   131 conETool =  ToolsProcess.getTool("ConE");
   129     for (i = 0; i < vars.size(); ++i) {
   132 vars = elements.get("arg");
   130         var = (Variable)vars.get(i);
   133 for (i = 0; i < vars.size(); ++i) {
   131         conETool.storeVariables(var.getName(), var.getValue());
   134     var = (VariableImpl)vars.get(i);
   132   }
   135     conETool.storeVariables(var.getName(), var.getValue());
   133   conETool.execute(project);
   136 }
   134 ]]>
   137 conETool.execute(project);
       
   138     ]]>
   135     </scriptdef>
   139     </scriptdef>
   136     
   140     
   137     
   141     
   138     <!-- This macro will read the line from file which matches the regexp -->
   142     <!-- This macro will read the line from file which matches the regexp -->
   139     <scriptdef name="grepMacro" language="beanshell" uri="http://www.nokia.com/helium">
   143     <scriptdef name="grepMacro" language="beanshell" uri="http://www.nokia.com/helium">
   140         <attribute name="filename"/>
   144         <attribute name="filename"/>
   141         <attribute name="output"/>
   145         <attribute name="output"/>
   142         <attribute name="regexp"/>
   146         <attribute name="regexp"/>
   143 <![CDATA[
   147         <![CDATA[
   144 import java.util.*;
   148 import java.util.*;
   145 import java.io.*;
   149 import java.io.*;
   146 import java.util.regex.Matcher;
   150 import java.util.regex.Matcher;
   147 import java.util.regex.Pattern;
   151 import java.util.regex.Pattern;
   148 
   152 
   149 if (attributes.get("filename") == null ||  attributes.get("output") == null || attributes.get("regexp") == null)
   153 if (attributes.get("filename") == null ||  attributes.get("output") == null || attributes.get("regexp") == null) {
   150     throw new BuildException("Filename/output/regexp attribute is not set for readLineMacro");
   154     throw new BuildException("Filename/output/regexp attribute is not set for readLineMacro");
       
   155 }
   151     
   156     
   152 String search = attributes.get("regexp");
   157 String search = attributes.get("regexp");
   153 String output = "";
   158 String output = "";
   154 pattern = Pattern.compile(search);
   159 pattern = Pattern.compile(search);
   155 
   160 
   156 BufferedReader input =  new BufferedReader(new FileReader(attributes.get("filename")));
   161 BufferedReader input =  new BufferedReader(new FileReader(attributes.get("filename")));
   157 try {
   162 try {
   158         String line = null;
   163     String line = null;
   159         Matcher match = null;
   164     Matcher match = null;
   160         while (( line = input.readLine()) != null) {
   165     while (( line = input.readLine()) != null) {
   161              match = pattern.matcher(line);
   166         match = pattern.matcher(line);
   162             if (match.find()) {
   167         if (match.find()) {
   163                 //self.log("Line containg " + search + " is = " + line + " returned vaue = " + match.group(1));
   168             //self.log("Line containg " + search + " is = " + line + " returned vaue = " + match.group(1));
   164                 int checkIndex = output.indexOf(match.group(1), 0);
   169             int checkIndex = output.indexOf(match.group(1), 0);
   165                 if (checkIndex == -1 ) {
   170             if (checkIndex == -1 ) {
   166                    output = output + match.group(1) + ",";
   171                 output = output + match.group(1) + ",";
   167                 }
       
   168             }
   172             }
   169         }
   173         }
   170     } catch (IOException ex) {
       
   171       ex.printStackTrace();
       
   172     }
   174     }
   173     project.setNewProperty(attributes.get("output") , output);
   175 }
   174 
   176 catch (IOException ex) {
   175 ]]>
   177     ex.printStackTrace();
       
   178 }
       
   179 project.setNewProperty(attributes.get("output") , output);
       
   180 
       
   181         ]]>
   176     </scriptdef>
   182     </scriptdef>
   177 
   183 
   178     
   184     
   179     <!-- This task allow to dump the content of a text file to the shell. -->
   185     <!-- This task allow to dump the content of a text file to the shell. -->
   180     <scriptdef name="echoFileMacro" language="beanshell" uri="http://www.nokia.com/helium">
   186     <scriptdef name="echoFileMacro" language="beanshell" uri="http://www.nokia.com/helium">
   181         <attribute name="file"/>
   187         <attribute name="file"/>
   182         <![CDATA[        
   188         <![CDATA[        
   183         //Open the file for reading
   189 //Open the file for reading
   184          try {
   190 try {
   185             java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(attributes.get("file")));
   191     java.io.BufferedReader in = new java.io.BufferedReader(new java.io.FileReader(attributes.get("file")));
   186             while ((thisLine = in.readLine()) != null) { // while loop begins here
   192     while ((thisLine = in.readLine()) != null) {
   187                  self.log(thisLine);
   193         self.log(thisLine);
   188             } // end while 
   194     }
   189         } catch (java.io.IOException e) {
   195 }
   190             self.log("Error: " + e);
   196 catch (java.io.IOException e) {
   191             throw e;
   197     self.log("Error: " + e);
   192         }        
   198     throw e;
       
   199 }        
   193         ]]>
   200         ]]>
   194     </scriptdef>
   201     </scriptdef>
   195     
   202     
   196     
   203     
   197     <!-- This task create the herder information in the symbian log file -->
   204     <!-- This task create the herder information in the symbian log file -->
   472         <attribute name="signal.input" />
   479         <attribute name="signal.input" />
   473         <attribute name="skip.count" default="false" />
   480         <attribute name="skip.count" default="false" />
   474         <attribute name="result" default="not-set"/>
   481         <attribute name="result" default="not-set"/>
   475         <sequential>
   482         <sequential>
   476             <var name="signal.errors.total" value="" unset="true"/>
   483             <var name="signal.errors.total" value="" unset="true"/>
   477             <var name="base.signal.log.file" value="" unset="true"/>
       
   478             <basename property="base.signal.log.file" file="@{logfile}"/>
       
   479             <if>
   484             <if>
   480                 <isfalse value="@{skip.count}" />
   485                 <isfalse value="@{skip.count}" />
   481                 <then>
   486                 <then>
   482                     <hlm:metadataCountSeverity severity="error" 
   487                     <hlm:metadataCountSeverity severity="error" 
   483                         log="@{logfile}"
   488                         log="@{logfile}"
   484                         db="${metadata.dbfile}" property="signal.errors.total"/>
   489                         database="${metadata.dbfile}" property="signal.errors.total"/>
   485                 </then>
   490                 </then>
   486                 <else>
   491                 <else>
   487                     <if>
   492                     <if>
   488                         <equals arg1="@{result}" arg2="not-set"/>
   493                         <equals arg1="@{result}" arg2="not-set"/>
   489                         <then>
   494                         <then>
   490                             <fail message="result parameter is missing for signa macro" />
   495                             <fail message="The result attribute is missing for signalMacro." />
   491                         </then>
   496                         </then>
   492                     </if>
   497                     </if>
   493                     <var name="signal.errors.total" value="@{result}" />
   498                     <var name="signal.errors.total" value="@{result}" />
   494                 </else>
   499                 </else>
   495             </if>
   500             </if>
   496             <if>
       
   497                 <isset property="@{phase}.log.dir" />
       
   498                 <then>
       
   499                     <var name="signal.log.dir" value="" unset="true"/>
       
   500                     <property name="signal.log.dir" value="${@{phase}.log.dir}"/>
       
   501                     <echo>signal.log.dir = ${signal.log.dir}</echo>
       
   502                 </then>
       
   503                 <else>
       
   504                     <var name="signal.log.dir" value="" unset="true"/>
       
   505                     <property name="signal.log.dir" value="${build.log.dir}"/>
       
   506                 </else>
       
   507             </if>
       
   508             <hlm:generateBuildStatus output-dir="${build.signal.status.dir}/" 
   501             <hlm:generateBuildStatus output-dir="${build.signal.status.dir}/" 
   509                 file="${base.signal.log.file}" />
   502                 file="@{logfile}" />
       
   503 
   510             <!-- signal for errors -->
   504             <!-- signal for errors -->
   511             <hlm:signal name="@{signal.input}" result="${signal.errors.total}" >
   505             <var name="internal.signal.macro.log.basename" value="" unset="true"/> 
       
   506             <basename property="internal.signal.macro.log.basename" file="@{logfile}" />
       
   507             <hlm:signal name="@{signal.input}" result="${signal.errors.total}"
       
   508                 message="Found ${signal.errors.total} errors under @{logfile}.">
   512                 <signalNotifierInput>
   509                 <signalNotifierInput>
   513                     <signalInput refid="@{signal.input}" />
   510                     <signalInput refid="@{signal.input}" />
   514                     <notifierInput>
   511                     <notifierInput>
   515                         <fileset casesensitive="false" dir="${build.log.dir}" >
   512                         <fileset casesensitive="false" dir="${build.signal.status.dir}"
   516                             <include name="**/${base.signal.log.file}*" />
   513                             includes="${internal.signal.macro.log.basename}.status.html" />
   517                         </fileset>
       
   518                     </notifierInput>
   514                     </notifierInput>
   519                 </signalNotifierInput>
   515                 </signalNotifierInput>
   520             </hlm:signal>
   516             </hlm:signal>
   521         </sequential>
   517         </sequential>
   522     </macrodef>
   518     </macrodef>
   619         path = str(iterator.next())
   615         path = str(iterator.next())
   620         fileutils.touch(path)
   616         fileutils.touch(path)
   621         ]]>
   617         ]]>
   622     </scriptdef>
   618     </scriptdef>
   623     
   619     
       
   620     <!--
       
   621         The fileBackupMacro enables the user to take the backup of any file(s).
       
   622         By default it will back up log files from srcdir to destdir.
       
   623         e.g
       
   624         <pre>
       
   625             <hlm:fileBackupMacro srcDir="${compile.log.dir}" destDir="${compile.log.dir}/backuplogs" regExp="(.*?_compile.log)$"/>
       
   626             <hlm:fileBackupMacro file="${compile.log.dir}/${build.id}.clean.cmaker.log"/>
       
   627         </pre>
       
   628     -->
       
   629     <macrodef name="fileBackupMacro" uri="http://www.nokia.com/helium">
       
   630         <attribute name="regExp" default=""/>
       
   631         <attribute name="file" default=""/>
       
   632         <attribute name="srcDir" default=""/>
       
   633         <attribute name="destDir" default=""/>
       
   634         <sequential>
       
   635             <!--Check is it required to do failback up or need to take backup log files
       
   636                 from specified source dir to destination dir -->
       
   637             <if>
       
   638                 <and>
       
   639                     <not>
       
   640                         <length string="@{file}" trim="true" length="0" when="greater"/>
       
   641                     </not>
       
   642                     <not>
       
   643                         <length string="@{srcDir}" trim="true" length="0" when="greater"/>
       
   644                     </not>
       
   645                 </and>
       
   646                 <then>
       
   647                     <fail message="'fileBackupMacro' requires 'file' or 'srcdir' attributes set"/>
       
   648                 </then>
       
   649             </if>
       
   650             
       
   651             <!-- Set the backup format for taking back up -->
       
   652             <var name="files.backup.format" unset="true"/>
       
   653             <tstamp>
       
   654                 <format property="files.backup.format" pattern="ddMMyyyyHHmmssSS" unit="millisecond"/>
       
   655             </tstamp>
       
   656             
       
   657             <!-- Set dest dir if not set -->
       
   658             <var name="files.dest.dir" unset="true"/>
       
   659             <if>
       
   660                 <length string="@{destDir}" trim="true" length="0" when="greater"/>
       
   661                 <then>
       
   662                     <property name="files.dest.dir" value="@{destDir}"/>
       
   663                 </then>
       
   664                 <else>
       
   665                     <property name="files.dest.dir" value="@{srcDir}"/>
       
   666                 </else>
       
   667             </if>
       
   668             
       
   669             <!-- Set dest dir if not set -->
       
   670             <var name="files.regular.exp" unset="true"/>
       
   671             <if>
       
   672                 <length string="@{regExp}" trim="true" length="0" when="greater"/>
       
   673                 <then>
       
   674                     <property name="files.regular.exp" value="@{regExp}"/>
       
   675                 </then>
       
   676                 <else>
       
   677                     <property name="files.regular.exp" value="^(.*?\.log)$"/>
       
   678                 </else>
       
   679             </if>
       
   680             
       
   681             <!-- To validate the unittest cases.-->
       
   682             <script language="beanshell"> <![CDATA[
       
   683                 backupFormat = project.getProperty("files.backup.format"); 
       
   684                 project.setProperty("file.backup.format",backupFormat);
       
   685                 ]]>
       
   686             </script>
       
   687                  
       
   688             <!-- Check need to do file back up -->
       
   689             <if>
       
   690                 <and>
       
   691                     <length string="@{file}" trim="true" length="0" when="greater"/>
       
   692                     <available file="@{file}"/>
       
   693                 </and>
       
   694                 <then>
       
   695                     <basename property="file.name" file="@{file}"/>
       
   696                     <dirname property="file.dir.path" file="@{file}"/>
       
   697                     <copy file="@{file}" tofile="${file.dir.path}/${file.name}.${files.backup.format}.bak" overwrite="true" failonerror="${failonerror}"/>
       
   698                 </then>
       
   699             </if>
       
   700             
       
   701             <!-- Check need to do mutliple files back up -->
       
   702             <if>
       
   703                 <and>
       
   704                     <length string="@{srcDir}" trim="true" length="0" when="greater"/>
       
   705                     <available file="@{srcDir}" type="dir"/>
       
   706                 </and>
       
   707                 <then>
       
   708                     <mkdir dir="${files.dest.dir}"/>
       
   709                     <copy todir="${files.dest.dir}" overwrite="true" failonerror="${failonerror}">
       
   710                         <regexpmapper from="${files.regular.exp}" to="\1.${files.backup.format}.bak" casesensitive="false"/>
       
   711                         <fileset dir="@{srcDir}"/>
       
   712                     </copy>
       
   713                 </then>
       
   714             </if>
       
   715         </sequential>
       
   716     </macrodef>
       
   717     
       
   718     <!-- Macro to generate an Ant database file for Helium. 
       
   719         
       
   720     @scope private
       
   721     -->
       
   722     <macrodef name="databaseMacro" uri="http://www.nokia.com/helium">
       
   723         <attribute name="file"/>
       
   724         <attribute name="scope"/>
       
   725         <sequential>
       
   726             <mkdir dir="${basedir}/build"/>
       
   727             <hlm:database output="@{file}" scope="@{scope}">
       
   728                 <fileset dir="${helium.dir}">
       
   729                     <include name="config/signaling_config_default.ant.xml"/>
       
   730                     <include name="config/stages_config_default.ant.xml"/>
       
   731                     <include name="config/metadata_filter_config_default.ant.xml"/>
       
   732                     <include name="tools/**/*.antlib.xml"/>
       
   733                 </fileset>
       
   734             </hlm:database>
       
   735         </sequential>
       
   736     </macrodef>
       
   737     
   624 </antlib>
   738 </antlib>