Subversion Repositories DevTools

Rev

Rev 2450 | Rev 2764 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2012 Vix Technology, All rights reserved
3
#
4
# Module name   : cc2svn_importpackage.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Get package information for a package name specified on the
10
#                 command line.
11
#
12
#                 Determine the package id
13
#                 Locate all packages that have the same package name
14
#                 Determine essential packages
15
#                 Prune uneeded packages
16
#
17
#                 Pump it into SVN
18
#
19
#                 Project Based Pumping, creating branches as needed
20
#
21
#......................................................................#
22
 
23
require 5.006_001;
24
use strict;
25
use warnings;
26
use JatsError;
27
use JatsRmApi;
28
use FileUtils;
29
use JatsSystem;
30
use HTTP::Date;
31
use JatsProperties;
32
use JatsEnv;
33
use ConfigurationFile;
34
use JatsSvn qw(:All);
1197 dpurdie 35
use JatsLocateFiles;
2429 dpurdie 36
use Encode;
392 dpurdie 37
 
38
 
39
#use Data::Dumper;
40
use Fcntl ':flock'; # import LOCK_* constants
41
use Cwd;
42
use DBI;
43
use Getopt::Long;
44
use Pod::Usage;                             # required for help support
1342 dpurdie 45
use Encode;
392 dpurdie 46
 
47
#
48
#   Options
49
#
50
my $opt_help = 0;
51
my $opt_manual = 0;
52
my $opt_verbose = 0;
53
my $opt_repo_base = 'AUPERASVN01/';
54
my $opt_repo = '';
55
my $opt_flat;
56
my $opt_test;
57
my $opt_reuse;
58
my $opt_age;
59
my $opt_dump = 0;
60
my $opt_images = 0;
61
my $opt_retaincount = 2;
62
my $opt_pruneModeString;
63
my $opt_listTags;
64
my $opt_name;
65
my $opt_log = 0;
66
my @opt_tip;
67
my $opt_postimage = 1;
68
my $opt_workDir = '/work';
69
my $opt_vobMap;
1197 dpurdie 70
my $opt_preserveProjectBase;
71
my $opt_ignoreProjectBaseErrors;
2429 dpurdie 72
my $opt_ignoreMakeProjectErrors;
2478 dpurdie 73
my $opt_ignoreBadPaths;
1270 dpurdie 74
my $opt_delete;
1272 dpurdie 75
my $opt_recentAge = 14;             # Days
2429 dpurdie 76
my $opt_relabel = 0;
2450 dpurdie 77
my $opt_protected;
78
my $opt_useSvn = 1;
79
my $opt_testRmDatabase;
2478 dpurdie 80
my $opt_extractFromSvn;
392 dpurdie 81
 
82
################################################################################
83
#   List of Projects Suffixes and Branch Names to be used within SVN
84
#
85
#       Name        - Name of branch for the project
86
#       Trunk       - Can be a trunk project
87
#                     First one seen will be placed on the trunk
88
#                     Others will create project branches
89
#
90
my $ProjectTrunk;
91
my %ProjectsBaseCreated;
92
my %Projects = (
93
    '.sea'      => { Name => 'Seattle' },
94
    '.coct'     => { Name => 'CapeTown' },
95
    '.sls'      => { Name => 'Stockholm' },
96
    '.syd'      => { Name => 'Sydney' },
97
    '.vtk'      => { Name => 'Vasttrafik' },
98
    '.bei'      => { Name => 'Beijing' },
99
    '.bkk'      => { Name => 'Bangkok' },
100
    '.ndl'      => { Name => 'NewDelhi' },
101
    '.nzs'      => { Name => 'NewZealandStageCoach' },
102
    '.wdc'      => { Name => 'Washington' },
103
    '.oso'      => { Name => 'Oslo' },
104
    '.lvs'      => { Name => 'LasVegas' },
105
    '.mlc'      => { Name => 'BeijingMlc' },
106
    '.sfo'      => { Name => 'SanFrancisco' },
107
    '.sg'       => { Name => 'Singapore' },
108
    '.gmp'      => { Name => 'GmpteProject' },
109
    '.ssw'      => { Name => 'UkStageCoach' },
110
    '.uk'       => { Name => 'UkProject' },
111
    '.pmb'      => { Name => 'Pietermaritzburg' },
112
    '.vps'      => { Name => 'VixPayments' },
113
    '.ncc'      => { Name => 'NSWClubCard' },
114
    '.rm'       => { Name => 'Rome' },
2429 dpurdie 115
    '.vss'      => { Name => 'SmartSite' },
392 dpurdie 116
    'unknown'   => { Name => 'UnknownProject' },
117
 
118
    '.ebr'      => { Name => 'eBrio' , Trunk => 1 },
119
    '.mas'      => { Name => 'Mass'  , Trunk => 1 },
120
    '.cr'       => { Name => 'Core'  , Trunk => 1 },
121
    '.cots'     => { Name => 'Cots'  , Trunk => 1 },
122
    '.tool'     => { Name => 'Tools' , Trunk => 1 },
123
);
124
 
125
my %suffixFixup = (
126
    '.sf'           => '.sfo',
127
    '.vt'           => '.vtk',
128
    '.lv'           => '.lvs',
129
    '.was'          => '.wdc',
130
    '.uk.1'         => '.uk',
131
    '.ssts.demo'    => '.ssts',
132
    '.u244.syd'     => '.syd',
133
    '.pxxx.sea'     => '.sea',
134
    '.pxxx.syd'     => '.syd',
135
    '.pxxx.sydddd'  => '.syd',
136
    '.oslo'         => '.oso',
1272 dpurdie 137
    '.osl'          => '.oso',
392 dpurdie 138
);
139
 
140
my %specialPackages = (
2429 dpurdie 141
    'core_devl'           =>  ',all,protected,',
142
    'daf_utils_mos'       => ',flat,',
143
    'mos_packager'        => ',all,',
144
    'cfmgr-cfmgr'         => ',flat,',
145
    'daf_utils_button_st' => ',flat,',
146
    'ReleaseName'         => ',flat,',
147
    'reports'             => ',utf8,',
148
    'cda_imports'         => ',utf8,',
149
    'cdxforms'            => ',utf8,',
150
    'db_cda'              => ',utf8,',
151
    'CommandServer'       => ',IgnoreMakeProject,',
2439 dpurdie 152
    'TDSExporterControl'  => ',IgnoreMakeProject,',
153
    'cdagui'              => ',IgnoreMakeProject,',
395 dpurdie 154
 
2450 dpurdie 155
    'daf_bvt'                 => ',IgnoreMakeProject,',  # Look OK
156
    'daf_dll'                 => ',IgnoreMakeProject,',  # MakeProject not in used makefile
157
    'PFTPi'                   => ',IgnoreMakeProject,',  # Looks OK
158
    'PFTPu'                   => ',IgnoreMakeProject,',  # Looks OK
159
    'WinCEBlocker'            => ',IgnoreMakeProject,',  # Looks OK
160
    'WinCEDeviceAutoInject'   => ',IgnoreMakeProject,',  # Looks OK
161
    'WinCEReboot'             => ',IgnoreMakeProject,',  # Looks OK
2429 dpurdie 162
 
395 dpurdie 163
 
1197 dpurdie 164
    'ftp'                   => 'SetProjectBase,',
2478 dpurdie 165
    'ddu_app_manager'       => 'SetProjectBase,IgnoreMakeProject,',
2450 dpurdie 166
    'ddu_afc'               => 'SetProjectBase,IgnoreMakeProject,',
2478 dpurdie 167
    'ddu_dog'               => 'IgnoreMakeProject,',
168
    'ddu_afc'               => 'SetProjectBase,IgnoreMakeProject,',
1197 dpurdie 169
 
170
    'icl'                   => 'IgnoreProjectBase,',
171
    'itso'                  => 'IgnoreProjectBase,',
2450 dpurdie 172
#    'daf_osa_mos'           => 'IgnoreProjectBase,',
1197 dpurdie 173
    'daf_utils_mos'         => 'IgnoreProjectBase,',
174
    'itso_ud'               => 'IgnoreProjectBase,',
175
#    'mos_api'               => 'IgnoreProjectBase,',
176
#    'mos_fonts'             => 'IgnoreProjectBase,',
177
#    'sntp'                  => 'IgnoreProjectBase,',
178
#    'time_it'               => 'IgnoreProjectBase,',
392 dpurdie 179
);
180
 
181
my %notCots = (
182
    'isl'       => 1,
183
);
184
 
1451 dpurdie 185
my $ukHopsMode = 0;
186
my %ukHopsReleases = (
187
    '6222'      => { name => 'MainLine', 'trunk' => 1 },
1453 dpurdie 188
    '14503'     => { name => 'Hops3' },
189
    '21864'     => { name => 'Hops3.6' },
190
    '22303'     => { name => 'Hops3.7' },
1451 dpurdie 191
    '17223'     => { name => 'Hops4' },
192
);
193
 
2016 dpurdie 194
# The following packages will have the version in the specified release forced to be on the trunk
195
# A trunk will be forced and the version will be on it.
196
#   May only work if the version in the release is also a TIP
197
my %ukHopsTip = (
198
    'ItsoMessaging'         => '6222',
199
    'MessageProcessor'      => '6222',
200
    'StrongNameKey'         => '6222',
201
);
202
 
392 dpurdie 203
################################################################################
204
#   Global data
205
#
206
my $VERSION = "1.0.0";
207
my $RM_DB;
208
my $last_pv_id;
209
my %pkg_ids;
210
my $first_pkg_id;
211
my %versions;
212
my %suffixes;
213
my @processOrder;
214
my @startPoints;
215
my @allStartPoints;
216
my @endPoints;
217
my $now = time();
218
my $logSummary;
219
my $firstVersionCreated;
220
my @EssentialPackages;
221
my $createBranch;
222
my $createSuffix;
223
my $currentBranchName;
224
my $singleProject;
225
my $pruneCount = 0;
226
my $trimCount = 0;
227
my $badVcsCount = 0;
228
my $ProjectCount = 0;
229
my $totalVersions = 0;
230
my $initialTrees = 0;
231
my $globalError;
232
my @unknownProjects;
233
my %knownProjects;
234
my $badSingletonCount = 0;
235
my @flatOrder;
236
my $pruneMode;
237
my $pruneModeString;
238
my $threadId = 0;
239
my $threadCount;
240
my %tipVersions;
241
my $allSvn;
242
my @multiplePaths;
243
my @badEssentials;
244
my %svnData;
245
my $cwd;
2429 dpurdie 246
my $mustConvertFileNames;
247
my $workDir;
392 dpurdie 248
 
249
my $packageNames;
250
my @packageNames;
251
my $multiPackages = -1;
252
my $visitId = 0;
253
my $noTransfer;
254
my $rippleCount = 0;
255
my $svnRepo;
1270 dpurdie 256
my $processCount = 0;
257
my $processTotal = 0;
1272 dpurdie 258
my $recentCount = 0;
2429 dpurdie 259
my $packageReLabelCount = 0;
260
my %saneLabels;
2478 dpurdie 261
my $adjustedPath = 0;
392 dpurdie 262
 
263
our $GBE_RM_URL;
264
my $UNIX = $ENV{'GBE_UNIX'};
265
 
266
my $result = GetOptions (
267
                "help+"         => \$opt_help,          # flag, multiple use allowed
268
                "manual:3"      => \$opt_help,
269
                "verbose:+"     => \$opt_verbose,       # Versose
270
                "repository:s"  => \$opt_repo,          # Name of repository
1272 dpurdie 271
                'rbase:s'       => \$opt_repo_base,     # Base of the repo
392 dpurdie 272
                "flat!"         => \$opt_flat,          # Flat structure
273
                "test!"         => \$opt_test,          # Test operations
274
                "reuse!"        => \$opt_reuse,         # Reuse ClearCase views
275
                "age:i"         => \$opt_age,           # Only recent versions
276
                "dump:1"        => \$opt_dump,          # Dump Data
277
                "images:1"      => \$opt_images,        # Create DOT images
278
                "retain:i"      => \$opt_retaincount,   # Retain N packages
279
                "pruneMode:s"   => \$opt_pruneModeString,
280
                "listtags:i"    => \$opt_listTags,
281
                "name:s"        => \$opt_name,          # Alternate output
282
                "tip:s"         => \@opt_tip,           # Force tip version(s)
283
                "log!"          => \$opt_log,
1270 dpurdie 284
                "delete!"       => \$opt_delete,
392 dpurdie 285
                "postimage!"    => \$opt_postimage,
286
                'workdir:s'     => \$opt_workDir,
2429 dpurdie 287
                'relabel!'      => \$opt_relabel,
2450 dpurdie 288
                'svn!'          => \$opt_useSvn,
289
                'testRmDatabase'    => \$opt_testRmDatabase,
2478 dpurdie 290
                'fromSvn!'          => \$opt_extractFromSvn,
392 dpurdie 291
                );
292
 
293
#
294
#   Process help and manual options
295
#
296
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
297
pod2usage(-verbose => 1)  if ($opt_help == 2 );
298
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
299
 
300
#
301
#   Configure the error reporting process now that we have the user options
302
#
303
SystemConfig ('ExitOnError' => 1);
304
ErrorConfig( 'name'    =>'CC2SVN_IMPORT',
305
             'verbose' => $opt_verbose,
306
              );
307
 
308
Error("Workdir does not exist" ) unless ( -d $opt_workDir );
309
Error("Specify a package as 'name'" ) unless ( defined $ARGV[0] );
310
EnvImport('GBE_RM_URL');
311
$cwd = Getcwd();
312
 
313
#
2450 dpurdie 314
#   Allow use of the test database
315
#   Defaut is live data, but some error recovery stuff can be done via
316
#   the test database.
317
#
318
if ( $opt_testRmDatabase )
319
{
320
    Warning ("Using Test Database");
321
    $ENV{GBE_RM_USERNAME} = 'RELEASE_MANAGER';
322
    $ENV{GBE_RM_PASSWORD} = 'RELEASE_MANAGER';
323
    $ENV{GBE_RM_LOCATION} = 'jdbc:oracle:thin:@auperaora07.vix.local:1521:RELMANU1';
324
}
325
 
326
#
392 dpurdie 327
#   Init the pruning mode
328
#
329
setPruneMode( $opt_pruneModeString || 'ripple');
330
 
331
#
332
#   Get data for all packages
333
#
334
foreach my $packageName ( @ARGV )
335
{
336
    next unless ( $packageName );
337
    Verbose( "Base Package: $packageName");
338
 
339
    my $pkg_id = GetPkgIdByName ( $packageName );
340
    GetData_by_pkg_id ( $pkg_id, $packageName  );
341
    $pkg_ids{$pkg_id} = 1;
342
    $first_pkg_id = $pkg_id unless ( $first_pkg_id );
343
    push @packageNames, $packageName;
344
    $multiPackages++;
345
}
346
 
347
{
348
    #
349
    #   Delete entries that have been created as we read in
350
    #   data, but don't exist in RM. They will not have a pvid.
351
    #
352
    foreach my $entry ( keys(%versions) )
353
    {
354
        delete $versions{$entry}
355
            unless ( exists $versions{$entry}{pvid} );
356
    }
357
}
358
 
359
$totalVersions = scalar keys %versions;
360
Error ("No packages specified") unless ( $multiPackages >= 0 );
361
Warning ("Multiple Packages being processed") if ( $multiPackages > 1 );
362
$packageNames = join ('_', @packageNames );
363
$packageNames = $opt_name if ( defined $opt_name );
364
Message ("PackageName: $packageNames" );
365
 
366
#
367
#   Save logging data
368
#
369
if ( $opt_log )
370
{
371
    my $opt_logfile = $packageNames . '.import';
372
    Message ("Logging outout: $opt_logfile" );
373
    open STDOUT, '>', $opt_logfile  or die "Can't redirect STDOUT: $!";
374
    open STDERR, ">&STDOUT"         or die "Can't dup STDOUT: $!";
375
}
376
 
377
#
378
#   Prepare tip version hash
379
#
380
$tipVersions{$_} = 1 foreach ( @opt_tip );
381
 
382
#
383
#   Read in external data and massage it all
384
#
385
getEssenialPackageVersions();
386
getVobMapping();
387
smartPackageType();                 # Determine special prune mode
388
ReportPathVariance();
389
massageData();
390
getSvnData();
391
smartPackageType();                 # Have another go
392
 
393
my @missedTips = keys %tipVersions;
394
Error ("Specified tip version not found: @missedTips") if ( @missedTips );
395
 
396
if ( $opt_flat )
397
{
398
#    @flatOrder = sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions);
399
#    @flatOrder = sort {$versions{$a}{created} cmp $versions{$b}{created}} keys(%versions);
400
    @flatOrder = sort {$a <=> $b} keys(%versions);
401
    my $tip = $flatOrder[-1];
402
    $versions{$tip}{Tip} = 1 if $tip;
403
}
404
 
405
#
406
#   Generate dumps and images
407
#
408
if ( $opt_images )
409
{
410
    createImages();
411
}
412
 
413
if ( $opt_dump )
414
{
415
    DebugDumpData ("Versions", \%versions );
416
    DebugDumpData ("Starts", \@startPoints );
417
    DebugDumpData ("Ends", \@endPoints );
418
    DebugDumpData ("Suffixes", \%suffixes );
419
}
420
 
421
 
422
#   Display VCS tags
423
#
424
if ( $opt_listTags )
425
{
426
    foreach my $entry (sort {$versions{$a}{version} cmp $versions{$b}{version}} keys(%versions) )
427
    {
428
        print $versions{$entry}{vcsTag} || '-' ,"\n";
429
    }
430
}
431
exit if ( ($opt_dump > 1) || ($opt_images > 1) );
432
 
433
transferPackageToSvn();
434
 
435
if ( $opt_postimage )
436
{
437
    getSvnData();
438
    createImages();
439
}
440
 
441
exit 0;
442
 
443
#-------------------------------------------------------------------------------
444
# Function        : transferPackageToSvn
445
#
446
# Description     : Transfer the package to SVN
447
#
448
# Inputs          : 
449
#
450
# Returns         : 
451
#
452
sub transferPackageToSvn
453
{
454
    Error ("Repository Path not setup")
455
        unless ( $svnRepo );
456
 
457
    #
458
    #   Going to do serious work
459
    #   Need to ensure we have more arguments
460
    #
2450 dpurdie 461
    if ( $opt_protected )
462
    {
463
        Warning("Protected Package not transferred: $packageNames[0] - $opt_protected",
464
                "See cc2svn_protected.txt for details");
465
        exit 0;
466
    }
467
 
392 dpurdie 468
    if ( $noTransfer )
469
    {
2450 dpurdie 470
        Warning("Protected Package not transferred: $packageNames[0]",
471
                "Configured within this program");
392 dpurdie 472
        exit 0;
473
    }
474
 
475
    #
476
    #   Perform all the work in a package specific subdirectory
477
    #
2429 dpurdie 478
    $workDir = $opt_workDir . '/' . $packageNames;
392 dpurdie 479
    mkdir $workDir unless ( -d $workDir );
480
    chdir $workDir || Error ("Cannot cd to $workDir");
481
 
482
    #
483
    #   Process all packages
484
    #       Going to create versions based on RM structure
485
    #       May have several starting points: Process each
486
    #
487
    newPackage();
488
    if ( $opt_flat )
489
    {
490
        newProject();
491
        foreach my $entry (@flatOrder )
492
        {
493
            newPackageVersion( $entry, $versions{$entry}{suffix} );
494
        }
495
    }
496
    else
497
    {
498
        processBranch(@allStartPoints);
499
    }
500
    endPackage();
501
 
502
    chdir $cwd || Error ("Cannot cd back to $cwd");
503
    rmdir $workDir;
504
    Warning ("Work Directory still exists: $workDir");
505
    saveData();
506
}
507
 
508
#-------------------------------------------------------------------------------
509
# Function        : setPruneMode
510
#
511
# Description     : Set the pruning mode
512
#
513
# Inputs          : mode                    - Text mode value
514
#
515
# Returns         : Nothing
516
#
517
sub setPruneMode
518
{
519
    my ($mode) = @_;
520
    my $value;
521
    if ( $mode )
522
    {
523
        if ( $mode =~ m/none/i) {
524
            $value = 0;
525
        } elsif ( $mode =~ m/ripple/i) {
526
            $value = 1;
527
        } elsif ( $mode =~ m/retain/i) {
528
            $value = 2;
529
        } elsif ( $mode =~ m/severe/i) {
530
            $value = 3;
531
        } else {
532
            Error ("Unknown pruning mode", "Use: none, ripple, retain or severe");
533
        }
534
 
535
        $pruneModeString = $mode;
536
        $pruneMode = $value;
537
    }
538
}
539
 
