Subversion Repositories DevTools

Rev

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

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