Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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