540
#-------------------------------------------------------------------------------
541
# Function        : smartPackageType
542
#
543
# Description     : Have a look at the projects in the package set and
544
#                   attempt to determine what sort of mechanism to use
545
#
546
# Inputs          : Uses %suffixes data
547
#
548
# Returns         : 
549
#
550
my $packageType = 'UNKNOWN';
551
sub smartPackageType
552
{
553
    #
554
    #   Rebuild suffixes hash based on  post massaged versions
555
    #
556
    my %suffixes;
557
    my @unknown;
558
    foreach my $entry ( keys %versions )
559
    {
560
        my $suffix = $versions{$entry}{suffix} || '';
561
        push (@unknown, $entry) if ($suffix eq 'unknown');
562
 
563
        next if ( exists $suffixes{$suffix} );
564
        next if ( $versions{$entry}{badSingleton} );
565
        next if ( $versions{$entry}{locked} eq 'N' || $versions{$entry}{isaWip} );
566
        $suffixes{$suffix} = 1;
567
        $knownProjects{$suffix}{seen} = 1;
568
 
569
    }
570
 
571
    #
572
    #   The 'unknown' suffix is really an 'empty' suffix
573
    #   Try to be clever
574
    #       Map unknown to 'cr' or 'mas' if present
575
    #
576
    #
577
    if ( exists $suffixes{'unknown'}  )
578
    {
579
        my $new_suffix;
580
        if ( exists $suffixes{'.cr'} ) {
581
            $new_suffix = '.cr';
582
        } elsif ( exists $suffixes{'.mas'} ) {
583
            $new_suffix = '.mas';
584
        }
585
 
586
        if ( $new_suffix )
587
        {
588
            foreach my $entry ( @unknown )
589
            {
590
                $versions{$entry}{suffix} = $new_suffix;
591
            }
592
            delete $suffixes{'unknown'};
593
            delete $knownProjects{'unknown'}{seen};
594
        }
595
    }
596
 
597
    if ( exists $suffixes{'.cots'} && !exists ($notCots{$packageNames}) ) {
598
        $packageType = 'COTS';
599
        $Projects{'.cots'}{Trunk} = 1;
600
        $singleProject = 1;
601
        $opt_flat = 1 unless defined $opt_flat;
602
        setPruneMode('none') unless (defined $opt_pruneModeString);
603
 
604
    } elsif ( exists $suffixes{'.tool'} ) {
605
        $packageType = 'TOOL';
2016 dpurdie 606
        $Projects{'.tool'}{Trunk} = 1;
392 dpurdie 607
        $singleProject = 1;
608
        setPruneMode('none') unless (defined $opt_pruneModeString);
609
#        $opt_flat = 1;
610
 
611
    } elsif ( scalar (keys %suffixes ) == 1 ) {
612
        $packageType = 'SINGLE_PROJECT';
613
        $singleProject = 1;
614
 
615
    } else {
616
        $packageType = 'MULTIPLE_PROJECT';
617
    }
618
 
619
    #
620
    #   Some packages are special
621
    #
2429 dpurdie 622
    if ( $svnRepo =~ m~/Manufacturing(/|$)~ )
623
    {
624
        Message ("Set Manufacturing Repo style");
625
        $opt_flat = 1;
626
        setPruneMode('none') unless (defined $opt_pruneModeString);
627
    }
392 dpurdie 628
 
2429 dpurdie 629
 
392 dpurdie 630
    if ( $packageNames[0] =~ m'^br_applet_' )
631
    {
2429 dpurdie 632
      $opt_flat = 1 unless defined $opt_flat;
392 dpurdie 633
    }
634
 
635
    if ( exists $specialPackages{$packageNames[0]} )
636
    {
637
        my $data = $specialPackages{$packageNames[0]};
638
        if ( index( $data, ',all' ) >= 0) {
639
            setPruneMode('none') unless (defined $opt_pruneModeString);
640
        }
641
 
642
        if ( index( $data, 'protected,' ) >= 0) {
643
            $noTransfer = 1;
644
        }
645
 
646
        if ( index( $data, 'flat,' ) >= 0) {
647
            $opt_flat = 1;
648
        }
1197 dpurdie 649
 
650
        if ( index( $data, 'SetProjectBase,' ) >= 0) {
651
            $opt_preserveProjectBase = 1;
652
            $opt_ignoreProjectBaseErrors = 1;
653
            Message ("Preserving ProjectBase");
654
        }
655
 
656
        if ( index( $data, 'IgnoreProjectBase,' ) >= 0) {
657
            $opt_ignoreProjectBaseErrors = 1;
658
            Message ("Ignore ProjectBase Errors");
659
        }
660
 
2429 dpurdie 661
        if ( index( $data, 'IgnoreMakeProject,' ) >= 0) {
662
            $opt_ignoreMakeProjectErrors = 1;
663
            Message ("Ignore MakeProject Usage");
664
        }
2478 dpurdie 665
 
666
        if ( index( $data, 'IgnoreBadPath,' ) >= 0) {
667
            $opt_ignoreBadPaths = 1;
668
            Message ("Ignore Bad Paths in makefilest Usage");
669
        }
2429 dpurdie 670
 
671
        if ( index( $data, 'utf8,' ) >= 0) {
672
            $mustConvertFileNames = 1;
673
            Message ("Convert filenames to UTF8");
674
        }
392 dpurdie 675
    }
676
 
677
    Message("Package Type: $packageType, $pruneModeString");
678
}
679
 
680
 
681
#-------------------------------------------------------------------------------
682
# Function        : massageData
683
#
684
# Description     : Massage all the data to create a tree of package versions
685
#                   that can be used to create images as well as an import order
686
#
687
# Inputs          : 
688
#
689
# Returns         : 
690
#
691
my $reprocess=0;
692
sub calcLinks
693
{
694
    #
695
    #   Process the 'versions' hash and:
696
    #   Add back references
697
    #   Find starts and ends
698
    #       Entry with no previous
699
    #       Entry with no next
700
    #
701
    $reprocess = 0;
702
    foreach my $entry ( keys(%versions) )
703
    {
704
        foreach ( @{ $versions{$entry}{next}} )
705
        {
706
            $versions{$_}{last} = $entry;
707
        }
708
    }
709
    @allStartPoints = ();
710
    @startPoints = ();
711
    @endPoints = ();
712
    foreach my $entry ( keys(%versions) )
713
    {
714
        push @startPoints, $entry
715
            unless ( exists $versions{$entry}{last} || $versions{$entry}{badSingleton} );
716
 
717
        push @allStartPoints, $entry
718
            unless ( exists $versions{$entry}{last} );
719
 
720
        push @endPoints, $entry
721
            unless ( @{$versions{$entry}{next}} > 0  )
722
    }
723
}
724
 
725
sub massageData
726
{
727
    #
728
    #   Report unknown suffixes
729
    #   Handle bad, or little known project suffixes by creating them
730
    #
731
    foreach my $suffix ( keys %suffixes )
732
    {
733
        if ( exists $Projects{$suffix} )
734
        {
735
            next;
736
        }
737
        Message ("Unknown project suffix: '$suffix'");
738
        push @unknownProjects, $suffix;
739
        my $cleanSuffix = ucfirst(lc(substr( $suffix, 1)));
740
        $Projects{$suffix}{Name} = 'Project_' . $cleanSuffix;
741
    }
742
 
743
    calcLinks();
744
 
745
    $initialTrees = scalar @allStartPoints;
746
    Message ('Total RM versions: ' . $totalVersions );
747
    Message ('Initial trees: ' . $initialTrees );
748
    #
749
    #   Attempt to glue all the start points into one chain.
750
    #   This should allow us to track projects that branch from each other
751
    #   in cases where the RM data is incorrect/incomplete
752
    #       Strays are those that have no next or last
753
    #
754
    #   Glue based on Name, then PVID (Creation Order)
755
    #
756
    {
757
        #
758
        #   Examine threads. If it is a single entry thats bad then drop it
759
        #   This is simple to do. Should examine all entries, but thats a
760
        #   bit harder. Perhaps later.
761
        #
762
        if (1) {
763
            Message ("Dropping Bad Singletons");
764
            my $badSingletons;
765
            foreach my $entry ( sort {$a <=> $b} @startPoints )
766
            {
767
                my $ep = $versions{$entry};
768
                unless ( $ep->{last} || $ep->{next}[0] )
769
                {
770
#                    if (  $ep->{isaWip}  )
771
                    if ( (exists $ep->{badVcsTag} && $ep->{badVcsTag}) || $ep->{isaWip}  )
772
                    {
773
                        $ep->{badSingleton} = 1;
774
                        $reprocess = 1;
775
                        $badSingletonCount++;
776
 
777
                        # Add to a list of its own.
778
                        if ( $badSingletons )
779
                        {
780
                            push @{$versions{$badSingletons}{next}}, $entry;
781
                        }
782
                        $badSingletons = $entry;
783
                    }
784
                }
785
            }
786
            calcLinks()
787
                if ( $reprocess );
788
        }
789
 
790
        #
791
        #   Create simple trees out of the chains
792
        #   Tree is based on suffix (project) and version
793
        #
794
        {
795
            my %trees;
796
            Message ("Entries into trees");
797
            foreach my $single ( @startPoints )
798
            {
799
                my $suffix = $versions{$single}{suffix} || '';
800
                push @{$trees{$suffix}}, $single;
801
            }
802
 
803
            foreach  ( keys %trees )
804
            {
805
                my $last;
806
                foreach my $entry ( sort { $versions{$a}{version} cmp $versions{$b}{version}  } @{$trees{$_}} )
807
                {
808
                    if ( $last )
809
                    {
810
                        $versions{$last}{MakeTree} = 1;
811
                        push @{$versions{$last}{next}}, $entry;
812
                        $reprocess = 1;
813
                    }
814
                    $last = $entry;
815
                }
816
            }
817
            calcLinks()
818
                if ( $reprocess );
819
        }
820
 
821
        #
822
        #   Have a number of trees that are project related
823
        #   Attempt to create a single tree by inserting
824
        #   Secondary trees into the main line at suitable points
825
        #
826
        my @AllVersions = sort { $a <=> $b } @startPoints;
827
        my $lastEntry = shift @AllVersions;
828
        Error ("Oldest entry has a previous version") if ( $versions{$lastEntry}{last}  );
829
#print "Oldest: $lastEntry\n";
830
        #
831
        #   Insert remaining entries into out list, which is now sorted
832
        #
833
        my @completeList;
834
        foreach my $base ( @AllVersions  )
835
        {
836
            push @completeList, recurseList($lastEntry);
837
            @completeList = sort {$a <=> $b} @completeList;
838
#            Message("Complete List: ", @completeList);
839
#            Message("Complete List($completeList[0]) Length: " . scalar @completeList);
840
            $lastEntry = $base;
841
 
842
            my $last;
843
            foreach my $entry ( @completeList )
844
            {
845
                if ( $entry > $base )
846
                {
847
                    Error ("Not expecting last to be empty. $base, $entry") unless ( $last );
848
                    last;
849
                }
850
                $last = $entry;
851
            }
852
 
853
            #
854
            #   Insert at end if point not yet found
855
            #
856
#print "Inserting $base at $last\n";
857
            push @{$versions{$last}{next}}, $base;
858
            $versions{$base}{GluedIn} = 1;
859
            $reprocess = 1;
860
        }
861
 
862
        #
863
        #   Recalc basic links if any processing done
864
        #
865
        calcLinks()
866
            if ( $reprocess );
867
 
868
    }
869
 
870
 
871
    #
872
    #   Remove Dead Ends
873
    #   Packages that were never released
874
    #       Not locked, unless essential or a branchpoint
875
    #   Won't consider these to be mainline path.
876
    #
877
    {
878
        Message ("Remove Dead Ends");
879
        foreach my $entry ( @endPoints )
880
        {
881
            my $deadWood;
882
            while ( $entry )
883
            {
884
                last if ( $versions{$entry}{Essential} );
885
 
886
                my @next = @{$versions{$entry}{next}};
887
                my $count = @next;
888
                last if ( $count > 1 );
889
 
890
                last unless ( $versions{$entry}{locked} eq 'N' || $versions{$entry}{isaWip} );
891
 
892
                $versions{$entry}{DeadWood} = 1;
893
                $trimCount++;
894
            } continue {
895
                $entry = $versions{$entry}{last};
896
            }
897
        }
898
    }
899
 
900
    #
901
    #   Walk each starting point list and determine new Projects
902
    #   branchpoints.
903
    #
904
    Message ("Locate Projects branch points");
905
    foreach my $bentry ( keys(%versions) )
906
    {
907
        my $baseSuffix = $versions{$bentry}{suffix};
908
        foreach my $entry ( @{$versions{$bentry}{next}} )
909
        {
910
            if ( $baseSuffix ne $versions{$entry}{suffix})
911
            {
912
                unless ( exists $versions{$entry}{DeadWood} || $versions{$entry}{badSingleton} )
913
                {
914
#print "--- Project Branch $versions{$entry}{vname}\n";
915
                    $versions{$entry}{branchPoint} = 1;
916
                    $versions{$entry}{newSuffix} = 1;
917
                }
918
            }
919
        }
920
    }
1451 dpurdie 921
 
922
    #
923
    #   Mark UkHops special points
924
    #
925
    foreach my $entry ( keys(%versions) ) {
926
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
927
            next unless ( exists $ukHopsReleases{$rtag_id} );
928
            next unless ( $svnRepo =~ m~/ITSO_TRACS$~ );
929
 
930
            #
931
            #   This package is current in a special ukHops release
932
            #   Need to handle the differently
933
            #
934
            my $ukData =  $ukHopsReleases{$rtag_id};
935
 
936
            # Mark version we want on the trunk
937
            # Will calculate tip later
938
            if ( $ukData->{trunk} )
939
            {
940
                #
941
                #   Can only place on trunk IFF its a tip
942
                #   May have a WIP.
943
                #   Solution. Walk to the tip, but only if there is one
944
                #             path.
945
                #
946
                my $end = $entry;
947
                my $last;
948
                while ( $end )
949
                {
950
                    $last = $end;
951
                    if ( @{$versions{$end}{next}} > 1)
952
                    {
953
                        Warning ("Uk Release. Preferred trunk is not a tip: $versions{$entry}{vname}");
954
                        last;
955
                    }
956
 
957
                    $end = @{$versions{$end}{next}}[0];
958
                }
959
                $versions{$last}{ukTrunk} = 1 ;
960
            }
961
 
962
            #
963
            #   What to do if the version is in more than one release
964
            #
965
            $versions{$entry}{ukBranch}++;
966
            if ( $versions{$entry}{ukBranch} > 1 )
967
            {
968
                Warning ("Version found in multiple Uk Releases - don't know what to do");
969
            }
970
 
971
            #
972
            #   What to do if the package has multiple version in a release
973
            #
974
            $ukData->{count}++;
975
            if ( $ukData->{count} > 1 )
976
            {
977
                Warning ("Package has multiple versions in the one Uk Release: $versions{$entry}{Releases}{$rtag_id}{rname}");
978
            }
979
        }
980
    }
392 dpurdie 981
 
982
    #
983
    #   Prune
984
    #   Marks paths to root for all essential packages
985
    #   Marks the last-N from all essential packages
986
    #
987
    if ( $pruneMode )
