releasing/cbrtools/perl/SourceInfo
author Zheng Shen <zheng.shen@nokia.com>
Tue, 20 Jul 2010 15:02:28 +0800
changeset 617 3a747a240983
parent 602 3145852acc89
permissions -rw-r--r--
ROM Tools 12.2.0.4 Postlinker 2.2.5 Revert package_definition.xml to changeset 360bd6b35136
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#!perl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use FindBin;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use lib "$FindBin::Bin";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use Getopt::Long;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
use IniData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
use EnvDb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
use CommandController;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
use DirHandle;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
use Utils;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
# Globals.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
my $verbose = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
my $iniData = IniData->New();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
my $commandController = CommandController->New($iniData, 'SourceInfo');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
my $envDb;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
my $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
my $comp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
my $listindividualfiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
my $includeignores;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
my $includebinaries;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
my $summary;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
my $expandepoc32;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
my $countfiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
my $skipWarnings;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
$envDb = EnvDb->Open($iniData, $verbose);
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
# Main.
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
ProcessCommandLine();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
SourceInfo();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
# Subs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
sub ProcessCommandLine {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
  Getopt::Long::Configure ("bundling");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  my $help;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  GetOptions('h' => \$help, 'v+' => \$verbose, 'f' => \$listindividualfiles, 'i' => \$includeignores, 'b' => \$includebinaries, 's' => \$summary, 'c' => \$countfiles, 'force' => \$skipWarnings);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  if ($help) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
    Usage(0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
  if (!$ARGV[0]) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
    $comp = undef; # it already is, but let's be explicit...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
    if ($envDb->Version($ARGV[0])) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
      $comp = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
      $file = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
      Utils::AbsoluteFileName(\$file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
  unless ($#ARGV == -1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
    print "Error: Invalid arguments\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
    Usage(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
sub Usage {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
  my $exitCode = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
  Utils::PrintDeathMessage($exitCode, "\nUsage: sourceinfo [options] [ component | file ]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
-h  help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
-v  verbose output (-vv very verbose)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
-f  list individual files, not just directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
-c  count the files in each directory (can be slow)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
-b  include binary files in report
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
-i  include 'ignored' files in report
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
--force (deprecated)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
-s  print summary report (don't specify a component or a file)\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
sub SourceInfo {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
  $expandepoc32 = WorkOutWhetherExpandEpoc32();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  if ($file) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
    die "Error: can't do summary report about a particular file.\n" if ($summary);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
    DoFileReport($file);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  } elsif ($comp) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
    die "Error: can't do summary report about a particular component.\n" if ($summary);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
    DoComponentReport($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  } elsif ($summary) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
    DoSummaryReport();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    DoFullReport();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
##############################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
# Implementation notes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
# This script is very complex. Here is a guide to what's going on.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
# First look at the main SourceInfo function, above. You'll see there's four different
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
# types of report, corresponding to the four ways the command line can be used. (-s is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
# treated as its own type of report).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
# Each one of these creates and uses a similar set of objects in different ways.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
# The objects used are:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
#   SourceInfo::OwnerFinder::xxxx - these classes are factories for SourceInfo::Owners.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
#   SourceInfo::Owner - these objects represent each way a directory or file can be owned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
#                       A single component may produce many 'owners' - for example,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
#                       one for each of its binary files and one for each of the 'source'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
#                       items in its MRP.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
#   SourceInfo::Item - this class is the heart of this script. It represents each item
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
#                      on disk (whether a directory or file). It may contain a link
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
#                      to one or more owners, if that directory or file is owned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
# Each of the reports work like this:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
#  1- build up (partial) tree of all the files/directories on disk made of SourceInfo::Items.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
#  2- create a load of SourceInfo::Owners.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
#  3- tell the owners to attach themselves to the relevant items in the tree of Items.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
#  4- tell the items to make themselves shown/hidden depending on various settings.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
#  5- gather the shown items into a list which can be made into a table.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
# The only exception is the -s option, which doesn't really stick to this pattern for
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
# stage 5. But it does for the rest.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
# The different reports work on this in different ways. For example, if a component is 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
# specified on the command line, OwnerFinders (and therefore owners) are only created for 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
# that component.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
# The tree created in Stage 1 starts out small. (In fact, it's just the root). It grows
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
# items under many circumstances:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
#  -- an owner item requests an item deep in the tree which hasn't been expanded that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
#     far yet.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
#  -- ExpandAll is called, corresponding to the -f option.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
#  -- ExpandUnownedDirs is called, which will list all the items inside each directory
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
#     that isn't owned. This ensures that all unowned files and directories are listed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
#     in the tree.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
#  -- we're a sourceinfo <file> and we have to expand the tree to include the file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
#  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
#  It's worth noting that the -b flag has two effects. Firstly, binary OwnerFinders
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
#  and Owners are not created. Secondly, (more importantly?) neither ExpandAll
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
#  nor ExpandUnownedDirs will do any expansion inside \epoc32. So you'll never
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
#  see items inside that tree, and 'binary' items outside that tree won't appear
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
#  either. (In fact, they'll be reported as having no owner).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
#  \epoc32 is not included if -i is specified, either.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
#
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
sub WorkOutWhetherExpandEpoc32 {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
  return 1 if $includebinaries && $includeignores;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
  return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
# The four following methods are the different types of report that can
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
# be done.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
sub DoFileReport {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
  my $file = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
  print "Warning: \"$file\" is not a file and is not a component that is currently installed. The following report assumes it is a file which you could install with \"getsource\"\n" unless -e $file;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
  my $owners = FindOwners(); # we have to create all possible owners
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
  my $root = new SourceInfo::Item("", undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
  $root->FindItem($file, 1); # expand the tree to include our file
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
  print "Finding owned items\n" if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
  FindOwnedItems($owners, $root, 0); # mark the Items as having Owners
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
  my $items = $root->GetAll;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
  $root->DecideVisibility;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
  $iniData->TableFormatter->PrintTable(MakeTable($items), 1); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
sub DoSummaryReport {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
  my $root = CreateRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
  $root->ExpandAll() if ($listindividualfiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
  my $owners = FindOwners();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
  FindOwnedItems($owners, $root, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
  $root->ExpandUnownedDirs();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
  $root->DecideVisibility;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
  my @noowners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
  my @multiowners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
  foreach my $item (@{$root->GetAllVisible}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
    my $count = $item->NumOwners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
    if ($count == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
      push @noowners, $item;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
    } elsif ($count > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
      push @multiowners, $item;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
      # This has exactly one ownership. Joy!
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
  print "Files/areas without ownership:\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
  foreach (@noowners) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
    print "  ".$_->Path . "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
  print "Files/areas with multiple ownership:\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
  foreach (@multiowners) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
    print "  ".$_->Path . "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
sub DoFullReport {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
  print "Doing full report\n" if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
  my $root = CreateRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
  $root->ExpandAll() if ($listindividualfiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
  my $owners = FindOwners();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
  FindOwnedItems($owners, $root, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
  $root->ExpandUnownedDirs() unless $listindividualfiles; # might have already done it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
  my $items = $root->GetAll;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
  if ($listindividualfiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
    $root->ShowAll();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
    $root->DecideVisibility();
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
  $iniData->TableFormatter->PrintTable(MakeTable($items), 1); 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
sub DoComponentReport {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
  my $component = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
  my $root = CreateRoot();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
  my $owners = FindOwners($component);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
  FindOwnedItems($owners, $root, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
  $root->ExpandOwnedDirs() if ($listindividualfiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
  my $items = $root->GetAll;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
  if ($listindividualfiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
    $root->ShowAll();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
    $root->DecideVisibility();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
  $iniData->TableFormatter->PrintTable(MakeTable($items), 1); 
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
# The following global functions are used by all the above types of report.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
sub CreateRoot {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
  return new SourceInfo::Item("",undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
sub LimitRelevantOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
  my $ownername = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
  my $owners = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
  my @owners = grep { $_->Component =~ m/^\Q$ownername\E$/i } @$owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
  return \@owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
# This takes a load of Items and makes a nice table. Mostly, it
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
# just tells each item to produce some relevant rows.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
sub MakeTable {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
  my $items = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
  my @header = ( "Area" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
  push @header, "Files" if $countfiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
  push @header, ( "Component", "Element", "Status", "Notes" );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
  my @rows = (\@header);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
  foreach my $item (sort { $a->Path cmp $b->Path } @$items) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
    next unless $item->{show};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
    push @rows, @{$item->MakeRows()};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
  return \@rows;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
# This tells each owner to attach itself to the right place
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
# in the tree of Items.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
sub FindOwnedItems {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
  my $owners = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
  my $root = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
  my $createnew = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
  foreach my $owner (@$owners) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
    $owner->FindOwnedItem($root, $createnew);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
# This produces all the Owner objects, by way of creating some
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
# ephemeral OwnerFinder objects. This is the only place
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
# OwnerFinders are used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
sub FindOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
  my $component = shift; # may be undefined
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
  my @owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
  my @ownerfinders = (new SourceInfo::OwnerFinder::Source);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
  push @ownerfinders, new SourceInfo::OwnerFinder::Ignores if $includeignores;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
  push @ownerfinders, new SourceInfo::OwnerFinder::Binaries if $includebinaries;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
  @owners = map { @{ $_->FindOwners($component) } } @ownerfinders;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
  return \@owners;
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
##########################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
package SourceInfo::Item;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
sub new {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
  my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
  my $name = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
  my $parent = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
  my $status = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
  die "No name provided" unless (defined $name);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
  return bless {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
    name => $name, # '' if root. NOT '\'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
    children => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
    parent => $parent, # undef if root
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
    category => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
    owners => [], # links to any Owner objects.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
    fullpath => undef,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
    status => $status,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
    children => {}, # yes, there are circular references and the whole tree won't die until global cleanup
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
    show => 0 # whether to show in the results
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
  }, (ref $class || $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
# Produce rows relevant to put into the results tables
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
sub MakeRows {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
  my $owners = $self->Owners();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
  my @rows;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
  foreach my $owner (@$owners) { # for each owner...
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
    push @rows, $self->MakeARow($owner);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
  if ($self->NumOwners == 0) { # or, if we don't have an owner :-(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
    push @rows, $self->MakeARow();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
  return \@rows;
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
sub MakeARow {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
  my $owner = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
  my @row = ($self->Path());
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
  push @row, $self->NumFiles() if ($countfiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
  if ($owner) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
    push @row, $owner->Component();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
    push @row, $owner->Element();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
    push @row, $self->Category() || $owner->Status() || "-";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
    push @row, ("-", "-");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
    push @row, $self->Category() || "-";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
  push @row, $self->Notes();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
  return \@row;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
sub NumOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
  return scalar @{$self->Owners()};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
# Will later be used for IPR category.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
# This currently isn't used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
sub Category {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
  return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
# These two methods are alternatives for making some or all of the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
# items visible, depending on their ownership.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
sub ShowAll {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
  $self->{show} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
  $self->ExecuteChildren(sub {$_->ShowAll});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
sub DecideVisibility {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
  print "Deciding visibility for ".$self->Path.". Is directory: ".$self->IsDirectory.", owners: ".@{$self->{owners}}.", children: ".%{$self->{children}}."\n" if $verbose > 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
  if ( $self->IsFile() || @{$self->{owners}} || !%{$self->{children}} ) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
    $self->{show} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
  $self->ExecuteChildren(sub { $_->DecideVisibility } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
sub NumFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
  $self->ExpandAll;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
  my $files = ($self->IsDirectory)?0:1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
  foreach (values %{$self->{children}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
    $files += $_->NumFiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
  return $files;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
sub Notes {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
  my $numowners = $self->NumOwners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
  if ($numowners == 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
    return "NONE";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
  } elsif ($numowners > 1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
    return "MULTIPLE";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
  } elsif ($self->Owners()->[0]->Type() eq "ignore") {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
    return "IGNORED";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
sub IsDirectory {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
  return -d ($self->Path || "\\");
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
sub IsFile {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
  return -f ($self->Path || "\\");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
# Destructor. Not currently used - just in case we want to delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
# a tree full of circular references.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
sub DeleteAll {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
  $self->{parent} = undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
  $self->ExecuteChildren( sub { $_->DeleteAll } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
# Returns a list of each item
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
sub GetAll {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
  my @items = ($self);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
  $self->ExecuteChildren(sub { push @items, @{$_->GetAll} } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
  return \@items;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
# Returns a list of each item that's visible
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
sub GetAllVisible {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
  my @items = grep { $_->{show} } @{$self->GetAll};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
  return \@items;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
sub ExpandAll {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
  print "." if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
  $self->FindChildren;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
  $self->ExecuteChildren( sub { $_->ExpandAll } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
# This expands any directories which don't have owners, but some
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
# of the subdirectories are owned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
sub ExpandUnownedDirs {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
  print "Expanding unowned for ".$self->Path."\n" if $verbose>1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
  return unless $self->IsDirectory;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
  return if $self->NumOwners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
  # We also return if NONE of the children are owned, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
  # i.e. we're a totally unowned directory.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
  return unless $self->{childownersfound};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
  $self->FindChildren;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
  $self->ExecuteChildren (sub { $_->ExpandUnownedDirs } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
sub ExpandOwnedDirs {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
  $self->ExpandAll() if (@{$self->{owners}});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
  $self->ExecuteChildren (sub { $_->ExpandOwnedDirs } );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
# Recursively applies a function to each item
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
sub ExecuteChildren {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
  my $sub = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
  &$sub($_) foreach (values %{$self->{children}});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
sub FindChildren {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
  print "Finding children for ".$self->Path."\n" if $verbose>1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
  return if defined $self->{foundchildren};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
  return if ($self->Path eq "\\epoc32" && !$expandepoc32);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
  $self->{foundchildren} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
  $self->ReadDir();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
  my %kids = map { (lc $_, new SourceInfo::Item($_, $self)) } @{$self->{dirlisting}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
  print "Currently has these children: ".(join (', ', map { "$_->{name} ".$_->NumOwners } values %{$self->{children}}))."\n" if $verbose>2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
  $self->{children} ||= {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
  $self->{children} = { %kids, %{$self->{children}} };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
sub NumChildren {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
  $self->ReadDir;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
  return @{$self->{dirlisting}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
sub ReadDir {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
  return if $self->{dirlisting};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
  $self->{dirlisting} = [] and return unless $self->IsDirectory();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
  print "Reading directory for ".$self->Path."\n" if $verbose > 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
  my $dh = new DirHandle($self->Path() || "\\") or die "Couldn't open directory handle for \"".$self->Path()||"\\"."\" because $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
  $self->{dirlisting} = [ grep { ! m/^\./ } $dh->read ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
  $dh = undef; # I know this is OBVIOUSLY going to happen at the end of this function but
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
               # I am getting strange out-of-file-descriptor errors.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
sub Path {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
  unless (defined $self->{fullpath}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
    if (defined $self->{parent}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
      $self->{fullpath} = $self->{parent}->Path() . "\\" . $self->{name};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
      $self->{fullpath} = $self->{name};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
  return $self->{fullpath};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
# This is used to find a particular item in the tree,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
# given a path. (It's used when searching for something
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
# that is owned, for example). The 'createnew' flag
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
# specifies whether it should create new files and directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
# if necessary.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
sub FindItem {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
  my $path = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
  my $createnew = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
  print "Asked to find \"$path\"...\n" if ($verbose > 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
  my @segments = split (/\\/, $path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
  unshift @segments, "" unless $segments[0] eq ""; # root segment has no name
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
  $self->FindItemBySegments($createnew, @segments);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
sub FindItemBySegments {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
  my ($self, $createnew, $firstseg, @othersegs) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
  print "\n$self->{name} (path ".$self->Path().") (createnew $createnew):--\n" if ($verbose > 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
  print "First segment $firstseg, others @othersegs\n" if ($verbose > 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
  die "No path provided" unless defined $firstseg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
  if (lc $firstseg eq lc $self->{name}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
    if (@othersegs) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
      foreach (values %{$self->{children}}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
        my $found = $_->FindItemBySegments($createnew, @othersegs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
        return $found if $found;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
      return undef unless $createnew;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
      return $self->CreateNewSegment(@othersegs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
    } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
      return $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
    return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
sub CreateNewSegment {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
  my ($self, $firstseg, @othersegs) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
  print "Creating new segment for $firstseg (others @othersegs) within ".$self->Path."\n" if $verbose>1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
  my $kid = new SourceInfo::Item($firstseg, $self);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
  $self->{children}->{lc $firstseg} = $kid;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
  $self->{childownersfound} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
  return $kid->FindItemBySegments(1, $firstseg, @othersegs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
sub Owners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
  my @allowners = @{$self->{owners}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
  return \@allowners unless ($self->{parent});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
  push @allowners, @{$self->{parent}->Owners};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
  return \@allowners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
sub AddOwner {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
  my $owner = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
  push @{$self->{owners}}, $owner;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
##########################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
##########################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
package SourceInfo::Owner;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
sub new {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
  my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
  my $type = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
  my $component = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
  my $element = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
  my $status = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
  return bless {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
    type => $type, # ignore, binary or source
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
    component => $component,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
    element => $element,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
    status => $status
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
  }, (ref $class || $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
sub FindOwnedItem {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
  my $root = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
  my $createnew = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
  
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
  print "About to find the owned item for \"$self->{element}\" ($createnew)\n" if ($verbose > 3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
  my $item = $root->FindItem($self->{element}, $createnew);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
  die "Failed to create new item" if (!$item && $createnew);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
  $item->AddOwner($self) if $item;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
sub Component {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
  return "-" if ($self->Type() eq "ignore");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
  return $self->{component};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
sub Element {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
  return "<binary>" if ($self->{type} eq "binary");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
  return "<ignore>" if ($self->Type() eq "ignore");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
  return $self->{element} || "-";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
sub Type {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
  return $self->{type};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
sub Status {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
  return $self->{status};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
##########################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
##########################################################################################
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
package SourceInfo::OwnerFinder;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
sub new {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
  my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
  return bless {}, (ref $class || $class);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
sub Components {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
  my $versionInfo = $envDb->VersionInfo();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
  return sort keys %$versionInfo;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
package SourceInfo::OwnerFinder::Ignores;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
BEGIN { @SourceInfo::OwnerFinder::Ignores::ISA = qw(SourceInfo::OwnerFinder); };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
sub FindOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
  my @owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
  # First, the ignored items
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
  print "Finding ignored binaries.\n" if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
  my $ignoreList = $iniData->BinariesToIgnore();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
  push (@$ignoreList, '\\epoc32\\relinfo\\*');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
  foreach my $ignore (@$ignoreList) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
    my @found = glob $ignore;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
    if (@found) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
      push @owners, new SourceInfo::Owner("ignore", undef, $_, undef) foreach (@found);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
    } elsif ($ignore =~ s/\\\*$//) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
      push @owners, new SourceInfo::Owner("ignore", undef, $ignore, undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
  return \@owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
package SourceInfo::OwnerFinder::Source;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
BEGIN { @SourceInfo::OwnerFinder::Source::ISA = qw(SourceInfo::OwnerFinder); };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
sub FindOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
  my $component = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
  print "Finding source directories owned.\n" if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
  my @owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
  my @comps_to_examine;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
  if ($component) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
    @comps_to_examine = ($component);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
    @comps_to_examine = $self->Components();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
  foreach my $comp (@comps_to_examine) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
    eval {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
      foreach my $element (keys %{$self->GetSourceInfo($comp)}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
        
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
        if($iniData->HasMappings()){
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
          $element = $iniData->PerformMapOnFileName($element);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
          $element = Utils::RemoveSourceRoot($element);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
	      
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
        push @owners, new SourceInfo::Owner("source", $comp, $element, undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
    };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
    if ($@) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
      print "Warning: could not find owner information for \"$comp\" because $@";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
  return \@owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
sub GetSourceInfo {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
  my $comp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
  my $ver = $envDb->Version($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
  my $relData = RelData->Open($iniData, $comp, $ver, $verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
  return $relData->SourceItems();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
package SourceInfo::OwnerFinder::Binaries;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
BEGIN { @SourceInfo::OwnerFinder::Binaries::ISA = qw(SourceInfo::OwnerFinder); };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
sub FindOwners {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
  my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
  my $component = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
  my @owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
  print "Finding binaries owned.\n" if $verbose;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
  my @comps_to_examine;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
  if ($component) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
    @comps_to_examine = ($component);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
    @comps_to_examine = $self->Components();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
  foreach my $comp (@comps_to_examine) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
    my $bfowned = $envDb->ListBins($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
    shift @$bfowned; # get rid of the header row
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
    foreach my $binfile (@$bfowned) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
      my $file = $binfile->[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
      my $status = $binfile->[1];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
      push @owners, new SourceInfo::Owner("binary", $comp, $file, $status);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
  return \@owners;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
SourceInfo - Displays information about the source code associated with components.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   785
  sourceinfo [options] [any file | component]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   786
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   787
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   788
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   789
  -h  help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   790
  -v  verbose output (-vv very verbose)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   791
  -f  list individual files, not just directories
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   792
  -b  include binary files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   793
  -i  include 'ignored' files
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   794
  -s  print summary report (don't specify a component or a file)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   795
  --force (deprecated)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   796
  -c  show a count of the files in each directory (and its subdirectories) -- can be slow
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   797
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   798
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   799
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   800
If given a filename, prints information about what component(s) release the source directory(ies) containing that file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   801
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   802
  Area                     Files   Component   Element     Status   Notes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   803
  \aardvark                6       aardvark    \aardvark   -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   804
  \aardvark\aardvark.mrp   1       aardvark    \aardvark   -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   805
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   806
The confusing 'element' column lists what MRP 'source' statement owns that item of source code. 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   807
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   808
If given a component name, prints information about what directories that component releases.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   809
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   810
  Area        Files   Component   Element     Status   Notes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   811
  \aardvark   6       aardvark    \aardvark   -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   812
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   813
If no component name is specified, then a full report will be provided for each component.  This will also report any files or directories that are not owned by any component, as well as any file or directories which are owned by more than one component.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   814
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   815
  Area             Files   Component   Element       Status Notes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   816
  \aardvark        6       aardvark    \aardvark     -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   817
  \albatross       6       albatross   \albatross    -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   818
  \anteater        6       anteater    \anteater     -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   819
  \buffalo         6       buffalo     \buffalo      -
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   820
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   821
If the -s flag is provided, then only the information about files/directories with zero or multiple ownership is shown.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   822
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   823
  Files/areas without ownership:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   824
    \prepenv-input.txt
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   825
    \reltools-tmp-cleanremote-conf.txt
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   826
  Files/areas with multiple ownership:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   827
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   828
The F<\epoc32> tree is not normally included in reports. Similarly, files owned as "binary" files by components aren't included in reports - so, if a component releases binary files outside of F<\epoc32> then they will be shown as having no ownership.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   829
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   830
For completeness, you can include binary ownership in the report using C<-b>. A similar option is C<-i>. This turns on the scanning of 'ignored' areas, such as F<\epoc32\wins\c>. 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   831
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   832
The final option is C<-f>. If a directory is uniformly owned, then normally the files inside that directory will not be listed. Adding C<-f> prompts the tool to list every file.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   833
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   834
Note that the output of this may NOT be suitable for distributing to licensees, because it may include directory structures of bits of IPR they are not licensed to see.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   835
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   836
=head1 STATUS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   837
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   838
Supported. If you find a problem, please report it to us.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   839
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   840
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   841
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   842
None, but this tool is still rather experimental so please treat the output with caution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   843
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   844
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   845
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   846
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   847
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   848
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   849
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   850
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   851
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   852
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   853
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   854
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   855
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   856
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   857
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   858
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   859
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   860
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   861
=cut
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   862