releasing/cbrtools/perl/PathData.pm
changeset 602 3145852acc89
equal deleted inserted replaced
600:6d08f4a05d93 602:3145852acc89
       
     1 # Copyright (c) 2002-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 
       
    17 package PathData;
       
    18 
       
    19 use strict;
       
    20 
       
    21 #
       
    22 # Constructor
       
    23 #
       
    24 
       
    25 sub New {
       
    26   my $pkg = shift;
       
    27   my $verbose = shift;
       
    28   my $self = {};
       
    29   bless $self, $pkg;
       
    30   $self->{verbose} = $verbose;
       
    31   return $self;
       
    32 }
       
    33 
       
    34 #
       
    35 # Public
       
    36 #
       
    37 #
       
    38 
       
    39 # This function is called by IniData when it comes across an archive_path*
       
    40 # line. It will only be called once, because the first thing it does
       
    41 # is reclassify this object as a PathData::ComponentBased or a
       
    42 # PathData::ProjectBased. Subsequent calls to ProcessLine will therefore
       
    43 # call the derived class methods.
       
    44 sub ProcessLine {
       
    45   my $self = shift;
       
    46   my $keywordref = shift;
       
    47   my $lineref = shift;
       
    48 
       
    49   $self->SubclassifyMyselfByKeyword($keywordref); # make myself a subclass
       
    50   $self->ProcessLine($keywordref, $lineref); 
       
    51       # now ask the subclass to process the line
       
    52 }
       
    53 
       
    54 sub LocalArchivePathForExistingOrNewComponent {
       
    55   my $self = shift;
       
    56   my $comp = shift;
       
    57   my $ver = shift;
       
    58   my $project = shift;
       
    59   my $result = $self->LocalArchivePathForExistingComponent($comp, $ver, $project);
       
    60   $result ||=  $self->LocalArchivePathForNewComponent($comp, $ver, $project);
       
    61   return $result;
       
    62 }
       
    63 
       
    64 sub LocalArchivePathForNewOrExistingComponent {
       
    65   die "You meant LocalArchivePathForExistingOrNewComponent... teehee";
       
    66 }
       
    67 
       
    68 # These methods must all be reimplemented by the subclass
       
    69 sub LocalArchivePathForNewComponent {
       
    70   my $self = shift;
       
    71   my $comp = shift;
       
    72   my $ver = shift;
       
    73   my $project = shift;
       
    74   die "No path data found in reldata.ini. Cannot provide local archive path for new component.\n";
       
    75 }
       
    76 
       
    77 sub LocalArchivePathForExistingComponent {
       
    78   my $self = shift;
       
    79   my $comp = shift;
       
    80   my $ver = shift;
       
    81   die "No archive found in reldata.ini. Cannot provide local archive path for existing component.\n";
       
    82 }
       
    83 
       
    84 sub LocalArchivePathForImportingComponent {
       
    85   my $self = shift;
       
    86   my $comp = shift;
       
    87   my $ver = shift;
       
    88   my $remotepath = shift;
       
    89   die "No path data found in reldata.ini. Cannot provide local archive path for importing component.\n";
       
    90 }
       
    91 
       
    92 sub RemoteArchivePathForExistingComponent {
       
    93   my $self = shift;
       
    94   my $comp = shift;
       
    95   my $ver = shift;
       
    96   die "No path data found in reldata.ini. Cannot provide remote archive path for existing component.\n";
       
    97 }
       
    98 
       
    99 sub RemoteArchivePathForExportingComponent {
       
   100   my $self = shift;
       
   101   my $comp = shift;
       
   102   my $ver = shift;
       
   103   my $localpath = shift;
       
   104   die "No path data found in reldata.ini. Cannot provide remote archive path for exporting component.\n";
       
   105 }
       
   106 
       
   107 sub ListComponents {
       
   108   my $self = shift;
       
   109   die "No path data found in reldata.ini. Cannot return list of components.\n";
       
   110 }
       
   111 
       
   112 sub ListVersions {
       
   113   my $self = shift;
       
   114   my $comp = shift;
       
   115   my $filter = shift;
       
   116   die "No path data found in reldata.ini. Cannot return a list of versions.\n";
       
   117 }
       
   118 
       
   119 sub ListProjects {
       
   120   my $self = shift;
       
   121   die "No path data found in reltools.ini. Cannot return list of projects.\n";
       
   122 }
       
   123 
       
   124 sub ComponentProjects {
       
   125   my $self = shift;
       
   126   my $comp = shift;
       
   127   my $ver = shift;
       
   128   die "No path data found in reldata.ini. Cannot return which project a component belongs to.\n";
       
   129 }
       
   130 
       
   131 sub ComponentProject {
       
   132   my $self = shift;
       
   133   my $comp = shift;
       
   134   my $ver = shift;
       
   135   die "No path data found in reldata.ini. Cannot return which project a component belongs to.";
       
   136 }
       
   137 
       
   138 sub ReleaseExists {
       
   139   my $self = shift;
       
   140   my $comp = shift;
       
   141   my $ver = shift;
       
   142 
       
   143   my $relDir = $self->LocalArchivePathForExistingComponent($comp, $ver);
       
   144   if ($relDir && -e $relDir) {
       
   145     return 1;
       
   146   }
       
   147   return 0;
       
   148 }
       
   149 
       
   150 sub CheckReleaseExists {
       
   151   my $self = shift;
       
   152   my $comp = shift;
       
   153   my $ver = shift;
       
   154 
       
   155   unless ($self->ReleaseExists($comp, $ver)) {
       
   156     die "Error: $comp $ver not found\n";
       
   157   }
       
   158 }
       
   159 
       
   160 
       
   161 #
       
   162 # Private
       
   163 #
       
   164 #
       
   165 
       
   166 sub SubclassifyMyselfByKeyword {
       
   167   my $self = shift;
       
   168   my $keywordref = shift;
       
   169 
       
   170   if ($$keywordref =~ m/archive_path_file/i) {
       
   171     require PathData::ComponentBased;
       
   172     bless ($self, "PathData::ComponentBased");
       
   173   } elsif ($$keywordref =~ m/archive_path/i) {
       
   174     require PathData::ProjectBased;
       
   175     bless ($self, "PathData::ProjectBased");
       
   176   } else {
       
   177     die "Unknown archive_path related keyword: ".$$keywordref."\n";
       
   178   }
       
   179   print "Using ".(ref $self)." type of archive path arrangement. Keyword was $$keywordref\n" if ($self->{verbose});
       
   180 }
       
   181 
       
   182 1;
       
   183 
       
   184 __END__
       
   185 
       
   186 =head1 NAME
       
   187 
       
   188 PathData.pm - Provides the location of archived releases.
       
   189 
       
   190 =head1 DESCRIPTION
       
   191 
       
   192 Provides a class to represent knowledge of the archive structure. The class is mostly abstract; however, an object of this class may exist temporarily before it converts itself to a subclass.
       
   193 
       
   194 =head1 INTERFACE
       
   195 
       
   196 =head2 New
       
   197 
       
   198 Expects to be passed a verbosity flag.
       
   199 
       
   200 =head2 ProcessLine
       
   201 
       
   202 Processes a line from the C<reltools.ini> file. This will cause the object to bless itself into a subclass, depending on the keyword, then it will ask the subclass to process the line.
       
   203 
       
   204 =head2 LocalArchivePathForExistingOrNewComponent
       
   205 
       
   206 This method returns C<LocalArchivePathForExistingComponent>, or failing that, C<LocalArchivePathForNewComponent>.
       
   207 
       
   208 =head2 ComponentProject
       
   209 
       
   210 This returns the first item returned by the subclass method C<ComponentProjects>.
       
   211 
       
   212 =head2 Methods to be implemented by the subclass
       
   213 
       
   214 All the remaining methods should be implemented by the subclass of the C<PathData>. All of these methods are expected to return the full location where the files should be stored; i.e. local archive paths should end in "\component\version" and remote archive paths should end in "/component".
       
   215 
       
   216 =head2 LocalArchivePathForNewComponent
       
   217 
       
   218 This takes a component and a version and (optionally) the name of the project to store the component in.
       
   219 
       
   220 =head2 LocalArchivePathForExistingComponent
       
   221 
       
   222 This takes a component and a version.
       
   223 
       
   224 =head2 LocalArchivePathForImportingComponent
       
   225 
       
   226 This takes a component, a version, and the remote path where the component was found.
       
   227 
       
   228 =head2 RemoteArchivePathForExistingComponent
       
   229 
       
   230 This takes a component, a version and a C<RemoteSite> object.
       
   231 
       
   232 =head2 RemoteArchivePathForExportingComponent
       
   233 
       
   234 This takes a component, a version, and the local path where the component was found.
       
   235 
       
   236 =head2 ListComponents
       
   237 
       
   238 This may take "1" to indicate that it should list the components stored remotely, not locally.
       
   239 
       
   240 =head2 ListVersions
       
   241 
       
   242 This takes a component. It may optionally take a "1" to indicate that it should list the versions stored remotely, not locally. The third parameter is also optional; a regular expression that can be applied to filter the list of versions that is returned.
       
   243 
       
   244 =head2 ListProjects
       
   245 
       
   246 =head2 ComponentProjects
       
   247 
       
   248 This takes a component and a version and returns the project name of all archives where the release is found.
       
   249 
       
   250 =head2 ComponentProject
       
   251 
       
   252 This takes a component name and a version and returns the project name of the first archive where the release is found.  It gives the corresponding project name to the path that LocalArchivePathForExistingComponent gives for the same arguments.
       
   253 
       
   254 =head2 ReleaseExists
       
   255 
       
   256 Takes a component name and a version number. Return true if the component release is present in the local archive, false otherwise.
       
   257 
       
   258 =head2 CheckReleaseExists
       
   259 
       
   260 Takes a component name and a version number. Dies if the component release is not present in the local archive.
       
   261 
       
   262 =head1 IMPLEMENTATION
       
   263 
       
   264 =head2 SubclassifyMyselfByKeyword
       
   265 
       
   266 This will convert the object to either a C<PathData::ProjectBased> or C<PathData::ComponentBased> depending on the keyword passed in.
       
   267 
       
   268 =head1 KNOWN BUGS
       
   269 
       
   270 None.
       
   271 
       
   272 =head1 COPYRIGHT
       
   273 
       
   274  Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
   275  All rights reserved.
       
   276  This component and the accompanying materials are made available
       
   277  under the terms of the License "Eclipse Public License v1.0"
       
   278  which accompanies this distribution, and is available
       
   279  at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
   280  
       
   281  Initial Contributors:
       
   282  Nokia Corporation - initial contribution.
       
   283  
       
   284  Contributors:
       
   285  
       
   286  Description:
       
   287  
       
   288 
       
   289 =cut