988
    {
989
        Message ("Prune Tree: $pruneModeString");
990
        foreach ( @EssentialPackages )
991
        {
992
            #next unless ( exists $versions{$_} );      # Aleady deleted
993
 
994
            # Mark previous-N to be retained as well
995
            my $entry = $_;
996
            my $count = 0;
997
            while ( $entry )
998
            {
999
                last if ( $versions{$entry}{KeepMe} );
1453 dpurdie 1000
#                unless ( $versions{$entry}{isaRipple} )
392 dpurdie 1001
                {
1002
                    my $keepFlag = ($count++ < $opt_retaincount);
1003
                    last unless ( $keepFlag );
1004
                    $versions{$entry}{KeepMe} = $keepFlag;
1005
                }
1006
                $entry = $versions{$entry}{last}
1007
            }
1008
        }
1009
 
1010
        #
1272 dpurdie 1011
        #   Keep recent versions
1012
        #       Keep versions created in the last N days
1013
        #       Will keep recent ripples too
1014
        #
1015
        if ( $pruneMode == 1 )
1016
        {
1017
            foreach my $entry ( keys(%versions) )
1018
            {
1019
                next unless ( $versions{$entry}{Age} <= $opt_recentAge  );
1020
                $versions{$entry}{keepRecent} = 1;
1021
                $recentCount++;
1022
#print "--- Recent version $versions{$entry}{vname}, $versions{$entry}{Age} <= $opt_recentAge\n";
1023
            }
1024
 
1025
#            #
1026
#            #   Keep the tip of each branch
1027
#            #
1028
#            foreach my $entry ( @endPoints )
1029
#            {
1030
#                next if exists $versions{$entry}{keepRecent};
1031
#                $versions{$entry}{keepRecent} = 1;
1032
##print "--- Tip version $versions{$entry}{vname}\n";
1033
#            }
1034
        }
1035
 
1036
        #
392 dpurdie 1037
        #   Keep versions that are common parents to Essential Versions
1038
        #       Mark paths through the tree to essential versions
1039
        #       Mark nodes with the number of essential versions that they sprout
1040
        #   Don't do it if we are ripple pruning
1041
        #
1042
        Message ("Prune Tree keep common parents");
1043
        if ( $pruneMode != 1 )
1044
        {
1045
            foreach my $entry ( @endPoints )
1046
            {
1047
                my $hasEssential = 0;
1048
                $visitId++;
1049
                while ( $entry )
1050
                {
1051
                    $hasEssential = 1 if ( exists ($versions{$entry}{Essential}) && $versions{$entry}{Essential} );
1052
                    if ( $hasEssential )
1053
                    {
1054
                        if ( @{$versions{$entry}{next}} > 1 )
1055
                        {
1056
                            $versions{$entry}{EssentialSplitPoint}++;
1057
                        }
1058
                        last if ( exists $versions{$entry}{EssentialPath} );
1059
                        $versions{$entry}{EssentialPath} = 1;
1060
                    }
1061
 
1062
                    if ( ($versions{$entry}{visitId} || 0) == $visitId )
1063
                    {
1064
                        DebugDumpData ("Versions", \%versions );
1065
                        Warning ("Circular dependency");
1066
                        last;
1067
                    }
1068
                    $versions{$entry}{visitId} = $visitId;
1069
 
1070
                    $entry = $versions{$entry}{last};
1071
                }
1072
            }
1073
        }
1074
 
1075
        #
1076
        #   Keep first version of each ripple. Must keep first
1077
        #   Group ripples together so that they can be proccessed at the same time
1078
        #
1079
        calcRippleGroups()
1080
            if ( $pruneMode == 1);
1081
 
1082
        #
1083
        #   Delete all nodes that are not marked for retention
1084
        #   This is rough on the tree
1085
        #
1086
        Message ("Prune Tree Deleting");
1087
 
1088
        # 0 - Keep me
1089
        # 1 - Prune me
1090
        sub pruneMe
1091
        {
1092
            my ($entry) = @_;
1093
 
1094
            return 0 unless ( exists $versions{$entry} );
1095
            return 0 unless ( $versions{$entry}{last} );
1454 dpurdie 1096
#            return 0 if ( ($pruneMode == 2) && exists $versions{$entry}{KeepMe} );
1097
            return 0 if ( exists $versions{$entry}{KeepMe} );
392 dpurdie 1098
            return 0 if ( exists $versions{$entry}{Essential} );
1099
            return 0 if ( $versions{$entry}{newSuffix} );
1100
            return 0 if ( $versions{$entry}{newSuffix} && (exists $versions{$entry}{EssentialPath}) );
1101
#            return 1 if ( exists $versions{$entry}{DeadWood} );
1102
            return 0 if ( exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
1103
            return 0 if ( exists $versions{$entry}{keepLowestRipple} &&  $versions{$entry}{keepLowestRipple} );
1104
            return 0 if ( ($pruneMode == 1) && ! $versions{$entry}{isaRipple} );
1272 dpurdie 1105
            return 0 if ( exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 1106
            return 1;
1107
        }
1108
 
1109
        foreach my $entry ( keys(%versions) )
1110
        {
1111
#last;
1112
            next unless ( pruneMe($entry) );
1113
#print "--- Prune: $versions{$entry}{vname}\n";
1114
 
1115
            # Delete the current node
1116
            #
1117
            my @newNext;
1118
            $pruneCount++;
1119
            my $last = $versions{$entry}{last};
1120
            foreach ( @{$versions{$last}{next}} )
1121
            {
1122
                next if ( $_ == $entry );
1123
                push @newNext, $_;
1124
            }
1125
            foreach ( @{$versions{$entry}{next}} )
1126
            {
1127
                push @newNext, $_;
1128
                $versions{$_}{last} = $last;
1129
            }
1130
 
1131
            @{$versions{$last}{next}} = @newNext;
1132
            delete $versions{$entry};
1133
        }
1134
 
1135
        # Recalculate endpoints
1136
        calcLinks();
1137
    }
1138
    else
1139
    {
1140
        #   No rippling happening
1141
        #   Some process still need to happen
1142
        #
1143
        calcRippleGroups();
1144
    }
1145
 
1146
    #
2016 dpurdie 1147
    #   Want some versions to be forced to tip trunk
1148
    #
1149
    foreach my $name ( keys %ukHopsTip )
1150
    {
1151
        foreach my $entry ( keys(%versions) )
1152
        {
1153
            next unless ( $versions{$entry}{name} eq $name  );
1154
            next unless ( exists $versions{$entry}{Releases}{$ukHopsTip{$name}} );
1155
 
1156
            #
1157
            #   Force this suffix to be the trunk
1158
            #   Remove all others
1159
            #
1160
            foreach my $suffix ( keys %Projects )
1161
            {
1162
                delete $Projects{$suffix}{Trunk};
1163
            }
1164
            my $suffix = $versions{$entry}{suffix};
1165
            $Projects{$suffix}{Trunk} = 1;
1166
        }
1167
    }
1168
 
1169
    #
392 dpurdie 1170
    #   Calculate best through-path for branches in the tree
1171
    #   Attempt to keep that 'max' version on the mainline
1172
    #   May be modified by -tip=nnnn
1173
    #
1174
    #   For each leaf (end point), walk backwards and mark each node with the
1175
    #   max version see. If we get to a node which already has been marked then
1176
    #   stop if our version is greater. We want the value to be the max version
1177
    #   to a leaf
1178
    #
1179
    #   Account for 'suffix'. When suffix changes, then the 'max' version must
1180
    #   be recalculated
1181
    #
1182
 
1183
    Message ("Calculate Max Version");
1184
    my $maxVersion;
1185
    foreach my $entry ( @endPoints )
1186
    {
1187
        my $lastSuffix;
1188
        my $forceTip;
1189
        while ( $entry )
1190
        {
1191
            if (!defined($lastSuffix) || ($versions{$entry}{suffix} ne $lastSuffix) )
1192
            {
1193
                $maxVersion = '0';
1194
                $visitId++;
1195
                $forceTip = ( exists $tipVersions{$versions{$entry}{vname}} );
1451 dpurdie 1196
                $forceTip = 1 if $versions{$entry}{ukTrunk};
392 dpurdie 1197
                delete $tipVersions{$versions{$entry}{vname}};
1198
                $maxVersion = '999.999.999.999.zzz' if ( $forceTip );
1199
                $lastSuffix = $versions{$entry}{suffix};
1200
#print "---Tip Found\n" if $forceTip;
1201
            }
1202
 
1203
            # Detect circular dependencies
1204
            if ( ($versions{$entry}{visitId} || 0) == $visitId )
1205
            {
1206
                DebugDumpData ("Circular dependency: Versions", \%versions );
1207
                Warning ("Circular dependency");
1208
                last;
1209
            }
1210
            $versions{$entry}{visitId} = $visitId;
1211
 
1212
            my $thisVersion = $versions{$entry}{version} || '';
1213
            if ( $thisVersion gt $maxVersion )
1214
            {
1215
                $maxVersion = $thisVersion;
1216
            }
1217
 
1218
            if ( exists $versions{$entry}{maxVersion} )
1219
            {
1220
                if ( $versions{$entry}{maxVersion} gt $maxVersion )
1221
                {
1222
                    last;
1223
                }
1224
            }
1225
 
1226
            $versions{$entry}{maxVersion} = $maxVersion;
1227
            $entry = $versions{$entry}{last};
1228
        }
1229
    }
1230
 
1231
 
1232
    #
1233
    #   Locate all instances where a package-version branches
1234
    #   Determine the version that should be on the non-branching path
1235
    #
1236
    #   Reorder the 'next' list so that the first item is the non-branching
1237
    #   path. This will be used in the data-insertion phase to simplify the
1238
    #   processing.
1239
    #
1240
    Message ("Calculate package version branches");
1241
    foreach my $entry ( sort {$a <=> $b} keys(%versions) )
1242
    {
1243
        calculateWalkOrder($entry);
1244
    }
1245
 
1246
    #
1247
    #   Mark Project Branch Tips as they will be in the Repository
1248
    #   Find each project head and walk primary entry to the end.
1249
    #
1250
    foreach my $entry ( keys(%versions) )
1251
    {
1252
        #
1253
        #   Root of each tree is 'new'
1254
        #
1255
        unless ( defined $versions{$entry}{last})
1256
        {
1257
            unless ( $versions{$entry}{badSingleton} )
1258
            {
1259
                $versions{$entry}{newSuffix} = 1;
1260
            }
1261
        }
1262
 
1263
        #
1264
        #   Update stats
1265
        #
1266
        $badVcsCount++ if ( $versions{$entry}{badVcsTag} );
1267
        $ProjectCount++ if ( $versions{$entry}{newSuffix} );
1268
        next if ( $opt_flat );
1269
 
1270
        next unless ($versions{$entry}{newSuffix} );
1271
#print "--- Project new Suffix $versions{$entry}{vname}\n";
1272
 
1273
 
1274
        my $suffix = $versions{$entry}{suffix};
1275
        $knownProjects{$suffix}{count}++;
1276
 
1277
        my $next = $versions{$entry}{next}[0];
1278
        my $tip;
1279
        while ( $next )
1280
        {
1281
            last if ( $suffix ne $versions{$next}{suffix} );
1282
            $tip = $next unless (exists ($versions{$next}{DeadWood}) || $versions{$next}{badSingleton});
1283
            $next = $versions{$next}{next}[0];
1284
        }
1285
 
1286
        $versions{$tip}{Tip} = 1 if $tip;
1287
    }
1288
 
1289
    unless ( $opt_flat )
1290
    {
1291
        my $finalTrees = scalar @startPoints;
1292
        Warning ("Still have multiple trees: $finalTrees") unless ( $finalTrees == 1 );
1293
    }
1294
 
1295
    #
1296
    #   Display warnings about multiple
1297
    #
1298
    foreach ( sort keys %knownProjects )
1299
    {
1300
        my $count = $knownProjects{$_}{count} || 0;
1301
        Warning ("Multiple Project Roots: $_ ($count)" )
1302
            if ( $count > 1 );
1303
    }
1304
 
1305
    #
1306
    #   Display warnings about Bad Essential Packages
1307
    #
1308
    $allSvn = 1;
1309
    foreach my $entry ( keys(%versions) )
1310
    {
1311
        $rippleCount++ if ( exists($versions{$entry}{isaRipple}) && $versions{$entry}{isaRipple} );
1312
        $allSvn = 0 unless ( $versions{$entry}{isSvn} );
1313
        next unless ( exists $versions{$entry}{Essential}  );
1314
        next unless ( $versions{$entry}{badVcsTag}  );
1315
        push @badEssentials, $entry;
1316
        Warning ("BadVCS Essential: " . GetVname($entry))
1317
    }
1318
 
1319
    #
1320
    #   All done
1321
    #
1270 dpurdie 1322
    $processTotal = scalar keys %versions;
1323
    Message("Retained entries: $processTotal" );
392 dpurdie 1324
    Message("Pruned entries: $pruneCount");
1325
    Message("Deadwood entries: $trimCount");
1326
    Message("Bad Singletons: $badSingletonCount");
1327
    Message("Ripples: $rippleCount");
1272 dpurdie 1328
    Message("Recent entries: $recentCount");
392 dpurdie 1329
}
1330
 
1331
sub calculateWalkOrder
1332
{
1333
    my ($entry) = @_;
1334
    my @next = @{$versions{$entry}{next}};
1335
    my $count = @next;
1336
    my @ordered;
1337
    my $main;
1338
 
1339
    if ( $count > 1 )
1340
    {
1341
        # Array to hash to simplify removal
1342
        my %nexts = map { $_ => 1 } @next;
1343
        foreach my $e ( @next )
1344
        {
1345
 
1346
            #
1347
            #   Locate branch points that are not a part of a new project
1348
            #   These will not be preferred paths for walking
1349
            #
1350
            if ( !defined($versions{$e}{branchPoint}) && $versions{$entry}{suffix} ne $versions{$e}{suffix} )
1351
            {
1352
                unless ( exists $versions{$e}{DeadWood} || $versions{$e}{badSingleton}  )
1353
                {
1354
#print "--- Project Branch (1) $versions{$e}{vname}\n";
1355
                    $versions{$e}{branchPoint} = 1;
1356
                    $versions{$e}{newSuffix} = 1;
1357
                }
1358
            }
1359
 
1360
            #
1361
            #   Remove those that already have a branch,
1362
            #
1363
            if ( $versions{$e}{branchPoint} || $versions{$e}{newSuffix} || $versions{$e}{DeadWood}  )
1364
            {
1365
                push @ordered, $e;
1366
                delete $nexts{$e};
1367
            }
1368
        }
1369
        #
1370
        #   Select longest arm as the non-branching path
1371
        #   Note: Reverse sort order
1372
        #         Done so that 'newest' item is given preference
1373
        #         to the main trunk in cases where all subtrees are
1374
        #         the same length
1375
        #
1376
        my $maxData = '';
1377
        my $countEntry;
1378
        foreach my $e ( sort {$b <=> $a} keys %nexts )
1379
        {
1380
            if ( $versions{$e}{maxVersion} gt $maxData )
1381
            {
1382
                $maxData = $versions{$e}{maxVersion};
1383
                $countEntry = $e;
1384
            }
1385
        }
1386
        if ($countEntry)
1387
        {
1388
            $main = $countEntry;
1389
            delete $nexts{$countEntry};
1390
        }
1391
 
1392
        #
1393
        #   Append the remaining
1394
        #
1395
        push @ordered, keys %nexts;
1396
 
1397
        #
1398
        #   Re-order 'next' so that the main path is first
1399
        #   Sort (non main) by number
1400
        #
1401
        @ordered = sort {$a <=> $b} @ordered;
1402
        unshift @ordered, $main if ( $main );
1403
        @{$versions{$entry}{next}} = @ordered;
1404
 
1405
        #
1406
        #   Ensure all except the first are a branch point
1407
        #   First may still be a branch point
1408
        #
1409
        shift @ordered;
1410
        foreach my $e ( @ordered )
1411
        {
1412
            $versions{$e}{branchPoint} = 1;
1413
        }
1414
    }
1415
}
1416
 
1417
#-------------------------------------------------------------------------------
1418
# Function        : calcRippleGroups
1419
#
1420
# Description     : Locate and mark ripple groups
1272 dpurdie 1421
#                   packages that are ripples of each other
392 dpurdie 1422
#                       Keep first version of each ripple. Must keep first
1423
#                       Group ripples together so that they can be
1424
#                       proccessed at the same time
1425
#
1426
# Inputs          : 
1427
#
1428
# Returns         : 
1429
#
1430
sub calcRippleGroups
1431
{
1432
    my %rippleVersions;
1433
    foreach my $entry ( keys(%versions) )
1434
    {
1435
        my $ep = $versions{$entry};
1436
        if ( defined $ep->{buildVersion} )
1437
        {
1438
            my $suffix = $ep->{suffix};
1439
            my ($major, $minor, $patch, $build) = @{$ep->{buildVersion}};
1440
#print "--- $major, $minor, $patch, $build, $suffix\n";
1441
            $rippleVersions{$suffix}{"$major.$minor.$patch"}{count}++;
1442
            my $rp = $rippleVersions{$suffix}{"$major.$minor.$patch"};
1443
            $rp->{list}{$entry} = 1;
1444
 
1445
            next if ( $ep->{badVcsTag} );
1446
            next if ( $ep->{locked} eq 'N');
1447
            if (!defined ($rp->{min}) || $rp->{min} > $build )
1448
            {
1449
                $rp->{pvid} = $entry;
1450
                $rp->{min} = $build;
1451
            }
1452
        }
1453
    }
1454
#            DebugDumpData("rippleVersions", \%rippleVersions );
1455
 
1456
    while ( my($suffix, $e1) = each %rippleVersions )
1457
    {
1458
        while ( my( $mmp, $e2) = each %{$e1} )
1459
        {
1460
            next unless ( exists  $e2->{pvid} );
1461
            my $entry = $e2->{pvid};
1462
            if ( !exists $versions{$entry} )
1463
            {
1464
                Error ("Internal: Expected entry not found: $entry, $mmp");
1465
            }
1466
 
1467
            $versions{$entry}{keepLowestRipple} = 1;
1468
#print "--- Keep Riple $versions{$entry}{vname}\n";
1469
 
1470
            #
1471
            #   Update entry with list of associated ripples, removing lowest
1472
            #
1473
            delete $e2->{list}{$entry};
1474
            my @rippleList = sort keys %{$e2->{list}};
1475
            if ( @rippleList)
1476
            {
1477
#DebugDumpData("LIST: $entry", $e2->{list}, \@rippleList  );
1478
                @{$versions{$entry}{rippleList}} = @rippleList;
1479
            }
1480
        }
1481
    }
1482
}
1483
 
1484
#-------------------------------------------------------------------------------
1485
# Function        : processBranch
1486
#
1487
# Description     : Process one complete branch within the tree of versions
1488
#                   May be called recursivly to walk the tree
1489
#
1490
# Inputs          : Array of package-version ID to process
1491
#
1492
# Returns         : Nothing
1493
#
1494
 
1495
sub processBranch
1496
{
1497
    foreach my $entry ( @_ )
1498
    {
1499
        #
1500
        #   Do we need to create a branch before we can process this package
1501
        #
1502
        if ( $versions{$entry}{newSuffix} || $versions{$entry}{branchPoint} )
1503
        {
1504
            newProject();
1505
            $createBranch = 1;
1506
            $createSuffix = 1 if $versions{$entry}{newSuffix};
1507
        }
1508
 
1509
        newPackageVersion( $entry );
1510
no warnings "recursion";
1511
        processBranch (@{$versions{$entry}{next}});
1512
    }
1513
}
1514
 
1515
#-------------------------------------------------------------------------------
1516
# Function        : newPackageVersion
1517
#
1518
# Description     : Create a package version
1519
#
1520
# Inputs          : $entry              - Ref to entry being proccessed
1521
#
1522
# Returns         :
1523
#
1524
sub newPackageVersion
1525
{
1526
    my ($entry) = @_;
1527
    my %data;
1528
    my $flags = 'e';
1529
    my $rv = 1;
1530
    my $startTime = time();
1531
    my $timestamp = localtime;
1532
 
1533
    $data{rmRef} = 'ERROR';
1534
    $data{tag} = 'ERROR';
1535
 
1536
    #
1537
    #   If its been processed then fake that its been done
1538
    #   May have been a ripple that we processed
1539
    #
1270 dpurdie 1540
    return if ($versions{$entry}{Processed});
1541
    $processCount++;
392 dpurdie 1542
    Message ("------------------------------------------------------------------" );
1270 dpurdie 1543
    Message ("Package $processCount of $processTotal");
1544
 
392 dpurdie 1545
    Message ("New package-version: " . GetVname($entry) . " Tag: " . $versions{$entry}{vcsTag} );
1546
 
1328 dpurdie 1547
    #
1548
    #   Detect user abort
1549
    #
1550
    if ( -f $cwd . '/stopfile' )
1551
    {
1552
        $globalError = 1;
1553
        Message ("Stop file located");
1554
    }
392 dpurdie 1555
 
1556
    #
1557
    #   If we have a global error,then we pretend to process, but we
1558
    #   report errors for the logging system
1559
    #
1342 dpurdie 1560
    if ( $globalError )
392 dpurdie 1561
    {
1342 dpurdie 1562
        Message ("Global error prevents futher importation");
1563
    }
1564
    else
1565
    {
392 dpurdie 1566
        #
1567
        #   Call worker function
1568
        #   It will exist on any error so that it can be logged
1569
        #
1570
        $rv = newPackageVersionBody( \%data, @_ );
1571
        $globalError = 1 if ( $rv >= 10 );
1572
    }
1573
 
1574
    #
1575
    #   Highlight essential packages that failed to transfer
1576
    #
1577
    if ( $globalError ) {
1578
        $flags = 'e';
1579
    } elsif ( $rv && ( exists $versions{$entry}{Essential} ) ) {
1580
        $flags = 'X';
1581
    } elsif ( $rv ) {
1582
        $flags = 'E';
1583
    } else {
1584
        $flags = 'G';
1585
    }
1586
 
1587
    #
1588
    #   Always log results to a file
1589
    #   Flags:
1590
    #       e - Error: Global Fatal causes other versions to be ignored
1591
    #       X - Essential Package NOT proccessed
1592
    #       E - Error processing package
1593
    #       G - Good
1594
    #
1595
    my $duration = time() - $startTime;
1596
    my $line = join(';',
1597
            $flags,
1598
            $entry,
1599
            $packageNames,
1600
            $versions{$entry}{vname},
1601
            $data{rmRef},
1602
            $data{tag},
1603
            $timestamp,
1604
            $duration,
1605
            $data{errStr} || ''
1606
            );
1607
    logToFile( $cwd . '/importsummary.txt', ";$line;");
2439 dpurdie 1608
 
392 dpurdie 1609
    #
1610
    #   Sava data
1611
    #
1270 dpurdie 1612
    $data{errFlags} = $flags;
1613
    $data{duration} = $duration;
392 dpurdie 1614
    $versions{$entry}{rmRef} = $data{rmRef};
1270 dpurdie 1615
    delete $data{rmRef};
1616
    delete $data{tag};
1340 dpurdie 1617
    ##delete $data{ViewRoot};
1270 dpurdie 1618
    $versions{$entry}{data} = \%data;
1619
 
392 dpurdie 1620
    #
1621
    #   Delete the created view
1622
    #   Its just a directory, so delete it
1623
    #
1624
    if ( $data{ViewRoot} && -d $data{ViewRoot})
1625
    {
2450 dpurdie 1626
        if ( !$opt_reuse || ($rv && ($rv != 4 && $rv != 12 && $rv != 5 )) )
1340 dpurdie 1627
        {
1628
            Message ("Delete View: $data{ViewRoot}");
1629
            RmDirTree ($data{ViewRoot} );
1630
        }
1631
        else
1632
        {
1633
            Message ("Retaining View: $data{ViewRoot}");
1634
        }
1635
 
392 dpurdie 1636
    }
1340 dpurdie 1637
    else
1638
    {
1639
        Message ("No view to delete");
1640
    }
392 dpurdie 1641
 
1642
 
1643
    #
1644
    #   If this version has any 'ripples' then process them while we have the
1645
    #   main view. Note the ripple list may contain entries that do not
1646
    #   exist - they will have been pruned.
1647
    #
2429 dpurdie 1648
if(1) {
392 dpurdie 1649
    foreach my $rentry ( @{$versions{$entry}{rippleList}} )
1650
    {
1651
        next unless( exists $versions{$rentry} );
1652
 
1653
        if ($versions{$rentry}{Processed})
1654
        {
1655
            Warning ("Ripple Processed before main entry");
1656
            $versions{$rentry}{rippleProcessed} = 1;
1657
        }
1658
 
1659
        Message ("Proccessing associated Ripple: " . GetVname($rentry));
1660
        newPackageVersion($rentry);
1661
    }
1662
}
2040 dpurdie 1663
}
392 dpurdie 1664
 
1665
#-------------------------------------------------------------------------------
1666
# Function        : newPackageVersionBody
1667
#
1668
# Description     : Perform the bulk of the work in creating a new PackageVersion
1669
#                   Designed to return on error and have error processing
1670
#                   performed by caller
1671
#
1672
# Inputs          : $data               - Shared data
1673
#                   $entry              - Package entry to process
1674
#
1675
# Returns         : Error Code
1676
#                         0 - All is well
1272 dpurdie 1677
#                       <10 - Recoverable error
2450 dpurdie 1678
#                               1 - Bad VCS Tag
1679
#                               2 - No Files in the extracted view
1680
#                                   Label not found
1681
#                                   Failed to extract files from CC
1682
#                                   No Files in the extracted view after labeling dirs
1683
#                               3 - Deadwood
1684
#                               4 - Bad usage of ProjectBase detected
1685
#                                   Use of MakeProject detected
1686
#                               5  - Subversion Import disabled
392 dpurdie 1687
#                       >10 - Fatal error
1688
#
1689
sub newPackageVersionBody
1690
{
1691
    my ($data, $entry) = @_;
1692
    my $rv;
2478 dpurdie 1693
    my $vcs_type;
392 dpurdie 1694
    my $cc_label;
1695
    my $cc_path;
2429 dpurdie 1696
    my $cc_path_original;
392 dpurdie 1697
 
1698
    #
1699
    #   Init Data
1700
    #
1701
    $data->{rmRef} = 'ERROR';
1702
    $data->{tag} = '';
1703
    $data->{ViewRoot} = undef;
1704
    $data->{ViewPath} = undef;
1705
    $data->{errStr} = '';
1706
    $versions{$entry}{Processed} = 1;
1707
 
1708
 
1709
    SystemConfig ('ExitOnError' => 0);
1710
 
1711
    push @processOrder, $entry;
1712
    return 0 if ( $opt_test );
1713
 
1714
#   Keep DeadWood. May be a WIP
1715
#    if ( exists $versions{$entry}{DeadWood} && $versions{$entry}{DeadWood} )
1716
#    {
1717
#        $data->{errStr} = 'Package is DeadWood';
1718
#        return 3;
1719
#    }
1720
 
1721
    #
1722
    #   Determine version information
1723
    #
1724
    $data->{tag} = $versions{$entry}{vcsTag} || '';
1725
    if ( $versions{$entry}{badVcsTag} )
1726
    {
1727
        Warning ("Error: Bad VcsTag for: " . GetVname($entry),
1728
                 "Tag: $data->{tag}" );
1729
        $data->{errStr} = 'VCS Tag Marked as Bad';
1730
        return 1;
1731
    }
1732
 
1733
 
1734
    $data->{tag} =~ m~^(.+?)::(.*?)(::(.+))?$~;
2478 dpurdie 1735
    $vcs_type = $1;
392 dpurdie 1736
    $cc_label = $4;
1737
    $cc_path = $2;
1738
    $cc_path = '/' . $cc_path;
1739
    $cc_path =~ tr~\\/~/~s;
2429 dpurdie 1740
    $cc_path_original = $cc_path;
392 dpurdie 1741
 
1742
    #
2478 dpurdie 1743
    #   Correct well known path mistakes in CC paths
392 dpurdie 1744
    #
2478 dpurdie 1745
    if ( $vcs_type eq 'CC' )
1746
    {
1747
        $cc_path =~ s~/build.pl$~~i;
1748
        $cc_path =~ s~/src$~~i;
1749
        $cc_path =~ s~/cpp$~~i;
1750
        $cc_path =~ s~/MASS_Dev/Infra/~/MASS_Dev_Infra/~i;
1751
        $cc_path =~ s~/MASS_Dev/Tools/~/MASS_Dev_Tools/~i;
1752
        $cc_path =~ s~/MASS_Dev/Bus/~/MASS_Dev_Bus/~i;
1753
        $cc_path =~ s~/MASS_Dev_Bus/Cbp/~/MASS_Dev_Bus/CBP/~i;
1754
        $cc_path =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
1755
        $cc_path =~ s~/MREF_../MREF_Package/~/MREF_Package/~i;
1756
        $cc_path =~ s~/MREF_Package/mass_ergocdp/~/MREF_Package/ergocdp/~i;
1757
        $cc_path =~ s~/MASS_Dev_Bus/CBP/systemCD.ejb~/MASS_Dev_Bus/CBP/systemCD/ejb~i;
1758
        $cc_path =~ s~/MASS_Dev_Bus/Financial/cpp/paymentmanager~/MASS_Dev_Bus/Financial/cpp/paymentmanager~i;
1759
        $cc_path =~ s~/MASS_Dev_Bus/WebServices~/MASS_Dev_Bus/WebServices~i;
1760
        $cc_path =~ s~/MASS_Dev_Bus/CBP/nullAdapter~//MASS_Dev_Bus/CBP/nullAdaptor~i;
392 dpurdie 1761
 
2478 dpurdie 1762
        $cc_path = '/MASS_Dev_Bus' if ( $cc_path =~ m~/MASS_Dev_Bus/ImageCapture(/|$)~i );
1763
        $cc_path = '/MASS_Dev_Bus/CBP/enquiry' if ( $versions{$entry}{name} eq 'EJBEnqPxyConnector');
1764
        $cc_path = '/MASS_Dev_Bus/CBP/enquiry' if ( $versions{$entry}{name} eq 'proxyif4j');
1765
        $cc_path = '/MASS_Dev_Bus' if ( $versions{$entry}{name} eq 'ImageCaptureTomcatDeployment');
1766
        $cc_path = '/MASS_Dev_Bus/WebServices/MassWS' if ( $versions{$entry}{name} eq 'MassWebServicesImpl');
1197 dpurdie 1767
 
2478 dpurdie 1768
        if (   $versions{$entry}{name} =~ m/^ERGagency$/i
1769
            || $versions{$entry}{name} =~ m/^ERGavm$/i
1770
            || $versions{$entry}{name} =~ m/^ERGboi$/i
1771
            || $versions{$entry}{name} =~ m/^ERGcallcenter$/i
1772
            || $versions{$entry}{name} =~ m/^ERGcardholder$/i
1773
            || $versions{$entry}{name} =~ m/^ERGcdaimports$/i
1774
            || $versions{$entry}{name} =~ m/^ERGcda$/i
1775
            || $versions{$entry}{name} =~ m/^ERGcscedit$/i
1776
            || $versions{$entry}{name} =~ m/^ERGcs$/i
1777
            || $versions{$entry}{name} =~ m/^ERGofs$/i
1778
            || $versions{$entry}{name} =~ m/^ERGols$/i
1779
            || $versions{$entry}{name} =~ m/^ERGtpf$/i
1780
            || $versions{$entry}{name} =~ m/^ERGorasys$/i
1781
            || $versions{$entry}{name} =~ m/^ERGoracs$/i
1782
            || $versions{$entry}{name} =~ m/^ERGpxyif$/i
1783
            || $versions{$entry}{name} =~ m/^ERGtp5upg$/i
1784
            || $versions{$entry}{name} =~ m/^ERGinstitutional$/i
1785
            || $versions{$entry}{name} =~ m/^ERGinfra$/i
1786
            || $versions{$entry}{name} =~ m/^ERGcrrpts$/i
1787
            || $versions{$entry}{name} =~ m/^ERGmiddle$/i
1788
            || $versions{$entry}{name} =~ m/^ERGmiddleapi$/i
1789
            || $versions{$entry}{name} =~ m/^ERGwebapi$/i
1790
            || $versions{$entry}{name} =~ m/^ERGwebtestui$/i
1791
            || $versions{$entry}{name} =~ m/^ERGwebesbui$/i
1792
            || $versions{$entry}{name} =~ m/^ERGwspiv$/i
1793
            || $versions{$entry}{name} =~ m/^ERGwscst$/i
1794
            || $versions{$entry}{name} =~ m/^sposMUG$/i
1795
            || $versions{$entry}{name} =~ m/^ERGfinman$/i
1796
            || $versions{$entry}{name} =~ m/^ERGkm$/i
1797
            || $versions{$entry}{name} =~ m/^ERGxml$/i
1798
            || $versions{$entry}{name} =~ m/^ERGoradacw$/i
1799
            || $versions{$entry}{name} =~ m/^ERGtru$/i
1800
            )
392 dpurdie 1801
        {
2429 dpurdie 1802
            $cc_path = '/MREF_Package';
392 dpurdie 1803
        }
1804
 
2478 dpurdie 1805
        if (   $versions{$entry}{name} =~ m/^tp5000_MUG$/i )
1806
        {
1807
            if ( $versions{$entry}{version} =~ m~vtk$~ )
1808
            {
1809
                $cc_path = '/MREF_Package';
1810
            }
1811
        }
1812
 
1813
        if ( $cc_path_original ne $cc_path )
1814
        {
1815
                Message ("Package: $versions{$entry}{name}. Forcing CC path to: $cc_path" );
1816
        }
2429 dpurdie 1817
    }
1818
 
1819
#print "--- Path: $cc_path, Label: $cc_label\n";
1197 dpurdie 1820
 
2478 dpurdie 1821
    if ( $vcs_type eq 'SVN' )
1822
    {
1823
        $rv = extractFilesFromSubversion( $data, $entry );
1824
        return $rv if ( $rv );
1825
    }
1826
    else
1827
    {
1828
        #
1829
        #   Create CC view
1830
        #   Import into Subversion View
1831
        #
1832
        $rv = extractFilesFromClearCase( $data, $cc_path, $cc_label );
1833
        return $rv if ( $rv );
1834
    }
1197 dpurdie 1835
 
1836
    #
1270 dpurdie 1837
    #   Developers have been slack
1838
    #       Sometime the mark the source path as 'GMTPE2005'
1839
    #       Sometimes as 'GMTPE2005/Package/Fred/Jill/Harry'
1840
    #
1841
    #   Attempt to suck up empty directories below the specified
1842
    #   source path
1843
    #
1844
    unless ( $opt_preserveProjectBase )
1845
    {
1846
        #
1847
        #   Look in ViewPath
1848
        #   If it contains only ONE directory then we can suck it up
1849
        #
1850
        my $testDir = findDirWithStuff( $data->{ViewPath} );
1328 dpurdie 1851
 
1270 dpurdie 1852
        unless ( $data->{ViewPath} eq $testDir  )
1853
        {
1854
            Message ("Adjust Base Dir: $testDir");
1855
            $data->{adjustedPath} = $data->{ViewPath};
1856
            $data->{ViewPath} = $testDir;
2478 dpurdie 1857
            $adjustedPath++;
1270 dpurdie 1858
        }
1859
    }
2450 dpurdie 1860
    Message ("BaseDir: $data->{ViewPath}");
2478 dpurdie 1861
 
2429 dpurdie 1862
    #
2478 dpurdie 1863
    #   Check for bad source paths
1864
    #
1865
    if (detectBadMakePaths($data) )
1866
    {
1867
        unless ( $opt_ignoreBadPaths )
1868
        {
1869
            $data->{BadPath}++;
1870
            $data->{errStr} = 'Bad Paths in Makefile';
1871
            return 4;           # Lets see what the others look like too
1872
#            return 14;
1873
        }
1874
    }
1875
 
1876
    #
2429 dpurdie 1877
    #   Some really ugly packages make use of a Jats feature called 'SetProjectBase'
1878
    #   Detect such packages as we will need to handle them differently
1879
    #   Can't really handle it on the fly
1880
    #   All we can do is detect it and report it - at the moment
1881
    #
2450 dpurdie 1882
    if (detectProjectBaseUsage($data) )
2429 dpurdie 1883
    {
1884
        unless ( $opt_ignoreProjectBaseErrors )
1885
        {
1886
            $data->{BadProjectBase}++;
1887
            $data->{errStr} = 'Bad usage of ProjectBase detected';
1888
            return 4;           # Lets see what the others look like too
1889
#            return 14;
1890
        }
1891
    }
1270 dpurdie 1892
 
1893
    #
2429 dpurdie 1894
    #   Some really really ugly packgaes make use of the MakeProject directive
1895
    #   and then use an 'include.txt file to access paths all over the VOB
1896
    #   The problem is with lines like
1897
    #           /I ..\..\..\..\..\..\DPG_SWCode\projects\seattle\ddu\component\DTIApp\dsi\inc
1898
    #   Two problems:
1899
    #       Vob Name is not a part of the migration
1900
    #       If we 'SuckUp' empty directories then this may break
1901
    #       the pathing.
1902
    #   All we can do is detect it and report it - at the moment
1903
    #
2478 dpurdie 1904
    if (detectMakeProjectUsage($data) )
2429 dpurdie 1905
    {
1906
        unless ( $opt_ignoreMakeProjectErrors )
1907
        {
1908
            $data->{BadMakeProject}++;
1909
            $data->{errStr} = 'Use of MakeProject detected';
1910
            return 4;           # Lets see what the others look like too
1911
#            return 14;
1912
        }
1913
    }
1914
 
1915
    #
1916
    #   Some packages have filenames that are need to be converted
1917
    #
1918
    if ( $mustConvertFileNames  )
1919
    {
1920
        $rv = system ( '/home/dpurdie/svn/tools/convmv-1.15/convmv',
1921
                 '-fiso-8859-1',
1922
                 '-tutf8',
1923
                 '-r',
1924
                 '--notest',
1925
                 $data->{ViewPath} );
1926
 
1927
        if ( $rv )
1928
        {
1929
            $data->{errStr} = 'Failed to convert filenames to UTF8';
1930
            return 14;
1931
        }
1932
 
1933
        #
1934
        #   Check to see if our ViewPath has been changed
1935
        #   If so, then try to fix it
1936
        #
1937
        unless ( -d $data->{ViewPath} )
1938
        {
1939
            Message ("Correct UTF-8 change to ViewPath");
1940
            $data->{ViewPath} = encode('UTF-8', $data->{ViewPath}, Encode::FB_DEFAULT);
1941
            Warning ("Correct UTF-8 change to ViewPath - FAILED") unless ( -d $data->{ViewPath} );
1942
        }
1943
    }
1944
 
1945
    #
392 dpurdie 1946
    #   Have a CC view
1947
    #   Now we can create the SVN package and branching point before we
1948
    #   import the CC data into SVN
1949
    #
2450 dpurdie 1950
    if ( !$opt_useSvn )
1951
    {
2478 dpurdie 1952
            $data->{errStr} = 'Subversion Import disabled' unless $data->{errStr};
2450 dpurdie 1953
            return 5;
1954
    }
1955
 
392 dpurdie 1956
    my @args;
1957
 
1958
    #
1959
    #   Calculate args for functions
1960
    #
1961
    my $author = $versions{$entry}{created_id};
1962
    if ( $author )
1963
    {
1964
        push @args, '-author', $author;
1965
    }
1966
    my $created = $versions{$entry}{created};
1967
    if ( $created )
1968
    {
1969
        $created =~ s~ ~T~;
1970
        $created .= '00000Z';
1971
        push @args, '-date', $created;
1972
    }
1973
 
1974
    my $log = $versions{$entry}{comment};
1975
    if ( $log )
1976
    {
1977
        push @args, '-log', $log;
1978
    }
1979
 
1980
    #
1981
    #   Create package skeleton if needed
1982
    #
1983
    $rv = createPackage( $author, $created);
1984
    if ( $rv )
1985
    {
1986
        $data->{errStr} = 'Failed to create Package';
1987
        return 10;
1988
    }
1989
 
1990
    #
1991
    #   Calculate the label for the target package
1992
    #   Use format <packageName>_<PackageVersion>
1993
    #   Need to handle WIPs too.
1994
    #
1995
    my $import_label = saneLabel($entry);
1996
 
1997
    #
1998
    #   May need to create the branchpoint
1999
    #   The process is delayed until its needed so avoid creating unneeded
2000
    #   branch points
2001
    #
2002
    if ( $createBranch )
2003
    {
2004
        $rv = createBranchPoint ($entry, $author, $created);
2005
        $createBranch = 0;
2006
        $createSuffix = 0;
2007
        if ( $rv )
2008
        {
2009
            $data->{errStr} = 'Failed to create Branch Point';
2010
            return 11;
2011
        }
2012
    }
2013
    push @args, "-branch=$currentBranchName" if ( defined $currentBranchName );
2014
 
2015
    my $datafile = "importdata.$import_label.properties";
2016
    $rv = JatsToolPrint ( 'jats_svn', 'import', '-reuse' ,
2017
                    "-package=$svnRepo/$packageNames",
2018
                    "-dir=$data->{ViewPath}",
2019
                    "-label=$import_label",
2020
                    "-datafile=$datafile",
2021
                    @args,
2022
                     );
2023
 
2024
    if ( $rv )
2025
    {
2026
        $data->{errStr} = 'Failed to import to SVN';
2027
        return 12;
2028
    }
2029
 
2030
    $versions{$entry}{TagCreated} = 1;
2031
    $firstVersionCreated = $entry unless ( $firstVersionCreated );
2032
 
2033
    #
2034
    #   Read in the Rm Reference
2035
    #   Retain entries in a global file
2036
    #
2037
    if ( -f $datafile  )
2038
    {
2039
        my $rmData = JatsProperties::New($datafile);
2040
        $data->{rmRef} = 'SVN::' . $rmData->getProperty('subversion.tag');
2041
    }
2042
 
2043
    unless ( $data->{rmRef}  )
2044
    {
1272 dpurdie 2045
        $data->{errStr} = 'Failed to determine Rm Reference';
392 dpurdie 2046
        return 13;
2047
    }
2048
 
1380 dpurdie 2049
######################## Deleted ###############################################
2050
#
2051
#
2052
#    #
2053
#    #   Add supplemental tags if this version is in a 'Release'
2054
#    #   But only for some packages - else looks like a mess
2055
#    #   Just a solution for the ITSO guys
2056
#    #
2057
#    foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  )
2058
#    {
2059
#        next unless ( $svnRepo =~ m~/ITSO_TRACS(/|$)~);
2060
#
2061
#        my $prog_id = $versions{$entry}{Releases}{$rtag_id}{proj_id};
2062
#        Message ("Adding Release Tag:$prog_id:$rtag_id");
2063
#
2064
#        my $rtext = 'Release_' . saneString($versions{$entry}{Releases}{$rtag_id}{rname});
2065
#        my @comment;
2066
#        push @comment, "Tagged by ClearCase to Subversion import";
2067
#        push @comment, "Project:$prog_id:$versions{$entry}{Releases}{$rtag_id}{pname}";
2068
#        push @comment, "Release:$rtag_id:$versions{$entry}{Releases}{$rtag_id}{rname}";
2069
#
2070
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{name} = $rtext;
2071
#
2072
#        $rv = JatsToolPrint ( 'jats_svnlabel' ,
2073
#                    '-comment', encode('UTF-8', join("\n", @comment), Encode::FB_DEFAULT),
2074
#                    $data->{rmRef},
2075
#                    '-clone',
2076
#                    $rtext,
2077
##                    @args,
2078
#                    '-author=buildadm',
2079
#                     );
2080
#        $data->{ReleaseTag}{$prog_id}{$rtag_id}{eState} = $rv;
2081
#        $data->{ReleaseTag}{tCount}++;
2082
#
2083
#        if ( $rv )
2084
#        {
2085
#            $data->{ReleaseTag}{eCount}++;
2086
#            Warning("Failed to add Release Tag: $rtext");
2087
#        }
2088
#    }
2089
#
2090
######################## Deleted ###############################################
1341 dpurdie 2091
 
392 dpurdie 2092
    Message ("RM Ref: $data->{rmRef}");
2093
    unlink $datafile;
2094
 
2095
    #
2096
    #   All is good
2097
    #
2098
    $data->{errStr} = '';
2099
    return 0;
2100
}
2101
 
2102
 
2103
#-------------------------------------------------------------------------------
2104
# Function        : newProject
2105
#
2106
# Description     : Start a new project within a package
2107
#
2108
# Inputs          : 
2109
#
2110
# Returns         : 
2111
#
2112
sub newProject
2113
{
2114
#    Message ("---- New Project");
2115
    $createSuffix = 0;
2116
 
2117
    #
2118
    #   New project
2119
    #   Kill the running import directory
2120
    #
2121
    RmDirTree ('SvnImportDir');
2122
}
2123
 
2124
#-------------------------------------------------------------------------------
2125
# Function        : newPackage
2126
#
2127
# Description     : Start processing a new package
2128
#
2129
# Inputs          : 
2130
#
2131
# Returns         : 
2132
#
2133
my $createPackageDone;
2134
sub newPackage
2135
{
2136
#    Message( "---- New Package");
2137
 
2138
    #
2139
    #   Create a package specific log file
2140
    #
2141
    $logSummary = $packageNames . ".summary.log";
2142
    unlink $logSummary;
2143
    Message( "PackageName: $packageNames");
2144
    $createPackageDone = 1;
2145
    $createBranch = 0;
2146
    $createSuffix = 0;
2147
 
2148
    #
2149
    #   First entry being created
2150
    #   Prime the work area
2151
    #
2152
    RmDirTree ('SvnImportDir');
2153
}
2154
 
2155
#-------------------------------------------------------------------------------
2156
# Function        : createPackage
2157
#
2158
# Description     : Create a new Package in SVN
2159
#                   Called before any serious SVN operation to ensure that the
2160
#                   package has been created. Don't create a package until
2161
#                   we expect to put something into it.
2162
#
2163
#                   Will only create a package once
2164
 
2165
#
2166
# Inputs          : $author         - Who done it
2167
#                   $date           - When
2168
#
2169
# Returns         : 
2170
#
2171
sub createPackage
2172
{
2173
    my ($author, $date) = @_;
2174
    my @opts;
2175
    push (@opts, '-date', $date) if ( $date );
2176
    push (@opts, '-author', $author) if ( $author );
2177
    #
2178
    #   Only do once
2179
    #
2180
    return unless ( $createPackageDone );
2181
    $createPackageDone = 0;
2182
 
1197 dpurdie 2183
    #
2184
    #   Real import
2185
    #       Do not Delete package if it exists
2186
    #       Package must NOT exist
2187
    #
392 dpurdie 2188
    Message ("Creating new SVN package: $packageNames");
1270 dpurdie 2189
    if ( $opt_delete )
2190
    {
2191
        Message ("Delete existing version of package: $packageNames");
2192
        JatsToolPrint ( 'jats_svn', 'delete-package', '-noerror',  "$svnRepo/$packageNames" );
2193
    }
1197 dpurdie 2194
    JatsToolPrint ( 'jats_svn', 'create', "$svnRepo/$packageNames", '-new', @opts );
392 dpurdie 2195
}
2196
 
2197
 
2198
#-------------------------------------------------------------------------------
2199
# Function        : createBranchPoint
2200
#
2201
# Description     : Create a branch point for the current work
2202
#                   Perform the calculation to determine the details of
2203
#                   the branch point. The work will only be done when its
2204
#                   needed. This will avoid the creation of branchpoints
2205
#                   that are not used.
2206
#
2207
# Inputs          : $entry                  Entry being processed
2208
#                   $author         - Who done it
2209
#                   $date           - When
2210
#
2211
# Returns         : 
2212
#
2213
sub createBranchPoint
2214
{
2215
    my ($entry, $author, $date) = @_;
2216
    my $forceNewProject;
2217
 
2218
#    Message ("---- Create Branch Point");
2219
 
2220
    #
2221
    #   Find previous good tag
2222
    #   We are walking a tree so something should have been created, but
2223
    #   the one we want may have had an error
2224
    #
2225
    #   Walk backwards looking for one that has been created
2226
    #
2227
    my $last = $versions{$entry}{last};
2228
    while ( $last )
2229
    {
2230
        unless ( $versions{$last}{TagCreated} )
2231
        {
2232
            $last = $versions{$last}{last};
2233
        }
2234
        else
2235
        {
2236
            last;
2237
        }
2238
    }
2239
 
2240
    #
2241
    #   If we have walked back to the base of the tree
2242
    #   If we transferred any software at all, then use the first
2243
    #   version as the base for this disconnected version
2244
    #
2245
    #   Otherwise we create a new, and empty, view
2246
    #
2247
    unless ( $last )
2248
    {
2249
        if ( $firstVersionCreated )
2250
        {
2251
            Warning ("Cannot find previous version to branch. Use first version");
2252
            $last = $firstVersionCreated;
2253
        }
2254
        else
2255
        {
2256
            Warning ("Forcing First instance of a Project");
2257
            $forceNewProject = 1;
2258
        }
2259
    }
2260
 
2261
    #
2262
    #   Determine source name
2263
    #   This MUST have been created before we can branch
2264
    #
2265
    my $src_label;
2266
    $src_label = saneLabel($last) if $last;
2267
 
2268
    #
2269
    #   Create target name
2270
    #
2271
    my $tgt_label;
2272
    if ( $forceNewProject || $versions{$entry}{newSuffix} || $createSuffix || !defined $src_label )
2273
    {
2274
        #
2275
        #   Create target name based on project
2276
        #
2277
        return if ( $singleProject );
2278
 
2279
        my $suffix = $versions{$entry}{suffix};
2280
        if ( $suffix )
2281
        {
2282
            Error ("Unknown Project: $suffix") unless ( defined $Projects{$suffix} );
2283
 
2284
            #
2285
            #   If this project can be considered to be a truck, then 'claim' the
2286
            #   truck for the first created element.
2287
            #
2288
            if ( $Projects{$suffix}{Trunk} )
2289
            {
2290
                # This project can use the trunk, if it has not been allocated.
2291
                $ProjectTrunk = $suffix unless ( defined $ProjectTrunk );
2292
 
2293
                #
2294
                #   If this package has multiple instances of the potential
2295
                #   trunk, then don't place either of them on the trunk as it
2296
                #   may cause confusion
2297
                #
2298
                if ($knownProjects{$suffix}{count} < 2 )
2299
                {
2300
                    if ( $suffix eq $ProjectTrunk )
2301
                    {
2302
                        return unless $currentBranchName;
2303
                    }
2304
                }
2305
            }
2306
 
2307
            $tgt_label = $Projects{$suffix}{Name};
2308
            $tgt_label = $versions{$entry}{name} . '_' . $tgt_label if ($multiPackages);
2309
            if ( !exists $ProjectsBaseCreated{$tgt_label}  )
2310
            {
2311
                $ProjectsBaseCreated{$tgt_label} = 1;
2312
            }
2313
            else
2314
            {
2315
                #   Project Base Already taken
2316
                #   Have disjoint starting points
2317
                $tgt_label .= '.' . $ProjectsBaseCreated{$tgt_label} ++;
2318
            }
2319
        }
2320
        else
2321
        {
2322
            #
2323
            #   No suffix in use
2324
            #
2325
            #   Currently not handled
2326
            #   May have to force the use of the trunk
2327
            #
2328
            Error ("INTERNAL ERROR: No suffix present");
2329
        }
2330
    }
2331
    else
2332
    {
2333
        $tgt_label = saneLabel($entry, $src_label . '_for_');
2334
    }
2335
 
2336
    #
2337
    #   Save branch name for use when populating sandbox
2338
    #
2339
    $currentBranchName = $tgt_label;
2340
 
2341
    #
2342
    #   Perform the branch
2343
    #
2344
    if ( defined $src_label )
2345
    {
1328 dpurdie 2346
        #
1341 dpurdie 2347
        #   The 'clone' operation will backtrack the branch point
2348
        #   to the source of the label. This will make the output version
2349
        #   tree much prettier
1328 dpurdie 2350
        #
392 dpurdie 2351
        my @opts;
2352
        push (@opts, '-date', $date) if ( $date );
2353
        push (@opts, '-author', $author) if ( $author );
2354
 
2355
        JatsToolPrint ( 'jats_svnlabel',
2356
                        '-packagebase', "$svnRepo/$packageNames",
1341 dpurdie 2357
                        'tags/' . $src_label,
392 dpurdie 2358
                        '-branch',
2359
                        '-clone', $tgt_label,
2360
                        @opts
2361
                      );
2362
    }
2363
}
2364
 
2365
 
2366
#-------------------------------------------------------------------------------
2367
# Function        : endPackage
2368
#
2369
# Description     : End of package processing
2370
#                   Clean up and display problems
2371
#
2372
# Inputs          : 
2373
#
2374
# Returns         : 
2375
#
2376
sub endPackage
2377
{
2429 dpurdie 2378
    Message ("-- Import Summary ------------------------------------------------" );
392 dpurdie 2379
    RmDirTree ('SvnImportDir');
2478 dpurdie 2380
    my $processedCount = 0;
2381
    my $inernalErrorCount = 0;
2382
    my $notProcessedCount = 0;
2383
    my $badPathCount = 0;
2384
    my $badProjectBaseCount = 0;
2385
    my $badMakeProjectCount = 0;
392 dpurdie 2386
 
2387
    #
2388
    #   Display versions that did get captured
2389
    #
2390
    foreach my $entry ( @processOrder )
2391
    {
2392
        $versions{$entry}{Scanned} = 1;
2393
        next unless ( $versions{$entry}{TagCreated} );
2394
        Warning ("Processed: " . GetVname($entry) . ' :: ' . $versions{$entry}{rmRef} || $versions{$entry}{errStr} || '???' );
2395
    }
2396
 
2397
    #
2398
    #   Display versions that did not get created
2399
    #
2400
    foreach my $entry ( @processOrder )
2401
    {
2402
        $versions{$entry}{Scanned} = 1;
2478 dpurdie 2403
        if ( $versions{$entry}{TagCreated} )
2404
        {
2405
            $processedCount++;
2406
            $badPathCount++ if ($versions{$entry}{data}{BadPath} );
2407
            $badProjectBaseCount++ if ($versions{$entry}{data}{BadProjectBase} );
2408
            $badMakeProjectCount++ if ($versions{$entry}{data}{BadMakeProject} );
2409
            next;
2410
        }
2411
 
2429 dpurdie 2412
        my $reason = $versions{$entry}{data}{errStr} || '';
2413
        my $tag = $versions{$entry}{vcsTag}|| 'No Tag';
2414
        Warning ("Not Processed: " . GetVname($entry) . ':' . $tag . ' : ' . $reason );
2478 dpurdie 2415
        $notProcessedCount++;
392 dpurdie 2416
    }
2417
 
2418
    foreach my $entry ( keys(%versions) )
2419
    {
2420
        next if ( $versions{$entry}{Scanned} );
2421
        Warning ("(E) INTERNAL ERROR. Package Not Processed: " . GetVname($entry) );
2478 dpurdie 2422
        $inernalErrorCount++;
392 dpurdie 2423
    }
2424
 
2478 dpurdie 2425
    if ( $adjustedPath || 1 )
2426
    {
2427
        Information ("Package Paths");
2428
        foreach my $entry ( @processOrder )
2429
        {
2430
            my $viewPath = $versions{$entry}{data}{ViewPath} || '';
2431
            Information (sprintf "ViewPath: %20s : %s", GetVname($entry), $viewPath);
2432
        }
2433
    }
2434
 
2435
    Message ("Packages processed: $processedCount");
2436
    Warning ("Packages not processed: $notProcessedCount") if ( $notProcessedCount );
2437
    Warning ("Internal Errors: $inernalErrorCount") if ( $inernalErrorCount );
2429 dpurdie 2438
    Message ("Packages Relabled: $packageReLabelCount") if ( $packageReLabelCount );
2478 dpurdie 2439
    Warning ("Packages with Bad Paths: $badPathCount") if ( $badPathCount );
2440
    Warning ("Packages with Bad ProjectBase: $badProjectBaseCount") if ( $badProjectBaseCount );
2441
    Warning ("Packages with MakeProjects: $badMakeProjectCount") if ( $badMakeProjectCount );
2442
    Warning ("Global Error Detected") if ( $globalError );
392 dpurdie 2443
    Message ("All Done");
2444
}
2445
 
1197 dpurdie 2446
#-------------------------------------------------------------------------------
2429 dpurdie 2447
# Function        : extractFilesFromClearCase
2448
#
2449
# Description     : Extract files from ClearCase
2450
#                   May take a while as we handle nasty errors
2451
#
2452
# Inputs          : $data           - Hash of good stuff from newPackageVersionBody
2453
#                   $cc_path
2454
#                   $cc_label
2455
#
2456
# Returns         : exit code
2457
#                   Sets up
2458
#                       $data->{errStr}
2459
#                       $data->{errCode}
2460
#                   As per newPackageVersionBody
2461
#
2462
sub extractFilesFromClearCase
2463
{
2464
    my ($data, $cc_path, $cc_label) = @_;
2465
    my $tryCount = 0;
2466
    my $rv = 99;
2467
 
2468
    $data->{ViewRoot} = $opt_name ? $opt_name : "$cc_label";
2469
    $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
2470
 
2471
    if ( $opt_preserveProjectBase )
2472
    {
2473
        my $cc_vob = $cc_path;
2474
        $cc_vob =~ s~^/~~;
2475
        $cc_vob =~ s~/.*~~;
2476
        $data->{ViewPath} =  $data->{ViewRoot} . '/' . $cc_vob;
2477
        Message ("Preserving Project Base");
2478
    }
2479
    $data->{ViewPath} =~  tr~/~/~s;
2480
 
2481
    if ( $opt_reuse && -d $data->{ViewPath}  )
2482
    {
2483
        Message ("Reusing view: $cc_label");
2484
        return 0;
2485
    }
2486
 
2487
    while ( $rv == 99 ) {
2488
        my @args;
2489
        push (@args, '-view', $opt_name ) if ( defined $opt_name );
2490
        $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
2491
                    "-label=$cc_label" ,
2492
                    "-path=$cc_path",
2493
                    @args
2494
                    );
2495
 
2496
        if ( $rv == 10 ) {
2497
 
2498
            #
2499
            #   No files found
2500
            #   If this is the first time then try really hard to find them
2501
            #
2502
            unless ( $tryCount++ )
2503
            {
2504
                if ( $opt_relabel )
2505
                {
2506
                    $packageReLabelCount++;
2507
                    $rv = JatsToolPrint('cc2svn_labeldirs',
2508
                                            '-vob', $cc_path,
2509
                                            $cc_label,
2510
                                            );
2511
                    $data->{DirsLabled} = 100 + $rv;
2512
                }
2513
 
2514
                #
2515
                #   Second attempt - massage the users path
2516
                #   We should have labled up to the VOB root so lets
2517
                #   just use the VOB and not the path
2518
                #
2519
                #   If we are not relabeling then we can still do this
2520
                #   in an attempt to fix user stupidity
2521
                #
2522
                $cc_path =~ s~^/~~;
2523
                $cc_path =~ s~/.*~~;
2524
                $cc_path = '/' . $cc_path;
2525
                $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
2526
                redo;
2527
            }
2528
 
2529
            $data->{errStr}  = 'No Files in the extracted view';
2530
            $data->{errCode} = '0';
2531
            return 2;
2532
        }
2533
        elsif ( $rv == 11 ) {
2534
            $data->{errStr} = 'Label not found';
2535
            $data->{errCode} = 'L';
2536
            return 2;
2537
        }
2538
 
2539
        unless ( -d $data->{ViewPath}  )
2540
        {
2541
            $data->{errStr} = 'Failed to extract files from CC';
2542
            return 2;
2543
        }
2544
 
2545
        #
2546
        #   Looks good
2547
        #
2548
        return 0;
2549
    };
2550
 
2551
    $data->{errStr}  = 'No Files in the extracted view after labeling dirs';
2552
    $data->{errCode} = '0';
2553
    return 2;
2554
 
2555
}
2556
 
