Subversion Repositories DevTools

Rev

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