Subversion Repositories DevTools

Rev

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

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