2557
#-------------------------------------------------------------------------------
2478 dpurdie 2558
# Function        : extractFilesFromSubversion
2559
#
2560
# Description     : Extract files from Subversion
2561
#                   May take a while as we handle nasty errors
2562
#
2563
# Inputs          : $data           - Hash of good stuff from newPackageVersionBody
2564
#                   $entry          - All the PV information
2565
#
2566
# Returns         : exit code
2567
#                   Sets up
2568
#                       $data->{errStr}
2569
#                       $data->{errCode}
2570
#                   As per newPackageVersionBody
2571
#
2572
sub extractFilesFromSubversion
2573
{
2574
    my ($data, $entry ) = @_;
2575
    my $tryCount = 0;
2576
    my $rv = 99;
2577
 
2578
    #
2579
    #   Create a nice name for the import
2580
    #
2581
    my $import_label = saneLabel($entry);
2582
 
2583
 
2584
    $data->{ViewRoot} = $opt_name ? $opt_name : $import_label;
2585
    $data->{ViewPath} =  $data->{ViewRoot};
2586
    $data->{ViewPath} =~  tr~/~/~s;
2587
 
2588
    if ( $opt_reuse && -d $data->{ViewPath}  )
2589
    {
2590
        Message ("Reusing view: $import_label");
2591
        return 0;
2592
    }
2593
 
2594
    #
2595
    #   Only allow import from SVN if asked nicely
2596
    #   May be used if we are correcting a package - and some have been
2597
    #   placed in SVN
2598
    #
2599
    unless ( $opt_extractFromSvn )
2600
    {
2601
        $data->{errStr} = 'Some Packages are in SVN';
2602
        return 15;
2603
    }
2604
 
2605
 
2606
#print "--- ViewRoot: $data->{ViewPath}\n";
2607
    $rv = JatsToolPrint ( 'jats_svnrelease',
2608
                          '-extractfiles',
2609
                          '-root=.' ,
2610
                          '-noprefix',
2611
                          '-DevMode=escrow',
2612
                          '-label', $data->{tag},
2613
                          '-view', $data->{ViewPath},
2614
                );
2615
 
2616
    if ( $rv == 10 ) {
2617
        $data->{errStr}  = 'No Files in the extracted view';
2618
        $data->{errCode} = '0';
2619
        return 2;
2620
 
2621
    } elsif ( $rv == 11 ) {
2622
        $data->{errStr} = 'Label not found';
2623
        $data->{errCode} = 'L';
2624
        return 2;
2625
    } elsif ( $rv ) {
2626
        $data->{errStr} = 'Subversion reported error';
2627
        return 2;
2628
    }
2629
 
2630
    unless ( -d $data->{ViewPath}  )
2631
    {
2632
        $data->{errStr} = 'Failed to extract files from Subversion';
2633
        return 2;
2634
    }
2635
 
2636
    #
2637
    #   Looks good
2638
    #
2639
    return 0;
2640
}
2641
 
