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