602
|
1 |
# Copyright (c) 2007-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 the License "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 |
# Description:
|
|
17 |
# Symbian::CBR::IPR::MRP
|
|
18 |
#
|
|
19 |
|
|
20 |
package Symbian::CBR::IPR::MRP;
|
|
21 |
|
|
22 |
use strict;
|
|
23 |
use Carp;
|
|
24 |
use File::Spec;
|
|
25 |
use File::Basename;
|
|
26 |
use Cwd;
|
|
27 |
use Symbian::CBR::MRP::Reader;
|
|
28 |
|
|
29 |
use base qw(Class::Singleton);
|
|
30 |
|
|
31 |
use constant SRCROOT => ($ENV{SRCROOT} || '\\');
|
|
32 |
|
|
33 |
BEGIN {
|
|
34 |
# The location of the CBR Tools may not be known to Perl, so we do a seach
|
|
35 |
# to see if they are available...
|
|
36 |
if (!eval {require IniData}) {
|
|
37 |
if (-e File::Spec->catdir(File::Basename::dirname("$0"), 'IniData.pm')) {
|
|
38 |
push @INC, File::Spec->catdir(File::Basename::dirname("$0"));
|
|
39 |
}
|
|
40 |
else {
|
|
41 |
for my $path (split(/;/,$ENV{PATH})) {
|
|
42 |
if (-e $path."\\IniData\.pm") {
|
|
43 |
push @INC, $path;
|
|
44 |
last;
|
|
45 |
}
|
|
46 |
}
|
|
47 |
}
|
|
48 |
}
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
sub _new_instance {
|
|
53 |
my $pkg = shift;
|
|
54 |
my $typeOfMrp = shift;
|
|
55 |
my $verbose = shift;
|
|
56 |
|
|
57 |
if (!$typeOfMrp || shift) {
|
|
58 |
# caller(0))[3] gives the package and the method called, e.g. Symbian::CBR::IPR::MRP::_new_instance
|
|
59 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
60 |
}
|
|
61 |
|
|
62 |
my $self = {};
|
|
63 |
bless $self, $pkg;
|
|
64 |
|
|
65 |
$self->{typeOfMrp} = $typeOfMrp;
|
|
66 |
$self->{verbose} = $verbose;
|
|
67 |
|
|
68 |
return $self;
|
|
69 |
}
|
|
70 |
|
|
71 |
sub PrepareInformationForComponent {
|
|
72 |
my $self = shift;
|
|
73 |
my $component = shift;
|
|
74 |
|
|
75 |
my @mrpLocation;
|
|
76 |
|
|
77 |
#if it's a comp name then look it up/read it
|
|
78 |
if (@mrpLocation = $self->GetMRPLocations($component)) {
|
|
79 |
$self->ReadMRPFiles(\@mrpLocation);
|
|
80 |
}
|
|
81 |
else {
|
|
82 |
# If we can't get any MRP locations then we can't use MRP files for IPR information
|
|
83 |
return undef;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
sub PrepareInformationForMrpFile {
|
|
88 |
my $self = shift;
|
|
89 |
my @mrps = shift;
|
|
90 |
|
|
91 |
#can take a single or a list
|
|
92 |
|
|
93 |
$self->ReadMRPFiles(\@mrps);
|
|
94 |
}
|
|
95 |
|
|
96 |
sub Populate {
|
|
97 |
my $self = shift;
|
|
98 |
|
|
99 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n" if (shift);
|
|
100 |
|
|
101 |
if (exists $self->{populated}) {
|
|
102 |
# We only need to populate the tree once
|
|
103 |
return 1;
|
|
104 |
}
|
|
105 |
else {
|
|
106 |
# Set a flag and continue
|
|
107 |
$self->{populated} = 1;
|
|
108 |
}
|
|
109 |
|
|
110 |
my @mrpFiles;
|
|
111 |
|
|
112 |
if (@mrpFiles = $self->GetMRPLocations()) {
|
|
113 |
$self->ReadMRPFiles(\@mrpFiles);
|
|
114 |
|
|
115 |
if (!(keys %{$self->{iprTree}})) {
|
|
116 |
# If we can't get any IPR information from MRP files then we can't use MPR files for IPR information
|
|
117 |
return undef;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
else {
|
|
121 |
# If we can't get any MRP locations then we can't use MRP files for IPR information
|
|
122 |
return undef;
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
|
|
127 |
sub GetMRPLocations {
|
|
128 |
my $self = shift;
|
|
129 |
my $component = shift;
|
|
130 |
|
|
131 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n" if (shift);
|
|
132 |
|
|
133 |
my @mrpFiles;
|
|
134 |
|
|
135 |
# Try to get MRP locations from environment database.
|
|
136 |
if ($self->InvokeCBRTools()) {
|
|
137 |
@mrpFiles = $self->{envDB}->GetMRPLocations($component);
|
|
138 |
|
|
139 |
if (scalar @mrpFiles) {
|
|
140 |
# envDb may return \
|
|
141 |
@mrpFiles = grep /\.mrp$/, @mrpFiles;
|
|
142 |
}
|
|
143 |
|
|
144 |
if (!scalar @mrpFiles) {
|
|
145 |
return ();
|
|
146 |
}
|
|
147 |
|
|
148 |
return (@mrpFiles);
|
|
149 |
}
|
|
150 |
else {
|
|
151 |
return ();
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
sub InvokeCBRTools {
|
|
157 |
my $self = shift;
|
|
158 |
|
|
159 |
# If we have already tried to use the CBR Tools but have been unable to then return undef
|
|
160 |
if ($self->{noCbrTools}) {
|
|
161 |
return undef;
|
|
162 |
}
|
|
163 |
|
|
164 |
# If we have successfully created a CBR Tools EnvDB object then return true
|
|
165 |
if (exists $self->{envDB}) {
|
|
166 |
return 1;
|
|
167 |
}
|
|
168 |
|
|
169 |
# Otherwise we try to create a CBR Tools EnvDB object...
|
|
170 |
my $iniData;
|
|
171 |
my @errors;
|
|
172 |
|
|
173 |
if (eval {require IniData} && eval {require EnvDb}) {
|
|
174 |
eval {$iniData = IniData->New()};
|
|
175 |
|
|
176 |
push @errors, $@ if ($@);
|
|
177 |
|
|
178 |
if ($iniData) {
|
|
179 |
eval {$self->{envDB} = EnvDb->Open($iniData)};
|
|
180 |
|
|
181 |
push @errors, $@ if ($@);
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
if ($iniData && $self->{envDB} && !scalar(@errors)) {
|
|
186 |
return 1;
|
|
187 |
}
|
|
188 |
else {
|
|
189 |
# If not successful then we produce a warning and return undef
|
|
190 |
carp "Warning: Unable to use the CBR Tools for obtaining MRP locations\n";
|
|
191 |
carp "The following errors were returned: @errors\n" if (scalar(@errors) > 0);
|
|
192 |
|
|
193 |
$self->{noCbrTools} = 1;
|
|
194 |
return undef;
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
sub ReadMRPFiles {
|
|
200 |
my $self = shift;
|
|
201 |
my $mrpFiles = shift;
|
|
202 |
|
|
203 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n" if (shift);
|
|
204 |
|
|
205 |
# Construct a reader object, specifying the type of MRP object to populate
|
|
206 |
if (!exists $self->{reader}) {
|
|
207 |
print "Obtaining IPR information from MRP files...\n" if ($self->{verbose});
|
|
208 |
$self->{reader} = Symbian::CBR::MRP::Reader->instance();
|
|
209 |
$self->{reader}->SetVerbose() if ($self->{verbose});
|
|
210 |
}
|
|
211 |
|
|
212 |
my @dependencies;
|
|
213 |
|
|
214 |
foreach my $mrpFile (@$mrpFiles) {
|
|
215 |
# It is possible that the file doesn't exist, e.g. only binaries may be installed
|
|
216 |
next if (!-e $mrpFile);
|
|
217 |
|
|
218 |
# Skip this file if it has already been processed
|
|
219 |
next if (exists $self->{processedMrpFiles}->{lc($mrpFile)});
|
|
220 |
|
|
221 |
# Keep a record of the MRP files that we have processed...
|
|
222 |
$self->{processedMrpFiles}->{lc($mrpFile)} = 1;
|
|
223 |
|
|
224 |
eval {
|
|
225 |
# Parse the MRP file. The reader returns an MRP object
|
|
226 |
my $mrpObj = $self->{reader}->ReadFile($mrpFile, $self->{typeOfMrp});
|
|
227 |
|
|
228 |
# Get the IPR information from the MRP object
|
|
229 |
my $iprInformation = $mrpObj->GetIPRInformation();
|
|
230 |
|
|
231 |
# Add it to the IPR lookup tree
|
|
232 |
$self->AddToTree($iprInformation);
|
|
233 |
|
|
234 |
if (scalar($mrpObj->GetExportComponentDependencies())) {
|
|
235 |
@dependencies = $mrpObj->GetExportComponentDependencies();
|
|
236 |
}
|
|
237 |
};
|
|
238 |
|
|
239 |
if ($@) {
|
|
240 |
print $@;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
# if any left over then call PrepareInformationForComponent
|
|
245 |
foreach my $dependancy (@dependencies) {
|
|
246 |
if (my @mrpLocations = $self->GetMRPLocations($dependancy)) {
|
|
247 |
$self->ReadMRPFiles(\@mrpLocations);
|
|
248 |
}
|
|
249 |
else {
|
|
250 |
carp "Warning: Unable to locate MRP file for dependant component \"$dependancy\"\n";
|
|
251 |
}
|
|
252 |
}
|
|
253 |
}
|
|
254 |
|
|
255 |
|
|
256 |
sub AddToTree {
|
|
257 |
my $self = shift;
|
|
258 |
my $iprInformation = shift;
|
|
259 |
|
|
260 |
if (!$iprInformation || shift) {
|
|
261 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
262 |
}
|
|
263 |
|
|
264 |
foreach my $path (keys %{$iprInformation}) {
|
|
265 |
my $lcPath = lc($path);
|
|
266 |
|
|
267 |
# each folder is a branch on the tree
|
|
268 |
$lcPath =~ s/^[\\\/]//;
|
|
269 |
my @folders = split /[\\\/]/, $lcPath;
|
|
270 |
|
|
271 |
# used to track position in tree
|
|
272 |
my $branch = \%{$self->{iprTree}};
|
|
273 |
|
|
274 |
foreach my $folder (@folders) {
|
|
275 |
if (!exists $branch->{$folder}) {
|
|
276 |
$branch->{$folder} = {};
|
|
277 |
}
|
|
278 |
|
|
279 |
# ignore the special folder '.'
|
|
280 |
unless ($folder eq '.') {
|
|
281 |
$branch = $branch->{$folder};
|
|
282 |
}
|
|
283 |
}
|
|
284 |
|
|
285 |
if (exists $branch->{'_category'}) {
|
|
286 |
if ($branch->{'_category'} ne $iprInformation->{$path}->{'category'} || $branch->{'_exportRestricted'} ne $iprInformation->{$path}->{'exportRestricted'}) {
|
|
287 |
# If IPR information has already been set and differs then we should set the data as null
|
|
288 |
# so that distribution policy files will be used instead.
|
|
289 |
$branch->{'_category'} = '';
|
|
290 |
$branch->{'_exportRestricted'} = '';
|
|
291 |
carp "Warning: IPR information for \"$path\" defined more than once in MRP files and differs and so will be ignored\n";
|
|
292 |
}
|
|
293 |
}
|
|
294 |
else {
|
|
295 |
$branch->{'_category'} = $iprInformation->{$path}->{'category'};
|
|
296 |
$branch->{'_exportRestricted'} = $iprInformation->{$path}->{'exportRestricted'};
|
|
297 |
}
|
|
298 |
}
|
|
299 |
}
|
|
300 |
|
|
301 |
|
|
302 |
sub Category {
|
|
303 |
my $self = shift;
|
|
304 |
my $path = shift;
|
|
305 |
|
|
306 |
if (!$path || shift) {
|
|
307 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
308 |
}
|
|
309 |
|
|
310 |
return $self->GetIPRinfo($path)->{'category'};
|
|
311 |
}
|
|
312 |
|
|
313 |
|
|
314 |
sub ExportRestricted {
|
|
315 |
my $self = shift;
|
|
316 |
my $path = shift;
|
|
317 |
|
|
318 |
if (!$path || shift) {
|
|
319 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
320 |
}
|
|
321 |
|
|
322 |
return $self->GetIPRinfo($path)->{'exportRestricted'};
|
|
323 |
}
|
|
324 |
|
|
325 |
|
|
326 |
sub GetIPRinfo {
|
|
327 |
my $self = shift;
|
|
328 |
my $path = lc(shift); # We need to lowercase the path
|
|
329 |
|
|
330 |
if (!$path || shift) {
|
|
331 |
croak "Invalid number of arguments passed to " . (caller(0))[3] . "\n";
|
|
332 |
}
|
|
333 |
|
|
334 |
if (!exists $self->{iprTree}) {
|
|
335 |
# If no information exists in the tree then try to populate all the information from the EnvDB database
|
|
336 |
$self->Populate();
|
|
337 |
}
|
|
338 |
|
|
339 |
# Turn paths into abs from rel, some tools may pass relative paths (e.g. ExportIPR.pl)
|
|
340 |
$path = File::Spec->rel2abs($path);
|
|
341 |
|
|
342 |
# We need to remove drive letters
|
|
343 |
$path =~ s/^[a-z]://i;
|
|
344 |
|
|
345 |
my $results = {
|
|
346 |
'category' => undef, # As the distribution policy modules return X if no category is found
|
|
347 |
'exportRestricted' => undef};
|
|
348 |
|
|
349 |
$path =~ s/^[\\\/]//; # Remove the first slash otherwise splitting the path on slashes will create an empty array entry
|
|
350 |
my @folders = split /[\\\/]/, $path;
|
|
351 |
|
|
352 |
my $branch = $self->{iprTree};
|
|
353 |
|
|
354 |
# find the path in the tree
|
|
355 |
foreach my $folder (@folders) {
|
|
356 |
if (exists $branch->{$folder}) {
|
|
357 |
$branch = $branch->{$folder};
|
|
358 |
|
|
359 |
if (exists $branch->{'_category'}) {
|
|
360 |
$results = {
|
|
361 |
'category' => $branch->{'_category'},
|
|
362 |
'exportRestricted' => $branch->{'_exportRestricted'}};
|
|
363 |
}
|
|
364 |
}
|
|
365 |
else {
|
|
366 |
last;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
|
|
370 |
return $results;
|
|
371 |
}
|
|
372 |
|
|
373 |
1;
|
|
374 |
|
|
375 |
|
|
376 |
__END__
|
|
377 |
|
|
378 |
=pod
|
|
379 |
|
|
380 |
=head1 NAME
|
|
381 |
|
|
382 |
Symbian::CBR::IPR::MRP - An interface to IPR information contained within MRP files
|
|
383 |
|
|
384 |
=head1 SYNOPSIS
|
|
385 |
|
|
386 |
use Symbian::CBR::IPR::MRP;
|
|
387 |
|
|
388 |
# Instantiate a Symbian::CBR::IPR::MRP object
|
|
389 |
my $iprMrp = Symbian::CBR::IPR::MRP->instance();
|
|
390 |
|
|
391 |
# Get the IPR category for a path
|
|
392 |
my $category = $iprMrp->Category('\aPath\somewhere');
|
|
393 |
|
|
394 |
# Get the export restricted flag for a path
|
|
395 |
my $exportRestricted = $iprMrp->ExportRestricted('\aPath\somewhere');
|
|
396 |
|
|
397 |
=head1 DESCRIPTION
|
|
398 |
|
|
399 |
This package collates IPR information for either an entire environment, or for a
|
|
400 |
component, and provides methods to access IPR information for a given path.
|
|
401 |
|
|
402 |
=head1 METHODS
|
|
403 |
|
|
404 |
=head2 instance(component, typeOfMrp, verbose)
|
|
405 |
|
|
406 |
Instantiates a Symbian::CBR::IPR::MRP object.
|
|
407 |
|
|
408 |
The typeOfMrp argument is non-optional. Valid types are MRP and MRPDATA. See the
|
|
409 |
documentation for Symbian::CBR::MRP::Reader for more information.
|
|
410 |
|
|
411 |
If a component had been specified then the MRP file for the component will be processed
|
|
412 |
and the IPR information obtained. Any MRP files for dependant components will be located
|
|
413 |
and processed too. If no component name has been specified all MRP files in the environment
|
|
414 |
will be processed.
|
|
415 |
|
|
416 |
=head2 Category(path)
|
|
417 |
|
|
418 |
Returns the IPR category of the path. If no IPR information exists for the
|
|
419 |
specified path then undef will be returned.
|
|
420 |
|
|
421 |
=head2 ExportRestricted(path)
|
|
422 |
|
|
423 |
Returns true if the specified path is export restricted, and false if it is not.
|
|
424 |
If no IPR information exists for the specified path then false will be returned.
|
|
425 |
|
|
426 |
=head1 COPYRIGHT
|
|
427 |
|
|
428 |
Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
429 |
All rights reserved.
|
|
430 |
This component and the accompanying materials are made available
|
|
431 |
under the terms of the License "Eclipse Public License v1.0"
|
|
432 |
which accompanies this distribution, and is available
|
|
433 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
434 |
|
|
435 |
Initial Contributors:
|
|
436 |
Nokia Corporation - initial contribution.
|
|
437 |
|
|
438 |
Contributors:
|
|
439 |
|
|
440 |
Description:
|
|
441 |
|
|
442 |
|
|
443 |
=cut
|