2642
#-------------------------------------------------------------------------------
2429 dpurdie 2643
# Function        : detectMakeProjectUsage
2644
#
2645
# Description     : etect and report usage of the MakeProject directive
2646
#
2647
# Inputs          : $data               - Ref to a hash of bits
2648
#
2649
# Returns         : true    - Bad usage (Really good usage not detected)
2650
#                   false   - Good usage detected
2651
#
2652
sub detectMakeProjectUsage
2653
{
2478 dpurdie 2654
    my ($data) = @_;
2429 dpurdie 2655
    my $retval = 0;
2656
    my $eSuf = $opt_ignoreMakeProjectErrors ? '' : 'Error';
2657
 
2658
    #
2659
    #   Find makefile.pl
2660
    #
2478 dpurdie 2661
    Message ("Detect MakeProject Usage");
2429 dpurdie 2662
    my $usesMakeProject = 0;
2663
    my $badIncludeFile = 0;
2664
 
2665
    my $search = JatsLocateFiles->new("--Recurse=1",
2666
                                       "--FilterIn=makefile.pl",
2667
                                       );
2668
    my @makefiles = $search->search($data->{ViewRoot});
2669
    foreach my $file ( @makefiles )
2670
    {
2671
#print "---Reading: $workDir/$data->{ViewRoot}/$file\n";
2672
        if ( open( my $fh, '<', "$data->{ViewRoot}/$file" ) )
2673
        {
2674
            my $eof = 0;
2675
            my $line = '';
2676
            until ( $eof )
2677
            {
2678
                my $in = <$fh>;
2679
                unless ( defined $in )
2680
                {
2681
                    $eof = 1;
2682
                }
2683
                else
2684
                {
2685
                $in =~ s~\s+$~~;
2686
                $in =~ s~^\s+~~;
2687
                $in =~ s~^#.*$~~;
2688
                $in =~ s~\s*[^\$]#.*$~~;
2689
                $line .= ' ' if ( $line );
2690
                $line .= $in;
2691
                $line =~ s~\s+~ ~g;
2692
#print "====== '$line'\n";
2693
                redo unless ( $line =~ m~;$~  );
2694
                }
2695
#print "---- $line\n";
2696
                if ( $line =~ m~^MakeProject~ )
2697
                {
2698
                    $usesMakeProject++;
2699
                    $data->{UsesMakeProject}++;
2700
                    Warning ("Package uses MakeProject:",
2701
                             "Line: " . $line,
2702
                             "Root: " . "$data->{ViewRoot}",
2703
                             "File: " . "$data->{ViewRoot}/$file",
2704
                            );
2705
 
2706
                    #
2707
                    #   Extract out the project name
2708
                    #
2709
                    my @myArgs;
2710
                    my $myProjectDir;
2711
                    my $myProject = "$data->{ViewRoot}/$file";
2712
                    $myProject =~ s~/[^/]+$~~;
2713
                    $line =~ s~MakeProject~push \@myArgs,~;
2714
                    eval $line;
2715
                    Error("Line did not compiler: $line", "Err: $@" ) if ($@);
2716
                    shift @myArgs;
2717
                    foreach ( @myArgs )
2718
                    {
2719
                        next if ( m~^--~ );
2720
                        $myProject .= '/' . $_;
2721
                        $myProjectDir = $myProject;
2722
                        $myProjectDir =~ s~/[^/]+$~~;
2723
                        last;
2724
                    }
2725
                    Error ("No project Found") unless ( defined $myProjectDir);
2478 dpurdie 2726
 
2727
                    #
2728
                    #   Look for 'include.txt' that may be bwteen the makefile and the project
2729
                    #
2730
 
2731
 
2429 dpurdie 2732
                    if ( -f "$myProjectDir/include.txt" )
2733
                    {
2734
                        Warning ("Co-located 'include.txt' file also found");
2735
                    }
2736
 
2737
                    # The only problem is if the include.txt file
2738
                    # escapes from the VOB - or even uses the vob root
2739
                    #
2740
                    # Examine the include file
2741
                    # Expect it to look like
2742
                    #   /I Path
2743
                    #
2744
 
2745
                    #
2746
                    #   Determine safe level
2747
                    #   Relative to the include file
2748
                    #
2749
                    my $depthPath = $myProjectDir;
2750
                    my $depth = 0;
2751
                    Error ("Expect this to work") unless ( $depthPath =~ s~^$data->{ViewRoot}/~~ );
2752
                    foreach ( split('/', $depthPath) )
2753
                    {
2754
                        if ( $_ eq '..' ) {
2755
                            $depth--;
2756
                        } else {
2757
                            $depth++;
2758
                        }
2759
                    }
2760
#print "Depth: $depth, $depthPath\n";
2761
 
2762
                    if ( open( my $if, '<', "$myProjectDir/include.txt" ) )
2763
                    {
2764
                        while ( <$if> )
2765
                        {
2766
                            s~\s+$~~;
2767
                            s~^\s+~~;
2768
                            next unless ( $_ );
2769
                            if ( m~/I\s+(.*)~ )
2770
                            {
2771
                                my $path = $1;
2772
                                $path =~ tr~\\/~/~s;
2773
                                $path =~ s~\\~/~g;
2774
#print "Examine: $path\n";
2775
                                my $minLevel = 0;
2776
                                my $level = 0;
2777
                                foreach ( split('/', $path) )
2778
                                {
2779
                                    if ( $_ eq '..' )
2780
                                    {
2781
                                        $level--;
2782
                                        $minLevel = $level if ($level < $minLevel);
2783
                                    }
2784
                                    else
2785
                                    {
2786
                                        $level++;
2787
                                    }
2788
                                }
2789
#print "Min: $minLevel, $level, ($depth + $minLevel)\n";
2790
                                if ( $depth + $minLevel <= 0)
2791
                                {
2792
                                    $badIncludeFile++;
2793
                                    Warning ("Included path escapes package:",
2794
                                             "Line: " . $_,
2795
                                             "File: " . "$myProjectDir/include.txt",
2796
                                            );
2797
                                    last;
2798
                                }
2799
                            }
2800
                        }
2801
                        close $if;
2802
                    }
2803
 
2804
                }
2805
                $line = '';
2806
            }
2807
            close $fh;
2808
        }
2809
        else
2810
        {
2811
            Warning ("MakeProject$eSuf - Cannot open makefile: $file");
2812
            $retval = 1;
2813
        }
2814
    }
2815
 
2816
    #
2817
    #   Used
2818
    #   May be improved latter
2819
    #
2820
    if ( $usesMakeProject && $badIncludeFile)
2821
    {
2822
        Warning ("MakeProject$eSuf - Problem detected");
2823
        $retval = 1;
2824
    }
2825
 
2826
    #
2827
    #   Until we have more faith in the detection algorithm
2828
    #
2829
    if ( $usesMakeProject )
2830
    {
2831
        Warning ("MakeProject$eSuf - Makeproject used. Must check manually");
2832
        $retval = 1;
2833
    }
2834
 
2835
    return $retval;
2836
}
2837
 
