Subversion Repositories DevTools

Rev

Rev 5709 | Details | Compare with Previous | Last modification | View Log | RSS feed

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