655
|
1 |
# Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
# All rights reserved.
|
|
3 |
# This component and the accompanying materials are made available
|
|
4 |
# under the terms of "Eclipse Public License v1.0"
|
|
5 |
# which accompanies this distribution, and is available
|
|
6 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
#
|
|
8 |
# Initial Contributors:
|
|
9 |
# Nokia Corporation - initial contribution.
|
|
10 |
#
|
|
11 |
# Contributors:
|
|
12 |
#
|
|
13 |
# Description:
|
|
14 |
#
|
|
15 |
|
|
16 |
package ParseXML;
|
|
17 |
|
|
18 |
use strict;
|
|
19 |
use Carp;
|
|
20 |
use XML::Parser;
|
|
21 |
|
|
22 |
# Package variables - these can also be accessed the from package "SubHandlers"
|
|
23 |
use vars qw($gDataSource @gCommands @gSetEnv);
|
|
24 |
|
|
25 |
# ParseXMLData
|
|
26 |
#
|
|
27 |
# Inputs
|
|
28 |
# $iDataSource - XML Command file.
|
|
29 |
#
|
|
30 |
# Outputs
|
|
31 |
# @gCommands - Contains commands. Each command has various attributes.
|
|
32 |
# @gSetEnv - Contains environment vars. Each var has a key and value.
|
|
33 |
#
|
|
34 |
# Description
|
|
35 |
# This function parses the XML file and returns two arrays.
|
|
36 |
sub ParseXMLData
|
|
37 |
{
|
|
38 |
my ($iDataSource) = @_;
|
|
39 |
|
|
40 |
eval { $gDataSource = File::Spec->rel2abs($iDataSource); };
|
|
41 |
|
|
42 |
undef @gCommands;
|
|
43 |
undef @gSetEnv;
|
|
44 |
|
|
45 |
# Create a new XML Parser
|
|
46 |
my $iParser = new XML::Parser(Style=>'Subs', Pkg=>'SubHandlers', ErrorContext => 2);
|
|
47 |
# Supply the XML Parser the data source
|
|
48 |
$iParser->parsefile($iDataSource);
|
|
49 |
|
|
50 |
return \@gCommands, \@gSetEnv;
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
package SubHandlers;
|
|
56 |
use FreezeThaw qw(freeze thaw);
|
|
57 |
|
|
58 |
# Execute
|
|
59 |
#
|
|
60 |
# Inputs
|
|
61 |
#
|
|
62 |
# Outputs
|
|
63 |
#
|
|
64 |
# Description
|
|
65 |
# This function handles the Execute tag in the XML
|
|
66 |
sub Execute
|
|
67 |
{
|
|
68 |
my $iExpat = shift; my $iElement = shift;
|
|
69 |
|
|
70 |
my (%iAttr);
|
|
71 |
|
|
72 |
# Read the attributes
|
|
73 |
while (@_) {
|
|
74 |
my $iAtt = shift;
|
|
75 |
my $iVal = shift;
|
|
76 |
$iAttr{$iAtt} = $iVal;
|
|
77 |
}
|
|
78 |
|
|
79 |
# Read in the attributes into temporary variables
|
|
80 |
my $iID = $iAttr{'ID'}; # ignored
|
|
81 |
my $iStage = $iAttr{'Stage'};
|
|
82 |
my $iComp = $iAttr{'Component'};
|
|
83 |
my $iCwd = $iAttr{'Cwd'};
|
|
84 |
my $iCommandLine = $iAttr{'CommandLine'};
|
|
85 |
my $iExitOnScanlogError = $iAttr{'ExitOnScanlogError'};
|
|
86 |
|
|
87 |
# Replace the magic words with values in the commandline
|
|
88 |
if ($ParseXML::gDataSource) {
|
|
89 |
$iCommandLine =~ s/%%%this_file%%%/$ParseXML::gDataSource/g;
|
|
90 |
} else {
|
|
91 |
$iCommandLine =~ s/%%%this_file%%%/this_file/g;
|
|
92 |
}
|
|
93 |
|
|
94 |
# Replace the server side environment variables with values in the commandline
|
|
95 |
$iCommandLine =~ s/%%(\w+)%%/$ENV{$1}/g;
|
|
96 |
# Replace the server side environment variables with values in the cwd
|
|
97 |
$iCwd =~ s/%%(\w+)%%/$ENV{$1}/g;
|
|
98 |
|
|
99 |
# Store the data about the command in a temporary hash
|
|
100 |
my %temp = (
|
|
101 |
'Type' => 'Execute',
|
|
102 |
'Stage' => $iStage,
|
|
103 |
'Component' => $iComp,
|
|
104 |
'Cwd' => $iCwd,
|
|
105 |
'CommandLine' => $iCommandLine,
|
|
106 |
'ExitOnScanlogError' => $iExitOnScanlogError,
|
|
107 |
);
|
|
108 |
push @ParseXML::gCommands, \%temp;
|
|
109 |
}
|
|
110 |
|
|
111 |
|
|
112 |
# Product
|
|
113 |
#
|
|
114 |
# Inputs
|
|
115 |
#
|
|
116 |
# Outputs
|
|
117 |
#
|
|
118 |
# Description
|
|
119 |
# This function handles the Product tag in the XML
|
|
120 |
sub Product
|
|
121 |
{
|
|
122 |
my $iExpat = shift; my $iElement = shift;
|
|
123 |
|
|
124 |
my (%iAttr);
|
|
125 |
|
|
126 |
# Read the attributes
|
|
127 |
while (@_) {
|
|
128 |
my $iAtt = shift;
|
|
129 |
my $iVal = shift;
|
|
130 |
$iAttr{$iAtt} = $iVal;
|
|
131 |
}
|
|
132 |
|
|
133 |
my $iName = $iAttr{'Name'};
|
|
134 |
|
|
135 |
print "$iElement = $iName\n";
|
|
136 |
}
|
|
137 |
|
|
138 |
# SetEnv
|
|
139 |
#
|
|
140 |
# Inputs
|
|
141 |
#
|
|
142 |
# Outputs
|
|
143 |
#
|
|
144 |
# Description
|
|
145 |
# This function handles the SetEnv tag in the XML
|
|
146 |
sub SetEnv
|
|
147 |
{
|
|
148 |
my $iExpat = shift; my $iElement = shift;
|
|
149 |
|
|
150 |
my (%iAttr);
|
|
151 |
|
|
152 |
# Read the attributes
|
|
153 |
while (@_) {
|
|
154 |
my $iAtt = shift;
|
|
155 |
my $iVal = shift;
|
|
156 |
$iAttr{$iAtt} = $iVal;
|
|
157 |
}
|
|
158 |
|
|
159 |
# Read in the attributes to temporary variables
|
|
160 |
my $iName = $iAttr{'Name'};
|
|
161 |
my $iValue = $iAttr{'Value'};
|
|
162 |
my $iOrder = $iAttr{'Order'}; # Ignored
|
|
163 |
|
|
164 |
# Replace the server side environment variables with values in the environment variable value
|
|
165 |
$iValue =~ s/%%(\w+)%%/$ENV{$1}/g;
|
|
166 |
|
|
167 |
# Store the data about the Environment
|
|
168 |
my %temp = (
|
|
169 |
'Name' => $iName,
|
|
170 |
'Value' => $iValue,
|
|
171 |
);
|
|
172 |
push @ParseXML::gSetEnv, \%temp;
|
|
173 |
}
|
|
174 |
|
|
175 |
# Exit
|
|
176 |
#
|
|
177 |
# Inputs
|
|
178 |
#
|
|
179 |
# Outputs
|
|
180 |
#
|
|
181 |
# Description
|
|
182 |
# This function handles the Exit tag in the XML which cause the client to exit
|
|
183 |
sub Exit
|
|
184 |
{
|
|
185 |
my $iExpat = shift; my $iElement = shift;
|
|
186 |
my (%iAttr);
|
|
187 |
|
|
188 |
# Read the attributes
|
|
189 |
while (@_) {
|
|
190 |
my $iAtt = shift;
|
|
191 |
my $iVal = shift;
|
|
192 |
$iAttr{$iAtt} = $iVal;
|
|
193 |
}
|
|
194 |
|
|
195 |
# Read in the attributes into temporary variables
|
|
196 |
my $iStage = $iAttr{'Stage'};
|
|
197 |
|
|
198 |
# Store the data about the command in a temporary hash
|
|
199 |
my %temp = (
|
|
200 |
'Type' => 'Exit',
|
|
201 |
'Stage' => $iStage
|
|
202 |
);
|
|
203 |
push @ParseXML::gCommands, \%temp;
|
|
204 |
}
|
|
205 |
1;
|