2838
#-------------------------------------------------------------------------------
2478 dpurdie 2839
# Function        : detectBadMakePaths
2840
#
2841
# Description     : Detect and report bad usage of some directives
2842
#
2843
# Inputs          : $data               - Ref to a hash of bits
2844
#
2845
# Returns         : true    - Bad usage (Really good usage not detected)
2846
#                   false   - Good usage detected
2847
#
2848
sub detectBadMakePaths
2849
{
2850
    my ($data) = @_;
2851
    my $retval = 0;
2852
    my $eSuf = $opt_ignoreBadPaths ? '' : 'Error';
2853
 
2854
    #
2855
    #   Find makefile.pl
2856
    #
2857
    Message ("Detect Bad Source Paths");
2858
    my $badPath = 0;
2859
 
2860
    my $search = JatsLocateFiles->new("--Recurse=1",
2861
                                       "--FilterIn=makefile.pl",
2862
                                       );
2863
    my @makefiles = $search->search($data->{ViewPath});
2864
    foreach my $file ( @makefiles )
2865
    {
2866
        $file =~ tr~/~/~s;
2867
        my $max_up = ($file =~ tr~/~/~);
2868
        my $shownPath;
2869
#print "---Reading: $workDir/$data->{ViewPath}/$file\n";
2870
        if ( open( my $fh, '<', "$data->{ViewPath}/$file" ) )
2871
        {
2872
            my $eof = 0;
2873
            my $line = '';
2874
 
2875
            until ( $eof )
2876
            {
2877
                my $in = <$fh>;
2878
                unless ( defined $in )
2879
                {
2880
                    $eof = 1;
2881
                }
2882
                else
2883
                {
2884
                $in =~ s~\s+$~~;
2885
                $in =~ s~^\s+~~;
2886
                $in =~ s~^#.*$~~;
2887
                $in =~ s~\s*[^\$]#.*$~~;
2888
                $line .= ' ' if ( $line );
2889
                $line .= $in;
2890
                $line =~ s~\s+~ ~g;
2891
#print "====== '$line'\n";
2892
                redo unless ( $line =~ m~;$~  );
2893
                }
2894
                if ( $line =~ m~^AddDir~ || $line =~ m~^AddSrcDir~ || $line =~ m~^AddIncDir~ || $line =~ m~^Src~ )
2895
                {
2896
                    #
2897
                    #   Extract out the arguments
2898
                    #
2899
                    my @myArgs;
2900
                    my $myProjectDir;
2901
                    my $myProject = "$data->{ViewRoot}/$file";
2902
                    $myProject =~ s~/[^/]+$~~;
2903
                    $line =~ s~.*\(~push \@myArgs, (~;
2904
                    eval $line;
2905
                    Error("Line did not compiler: $line", "Err: $@" ) if ($@);
2906
                    shift @myArgs;
2907
                    foreach ( @myArgs )
2908
                    {
2909
                        next if ( m~^--~ );
2910
                        next unless ( m~^\.\./~ );
2911
                        my $tmp = $_;
2912
                        $tmp =~ s~Z~z~g;
2913
                        $tmp =~ s~\.\./~Z~g;
2914
                        my $upCount = ( $tmp =~ tr~Z~Z~ );
2915
                        if ( $upCount > $max_up )
2916
                        {
2917
                            Warning ("Makefile Path: $file ") unless $shownPath;
2918
                            Warning ("Path escapes view: $max_up, $upCount, $_");
2919
                            $badPath++;
2920
                            $shownPath = 1;
2921
                        }
2922
#print "---x Path : $max_up, $upCount, $_\n";
2923
                    }
2924
                }
2925
                $line = '';
2926
            }
2927
            close $fh;
2928
        }
2929
        else
2930
        {
2931
            Warning ("detectBadMakePaths$eSuf - Cannot open makefile: $file");
2932
            $retval = 1;
2933
        }
2934
    }
2935
 
2936
    #
2937
    #   Used
2938
    #   May be improved latter
2939
    #
2940
    if ( $badPath )
2941
    {
2942
        Warning ("detectBadMakePaths$eSuf - Bad Path seen. Must check manually");
2943
        $retval = 1;
2944
    }
2945
 
2946
    return $retval;
2947
}
2948
 
2949
 
2950
#-------------------------------------------------------------------------------
1197 dpurdie 2951
# Function        : detectProjectBaseUsage
2952
#
2953
# Description     : Detect and report usage of the SetProjectBase directive
2954
#
2955
# Inputs          : $data               - Ref to a hash of bits
2956
#
2957
# Returns         : true    - Bad usage (Really good usage not detected)
2958
#                   false   - Good usage detected
2959
#
2960
sub detectProjectBaseUsage
2961
{
2450 dpurdie 2962
    my ($data) = @_;
1197 dpurdie 2963
    my $retval = 0;
2964
    my $eSuf = $opt_ignoreProjectBaseErrors ? '' : 'Error';
2965
 
2966
    #
2967
    #   Find makefile.pl
2968
    #
2478 dpurdie 2969
    Message ("Detect ProjectBase Usage");
1197 dpurdie 2970
    my $usesProjectBase = 0;
2971
    my $definesProjectBase = 0;
2972
    my $definitionError = 0;
2973
 
2974
    my $search = JatsLocateFiles->new("--Recurse=1",
2975
                                       "--FilterIn=makefile.pl",
2976
                                       );
2450 dpurdie 2977
    my @makefiles = $search->search($data->{ViewPath});
1197 dpurdie 2978
    foreach my $file ( @makefiles )
2979
    {
2450 dpurdie 2980
        if ( open( my $fh, '<', "$data->{ViewPath}/$file" ) )
1197 dpurdie 2981
        {
2982
            while ( <$fh> )
2983
            {
2984
                s~\s+$~~;
2985
                s~^\s+~~;
2986
                next if ( m~^#~ );
2987
 
2988
                if ( m~\$ProjectBase~ )
2989
                {
2990
                    $usesProjectBase++;
2991
                    Message ("Project Base Use: $_");
2992
                    $data->{UsesProjectBase}++;
2993
                }
2994
 
2995
                if ( m~^SetProjectBase~ )
2996
                {
2997
                    $definesProjectBase++;
2998
                    $data->{DefinesProjectBase}++;
2429 dpurdie 2999
                    Warning ("Package initialises SetProjectBase:",
2450 dpurdie 3000
                             "Line : " . $_,
3001
                             "Root : " . "$data->{ViewRoot}",
3002
                             "Path : " . "$data->{ViewPath}",
3003
                             "File : " . "$data->{ViewPath}/$file",
1197 dpurdie 3004
                            );
3005
 
3006
                    # The only problem is if the user attempts to escape
3007
                    # from the root of the view.
3008
                    #
3009
                    # Examine the depth of the makefile with the directive
3010
                    # Examine the depth of the view base
3011
                    #
3012
                    #
3013
                    # Locate the build.pl file
3014
                    # This is the basis for for the directive
3015
                    #
3016
                    my $blevel;
3017
                    my @bpaths = split ('/', $file );
2450 dpurdie 3018
                    my $buildFile;
1197 dpurdie 3019
                    while ( @bpaths )
3020
                    {
3021
                        $bpaths[-1] = 'build.pl';
3022
                        my $bfile = join '/', @bpaths ;
2450 dpurdie 3023
                        $buildFile = "$data->{ViewPath}/$bfile";
3024
                        if ( -f $buildFile )
1197 dpurdie 3025
                        {
3026
                            $blevel = scalar @bpaths;
3027
                            last;
3028
                        }
3029
                        pop @bpaths;
3030
                    }
3031
                    unless (defined $blevel)
3032
                    {
3033
                        Warning ("SetProjectBase$eSuf calculation failed - can't find build.pl");
2429 dpurdie 3034
#                        $retval = 1;
3035
                         $definitionError++;
1197 dpurdie 3036
                    }
3037
                    else
3038
                    {
3039
                        #
3040
                        #   Determine the depth of the view root
3041
                        #
2450 dpurdie 3042
                        Warning ("Build: $buildFile");
3043
                        my $countPath = ($data->{ViewPath} =~ tr~/~/~);
3044
                        my $countBuild = ($buildFile =~ tr~/~/~);
3045
                        my $max_up = $countBuild - $countPath -1;
1197 dpurdie 3046
 
3047
                        m~--Up=(\d+)~i;
3048
                        my $ulevel = $1;
3049
                        if ( defined $ulevel )
3050
                        {
3051
                            my @paths = split ('/', $file );
3052
                            my $plevel = scalar @paths;
3053
 
3054
#print "--- blevel: $blevel\n";
3055
#print "--- bpaths: @bpaths\n";
3056
#print "--- ulevel: $ulevel\n";
3057
#print "--- paths: @paths\n";
3058
#print "--- plevel: $plevel\n";
3059
#print "--- max_up: $max_up\n";
3060
 
3061
                            if ( $ulevel > $max_up )
3062
                            {
3063
                                Warning ("SetProjectBase escapes view. MaxUp: $max_up, Up: $ulevel");
3064
                                $definitionError++;
3065
                            }
3066
                        }
3067
                        else
3068
                        {
3069
                            $retval = 1;
3070
                            Warning ("SetProjectBase$eSuf MAY escape view - can't detect level")
3071
                        }
3072
                    }
3073
                }
3074
            }
3075
            close $fh;
3076
        }
3077
        else
3078
        {
3079
            Warning ("SetProjectBase$eSuf - Cannot open makefile: $file");
3080
            $retval = 1;
3081
        }
3082
    }
3083
 
3084
    #
3085
    #   Detect defined, but not used
3086
    #
3087
    if ( $usesProjectBase && ! $definesProjectBase )
3088
    {
3089
        Warning ("SetProjectBase - Uses ProjectBase without defining it");
3090
    }
3091
 
3092
    if ( ! $usesProjectBase && $definesProjectBase )
3093
    {
3094
        Warning ("SetProjectBase - Defines ProjectBase without using it");
3095
    }
3096
 
3097
    if ( $usesProjectBase && $definesProjectBase && $definitionError )
3098
    {
3099
        Warning ("SetProjectBase$eSuf - Problem detected");
3100
        $retval = 1;
3101
    }
3102
    return $retval;
3103
}
3104
 
1270 dpurdie 3105
#-------------------------------------------------------------------------------
3106
# Function        : findDirWithStuff
3107
#
3108
# Description     : Find a directory that contains more than just another subdir
2429 dpurdie 3109
#                   Note: don't use 'glob' it doesn't work if the name has a space in it.
1270 dpurdie 3110
#
3111
# Inputs          : $base               - Start of the scan
3112
#
3113
# Returns         : Path to dir with more than just a single dir in it
3114
#
3115
sub findDirWithStuff
3116
{
3117
    my ($base) = @_;
1197 dpurdie 3118
 
1270 dpurdie 3119
    while ( $base )
3120
    {
3121
    my $fileCount = 0;
3122
    my $dirCount = 0;
1272 dpurdie 3123
    my $firstDir;
1270 dpurdie 3124
 
2429 dpurdie 3125
    opendir (my $dh, $base ) || Error ("Cannot opendir $base. $!");
3126
    my @list =readdir $dh;
3127
    closedir $dh;
1270 dpurdie 3128
    foreach ( @list )
3129
    {
3130
        next if ( $_ eq '.' );
3131
        next if ( $_ eq '..' );
2429 dpurdie 3132
 
3133
        $_ = $base . '/' . $_;
1270 dpurdie 3134
        if ( -d $_ )
3135
        {
3136
            $dirCount++;
1272 dpurdie 3137
            $firstDir = $_ unless ( defined $firstDir );
2429 dpurdie 3138
            return $base
3139
                if ( $dirCount > 1  )
1270 dpurdie 3140
        }
1272 dpurdie 3141
        elsif ( -e $_ )
1270 dpurdie 3142
        {
3143
            return $base;
3144
        }
1272 dpurdie 3145
 
3146
        # else its probably a dead symlink
1270 dpurdie 3147
    }
2429 dpurdie 3148
 
3149
    return $base
3150
        unless ( $dirCount == 1  );
1272 dpurdie 3151
    $base = $firstDir;
1270 dpurdie 3152
    }
3153
}
3154
 
1197 dpurdie 3155
#-------------------------------------------------------------------------------
3156
# Function        : JatsToolPrint
3157
#
3158
# Description     : Print and Execuate a JatsTool command
3159
#
3160
# Inputs          : 
3161
#
3162
# Returns         : 
3163
#
3164
 
392 dpurdie 3165
sub JatsToolPrint
3166
{
3167
    Information ("Command: @_");
3168
    JatsTool @_;
3169
}
3170
 
3171
sub GetVname
3172
{
3173
    my ($entry) = @_;
3174
    my $me = 'NONE';
3175
    if ( $entry )
3176
        {
3177
        $me = $versions{$entry}{vname};
3178
        unless ( $me )
3179
        {
3180
            $me = 'Unknown-' . $entry;
3181
        }
3182
    }
3183
    return $me;
3184
}
3185
 
2429 dpurdie 3186
#-------------------------------------------------------------------------------
3187
# Function        : saneLabel
3188
#
3189
# Description     : Generate a sane version label
3190
#                   Handle suplicates (due to character squishing)
3191
#                   Cache results for repeatability
3192
#
3193
# Inputs          : $entry          - Version info
3194
#                   $pkgname        - Alternate pkgname (branching)
3195
#
3196
# Returns         : Sane string
3197
#
392 dpurdie 3198
sub saneLabel
3199
{
3200
    my ($entry, $pkgname) = @_;
1272 dpurdie 3201
    my $me;
3202
    $me = $versions{$entry}{vname};
392 dpurdie 3203
    $pkgname = $versions{$entry}{name} unless ( defined $pkgname );
3204
 
2429 dpurdie 3205
    #
3206
    #   If we have calculated it, then reuse it.
3207
    #
3208
    if ( exists $versions{$entry}{saneLabel}{$pkgname} )
3209
    {
3210
        return $versions{$entry}{saneLabel}{$pkgname};
3211
    }
3212
 
3213
 
392 dpurdie 3214
    Error ("Package does have a version string: pvid: $entry")
3215
        unless ( defined $me );
3216
 
3217
    #
3218
    #   Convert Wip format (xxxx) into a string that can be used for a label
3219
    #
3220
    if ( $me =~ m~^(.*)\((.*)\)(.*)$~ )
3221
    {
3222
        $me = $1 . '_' . $2 . '_' . $3 . '.WIP';
3223
        $me =~ s~_\.~.~;
3224
        $me =~ s~^_~~;
3225
    }
3226
 
3227
    #
3228
    #   Allow for WIPS
3229
    #   Get rid of multiple '_'
3230
    #   Replace space with -
3231
    #
3232
    $me = $pkgname . '_' . $me;
3233
    $me =~ tr~ ~-~s;
3234
    $me =~ tr~-~-~s;
3235
    $me =~ tr~_~_~s;
3236
 
2429 dpurdie 3237
    #
3238
    #   Due to some sillyness ( package version starting with _ )
3239
    #   we may get duplicates. Detect and allocate different numbers
3240
    #
3241
    if ( exists $saneLabels{$me} )
3242
    {
3243
        $saneLabels{$me}++;
3244
        $me = $me . '.' . $saneLabels{$me};
3245
        Message ("Duplicate SaneLabel resolved as: $me");
3246
    }
3247
    else
3248
    {
3249
        $saneLabels{$me} = 0;
3250
    }
3251
 
3252
    #
3253
    #   Cache value
3254
    #
3255
    $versions{$entry}{saneLabel}{$pkgname} = $me;
392 dpurdie 3256
    return $me;
3257
}
3258
 
1341 dpurdie 3259
sub saneString
3260
{
3261
    my ($string) = @_;
3262
    #
3263
    #   Get rid of multiple '_'
3264
    #   Replace space with -
3265
    #
3266
    $string =~ s~\W~_~g;
3267
    $string =~ tr~ ~_~s;
3268
    $string =~ tr~_-~-~s;
3269
    $string =~ tr~-_~-~s;
3270
    $string =~ tr~-~-~s;
3271
    $string =~ tr~_~_~s;
3272
    $string =~ s~-$~~;
3273
    $string =~ s~_$~~;
392 dpurdie 3274
 
1341 dpurdie 3275
    return $string;
3276
}
3277
 
3278
 
392 dpurdie 3279
exit 0;
3280
 
3281
 
3282
#-------------------------------------------------------------------------------
3283
# Function        : GetPkgIdByName
3284
#
3285
# Description     :
3286
#
3287
# Inputs          : pkg_name
3288
#
3289
# Returns         : pkg_id
3290
#
3291
sub GetPkgIdByName
3292
{
3293
    my ( $pkg_name ) = @_;
3294
    my (@row);
3295
    my $pv_id;
3296
    my $pkg_id;
3297
 
3298
    #
3299
    #   Establish a connection to Release Manager
3300
    #
3301
    connectRM(\$RM_DB) unless ( $RM_DB );
3302
 
3303
    #
3304
    #   Extract data from Release Manager
3305
    #
3306
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
3307
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
3308
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
3309
 
3310
    my $sth = $RM_DB->prepare($m_sqlstr);
3311
    if ( defined($sth) )
3312
    {
3313
        if ( $sth->execute( ) )
3314
        {
3315
            if ( $sth->rows )
3316
            {
3317
                while ( @row = $sth->fetchrow_array )
3318
                {
3319
                    Verbose( "DATA: " . join(',', @row) );
3320
                    $pkg_id = $row[1] || 0;
3321
                    last;
3322
                }
3323
            }
3324
            else
3325
            {
3326
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
3327
            }
3328
            $sth->finish();
3329
        }
3330
    }
3331
    else
3332
    {
3333
        Error("GetPkgIdByName:Prepare failure" );
3334
    }
3335
 
3336
    return $pkg_id;
3337
}
3338
 
3339
#-------------------------------------------------------------------------------
3340
# Function        : GetData_by_pkg_id
3341
#
3342
# Description     :
3343
#
3344
# Inputs          : pv_id
3345
#
3346
# Returns         :
3347
#
3348
sub GetData_by_pkg_id
3349
{
3350
    my ( $pkg_id, $packageName ) = @_;
3351
    my (@row);
3352
 
3353
    #
3354
    #   Establish a connection to Release Manager
3355
    #
3356
    Message ("Extract package versions from Release Manager: $packageName");
3357
    connectRM(\$RM_DB) unless ( $RM_DB );
3358
 
3359
    #
3360
    #   Extract data from Release Manager
3361
    #
2429 dpurdie 3362
    my $m_sqlstr = "SELECT " .
3363
                       "pkg.PKG_NAME, " .                                       # row[0]
3364
                       "pv.PKG_VERSION, " .                                     # row[1]
3365
                       "pkg.PKG_ID, " .                                         # row[2]
3366
                       "pv.PV_ID, " .                                           # row[3]
3367
                       "pv.LAST_PV_ID, " .                                      # row[4]
3368
                       "pv.MODIFIED_STAMP, " .                                  # row[5]
3369
                       "release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), " .  # row[6]
3370
                       "amu.USER_NAME, " .                                      # row[7]
3371
                       "pv.COMMENTS, " .                                        # row[8]
3372
                       "pv.DLOCKED, " .                                         # row[9]
3373
                       "pv.CREATOR_ID, ".                                       # row[10]
3374
                       "pv.BUILD_TYPE ".                                        # row[11]
3375
                   " FROM " .
3376
                        "RELEASE_MANAGER.PACKAGES pkg, " .
3377
                        "RELEASE_MANAGER.PACKAGE_VERSIONS pv, " .
3378
                        "ACCESS_MANAGER.USERS amu" .
3379
                   " WHERE " .
3380
                        "pv.PKG_ID = \'$pkg_id\' " .
3381
                        "AND pkg.PKG_ID = pv.PKG_ID " .
3382
                        "AND amu.USER_ID (+) = pv.CREATOR_ID";
3383
 
392 dpurdie 3384
    my $sth = $RM_DB->prepare($m_sqlstr);
3385
    if ( defined($sth) )
3386
    {
3387
        if ( $sth->execute( ) )
3388
        {
3389
            if ( $sth->rows )
3390
            {
3391
                while ( @row = $sth->fetchrow_array )
3392
                {
3393
                    Verbose( "DATA: " . join(',', @row) );
3394
                    my $pkg_name = $row[0] || 'Unknown';
3395
                    my $pkg_ver = $row[1] || 'Unknown';
3396
                       $pkg_ver =~ s~\s+$~~;
3397
                       $pkg_ver =~ s~^\s+~~;
3398
                    my $pv_id = $row[3] || 'Unknown';
3399
                    my $last_pv_id = $row[4];
3400
                    my $created =  $row[5] || 'Unknown';
3401
                    my $vcstag =  $row[6] || 'Unknown';
395 dpurdie 3402
 
392 dpurdie 3403
                    my $created_id =  $row[7] || ($row[10] ? "Userid_$row[10]" :'Unknown');
3404
                    my $comment =  $row[8] || '';
3405
                    my $locked =  $row[9] || 'N';
2429 dpurdie 3406
                    my $manual = $row[11] || 'M';
392 dpurdie 3407
 
3408
                    #
3409
                    #   Some developers have a 'special' package version
3410
                    #   We really need to ignore them
3411
                    #
3412
                    next if ( $pkg_ver eq '23.23.23.ssw' );
3413
 
3414
                    #
3415
                    #   Add data to the hash
3416
                    #       Remove entries that address themselves
3417
                    #
3418
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id || $last_pv_id == 0) ;
3419
                    $versions{$pv_id}{name} = $pkg_name;
3420
                    $versions{$pv_id}{pvid} = $pv_id;
3421
                    $versions{$pv_id}{vname} = $pkg_ver;
3422
                    $versions{$pv_id}{vcsTag} = $vcstag;
3423
                    $versions{$pv_id}{created} = $created;
3424
                    $versions{$pv_id}{created_id} = $created_id;
3425
                    $versions{$pv_id}{comment} = $comment;
3426
                    $versions{$pv_id}{locked} = $locked;
3427
                    $versions{$pv_id}{TimeStamp} = str2time( $created );
3428
                    $versions{$pv_id}{Age} = ($now - $versions{$pv_id}{TimeStamp}) / (60 * 60 * 24);
3429
                    $versions{$pv_id}{TooOld} = 1 if ( $opt_age && $opt_age <= $versions{$pv_id}{Age} );
2429 dpurdie 3430
                    $versions{$pv_id}{BuildType} = $manual;
392 dpurdie 3431
                    examineVcsTag($pv_id);
3432
 
3433
                    #
3434
                    #   Process version number
3435
                    #
3436
                    my ($suffix, $version, $isaR, $isaWip, $buildVersion ) = massageVersion($pkg_ver, $pkg_name);
3437
 
3438
                    $versions{$pv_id}{version} = $version;
3439
                    $versions{$pv_id}{buildVersion} = $buildVersion;
3440
                    $versions{$pv_id}{isaWip} = 1 if ( $isaWip );
3441
 
3442
                    #
2429 dpurdie 3443
                    #   New methof for detecting a ripple
3444
                    #       Don't look at the version number
3445
                    #       Use RM data
3446
                    #       Inlude the comment - there are some cases where the comment
3447
                    #       appears to have been user modified.
3448
                    #
3449
#                    $versions{$pv_id}{isaRipple} = 1 if ( $isaR );
3450
#                    $versions{$pv_id}{isaRipple} = 1 if ( uc($manual) eq 'Y' );
3451
                    $versions{$pv_id}{isaRipple} = ( $comment =~ m~^Rippled Build~i && ( uc($manual) eq 'Y' ));
3452
 
3453
                    #
392 dpurdie 3454
                    #   Process suffix
3455
                    #
3456
                    $suffix = 'Unknown' unless ( $suffix );
3457
                    $suffix = lc ($suffix);
3458
                    $versions{$pv_id}{suffix} = $suffix;
3459
                    push @{$suffixes{$suffix}}, $pv_id;
3460
 
3461
#                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $locked, $created, $created_id, $suffix\n";
3462
                }
3463
            }
3464
            else
3465
            {
3466
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
3467
            }
3468
            $sth->finish();
3469
        }
3470
        else
3471
        {
3472
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
3473
        }
3474
    }
3475
    else
3476
    {
3477
        Error("GetData_by_pkg_id:Prepare failure" );
3478
    }
3479
}
3480
 
3481
#-------------------------------------------------------------------------------
3482
# Function        : massageVersion
3483
#
3484
# Description     : Process a version number and return usful bits
3485
#
3486
# Inputs          : Version Number
3487
#                   Package Name - debug only
3488
#
3489
# Returns         : An array
3490
#                       suffix
3491
#                       multipart version string useful for text comparisons
3492
#
3493
sub massageVersion
3494
{
3495
    my ($version, $name) = @_;
3496
    my ($major, $minor, $patch, $build, $suffix);
3497
    my $result;
3498
    my $buildVersion;
3499
    my $isaRipple;
3500
    my $isaWIP;
3501
    $build = 0;
3502
 
3503
#print "--- $name, $version\n";
3504
    $version =~ s~^_~~;
3505
    $version =~ s~^${name}_~~;
3506
 
3507
    #
3508
    #   xxxxxxxxx.nnnn.cots
3509
    #
3510
    if ( $version =~ m~(.*)\.cots$~ ) {
3511
        my $cots_base = $1;
3512
        $suffix = '.cots';
3513
        if ( $version =~ m~(.*?)\.([0-9]{4})\.cots$~ )
3514
        {
3515
            $result = $1 . sprintf (".%4.4d", $2) . $suffix;
3516
        }
3517
        else
3518
        {
3519
            $result = $cots_base . '.0000.cots';
3520
        }
3521
    }
3522
    #
3523
    #   Convert version into full form for comparisions
3524
    #       nnn.nnn.nnn.[p]nnn.xxx
3525
    #       nnn.nnn.nnn.[p]nnn-xxx
3526
    #       nnn.nnn.nnn-[p]nnn.xxx
3527
    #       nnn.nnn.nnn-[p]nnn-xxx
3528
    #       nnn.nnn.nnn[p]nnn-xxx
3529
    #   Don't flag as ripples - they are patches
3530
    #
3531
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-.p][p]?(\d+)([-.](.*))?$~ ) {
3532
        $major = $1;
3533
        $minor = $2;
3534
        $patch = $3;
3535
        $build = $4;
3536
        $suffix = defined $6 ? ".$6" : '';
3537
        $isaRipple = 0;
3538
    }
3539
    #
3540
    #       nn.nnn.nnnnn.xxx
3541
    #       nn.nnn.nnnnn-xxx
3542
    #       nnn.nnn.nnnx.xxx
3543
    #   Don't flag as ripples - they are patches
3544
    #
3545
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)\w?([-.](.*))?$~ ) {
3546
        $major = $1;
3547
        $minor = $2;
3548
        $patch = $3;
3549
        if ( length( $patch) >= 4 )
3550
        {
3551
            $build = substr( $patch, -3 ,3);
3552
            $patch = substr( $patch,  0 ,length($patch)-3);
3553
        }
3554
        $suffix = defined $5 ? ".$5" : '';
3555
    }
3556
 
3557
    #
3558
    #       nnn.nnn.nnn
3559
    #       nnn.nnn-nnn
3560
    #       nnn.nnn_nnn
3561
    #
3562
    elsif ( $version =~ m~^(\d+)\.(\d+)[-._](\d+)$~ ) {
3563
        $major = $1;
3564
        $minor = $2;
3565
        $patch = $3;
3566
        $suffix = '';
3567
    }
3568
 
3569
    #
3570
    #       nnn.nnn.nnn.nnn
3571
    #       nnn.nnn.nnn-nnn
3572
    #       nnn.nnn.nnn_nnn
3573
    #
3574
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-._](\d+)$~ ) {
3575
        $major = $1;
3576
        $minor = $2;
3577
        $patch = $3;
3578
        $build = $4;
3579
        $suffix = '';
3580
        $isaRipple = 0;
3581
    }
