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