releasing/cbrtools/perl/DiffEnv
author jjkang
Fri, 25 Jun 2010 18:37:20 +0800
changeset 602 3145852acc89
permissions -rw-r--r--
add releasing to new structure
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 EnvDifferencer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
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
# Constants.
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 $margin = 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
# Globals.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
my $verbose = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
my $iniData = IniData->New();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
my $commandController = CommandController->New($iniData, 'DiffEnv');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
my $comp1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
my $ver1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
my $comp2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
my $ver2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
my $doDateComparison = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
# Main.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
ProcessCommandLine();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
DiffEnv();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
# Subs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
sub ProcessCommandLine {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
  Getopt::Long::Configure ("bundling");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
  my $help;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  GetOptions('h' => \$help, 'd' => \$doDateComparison, 'v+' => \$verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
  if ($help) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
    Usage(0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
  $comp1 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
  $ver1 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  $comp2 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
  $ver2 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
  unless (defined $comp1 and defined $ver1 and $#ARGV == -1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
    print "Error: Invalid number of arguments\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
    Usage(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
  if (defined $comp2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
    unless (defined $ver2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
      print "Error: Invalid number of arguments\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
      Usage(1);
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
  if ($verbose && $doDateComparison) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
    print "Warning: -v disables -d\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
    $doDateComparison = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
sub Usage {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
  my $exitCode = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
  Utils::PrintDeathMessage($exitCode, "\nUsage: diffenv [options] <component_1> <version_1> [<component_2> <version_2>]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
-h  help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
-d  ignore differences when components in the first environment are younger than the second
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
-v  verbose output\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
sub DiffEnv {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
  my $env1Name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  my $env2Name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
  my $envDifferencer = EnvDifferencer->New($iniData, $verbose);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  if (defined $comp2 and $ver2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
    $envDifferencer->SetStartCompVer($comp1, $ver1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
    $envDifferencer->SetEndCompVer($comp2, $ver2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
    $env1Name = "$comp1 $ver1";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
    $env2Name = "$comp2 $ver2";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
    $env1Name = "current";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
    $env2Name = "$comp1 $ver1";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
    $envDifferencer->SetEndCompVer($comp1, $ver1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
    # no need to specify the other environment since the default
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
    # is to use the current environment
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
  my @tableData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  foreach my $comp (@{$envDifferencer->OnlyEnd()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
    push @tableData, [ $comp, '-', $envDifferencer->EndVersion($comp) ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
  foreach my $comp (@{$envDifferencer->OnlyStart()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
    push @tableData, [ $comp, $envDifferencer->StartVersion($comp), '-'  ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  if ($verbose) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
    foreach my $comp (@{$envDifferencer->UnchangedComps()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
      my $ver = $envDifferencer->StartVersion($comp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
      push @tableData, [ $comp, $ver, $ver  ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  if ($doDateComparison) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
    foreach my $comp (@{$envDifferencer->NewerComps()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
      push @tableData, [ $comp, $envDifferencer->StartVersion($comp), $envDifferencer->EndVersion($comp)  ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
  } else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
    foreach my $comp (@{$envDifferencer->ChangedComps()}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
      push @tableData, [ $comp, $envDifferencer->StartVersion($comp), $envDifferencer->EndVersion($comp)  ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
  if (@tableData) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
    my @sortedTableData = sort { $a->[0] cmp $b->[0] } @tableData;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
    unshift @sortedTableData, ['', $env1Name, $env2Name]; # Heading.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
    $iniData->TableFormatter->PrintTable(\@sortedTableData, 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
    print "Environments identical\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
DiffEnv - Compare the component versions of a pair of environments.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
  diffenv [options] <component_1> <version_1> [<component_2> <version_2>]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
options:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
  -h  help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
  -d  ignore differences when components in the first environment are younger than the second
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
  -v  verbose output
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
Displays a table of component version differences. If the second component / version pair is ommitted, the comparison is made against the current environment. If the C<-v> switch is specified, all versions will be displayed, even those that are identical. The results will be displayed in a table. The C<-d> option may be useful when newer version of a component are known to be backwards compatible with older versions.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
 Description:
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
=cut