3582
 
3583
 
3584
    #
3585
    #       nnn.nnn
3586
    #
3587
    elsif ( $version =~ m~^(\d+)\.(\d+)$~ ) {
3588
        $major = $1;
3589
        $minor = $2;
3590
        $patch = 0;
3591
        $suffix = '';
3592
    }
3593
    #
3594
    #       nnn.nnn.xxx
3595
    #
3596
    elsif ( $version =~ m~^(\d+)\.(\d+)(\.\w+)$~ ) {
3597
        $major = $1;
3598
        $minor = $2;
3599
        $patch = 0;
3600
        $suffix = $3;
3601
    }
3602
 
3603
    #
3604
    #       nnn.nnn.nnnz
3605
    #
3606
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)([a-z])$~ ) {
3607
        $major = $1;
3608
        $minor = $2;
3609
        $patch = $3;
3610
        $build = ord($4) - ord('a');
3611
        $suffix = '.cots';
3612
        $isaRipple = 0;
3613
    }
3614
    #
3615
    #       ???REV=???
3616
    #
3617
    elsif ( $version =~ m~REV=~ ) {
3618
        $suffix = '.cots';
3619
        $result = $version . '.0000.cots';
3620
    }
3621
 
3622
    #
3623
    #   Wip Packages
3624
    #   (nnnnnn).xxx
3625
    #   Should be essential, but want to sort very low
3626
    #
3627
    elsif ($version =~ m~\((.*)\)(\..*)?~) {
3628
        $suffix = $2 || '';
3629
        $result = "000.000.000.000$suffix";
3630
        $isaWIP = 1;
3631
    }
3632
 
3633
    #
3634
    #   !current
3635
    #
3636
    elsif ($version eq '!current' || $version eq 'current_$USER' || $version eq 'current' || $version eq 'beta' || $version eq 'latest' || $version eq 'beta.cr' || $version eq 'CREATE') {
3637
        $suffix = '';
3638
        $result = "000.000.000.000$suffix";
3639
        $isaWIP = 1;
3640
    }
3641
 
3642
    #
3643
    #   Also WIP: FINRUN.103649.BEI.WIP
3644
    elsif ($version =~ m~(\.[a-zA-Z]+)\.WIP$~) {
3645
        $suffix = lc($1);
3646
        $result = "000.000.000.000$suffix";
3647
        $isaWIP = 1;
3648
    }
3649
 
3650
    #
3651
    #   Also ERGOFSSLS190100_015
3652
    #   Don't flag as a ripple
3653
    elsif ($version =~ m~^ERG[A-Z]+(\d\d)(\d\d)(\d\d)[-_](\d+)(\.\w+)?$~) {
3654
        $major = $1;
3655
        $minor = $2;
3656
        $patch = $3;
3657
        $build = $4;
3658
        $suffix = $5 || '.sls';
3659
        $isaRipple = 0;
3660
    }
3661
 
3662
    #
3663
    #   Stuff we don't yet handle
3664
    #
3665
    else  {
3666
        Warning ("Unknown version number: $name,$version");
3667
        $version =~ m~(\.\w+)$~;
3668
        $suffix = $1 || '';
3669
        $result = $version;
3670
    }
3671
 
3672
    $isaRipple = ($build > 0) unless defined $isaRipple;
3673
    unless ( $result )
3674
    {
3675
        # Major and minor of 99.99 are normally funy versions
3676
        # Don't make important desicions on them
3677
        #
3678
        if ( $major == 99 && $minor == 99 )
3679
        {
3680
            $major = 0;
3681
            $minor = 0;
3682
            $patch = 0;
3683
        }
3684
 
3685
        $result = sprintf("%3.3d.%3.3d.%3.3d.%3.3d%s", $major,$minor,$patch,$build,$suffix || '.0000');
3686
        $buildVersion = [ $major, $minor, $patch, $build ];
3687
    }
3688
 
3689
    $suffix = lc( $suffix );
3690
    if ( exists $suffixFixup{$suffix} )
3691
    {
3692
        $suffix = $suffixFixup{$suffix} ;
3693
    }
3694
 
3695
    return ($suffix, $result, $isaRipple, $isaWIP, $buildVersion );
3696
}
3697
 
3698
#-------------------------------------------------------------------------------
395 dpurdie 3699
# Function        : vcsCleanup
3700
#
3701
# Description     : Cleanup and rewrite a vcstag
3702
#
3703
#                   DUPLICATED IN:
3704
#                       - cc2svn_procdata
3705
#                       - cc2svn_importpackage
3706
#
3707
# Inputs          : vcstag
3708
#
3709
# Returns         : Cleaned up vcs tag
3710
#
3711
sub vcsCleanup
3712
{
3713
    my ($tag) = @_;
3714
    $tag =~ tr~\\/~/~;
3715
    if ( $tag =~ m~^CC::~ )
3716
    {
2429 dpurdie 3717
        $tag =~ s~CC::load\s+~CC::~;                # Load rule
3718
        $tag =~ s~CC::\s+~CC::~;                    # Leading white space
3719
        $tag =~ s~CC::[A-Za-z]\:/~CC::/~;           # Leading driver letter
3720
        $tag =~ s~CC::/+~CC::/~;                    # Multiple initial /'s
3721
        $tag =~ s~/build.pl::~::~i;
3722
        $tag =~ s~/src::~::~i;
395 dpurdie 3723
        $tag =~ s~MASS_Dev_Bus/Cbp/~MASS_Dev_Bus/CBP/~i;
3724
        $tag =~ s~MASS_Dev_Bus~MASS_Dev_Bus~i;
3725
        $tag =~ s~/MASS_Dev/Infra~MASS_Dev_Infra~i;
3726
        $tag =~ s~/MASS_Dev/Bus/web~/MASS_Dev_Bus/web~i;
3727
 
3728
        $tag =~ s~/Vastraffik/~/Vasttrafik/~;
3729
        $tag =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
3730
        $tag =~ s~DPC_SWCode/~DPG_SWCode/~i;
3731
    }
3732
    return $tag;
3733
}
3734
 
