Subversion Repositories DevTools

Rev

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

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