Subversion Repositories DevTools

Rev

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