3735
#-------------------------------------------------------------------------------
392 dpurdie 3736
# Function        : examineVcsTag
3737
#
3738
# Description     : Examine a VCS Tag and determine if it looks like rubbish
395 dpurdie 3739
#                   Give it a clean
392 dpurdie 3740
#
3741
# Inputs          : $entry
3742
#
3743
# Returns         : Will add Data to the $entry
3744
#
3745
sub examineVcsTag
3746
{
3747
    my ($entry) = @_;
3748
    my $bad = 0;
395 dpurdie 3749
 
3750
    $versions{$entry}{vcsTag} = vcsCleanup($versions{$entry}{vcsTag});
392 dpurdie 3751
    my $vcstag = $versions{$entry}{vcsTag};
395 dpurdie 3752
 
392 dpurdie 3753
    if ( $vcstag =~ m~^SVN::~ ) {
3754
        $versions{$entry}{isSvn} = 1;
3755
 
3756
    } elsif ( $vcstag =~ m~^CC::(.*?)(::(.+))?$~ ) {
3757
        my $path = $1  || '';
3758
        my $label = $2 || '';
3759
        $bad = 1 unless ( $label );
3760
        $bad = 1 if ( $label =~ m~^N/A$~i || $label  =~ m~^na$~i );
3761
 
3762
        $bad = 1 unless ( $path );
3763
        $bad = 1 if ( $path =~ m~^N/A$~i || $path  =~ m~^na$~i );
3764
        $bad = 1 if ( $path =~ m~^/dpkg_archive~ || $path  =~ m~^dpkg_archive~ );
3765
        $bad = 1 if ( $path =~ m~^/devl/~ || $path  =~ m~^devl/~ );
395 dpurdie 3766
        $bad = 1 if ( $path =~ m~^CVS~ );
392 dpurdie 3767
        $bad = 1 if ( $path =~ m~^http:~i );
3768
        $bad = 1 if ( $path =~ m~^[A-Za-z]\:~ );
3769
        $bad = 1 if ( $path =~ m~^//~ );
395 dpurdie 3770
        $bad = 1 if ( $path =~ m~^/*none~i );
3771
        $bad = 1 if ( $path =~ m~^/*NoWhere~i );
3772
        $bad = 1 if ( $path =~ m~^-$~i );
392 dpurdie 3773
        $bad = 1 if ( $path =~ m~^cvsserver:~ );
3774
        $bad = 1 if ( $path =~ m~,\s*module:~ );
3775
#        $bad = 1 unless ( $path =~ m~^/~ );
3776
    }
3777
    else
3778
    {
3779
        $bad = 1;
3780
    }
3781
    $versions{$entry}{badVcsTag} = 1 if ( $bad );
3782
}
3783
 
3784
#-------------------------------------------------------------------------------
3785
# Function        : logToFile
3786
#
3787
# Description     : Log some data to a named file
3788
#                   Use file locking to allow multiple process to log
3789
#
3790
# Inputs          : $filename           - Name of file to log
3791
#                   ...                 - Data to log
3792
#
3793
# Returns         : Nothing
3794
#
3795
sub logToFile
3796
{
3797
    my ($file, @data) = @_;
3798
 
3799
    open  (LOGFILE, '>>', $file);
3800
    flock (LOGFILE, LOCK_EX);
3801
    print  LOGFILE "@data\n";
3802
    flock (LOGFILE, LOCK_UN);
3803
    close (LOGFILE);
3804
}
3805
 
3806
#-------------------------------------------------------------------------------
3807
# Function        : createImages
3808
#
3809
# Description     : Create nice images of the RM version tree
3810
#
3811
# Inputs          : 
3812
#
3813
# Returns         : 
3814
#
3815
sub createImages
3816
{
3817
 
3818
    my $filebase = "${packageNames}";
2439 dpurdie 3819
    open (FH, '>', $cwd . "/$filebase.dot" ) or die "Cannot open output";
392 dpurdie 3820
    print FH "digraph \"${packageNames}\" {\n";
3821
    #print FH "rankdir=LR;\n";
3822
    print FH "node[fontsize=16];\n";
3823
    print FH "node[target=_graphviz];\n";
3824
#    print FH "subgraph cluster_A {\n";
3825
#    print FH "node[fontsize=12];\n";
3826
 
3827
    {
3828
        my @text;
3829
        push @text, $packageNames;
3830
        push @text, 'HyperLinked to Release Manager';
3831
        push @text, 'Created:' . localtime();
3832
        push @text, '|';
3833
 
3834
        push @text, 'Total RM versions: ' . $totalVersions;
3835
        push @text, 'Essential Entries: ' . scalar @EssentialPackages;
3836
        push @text, 'Initial trees: ' . $initialTrees;
3837
 
1270 dpurdie 3838
        push @text, 'Number of Entries: ' . $processTotal;
392 dpurdie 3839
        push @text, 'Type : ' . $packageType;
3840
        push @text, 'All versions in Subversion' if ( $allSvn );
3841
 
3842
        push @text, '|';
3843
        push @text, 'Total Project Branches: ' . $ProjectCount;
3844
        foreach ( sort keys %knownProjects )
3845
        {
3846
            my $count = $knownProjects{$_}{count} || 0;
3847
            if ( $count )
3848
            {
3849
                my $text = 'Project Branch: ' . $_;
3850
                $text .= " (" . $count . ")" if ( $count > 1 );
3851
                push @text, $text;
3852
            }
3853
        }
3854
 
3855
        push @text, '|';
3856
        push @text, 'Bad VCS : ' . $badVcsCount;
3857
        push @text, 'Bad Singletions : ' . $badSingletonCount;
3858
        push @text, 'Deadwood entries : ' . $trimCount;
3859
        push @text, 'Walking Mode : Flat' if ($opt_flat);
3860
        push @text, 'Pruned Mode : ' . $pruneModeString;
3861
        push @text, 'Pruned entries : ' . $pruneCount;
1272 dpurdie 3862
        push @text, 'Recent entries : ' . $recentCount;
392 dpurdie 3863
 
3864
        if ( @unknownProjects )
3865
        {
3866
            push @text, '|';
3867
            push @text, 'Unknown Projects';
3868
            push @text, 'Unknown Project: ' . $_ foreach (sort @unknownProjects );
3869
        }
3870
 
3871
        #
3872
        #   Multiple Paths
3873
        #
3874
        if ( scalar @multiplePaths > 1 )
3875
        {
3876
            push @text, '|';
3877
            push @text, 'Multiple Paths';
3878
            push @text, @multiplePaths;
3879
        }
3880
 
3881
        #
3882
        #   Bad essentials
3883
        #
3884
        if ( @badEssentials  )
3885
        {
3886
            push @text, '|';
3887
            push @text, 'Bad Essential Versions';
3888
            push @text, GetVname($_) foreach ( @badEssentials );
3889
        }
3890
 
3891
        #
3892
        #   Subversion Data
3893
        #
3894
        if ( %svnData )
3895
        {
3896
            push @text, '|';
3897
            push @text, 'Subversion';
3898
            push @text, 'Trunk used' if exists $svnData{branches}{trunk} ;
3899
            push @text, 'Labels: ' . scalar keys %{$svnData{tags}} ;
3900
            push @text, 'Branches: ' . scalar keys %{$svnData{branches}} ;
2429 dpurdie 3901
            push @text, 'Relabled Packages : ' . $packageReLabelCount;
392 dpurdie 3902
        }
3903
 
3904
        push @text, '';
3905
        my $text = join '\l', @text;
3906
        $text =~ s~\|\\l~|~g;
3907
 
3908
        my @attributes;
3909
        push @attributes, "shape=record";
3910
        push @attributes, "label=\"{$text}\"";
3911
        push @attributes, "tooltip=\"$packageNames\"";
1272 dpurdie 3912
        push (@attributes, "URL=\"" . $GBE_RM_URL . "/view_by_version.asp?pkg_id=$first_pkg_id" . "\"" )if $first_pkg_id;
392 dpurdie 3913
        push @attributes, "color=red";
3914
        my $attr = join( ' ', @attributes);
3915
 
3916
        my $tld_done = 'TitleBlock';
3917
        print FH "$tld_done [$attr]\n";
3918
    }
3919
 
3920
    #
3921
    #   Generate Legend
3922
    #
3923
    {
3924
        my @text;
3925
        push @text, 'Legend';
3926
        push @text, '|';
3927
        push @text, 'Node Content';
3928
        push @text, 'Package Version';
3929
#        push @text, 'Release Manager Ref (pvid)';
3930
        push @text, 'Creation Date: yyyy-mm-dd';
3931
        push @text, '(Coded information)';
3932
        push @text, '|{Code';
3933
        push @text, '|{N: Not Locked';
3934
        push @text, 'b: Bad Singleton';
3935
        push @text, 'B: Bad VCS Tag';
3936
        push @text, 'D: DeadWood';
1272 dpurdie 3937
        push @text, 'E: Essential Release Version';
2429 dpurdie 3938
        push @text, 'F: Package directories labled';
392 dpurdie 3939
        push @text, 'G: Glued into Version Tree';
2429 dpurdie 3940
        push @text, 'L: Label not in VOB';
1272 dpurdie 3941
        push @text, 'r: Recent version';
1328 dpurdie 3942
        push @text, 'R: Ripple';
392 dpurdie 3943
        push @text, 'S: Splitpoint';
3944
        push @text, 't: Glued into Project Tree';
3945
        push @text, 'T: Tip version';
3946
        push @text, 'V: In SVN';
3947
        push @text, '+: In Subversion';
2429 dpurdie 3948
        push @text, '0: Zero files extracted';
392 dpurdie 3949
        push @text, '}}';
3950
 
3951
        push @text, '|';
3952
        push @text, 'Outline';
3953
        push @text, 'Red: Dead or Bad VCS Tag';
3954
        push @text, 'Orange: Project Branch Root';
3955
        push @text, 'Green: Ripple Build Version';
3956
        push @text, 'Blue: Essential Version';
3957
        push @text, 'Darkmagenta: Entry Glued into tree';
3958
        push @text, 'Magenta: Entry added to project tree';
2429 dpurdie 3959
        push @text, 'DeepPink: Label not in VOB';
3960
        push @text, 'DarkViolet: Zero files extracted';
392 dpurdie 3961
 
3962
 
3963
        push @text, '|';
3964
        push @text, 'Fill';
3965
        push @text, 'PowderBlue: Essential Version';
3966
        push @text, 'Red: Bad Essential Version';
3967
        push @text, 'Light Green: Migrated to SVN';
3968
#        push @text, 'Red: Entry Glued into tree';
3969
#        push @text, 'Green: Entry added to project tree';
3970
 
3971
        push @text, '|';
3972
        push @text, 'Shape';
3973
        push @text, 'Oval: Normal Package Version';
3974
        push @text, 'Invhouse: Project Branch Root';
3975
        push @text, 'Octagon: Branch Point';
3976
        push @text, 'Box: Bad Single version with no history';
3977
        push @text, 'Doublecircle: Tip of a Project Branch';
3978
 
3979
        push @text, '';
3980
        my $text = join '\l', @text;
3981
        $text =~ s~\|\\l~|~g;
3982
        $text =~ s~\}\\l~}~g;
3983
 
3984
        my @attributes;
3985
        push @attributes, "shape=record";
3986
        push @attributes, "label=\"{$text}\"";
3987
        push @attributes, "color=red";
3988
        my $attr = join( ' ', @attributes);
3989
 
3990
        my $tld_done = 'LegendBlock';
3991
        print FH "$tld_done [$attr]\n";
3992
    }
3993
 
3994
#    print FH "\n}\n";
3995
    print FH "TitleBlock -> LegendBlock [style=invis]\n";
3996
 
3997
    sub genLabelText
3998
    {
3999
        my ($entry) = @_;
4000
        my @label;
4001
        push @label, $versions{$entry}{name} if ( $multiPackages );
4002
        push @label, $versions{$entry}{vname};
4003
#        push @label, $entry;       # Add PVID
4004
        push @label, substr( $versions{$entry}{created}, 0, 10); #  2008-02-19
4005
#        push @label, 'V=' . $versions{$entry}{maxVersion};
4006
#        push @label, 'B=' . $versions{$entry}{svnBranchTip} if ( exists $versions{$entry}{svnBranchTip} );
4007
 
4008
 
4009
        my $stateText = '';
4010
        $stateText .= 'N' if ($versions{$entry}{locked} eq 'N');
4011
        $stateText .= 'b' if (exists $versions{$entry}{badSingleton});
4012
        $stateText .= 'B' if (exists $versions{$entry}{badVcsTag});
4013
        $stateText .= 'G' if (exists $versions{$entry}{GluedIn});
4014
        $stateText .= 't' if (exists $versions{$entry}{MakeTree});
4015
        $stateText .= 'E' if (exists $versions{$entry}{Essential});
4016
        $stateText .= 'D' if (exists $versions{$entry}{DeadWood});
1328 dpurdie 4017
        $stateText .= 'R' if ( $versions{$entry}{isaRipple} );
1272 dpurdie 4018
        $stateText .= 'r' if (exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
392 dpurdie 4019
        $stateText .= 'S' if (exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
4020
        $stateText .= 'T' if (exists $versions{$entry}{Tip} );
4021
        $stateText .= 'V' if (exists $versions{$entry}{isSvn} );
4022
        $stateText .= '+' if (exists $versions{$entry}{svnVersion} );
2429 dpurdie 4023
        $stateText .= '0' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq '0');
4024
        $stateText .= 'L' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq 'L');
4025
        $stateText .= 'F' if ($versions{$entry}{data}{DirsLabled});
4026
 
4027
 
392 dpurdie 4028
#        $stateText .= 's' if (exists $versions{$entry}{branchPoint} );
4029
#        $stateText .= ' T='. $versions{$entry}{threadId} if (exists $versions{$entry}{threadId});
4030
#        $stateText .= ' EssentalPath' if (exists $versions{$entry}{EssentialPath});
4031
#        $stateText .= ' Count='. $versions{$entry}{EssentialSplitPoint} if (exists $versions{$entry}{EssentialSplitPoint});
4032
#        $stateText .= ' M='. $versions{$entry}{maxVersion} if (exists $versions{$entry}{maxVersion});
4033
 
2429 dpurdie 4034
        push @label, "(${stateText})" if ( length($stateText) );
392 dpurdie 4035
 
1341 dpurdie 4036
##       Insert Release Names
1451 dpurdie 4037
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
4038
            next unless ( exists $ukHopsReleases{$rtag_id} );
4039
            push @label, "Release: $versions{$entry}{Releases}{$rtag_id}{rname}";
4040
        }
1341 dpurdie 4041
 
392 dpurdie 4042
        return join ('\n', @label );
4043
    }
4044
 
4045
    sub genAttributes
4046
    {
4047
        my ($entry) = @_;
4048
        my @attributes;
4049
        push @attributes, 'label="' . genLabelText($entry) . '"';
4050
        push @attributes, 'URL="' . dotUrl($entry) . '"';
4051
        push @attributes, 'tooltip="' . "Goto: $versions{$entry}{vname}, PVID=$entry" ,'"';
4052
        my $shape;
4053
            $shape = 'box' if ($versions{$entry}{badSingleton});
4054
            $shape = 'octagon'  if ($versions{$entry}{branchPoint});
4055
            $shape = 'invhouse' if ($versions{$entry}{newSuffix});
4056
            $shape = 'doublecircle' if ($versions{$entry}{Tip});
4057
 
4058
 
4059
        push @attributes, 'shape=' . $shape if ( $shape );
4060
 
4061
        my $color;
4062
        my $fill;
4063
           $color = 'color=green style=bold' if ( $versions{$entry}{isaRipple} );
4064
           $color = 'color=orange style=bold' if ( $versions{$entry}{newSuffix} );
4065
           $color = 'color=red style=bold' if ( $versions{$entry}{DeadWood} || $versions{$entry}{badVcsTag} );
4066
           $color = 'color=blue style=bold' if ( $versions{$entry}{Essential} );
4067
           $color = 'color=darkmagenta style=bold' if ( $versions{$entry}{GluedIn} );
4068
           $color = 'color=magenta style=bold' if ( $versions{$entry}{MakeTree} );
2429 dpurdie 4069
           $color = 'color=DeepPink style=bold' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq 'L');
4070
           $color = 'color=DarkViolet style=bold' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq '0');
392 dpurdie 4071
 
4072
           $fill = 'style=filled fillcolor=powderblue' if ( $versions{$entry}{Essential} );
4073
           $fill = 'style=filled fillcolor=red' if ( $versions{$entry}{Essential} && $versions{$entry}{badVcsTag} );
4074
           $fill = 'style=filled fillcolor="#99FF99"' if ( exists $versions{$entry}{svnVersion} );
4075
 
4076
 
4077
        push @attributes, $color if ( $color );
4078
        push @attributes, $fill if ( $fill );
4079
 
4080
        return '[' . join( ' ', @attributes) . ']';
4081
    }
4082
 
4083
    sub genArrowAttributes
4084
    {
4085
        my ($not_first, $entry) = @_;
4086
        my @attributes;
4087
 
4088
        push @attributes, 'arrowhead=empty' if ( $not_first );
4089
        push ( @attributes, 'label="' . $versions{$entry}{svnBranchTip} .'"' ) if ( exists $versions{$entry}{svnBranchTip} );
4090
 
4091
        return ('[' . join( ' ', @attributes) . ']') if ( @attributes ) ;
4092
        return '';
4093
    }
4094
 
4095
    #
4096
    #   Flat
4097
    #
4098
    if ( $opt_flat )
4099
    {
4100
        my $last = 0;
4101
        foreach my $entry (@flatOrder )
4102
        {
4103
            if ( $last )
4104
            {
4105
                my $me = dotTag($last);
4106
 
4107
                print FH pentry($me)  ,' -> ', pentry(dotTag($entry)), genArrowAttributes(0, $entry) ,";\n";
4108
                print FH pentry($me)  ,genAttributes($last) . ";\n";
4109
            }
4110
            $last = $entry;
4111
        }
4112
        print FH pentry(dotTag($last))  ,genAttributes($last) . ";\n";
4113
 
4114
    }
4115
    else
4116
    {
4117
        foreach my $entry ( sort {$a <=> $b} keys(%versions) )
4118
        {
4119
            my $me = dotTag($entry);
4120
            my @versions = @{ $versions{$entry}{next}};
4121
            my $ii = 0;
4122
            foreach ( @versions )
4123
            {
4124
                print FH pentry($me)  ," -> ",pentry(dotTag($_)), genArrowAttributes($ii++, $_), ";\n";
4125
            }
4126
 
4127
            print FH pentry($me)  ,genAttributes($entry) . ";\n";
4128
        }
4129
    }
4130
 
4131
    print FH "\n};\n";
4132
    close FH;
4133
 
4134
    #
4135
    #   Convert DOT to a SVG
4136
    #
4137
    unless ( $UNIX )
4138
    {
4139
    print "Generating graphical images\n";
4140
#    system( "dot $filebase.dot -Tjpg -o$filebase.jpg" );  # -v
4141
    system( "dot $filebase.dot -Tsvg -o$filebase.svg" );  # -v
4142
#    unlink("$filebase.dot");
4143
 
4144
    #
4145
    #   Display a list of terminal packages
4146
    #   These are packages that are not used by any other package
4147
    #
4148
    print "\n";
4149
#    print "Generated: $filebase.dot\n";
4150
#    print "Generated: $filebase.jpg\n";
4151
    print "Generated: $filebase.svg\n";
4152
    }
4153
    else
4154
    {
4155
        print "Generated: $filebase.dot\n";
4156
    }
4157
}
4158
 
4159
sub dotTag
4160
{
4161
    my ($entry) = @_;
4162
 
4163
    my $label = '';
4164
    $label .= $versions{$entry}{name} if $multiPackages;
4165
    $label .= $versions{$entry}{vname};
4166
    $label =~ s~[-() ]~_~g;
4167
    return $label;
4168
}
4169
 
4170
sub dotUrl
4171
{
4172
    my ($entry) = @_;
4173
 
4174
    my $pv_base = $GBE_RM_URL . "/fixed_issues.asp?pv_id=$entry";
4175
}
4176
 
4177
#-------------------------------------------------------------------------------
4178
# Function        : pentry
4179
#
4180
# Description     : Generate an entry list as text
4181
#                   Replace "." with "_" since DOT doesn't like .'s
4182
#                   Seperate the arguments
4183
#
4184
# Inputs          : @_          - An array of entries to process
4185
#
4186
# Returns         : A string
4187
#
4188
sub pentry
4189
{
4190
    my ($data) = @_;
4191
    $data =~ s~\.~_~g;
4192
    $result = '"' . $data . '"' ;
4193
    return $result;
4194
}
4195
 
4196
#-------------------------------------------------------------------------------
4197
# Function        : getVobMapping
4198
#
4199
# Description     : Read in Package to Repository Mapping
4200
#
4201
# Inputs          : 
4202
#
4203
# Returns         : Populates %VobMapping
4204
#                             Mapping of PackageName to RepoName[/Subdir]
4205
#
4206
our %ScmRepoMap;
4207
sub getVobMapping
4208
{
4209
    Message ("Read in Vob Mapping");
4210
 
4211
    my $fname = 'cc2svn.repo.dat';
4212
    Error "Cannot locate $fname" unless ( -f $fname );
4213
    require $fname;
4214
 
4215
    Error "Data in $fname is not valid\n"
4216
        unless ( keys(%ScmRepoMap) >= 0 );
4217
 
4218
    $opt_vobMap = $ScmRepoMap{$packageNames}{repo}
4219
        if (exists $ScmRepoMap{$packageNames});
4220
 
2450 dpurdie 4221
    $opt_protected = $ScmRepoMap{$packageNames}{protected}
4222
        if (exists $ScmRepoMap{$packageNames}{protected});
4223
 
392 dpurdie 4224
    #
4225
    #   Free the memory
4226
    #
4227
    %ScmRepoMap = ();
4228
 
4229
    #
4230
    #   Calculate Target Repo
4231
    #
4232
    Warning ("No VOB Mapping found")
4233
        unless ($opt_vobMap);
4234
    Error("No repository specified. ie -repo=DevTools or -repo=COTS")
4235
        unless ( $opt_repo || $opt_vobMap );
4236
 
4237
    my $r1 = ($opt_repo || '') . '/' . ($opt_vobMap || '');
4238
    $r1 =~ s~^/~~;
4239
    $r1 =~ s~/$~~;
4240
    $svnRepo = $opt_repo_base . $r1;
4241
 
4242
    Verbose( "Repo URL: $svnRepo");
4243
}
4244
 
4245
 
4246
#-------------------------------------------------------------------------------
4247
# Function        : getEssenialPackageVersions
4248
#
4249
# Description     : Determine the 'Essental' Package Versions
4250
#                   Read the data in from an external file
4251
#
4252
# Inputs          : 
4253
#
4254
# Returns         : Populates @EssentialPackages
4255
#
4256
 
4257
our %ScmReleases;
4258
our %ScmPackages;
4259
our %ScmSuffixes;
4260
sub getEssenialPackageVersions
4261
{
4262
    Message ("Read in Essential Package Versions");
4263
 
4264
    my $fname = 'cc2svn.raw.txt';
4265
    Error "Cannot locate $fname" unless ( -f $fname );
4266
    require $fname;
4267
 
4268
    Error "Data in $fname is not valid\n"
4269
        unless ( keys(%ScmReleases) >= 0 );
4270
 
4271
#    DebugDumpData("ScmReleases", \%ScmReleases );
4272
#    DebugDumpData("ScmPackages", \%ScmPackages );
4273
#    DebugDumpData("ScmSuffixes", \%ScmSuffixes );
4274
 
4275
    #
4276
    #   Create a list of essential packages
4277
    #   Retain packages-versions used in this program
4278
    #
4279
    foreach ( keys %ScmPackages )
4280
    {
4281
        next unless ( exists  $pkg_ids{ $ScmPackages{$_}{pkgid} } );
4282
        push @EssentialPackages, $_;
4283
        Error ("Essential Package Version not in extracted Release Manager Data: $_")
4284
            unless ( exists $versions{$_} );
4285
        $versions{$_}{Essential} = 1;
1341 dpurdie 4286
 
4287
        # Retain which RM Release this package-version is the tip
4288
        # Release of
1342 dpurdie 4289
        foreach my $rtag_id ( @{$ScmPackages{$_}{'release'}} )
1341 dpurdie 4290
        {
1342 dpurdie 4291
            $versions{$_}{Releases}{$rtag_id}{rname}   = $ScmReleases{$rtag_id}{name};
4292
            $versions{$_}{Releases}{$rtag_id}{pname}   = $ScmReleases{$rtag_id}{pName};
4293
            $versions{$_}{Releases}{$rtag_id}{proj_id} = $ScmReleases{$rtag_id}{proj_id};
1341 dpurdie 4294
        }
4295
 
392 dpurdie 4296
        #print "ESSENTIAL: $versions{$_}{name} $versions{$_}{vname}\n";
4297
    }
4298
 
4299
    #
4300
    #   Free memory
4301
    #
4302
    %ScmReleases = ();
4303
    %ScmPackages = ();
4304
    %ScmSuffixes = ();
4305
 
4306
#    DebugDumpData("Essential", \@EssentialPackages );
4307
    Message ("Essential Versions: " . scalar @EssentialPackages );
4308
}
4309
 
4310
#-------------------------------------------------------------------------------
4311
# Function        : ReportPathVariance
4312
#
4313
# Description     : Report variance in paths used by the versions
4314
#
4315
# Inputs          : 
4316
#
4317
# Returns         : 
4318
#
4319
my %VobPaths;
4320
sub ReportPathVariance
4321
{
4322
    Message ("Detect Multiple Paths");
4323
    foreach my $entry ( keys(%versions) )
4324
    {
4325
        my $e = $versions{$entry};
4326
        next if ( isSet ($e, 'DeadWood' ) );
4327
        next if ( isSet ($e, 'badVcsTag') );
4328
        next if ( isSet ($e, 'isSvn') );
4329
        my $tag = $e->{vcsTag};
4330
        next unless ( $tag );
4331
 
4332
        $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
4333
        my $vcsType = $1;
4334
        my $cc_label = $4;
4335
        my $cc_path = $2;
4336
        $cc_path = '/' . $cc_path;
4337
        $cc_path =~ tr~\\/~/~s;
4338
 
4339
        $VobPaths{$cc_path}++;
4340
    }
4341
 
4342
    @multiplePaths = sort keys %VobPaths;
4343
    if ( scalar @multiplePaths > 1 )
4344
    {
4345
        Warning ("Multiple Paths:" . $_ ) foreach (@multiplePaths);
4346
    }
4347
}
4348
 
4349
sub isSet
4350
{
4351
    my ($base, $element) = @_;
4352
    return 0 unless ( exists $base->{$element} );
4353
    return $base->{$element};
4354
}
4355
 
4356
 
4357
#-------------------------------------------------------------------------------
4358
# Function        : recurseList
4359
#
4360
# Description     : Return a list of all element below a given head element
4361
#
4362
# Inputs          : $head               - Head element
4363
#
4364
# Returns         : A list, not in any particular order
4365
#
4366
 
4367
our @recurseList;
4368
sub recurseList
4369
{
4370
    @recurseList = ();
4371
    recurseListBody (@_);
4372
    return @recurseList;
4373
}
4374
sub recurseListBody
4375
{
4376
    foreach my $entry ( @_ )
4377
    {
4378
        push @recurseList, $entry;
4379
no warnings "recursion";
4380
        recurseListBody (@{$versions{$entry}{next}});
4381
    }
4382
}
4383
 
4384
#-------------------------------------------------------------------------------
4385
# Function        : getSvnData
4386
#
4387
# Description     : Read the SVN tree and see what we have
4388
#
4389
# Inputs          : 
4390
#
4391
# Returns         : 
4392
#
4393
my @svnDataItems;
4394
sub getSvnData
4395
{
4396
    Message ("Examine Subversion Tree");
4397
 
4398
    #
4399
    #   Re-init data
4400
    #
4401
    @svnDataItems = ();
4402
    %svnData = ();
4403
 
4404
    #
4405
    #   Create an SVN session
4406
    #
4407
    return unless ( $svnRepo );
4408
    my $svn = NewSessionByUrl ( "$svnRepo/$packageNames" );
4409
    return unless ( $svn );
4410
 
4411
    #
4412
    #   extract data
4413
    #
4414
#    DebugDumpData("SVN", $svn );
4415
    $svn->SvnCmd ( 'log', '-v', '--xml', '--stop-on-copy', $svn->Full()
4416
                    , { 'credentials' => 1,
4417
                        'process' => \&ProcessSvnLog,
4418
                         }
4419
                        );
4420
 
4421
    #
4422
    #   Process data
4423
    foreach my $entry ( @svnDataItems )
4424
    {
4425
        my $name;
4426
        my $isaBranch;
4427
        my $target = $entry->{target};
4428
        if ( $target =~ m~/tags/(.*)~ ) {
4429
            $name = $1;
4430
            $svnData{tags}{$name} = 1;
4431
        } elsif ( $target =~ m~/branches/(.*)~ )  {
4432
            $name = $1;
4433
    #        $branches{$1} = 1;
4434
        } else {
4435
            $svnData{nonTag}{$target} = 1;
4436
        }
4437
 
4438
        my $fromBranch;
4439
        if ( $entry->{fromPath} =~ m~/trunk$~  ) {
4440
            $fromBranch = 'trunk';
4441
        } elsif ( $entry->{fromPath} =~ m~/branches/(.*)~ ) {
4442
            $fromBranch = $1;
4443
        }
4444
 
1341 dpurdie 4445
        # largest Rev number on branch
4446
        if ( exists $svnData{max}{$fromBranch} )
392 dpurdie 4447
        {
1341 dpurdie 4448
            if ( $svnData{max}{$fromBranch}{rev} <  $entry->{fromRev} )
392 dpurdie 4449
            {
1341 dpurdie 4450
                $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
4451
                $svnData{max}{$fromBranch}{name} = $name;
392 dpurdie 4452
            }
4453
        }
1341 dpurdie 4454
        else
4455
        {
4456
            $svnData{max}{$fromBranch}{rev} =  $entry->{fromRev};
4457
            $svnData{max}{$fromBranch}{name} = $name;
4458
        }
392 dpurdie 4459
    }
1341 dpurdie 4460
 
4461
    foreach my $branch ( keys %{$svnData{max}} )
4462
    {
4463
        $svnData{tips}{$svnData{max}{$branch}{name}} = $branch;
4464
    }
4465
#    DebugDumpData("svnDataItems", \@svnDataItems);
392 dpurdie 4466
#    DebugDumpData("SvnData", \%svnData);
4467
 
1341 dpurdie 4468
 
392 dpurdie 4469
    foreach my $entry ( keys(%versions) )
4470
    {
4471
        my $import_label = saneLabel($entry);
4472
        delete $versions{$entry}{svnVersion};
4473
        delete $versions{$entry}{svnBranchTip};
4474
 
4475
        if ( exists $svnData{tags}{$import_label} )
4476
        {
4477
            $versions{$entry}{svnVersion} = 1;
4478
        }
4479
 
4480
        if ( exists $svnData{tips}{$import_label} )
4481
        {
4482
            $versions{$entry}{svnBranchTip} = $svnData{tips}{$import_label};
4483
        }
4484
    }
4485
 
1341 dpurdie 4486
    Message ( 'Trunk used: ' . (exists $svnData{'max'}{trunk} ? 'Yes' : 'No') );
392 dpurdie 4487
    Message ( 'Labels    : ' . scalar keys %{$svnData{tags}} );
1341 dpurdie 4488
    Message ( 'Branches  : ' . scalar keys %{$svnData{'max'}} );
392 dpurdie 4489
}
4490
 
4491
#-------------------------------------------------------------------------------
4492
# Function        : ProcessSvnLog
4493
#
4494
# Description     :
4495
#                   Parse
4496
#                       <logentry
4497
#                          revision="24272">
4498
#                       <author>bivey</author>
4499
#                       <date>2005-07-25T15:45:35.000000Z</date>
4500
#                       <paths>
4501
#                       <path
4502
#                          prop-mods="false"
4503
#                          text-mods="false"
4504
#                          kind="dir"
4505
#                          copyfrom-path="/enqdef/branches/Stockholm"
4506
#                          copyfrom-rev="24271"
4507
#                          action="A">/enqdef/tags/enqdef_24.0.1.sls</path>
4508
#                       </paths>
4509
#                       <msg>COTS/enqdef: Tagged by Jats Svn Import</msg>
4510
#                       </logentry>
4511
#
4512
# Inputs          : 
4513
#
4514
# Returns         : 
4515
#
4516
my $entryData;
4517
sub  ProcessSvnLog
4518
{
4519
    my ($self, $line ) = @_;
4520
#print "----- $line\n";
4521
    if ( $line =~ m~^<logentry~ ) {
4522
        $entryData = ();
4523
 
4524
    } elsif ( $line =~ m~^\s+revision="(\d+)"~ ) {
4525
        $entryData->{Rev} = $1;
4526
 
4527
    } elsif ( $line =~ m~^\s+copyfrom-path="(.*)"~ ) {
4528
        $entryData->{fromPath} = $1;
4529
 
4530
    } elsif ( $line =~ m~^\s+copyfrom-rev="(\d+)"~ ) {
4531
        $entryData->{fromRev} = $1;
4532
 
4533
    } elsif ( $line =~ m~\s+action=.*?>(.*)</path~ ) {
4534
        $entryData->{target} = $1;
4535
 
4536
    } elsif ( $line =~ m~</logentry~ ) {
4537
        if ( exists $entryData->{fromPath} )
4538
        {
4539
#            DebugDumpData("Data", $entryData);
4540
            push @svnDataItems, $entryData;
4541
        }
4542
    }
4543
 
4544
    #
4545
    #   Return 0 to keep on going
4546
    return 0;
4547
}
4548
 
1328 dpurdie 4549
#-------------------------------------------------------------------------------
392 dpurdie 4550
# Function        : saveData
4551
#
4552
# Description     : Save essential data
4553
#
4554
# Inputs          : 
4555
#
4556
# Returns         : 
4557
#
4558
sub saveData
4559
{
4560
    my $file = $cwd . "/${packageNames}.data";
4561
 
4562
    Message ("Create: $file");
4563
    my $fh = ConfigurationFile::New( $file );
4564
 
4565
    $fh->DumpData(
4566
        "\n# ScmVersions.\n#\n",
4567
        "ScmVersions", \%versions );
4568
 
4569
    #
4570
    #   Close out the file
4571
    #
4572
    $fh->Close();
4573
}
4574
 
4575
 
4576
#-------------------------------------------------------------------------------
4577
#   Documentation
4578
#
4579
 
4580
=pod
4581
 
4582
=for htmltoc    SYSUTIL::cc2svn::
4583
 
4584
=head1 NAME
4585
 
4586
cc2svn_gendata - CC2SVN tool to import an entire package into SVN
4587
 
4588
=head1 SYNOPSIS
4589
 
4590
  jats cc2svn_importpackage [options] package_name
4591
 
4592
 Options:
4593
    -help              - brief help message
4594
    -help -help        - Detailed help message
4595
    -man               - Full documentation
4596
    -repository=name   - Specify target repository
4597
    -[no]flat          - Do not create project tree. Def: -noflat
4598
    -prunemode=mode    - Mode: none, ripple, retain, severe, Def=ripple
4599
    -retain=N          - Specify retain count for pruning. Def=2
4600
    -[no]test          - Do not create packages. Def:-notest
4601
    -[no]reuse         - Keep and reuse ClearCase views
4602
    -age=nnDays        - Only keep recent package
4603
    -dump[=n]          - Dump raw data. N=0,1,2
4604
    -images[=n]        - Create SVG of version tree. N=0,1,2
4605
    -name=aaa          - Alternate output package name. Test Only
4606
    -[no]log           - Write output to log file. Def: -nolog
4607
    -[no]postimage     - Create image after transger: Def: -post
4608
    -workdir=path      - Use for temp storage (def:/work)
1270 dpurdie 4609
    -delete            - Delete SVN package before test
2429 dpurdie 4610
    -[no]relabel       - Attempt to relabel dirs in packages that don't extract
2450 dpurdie 4611
    -testRmDatabase    - Use test database
2478 dpurdie 4612
    -[no]fromSvn       - Also extract packages from SVN
392 dpurdie 4613
 
4614
=head1 OPTIONS
4615
 
4616
=over 8
4617
 
4618
=item B<-help>
4619
 
4620
Print a brief help message and exits.
4621
 
4622
=item B<-help -help>
4623
 
4624
Print a detailed help message with an explanation for each option.
4625
 
4626
=item B<-man>
4627
 
4628
Prints the manual page and exits.
4629
 
4630
=item B<-prunemode=mode>
4631
 
4632
This option control the manner in which excess versions will be pruned. Valid
4633
modes are:
4634
 
4635
=over 8
4636
 
4637
=item   none
4638
 
4639
No pruning will be performed
4640
 
4641
=item   ripple
4642
 
4643
Non-Essential packages that are ripple builds will be removed.
4644
 
4645
=item   retain
4646
 
4647
Versions that preceed an Essential version will be retained.
4648
 
4649
=item   severe
4650
 
4651
Only Essential Versions, and Branching points will be retained.
4652
 
4653
=back
4654
 
4655
=back
4656
 
4657
=head1 DESCRIPTION
4658
 
4659
This program is a tool used in the conversion of ClearCase VOBS to subversion.
4660
It will take a complete package and all relevent versions from ClearCase and
4661
insert them into subversion in a sessible manner. It will attempt to retain
4662
file change order and history.
4663
 
4664
It will:
4665
 
4666
=over 8
4667
 
4668
=item *
4669
 
4670
Read in the Essential Package Version list.
4671
 
4672
=item *
4673
 
4674
Extract, from Release Manager, all known versions of the specified package.
4675
 
4676
=item *
4677
 
4678
It will attempt to determine the type of package: COTS, TOOL, CORE, PROJECT
4679
and alter the processing accordingly.
4680
 
4681
=item *
4682
 
4683
It will create a version dependency tree and determine 'new' project branch
4684
points. It will remove (prune) versions that are excess to requirements.
4685
 
4686
=item *
4687
 
4688
It will extract source from ClearCase and insert it into SVN, creating
4689
branches and tags as it goes.
4690
 
4691
=back
4692
 
4693
The program can also be used to create a SVG image of the version dependency
4694
tree. This does not work on Linux; only Windows with 'dot' installed.
4695
 
4696
=cut
4697