Subversion Repositories DevTools

Rev

Rev 2764 | Rev 4022 | Go to most recent revision | 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;
4003 dpurdie 36
use JatsBuildFiles;
2439 dpurdie 37
use Encode;
1271 dpurdie 38
 
39
 
40
#use Data::Dumper;
41
use Fcntl ':flock'; # import LOCK_* constants
42
use Cwd;
43
use DBI;
44
use Getopt::Long;
45
use Pod::Usage;                             # required for help support
2429 dpurdie 46
use Encode;
1271 dpurdie 47
 
48
#
49
#   Options
50
#
51
my $opt_help = 0;
52
my $opt_manual = 0;
53
my $opt_verbose = 0;
54
my $opt_repo_base = 'AUPERASVN01/';
55
my $opt_repo = '';
2439 dpurdie 56
my $opt_repoSubdir = '';
1271 dpurdie 57
my $opt_flat;
58
my $opt_test;
2764 dpurdie 59
my $opt_reuse = 0;
1271 dpurdie 60
my $opt_age;
61
my $opt_dump = 0;
62
my $opt_images = 0;
63
my $opt_retaincount = 2;
64
my $opt_pruneModeString;
65
my $opt_listTags;
66
my $opt_name;
67
my $opt_log = 0;
68
my @opt_tip;
69
my $opt_postimage = 1;
70
my $opt_workDir = '/work';
71
my $opt_vobMap;
72
my $opt_fileList;
2764 dpurdie 73
my $opt_ccbase;
1271 dpurdie 74
my $opt_preserveProjectBase;
75
my $opt_ignoreProjectBaseErrors;
2439 dpurdie 76
my $opt_ignoreMakeProjectErrors;
4003 dpurdie 77
my $opt_ignoreBuildFileClashes;
2764 dpurdie 78
my $opt_forceProjectBase;
79
my @opt_limitProjectBase;
4003 dpurdie 80
my @opt_selectProjectBase;
2764 dpurdie 81
my @opt_mergePaths;
82
my $opt_ignoreBadPaths;
1272 dpurdie 83
my $opt_delete;
2429 dpurdie 84
my $opt_recentAge = 14;             # Days
2764 dpurdie 85
my $opt_relabel = 0;
86
my $opt_protected;
87
my $opt_useSvn = 1;
88
my $opt_testRmDatabase;
89
my $opt_extractFromSvn;
90
my $opt_AllowMuliplePaths = 1;      #29-Nov-2012
91
my $opt_resume;
92
my $opt_processRipples = 1;
93
my $opt_mergePackages;
4003 dpurdie 94
my @opt_deleteFiles;
95
my $opt_useTestRepo;
96
my $opt_saveCompressed;
97
my $opt_skipBuildNameCheck;
98
my $opt_deleteLinks;
99
my $count_BadPaths = 0;
100
my $opt_IgnoreBadSourcePath;
101
my $opt_forceSuck;
102
my $opt_noVCS;
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' },
2429 dpurdie 137
    '.vss'      => { Name => 'SmartSite' },
4003 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',
4003 dpurdie 161
    '.0x3'          => '.cr',
162
    '.0x4'          => '.cr',
163
    '.0x5'          => '.cr',
164
    '.0x13'         => '.cr',
1271 dpurdie 165
);
166
 
167
my %specialPackages = (
2429 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,',
2450 dpurdie 178
    'Dataman'             => ',utf8,',
2439 dpurdie 179
    'CommandServer'       => ',IgnoreMakeProject,',
180
    'TDSExporterControl'  => ',IgnoreMakeProject,',
181
    'cdagui'              => ',IgnoreMakeProject,',
1271 dpurdie 182
 
4003 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
2429 dpurdie 190
 
2764 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
 
2764 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',
2429 dpurdie 257
 
258
 
2764 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
 
2764 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',
4003 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',
2764 dpurdie 283
 
4003 dpurdie 284
    'LinuxDrivers'                  => 'flatTime,processRipples,LimitProjectBase=/LMOS/linux/drivers'.
2764 dpurdie 285
                                       ',mergePaths=modules:bcp4600:cobra:eb5600:etx86:tp5600:viper',
286
 
4003 dpurdie 287
    'flashCopier'                   => 'flatTime,LimitProjectBase=/LMOS/tools/flashCopier'.
2764 dpurdie 288
                                       ',mergePaths=+:src:pcp5700:eb5600:tp5600',
289
 
4003 dpurdie 290
    'u-boot'                        => 'flatTime,LimitProjectBase=/LMOS/linux/bootstrap/u-boot'.
291
                                       ',mergePaths=+:src:u-boot:u-boot-hk',
2764 dpurdie 292
 
4003 dpurdie 293
    'dams_gen1'                      => 'flatTime,LimitProjectBase=/LMOS/apps/dams'.
294
                                       ',mergePaths=+:tp5600:eb5600:pcp5700:core:doc'.
295
                                       ',processRipples',
2764 dpurdie 296
 
4003 dpurdie 297
    'linux_day0fs_gen1'            => 'flatTime,LimitProjectBase=/LMOS/linux/filesystems/day0-fs'.
298
                                       ',mergePaths=+:tp5600:eb5600:pcp5700:etx86:common'.
299
                                       ',processRipples',
2764 dpurdie 300
 
4003 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,',
2764 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,',
4003 dpurdie 401
 
402
    'MOS'      => 'RetainCompressed,IgnoreProjectBase,',
403
 
404
 
405
 
1271 dpurdie 406
);
407
 
4003 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
 
2429 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;
4003 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;
2429 dpurdie 496
my $mustConvertFileNames;
2439 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;
2429 dpurdie 508
my $recentCount = 0;
509
my $packageReLabelCount = 0;
510
my %saneLabels;
2764 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 (
4003 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,
2764 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
4003 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,
2764 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] );
2764 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
#
2764 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
 
2764 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
    {
4003 dpurdie 602
        $opt_name = $opt_mergePackages;
2764 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
 
4003 dpurdie 610
 
611
    } elsif ( $opt_mergePackages eq 'flashCopier' ) {
2764 dpurdie 612
        $opt_name = $opt_mergePackages;
613
        @ARGV = qw (
614
                flash_copier_eb5600
615
                flash_copier_pcp5700
616
                flash_copier_tp5600
617
                );
618
 
4003 dpurdie 619
    } elsif ( $opt_mergePackages eq 'u-boot' ) {
2764 dpurdie 620
        $opt_name = $opt_mergePackages;
4003 dpurdie 621
        @ARGV = qw (
622
                u-boot
623
                u-boot-hk
624
                );
2764 dpurdie 625
 
4003 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
                );
2764 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
2764 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);
2764 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);
4003 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);
2764 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
#
4003 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
    #
2764 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
    {
2764 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
    #
2439 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';
2429 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
    #
2429 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
 
2429 dpurdie 1055
 
2764 dpurdie 1056
    if ( $packageNames =~ m'^br_applet_' )
1271 dpurdie 1057
    {
2429 dpurdie 1058
      $opt_flat = 1 unless defined $opt_flat;
1271 dpurdie 1059
    }
1060
 
2764 dpurdie 1061
    if ( exists $specialPackages{$packageNames} )
2429 dpurdie 1062
    {
2764 dpurdie 1063
        my $data = ',' . $specialPackages{$packageNames} . ',';
2429 dpurdie 1064
 
1271 dpurdie 1065
        if ( index( $data, ',all' ) >= 0) {
1066
            setPruneMode('none') unless (defined $opt_pruneModeString);
1067
        }
1068
 
2764 dpurdie 1069
        if ( index( $data, ',protected,' ) >= 0) {
1271 dpurdie 1070
            $noTransfer = 1;
1071
        }
1072
 
2764 dpurdie 1073
        if ( index( $data, ',flat,' ) >= 0) {
1271 dpurdie 1074
            $opt_flat = 1;
1075
        }
1076
 
2764 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
 
4003 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
 
2764 dpurdie 1105
        if ( index( $data, ',SetProjectBase,' ) >= 0) {
1271 dpurdie 1106
            $opt_preserveProjectBase = 1;
1107
            $opt_ignoreProjectBaseErrors = 1;
1108
            Message ("Preserving ProjectBase");
1109
        }
1110
 
2764 dpurdie 1111
        if ( index( $data, ',AllowMultiPath,' ) >= 0) {
1112
            $opt_AllowMuliplePaths = 1;
1113
            Message ("Allowing Multiple Paths");
1114
        }
1115
 
4003 dpurdie 1116
        if ( index( $data, ',IgnoreBadSourcePath,' ) >= 0) {
1117
            $opt_IgnoreBadSourcePath = 1;
1118
            Message ("Ignore Source Paths tagged as Bad");
1119
        }
1120
 
2764 dpurdie 1121
        if ( $data =~ m~,ForceProjectBase=(.*?),~ ) {
1122
            $opt_forceProjectBase = $1;
1123
            $opt_AllowMuliplePaths = 1;
1124
            Message ("Force Project Base: $opt_forceProjectBase");
1125
        }
1126
 
4003 dpurdie 1127
 
2764 dpurdie 1128
        if ( $data =~ m~,LimitProjectBase=(.*?),~ ) {
1129
            $opt_AllowMuliplePaths = 1;
1130
            @opt_limitProjectBase = split(':', $1);
1131
            Message ("Limit Project Base: @opt_limitProjectBase");
1132
        }
1133
 
4003 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
 
2764 dpurdie 1140
        if ( $data =~ m~,mergePaths=(.*?),~ ) {
1141
            @opt_mergePaths = split(':', $1);
1142
            Message ("Merge Paths: @opt_mergePaths");
1143
        }
1144
 
4003 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
 
2764 dpurdie 1160
        if ( index( $data, ',IgnoreProjectBase,' ) >= 0) {
1271 dpurdie 1161
            $opt_ignoreProjectBaseErrors = 1;
1162
            Message ("Ignore ProjectBase Errors");
1163
        }
1164
 
2764 dpurdie 1165
        if ( index( $data, ',IgnoreMakeProject,' ) >= 0) {
2439 dpurdie 1166
            $opt_ignoreMakeProjectErrors = 1;
1167
            Message ("Ignore MakeProject Usage");
1168
        }
2764 dpurdie 1169
 
4003 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
 
2764 dpurdie 1180
        if ( index( $data, ',IgnoreBadPath,' ) >= 0) {
1181
            $opt_ignoreBadPaths = 1;
1182
            Message ("Ignore Bad Paths in makefile Usage");
1183
        }
2439 dpurdie 1184
 
2764 dpurdie 1185
        if ( index( $data, ',utf8,' ) >= 0) {
2429 dpurdie 1186
            $mustConvertFileNames = 1;
1187
            Message ("Convert filenames to UTF8");
1188
        }
4003 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}  )
4003 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
        #
4003 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;
4003 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
    }
2429 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
2764 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} );
2429 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
        #
2429 dpurdie 1641
        #   Keep recent versions
1642
        #       Keep versions created in the last N days
1643
        #       Will keep recent ripples too
1644
        #
2764 dpurdie 1645
        if ( $pruneMode == 1 )                      # 1 == ripple
2429 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
 
2764 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
            }
2429 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} );
2429 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} );
2429 dpurdie 1749
            return 0 if ( exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
1271 dpurdie 1750
            return 1;
1751
        }
1752
 
2764 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
        {
2764 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
    #
2429 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}} );
2429 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
    {
4003 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;
4003 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");
2429 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
2429 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};
4003 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
 
4003 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
            }
4003 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
    {
4003 dpurdie 2154
#DebugDumpData("rippleVersions. Suffix , e1", $suffix, $e1 );
2155
 
1271 dpurdie 2156
        while ( my( $mmp, $e2) = each %{$e1} )
2157
        {
4003 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
            #
4003 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  );
4003 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
    }
4003 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 );
2429 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
 
2429 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
    #
2429 dpurdie 2268
    if ( $globalError )
1271 dpurdie 2269
    {
2429 dpurdie 2270
        Message ("Global error prevents futher importation");
2271
    }
2272
    else
2273
    {
1271 dpurdie 2274
        #
2275
        #   Call worker function
4003 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
    #
2764 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};
2429 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
    {
4003 dpurdie 2337
        my $cfile = saneLabel($entry) . '.tgz';
2764 dpurdie 2338
        if ( $opt_reuse == 0 || $opt_reuse == 2 || ($rv && ($rv != 4 && $rv != 12 && $rv != 5 )) )
2429 dpurdie 2339
        {
2340
            Message ("Delete View: $data{ViewRoot}");
2341
            RmDirTree ($data{ViewRoot} );
4003 dpurdie 2342
            unlink $cfile;
2429 dpurdie 2343
        }
2344
        else
2345
        {
2346
            Message ("Retaining View: $data{ViewRoot}");
4003 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
            }
2429 dpurdie 2364
        }
2365
 
1271 dpurdie 2366
    }
2429 dpurdie 2367
    else
2368
    {
2439 dpurdie 2369
        Message ("No view to delete");
2429 dpurdie 2370
    }
1271 dpurdie 2371
 
4003 dpurdie 2372
    #
2373
    #   Create pretty pictures
2374
    #
2375
    unless ( $rv )
2376
    {
2377
        getSvnData();
2378
        createImages();
2379
    }
1271 dpurdie 2380
 
4003 dpurdie 2381
 
2764 dpurdie 2382
    if($opt_processRipples)
1271 dpurdie 2383
    {
2764 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
 
2764 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
    }
4003 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
2764 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;
2764 dpurdie 2435
    my $vcs_type;
1271 dpurdie 2436
    my $cc_label;
2437
    my $cc_path;
2429 dpurdie 2438
    my $cc_path_original;
4003 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
 
2764 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
    #
4003 dpurdie 2512
    #   Check for a handcrafted substitute package
2513
    #       May have been created with gen_cots
1271 dpurdie 2514
    #
4003 dpurdie 2515
    testDpkgArchive($entry);
2516
    if (extractFilesFromStore($data, $entry) )
1271 dpurdie 2517
    {
4003 dpurdie 2518
        Message ("Using package from store");
1271 dpurdie 2519
    }
4003 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
 
4003 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
 
4003 dpurdie 2541
        }
1271 dpurdie 2542
 
2543
 
4003 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
 
4003 dpurdie 2552
        #
2553
        #   Process IgnoreBadSourcePath
2554
        #
2555
        if ($opt_IgnoreBadSourcePath)
1271 dpurdie 2556
        {
4003 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
 
4003 dpurdie 2567
        #
2568
        #   Correct well known path mistakes in CC paths
2569
        #
2570
        if ( $vcs_type eq 'CC' )
2764 dpurdie 2571
        {
4003 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
                )
2764 dpurdie 2633
            {
2634
                $cc_path = '/MREF_Package';
2635
            }
2636
 
4003 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
            }
2764 dpurdie 2644
 
4003 dpurdie 2645
            $cc_path = $opt_forceProjectBase
2646
                if ( $opt_forceProjectBase );
2647
 
2648
            foreach ( @opt_limitProjectBase )
2764 dpurdie 2649
            {
4003 dpurdie 2650
                if ( $cc_path =~ m~$_~ )
2651
                {
2652
                    $cc_path = $_;
2653
                    last;
2654
                }
2764 dpurdie 2655
            }
4003 dpurdie 2656
 
2657
            if ( $cc_path_original ne $cc_path )
2658
            {
2659
                    Message ("Package: $versions{$entry}{name}. Forcing CC path to: $cc_path" );
2660
            }
2764 dpurdie 2661
        }
4003 dpurdie 2662
 
2663
    #print "--- Path: $cc_path, Label: $cc_label\n";
2664
 
2665
        if ( $vcs_type eq 'SVN' )
2764 dpurdie 2666
        {
4003 dpurdie 2667
            $rv = extractFilesFromSubversion( $data, $entry );
2668
            return $rv if ( $rv );
2764 dpurdie 2669
        }
4003 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
        }
2429 dpurdie 2706
    }
1271 dpurdie 2707
 
4003 dpurdie 2708
    #
2709
    #   Delete specified files from the source tree
2710
    #
2711
    if ( @opt_deleteFiles )
2764 dpurdie 2712
    {
4003 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
        }
2764 dpurdie 2726
    }
4003 dpurdie 2727
 
2728
    #
2729
    #   Some packages contain softlinks - that break the file scanner
2730
    #
2731
    if ( $opt_deleteLinks )
2764 dpurdie 2732
    {
4003 dpurdie 2733
        # Not doing anything yet - fixed the JATS find bit
2764 dpurdie 2734
    }
2429 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
    #
4003 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} );
2429 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;
2764 dpurdie 2757
            $adjustedPath++;
1272 dpurdie 2758
        }
2759
    }
2764 dpurdie 2760
    Message ("BaseDir: $data->{ViewPath}");
2761
 
2439 dpurdie 2762
    #
2764 dpurdie 2763
    #   Check for bad source paths
2764
    #
2765
    if (detectBadMakePaths($data) )
2766
    {
4003 dpurdie 2767
        $count_BadPaths++;
2764 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
    #
2439 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
    #
2764 dpurdie 2783
    if (detectProjectBaseUsage($data) )
2439 dpurdie 2784
    {
2785
        unless ( $opt_ignoreProjectBaseErrors )
2786
        {
2787
            $data->{BadProjectBase}++;
2788
            $data->{errStr} = 'Bad usage of ProjectBase detected';
2764 dpurdie 2789
            Warning ("ProjectBase Error");
2439 dpurdie 2790
            return 4;           # Lets see what the others look like too
2791
#            return 14;
2792
        }
2793
    }
2429 dpurdie 2794
 
2795
    #
2439 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
    #
2764 dpurdie 2806
    if (detectMakeProjectUsage($data) )
2439 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
    #
2429 dpurdie 2818
    #   Some packages have filenames that are need to be converted
2819
    #
2439 dpurdie 2820
    if ( $mustConvertFileNames  )
2429 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
        }
2439 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
        }
2429 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
    #
2764 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
    }
2764 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 );
2764 dpurdie 2920
    my $datafile = "importdata.$import_label.properties";
1271 dpurdie 2921
 
4003 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,
4003 dpurdie 2947
                    @mergeArg,
1271 dpurdie 2948
                     );
2949
 
2950
    if ( $rv )
2951
    {
2952
        $data->{errStr} = 'Failed to import to SVN';
2953
        return 12;
2954
    }
2955
 
4003 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
 
2429 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);
2764 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
 
2429 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 );
2764 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
#
4003 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;
4003 dpurdie 3235
    if ($versions{$entry}{isaPatch} )
1271 dpurdie 3236
    {
4003 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 );
4003 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;
4003 dpurdie 3309
#    Message ("Setting currentBranchName: $currentBranchName");
1271 dpurdie 3310
 
3311
    #
3312
    #   Perform the branch
3313
    #
3314
    if ( defined $src_label )
3315
    {
2764 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
 
2429 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
{
2429 dpurdie 3358
    Message ("-- Import Summary ------------------------------------------------" );
1271 dpurdie 3359
    RmDirTree ('SvnImportDir');
2764 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;
4003 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} );
2764 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;
2764 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} );
4003 dpurdie 3391
            $buildFileClashes++ if ($versions{$entry}{data}{BuildFileClash} );
2764 dpurdie 3392
            next;
3393
        }
3394
 
2429 dpurdie 3395
        my $reason = $versions{$entry}{data}{errStr} || '';
3396
        my $tag = $versions{$entry}{vcsTag}|| 'No Tag';
2764 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) );
2764 dpurdie 3406
        $inernalErrorCount++;
1271 dpurdie 3407
    }
3408
 
2764 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 );
2429 dpurdie 3427
    Message ("Packages Relabled: $packageReLabelCount") if ( $packageReLabelCount );
2764 dpurdie 3428
    Warning ("Packages with Bad Paths: $badPathCount") if ( $badPathCount );
4003 dpurdie 3429
    Warning ("Packages with Ignored Bad Paths: $badPathCount") if ( $count_BadPaths );
3430
 
2764 dpurdie 3431
    Warning ("Packages with Bad ProjectBase: $badProjectBaseCount") if ( $badProjectBaseCount );
3432
    Warning ("Packages with MakeProjects: $badMakeProjectCount") if ( $badMakeProjectCount );
4003 dpurdie 3433
    Warning ("Build File Clashes Found: $buildFileClashes") if ( $buildFileClashes );
2764 dpurdie 3434
    Warning ("Global Error Detected") if ( $globalError );
3435
    Message ("---- All Done -----");
1271 dpurdie 3436
}
3437
 
3438
#-------------------------------------------------------------------------------
2429 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
4003 dpurdie 3447
#                   $entry          - original PV entry
2429 dpurdie 3448
#
3449
# Returns         : exit code
3450
#                   Sets up
3451
#                       $data->{errStr}
3452
#                       $data->{errCode}
3453
#                   As per newPackageVersionBody
3454
#
3455
sub extractFilesFromClearCase
3456
{
4003 dpurdie 3457
    my ($data, $cc_path, $cc_label, $entry) = @_;
2429 dpurdie 3458
    my $tryCount = 0;
3459
    my $rv = 99;
3460
 
2764 dpurdie 3461
    $data->{ViewRoot} = ( defined $opt_name && ! defined $opt_mergePackages )? $opt_name : "$cc_label";
2429 dpurdie 3462
    $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
3463
 
2764 dpurdie 3464
    if ( $opt_preserveProjectBase && !$opt_forceProjectBase )
2429 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
 
4003 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");
3502
                $data->{errStr} = 'Failed to de-tar compressed image';
3503
                return 2;
3504
            }
3505
            else
3506
            {
3507
                my $cc_vob = $cc_path;
3508
                $cc_vob =~ s~^/~~;
3509
                $cc_vob =~ s~/.*~~;
3510
                my $detarPath =  $data->{ViewRoot} . '/' . $cc_vob;
3511
 
3512
 
3513
                unless ( -d $detarPath  )
3514
                {
3515
                    Warning ("Logic error: Did not de-tar into expected location", $detarPath)
3516
                }
3517
                else
3518
                {
3519
                    if ( -d $data->{ViewPath}  )
3520
                    {
3521
                        # All is good
3522
                        return 0;
3523
                    }
3524
 
3525
                    # Recalc ViewPath to the root of the VOB
3526
                    $cc_path =~ s~^/~~;
3527
                    $cc_path =~ s~/.*~~;
3528
                    $cc_path = '/' . $cc_path;
3529
                    $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
3530
                    return 0;
3531
                }
3532
            }
3533
        }
3534
    }
3535
 
2429 dpurdie 3536
    if ( $opt_reuse && -d $data->{ViewPath}  )
3537
    {
3538
        Message ("Reusing view: $cc_label");
4003 dpurdie 3539
 
3540
        #
3541
        #   Br applet kludge - can be removed later
3542
        #   Add some nice data to each view
3543
#        open (FH, '>' , $data->{ViewRoot} . '/cc2svn_tag' ) || Error ("Cannot open '$data->{ViewRoot}/cc2svn_tag'");
3544
#        print FH $versions{$entry}{name},' ',$versions{$entry}{vname},"\n";
3545
#        close FH;
2429 dpurdie 3546
        return 0;
3547
    }
3548
 
4003 dpurdie 3549
    while ( ($rv == 99)  && ! $opt_noVCS) {
2429 dpurdie 3550
        my @args;
2764 dpurdie 3551
        push (@args, '-view', $opt_name ) if ( defined $opt_name && ! defined $opt_mergePackages );
2429 dpurdie 3552
        $rv = JatsToolPrint ( 'jats_ccrelease', '-extractfiles', '-root=.' , '-noprefix',
3553
                    "-label=$cc_label" ,
3554
                    "-path=$cc_path",
3555
                    @args
3556
                    );
3557
 
3558
        if ( $rv == 10 ) {
3559
 
3560
            #
3561
            #   No files found
3562
            #   If this is the first time then try really hard to find them
3563
            #
3564
            unless ( $tryCount++ )
3565
            {
3566
                if ( $opt_relabel )
3567
                {
3568
                    $packageReLabelCount++;
3569
                    $rv = JatsToolPrint('cc2svn_labeldirs',
3570
                                            '-vob', $cc_path,
3571
                                            $cc_label,
3572
                                            );
3573
                    $data->{DirsLabled} = 100 + $rv;
3574
                }
3575
 
3576
                #
3577
                #   Second attempt - massage the users path
3578
                #   We should have labled up to the VOB root so lets
3579
                #   just use the VOB and not the path
3580
                #
3581
                #   If we are not relabeling then we can still do this
3582
                #   in an attempt to fix user stupidity
3583
                #
3584
                $cc_path =~ s~^/~~;
3585
                $cc_path =~ s~/.*~~;
3586
                $cc_path = '/' . $cc_path;
3587
                $data->{ViewPath} =  $data->{ViewRoot} . $cc_path;
3588
                redo;
3589
            }
3590
 
3591
            $data->{errStr}  = 'No Files in the extracted view';
3592
            $data->{errCode} = '0';
3593
            return 2;
3594
        }
3595
        elsif ( $rv == 11 ) {
3596
            $data->{errStr} = 'Label not found';
3597
            $data->{errCode} = 'L';
3598
            return 2;
3599
        }
3600
 
3601
        unless ( -d $data->{ViewPath}  )
3602
        {
3603
            $data->{errStr} = 'Failed to extract files from CC';
3604
            return 2;
3605
        }
3606
 
3607
        #
3608
        #   Looks good
3609
        #
3610
        return 0;
3611
    };
3612
 
3613
    $data->{errStr}  = 'No Files in the extracted view after labeling dirs';
3614
    $data->{errCode} = '0';
3615
    return 2;
3616
 
3617
}
3618
 
3619
#-------------------------------------------------------------------------------
2764 dpurdie 3620
# Function        : extractFilesFromSubversion
3621
#
3622
# Description     : Extract files from Subversion
3623
#                   May take a while as we handle nasty errors
3624
#
3625
# Inputs          : $data           - Hash of good stuff from newPackageVersionBody
3626
#                   $entry          - All the PV information
3627
#
3628
# Returns         : exit code
3629
#                   Sets up
3630
#                       $data->{errStr}
3631
#                       $data->{errCode}
3632
#                   As per newPackageVersionBody
3633
#
3634
sub extractFilesFromSubversion
3635
{
3636
    my ($data, $entry ) = @_;
3637
    my $tryCount = 0;
3638
    my $rv = 99;
3639
 
3640
    #
3641
    #   Create a nice name for the import
3642
    #
3643
    my $import_label = saneLabel($entry);
3644
 
4003 dpurdie 3645
    $data->{ViewRoot} = ( defined $opt_name && ! defined $opt_mergePackages )? $opt_name : $import_label;
2764 dpurdie 3646
    $data->{ViewPath} =  $data->{ViewRoot};
3647
    $data->{ViewPath} =~  tr~/~/~s;
4003 dpurdie 3648
 
2764 dpurdie 3649
    if ( $opt_reuse && -d $data->{ViewPath}  )
3650
    {
4003 dpurdie 3651
        #
3652
        #   Br applet kludge - can be removed later
3653
        #   Add some nice data to each view
3654
#        open (FH, '>' , $data->{ViewRoot} . '/cc2svn_tag' ) || Error ("Cannot open '$data->{ViewRoot}/cc2svn_tag'");
3655
#        print FH $versions{$entry}{name},' ',$versions{$entry}{vname},"\n";
3656
#        close FH;
3657
 
2764 dpurdie 3658
        Message ("Reusing view: $import_label");
3659
        return 0;
3660
    }
3661
 
3662
    #
3663
    #   Only allow import from SVN if asked nicely
3664
    #   May be used if we are correcting a package - and some have been
3665
    #   placed in SVN
3666
    #
3667
    unless ( $opt_extractFromSvn )
3668
    {
3669
        $data->{errStr} = 'Some Packages are in SVN';
3670
        return 15;
3671
    }
3672
 
3673
 
3674
#print "--- ViewRoot: $data->{ViewPath}\n";
3675
    $rv = JatsToolPrint ( 'jats_svnrelease',
3676
                          '-extractfiles',
3677
                          '-root=.' ,
3678
                          '-noprefix',
3679
                          '-DevMode=escrow',
3680
                          '-label', $data->{tag},
3681
                          '-view', $data->{ViewPath},
3682
                );
3683
 
3684
    if ( $rv == 10 ) {
3685
        $data->{errStr}  = 'No Files in the extracted view';
3686
        $data->{errCode} = '0';
3687
        return 2;
3688
 
3689
    } elsif ( $rv == 11 ) {
3690
        $data->{errStr} = 'Label not found';
3691
        $data->{errCode} = 'L';
3692
        return 2;
3693
    } elsif ( $rv ) {
3694
        $data->{errStr} = 'Subversion reported error';
3695
        return 2;
3696
    }
3697
 
3698
    unless ( -d $data->{ViewPath}  )
3699
    {
3700
        $data->{errStr} = 'Failed to extract files from Subversion';
3701
        return 2;
3702
    }
3703
 
3704
    #
3705
    #   Looks good
3706
    #
3707
    return 0;
3708
}
3709
 
3710
#-------------------------------------------------------------------------------
4003 dpurdie 3711
# Function        : extractFilesFromStore
3712
#
3713
# Description     : Extract files from Store
3714
#                   Local directory under dpkgExtract
3715
#
3716
# Inputs          : $data           - Hash of good stuff from newPackageVersionBody
3717
#                   $entry          - All the PV information
3718
#
3719
# Returns         : exit code
3720
#                       1 - Files found
3721
#                       0 - Not found
3722
#
3723
sub extractFilesFromStore
3724
{
3725
    my ($data, $entry ) = @_;
3726
    #
3727
    #   Create a nice name for the import
3728
    #
3729
    my $import_label = saneLabel($entry);
3730
 
3731
    $data->{ViewRoot} = ( defined $opt_name && ! defined $opt_mergePackages )? $opt_name : $import_label;
3732
    $data->{ViewPath} =  'dpkgExtract/' . $data->{ViewRoot};
3733
    $data->{ViewPath} =~  tr~/~/~s;
3734
 
3735
    if ( -d $data->{ViewPath}  )
3736
    {
3737
        $data->{fromStore} = 1;
3738
        Message ("Reusing Stored view: $import_label");
3739
        return 1;
3740
    }
3741
 
3742
    #
3743
    #   Not found in store
3744
    #
3745
    delete $data->{ViewRoot};
3746
    delete $data->{ViewPath};
3747
    return 0;
3748
}
3749
 
3750
#-------------------------------------------------------------------------------
3751
# Function        : testDpkgArchive
3752
#
3753
# Description     : Indicate if the package exists in dpkg_archive
3754
#
3755
# Inputs          : 
3756
#
3757
# Returns         : 
3758
#
3759
sub testDpkgArchive
3760
{
3761
    my ($entry) = @_;
3762
    my $vname = $versions{$entry}{vname};
3763
 
3764
    if ( -d join('/', $ENV{GBE_DPKG}, $packageNames, $vname )) {
3765
        Message ("Version found in dpkg_archive");
3766
    } else {
3767
        Message ("Version NOT found in dpkg_archive");
3768
    }
3769
}
3770
 
3771
#-------------------------------------------------------------------------------
3772
# Function        : markDpkgArchive
3773
#
3774
# Description     : Indicate if the package exists in dpkg_archive
3775
#
3776
# Inputs          : 
3777
#
3778
# Returns         : 
3779
#
3780
sub markDpkgArchive
3781
{
3782
    my ($entry) = @_;
3783
    my $vname = $versions{$entry}{vname};
3784
    my $path = join('/', $ENV{GBE_DPKG}, $packageNames, $vname );
3785
    delete $versions{$entry}{dpkgArchive};
3786
    if ( -d $path ) {
3787
        $versions{$entry}{dpkgArchive} = $path;
3788
    }
3789
}
3790
 
3791
#-------------------------------------------------------------------------------
2439 dpurdie 3792
# Function        : detectMakeProjectUsage
3793
#
3794
# Description     : etect and report usage of the MakeProject directive
3795
#
3796
# Inputs          : $data               - Ref to a hash of bits
3797
#
3798
# Returns         : true    - Bad usage (Really good usage not detected)
3799
#                   false   - Good usage detected
3800
#
3801
sub detectMakeProjectUsage
3802
{
2764 dpurdie 3803
    my ($data) = @_;
2439 dpurdie 3804
    my $retval = 0;
3805
    my $eSuf = $opt_ignoreMakeProjectErrors ? '' : 'Error';
3806
 
3807
    #
3808
    #   Find makefile.pl
3809
    #
2764 dpurdie 3810
    Message ("Detect MakeProject Usage");
2439 dpurdie 3811
    my $usesMakeProject = 0;
3812
    my $badIncludeFile = 0;
3813
 
3814
    my $search = JatsLocateFiles->new("--Recurse=1",
3815
                                       "--FilterIn=makefile.pl",
3816
                                       );
3817
    my @makefiles = $search->search($data->{ViewRoot});
3818
    foreach my $file ( @makefiles )
3819
    {
3820
#print "---Reading: $workDir/$data->{ViewRoot}/$file\n";
3821
        if ( open( my $fh, '<', "$data->{ViewRoot}/$file" ) )
3822
        {
3823
            my $eof = 0;
3824
            my $line = '';
3825
            until ( $eof )
3826
            {
3827
                my $in = <$fh>;
3828
                unless ( defined $in )
3829
                {
3830
                    $eof = 1;
3831
                }
3832
                else
3833
                {
3834
                $in =~ s~\s+$~~;
3835
                $in =~ s~^\s+~~;
3836
                $in =~ s~^#.*$~~;
3837
                $in =~ s~\s*[^\$]#.*$~~;
3838
                $line .= ' ' if ( $line );
3839
                $line .= $in;
3840
                $line =~ s~\s+~ ~g;
3841
#print "====== '$line'\n";
3842
                redo unless ( $line =~ m~;$~  );
3843
                }
3844
#print "---- $line\n";
3845
                if ( $line =~ m~^MakeProject~ )
3846
                {
3847
                    $usesMakeProject++;
3848
                    $data->{UsesMakeProject}++;
3849
                    Warning ("Package uses MakeProject:",
3850
                             "Line: " . $line,
3851
                             "Root: " . "$data->{ViewRoot}",
3852
                             "File: " . "$data->{ViewRoot}/$file",
3853
                            );
3854
 
3855
                    #
3856
                    #   Extract out the project name
3857
                    #
3858
                    my @myArgs;
3859
                    my $myProjectDir;
3860
                    my $myProject = "$data->{ViewRoot}/$file";
3861
                    $myProject =~ s~/[^/]+$~~;
2764 dpurdie 3862
 
3863
                    unless ($line =~ m~\s*(\w+)\s*\((.*)\)\s*;\s*$~ )
3864
                    {
3865
                        Error("Could not detect arguments: $line");
3866
                    }
3867
                    my $args = $2;
3868
                    $args =~ tr~'" ~ ~s;
3869
                    @myArgs = split (/\s*,\s*/, $args);
2439 dpurdie 3870
                    shift @myArgs;
3871
                    foreach ( @myArgs )
3872
                    {
3873
                        next if ( m~^--~ );
3874
                        $myProject .= '/' . $_;
3875
                        $myProjectDir = $myProject;
3876
                        $myProjectDir =~ s~/[^/]+$~~;
3877
                        last;
3878
                    }
3879
                    Error ("No project Found") unless ( defined $myProjectDir);
2764 dpurdie 3880
 
3881
                    #
3882
                    #   Look for 'include.txt' that may be bwteen the makefile and the project
3883
                    #
3884
 
3885
 
2439 dpurdie 3886
                    if ( -f "$myProjectDir/include.txt" )
3887
                    {
3888
                        Warning ("Co-located 'include.txt' file also found");
3889
                    }
3890
 
3891
                    # The only problem is if the include.txt file
3892
                    # escapes from the VOB - or even uses the vob root
3893
                    #
3894
                    # Examine the include file
3895
                    # Expect it to look like
3896
                    #   /I Path
3897
                    #
3898
 
3899
                    #
3900
                    #   Determine safe level
3901
                    #   Relative to the include file
3902
                    #
3903
                    my $depthPath = $myProjectDir;
3904
                    my $depth = 0;
3905
                    Error ("Expect this to work") unless ( $depthPath =~ s~^$data->{ViewRoot}/~~ );
3906
                    foreach ( split('/', $depthPath) )
3907
                    {
3908
                        if ( $_ eq '..' ) {
3909
                            $depth--;
3910
                        } else {
3911
                            $depth++;
3912
                        }
3913
                    }
3914
#print "Depth: $depth, $depthPath\n";
3915
 
3916
                    if ( open( my $if, '<', "$myProjectDir/include.txt" ) )
3917
                    {
3918
                        while ( <$if> )
3919
                        {
3920
                            s~\s+$~~;
3921
                            s~^\s+~~;
3922
                            next unless ( $_ );
3923
                            if ( m~/I\s+(.*)~ )
3924
                            {
3925
                                my $path = $1;
3926
                                $path =~ tr~\\/~/~s;
3927
                                $path =~ s~\\~/~g;
3928
#print "Examine: $path\n";
3929
                                my $minLevel = 0;
3930
                                my $level = 0;
3931
                                foreach ( split('/', $path) )
3932
                                {
3933
                                    if ( $_ eq '..' )
3934
                                    {
3935
                                        $level--;
3936
                                        $minLevel = $level if ($level < $minLevel);
3937
                                    }
3938
                                    else
3939
                                    {
3940
                                        $level++;
3941
                                    }
3942
                                }
3943
#print "Min: $minLevel, $level, ($depth + $minLevel)\n";
3944
                                if ( $depth + $minLevel <= 0)
3945
                                {
3946
                                    $badIncludeFile++;
3947
                                    Warning ("Included path escapes package:",
3948
                                             "Line: " . $_,
3949
                                             "File: " . "$myProjectDir/include.txt",
3950
                                            );
3951
                                    last;
3952
                                }
3953
                            }
3954
                        }
3955
                        close $if;
3956
                    }
3957
 
3958
                }
3959
                $line = '';
3960
            }
3961
            close $fh;
3962
        }
3963
        else
3964
        {
3965
            Warning ("MakeProject$eSuf - Cannot open makefile: $file");
3966
            $retval = 1;
3967
        }
3968
    }
3969
 
3970
    #
3971
    #   Used
3972
    #   May be improved latter
3973
    #
3974
    if ( $usesMakeProject && $badIncludeFile)
3975
    {
3976
        Warning ("MakeProject$eSuf - Problem detected");
3977
        $retval = 1;
3978
    }
3979
 
3980
    #
3981
    #   Until we have more faith in the detection algorithm
3982
    #
3983
    if ( $usesMakeProject )
3984
    {
3985
        Warning ("MakeProject$eSuf - Makeproject used. Must check manually");
3986
        $retval = 1;
3987
    }
3988
 
3989
    return $retval;
3990
}
3991
 
3992
#-------------------------------------------------------------------------------
2764 dpurdie 3993
# Function        : detectBadMakePaths
3994
#
3995
# Description     : Detect and report bad usage of some directives
3996
#
3997
# Inputs          : $data               - Ref to a hash of bits
3998
#
3999
# Returns         : true    - Bad usage (Really good usage not detected)
4000
#                   false   - Good usage detected
4001
#
4002
sub detectBadMakePaths
4003
{
4004
    my ($data) = @_;
4005
    my $retval = 0;
4006
    my $eSuf = $opt_ignoreBadPaths ? '' : 'Error';
4007
 
4008
    #
4009
    #   Find makefile.pl
4010
    #
4011
    Message ("Detect Bad Source Paths");
4012
    my $badPath = 0;
4013
 
4014
    my $search = JatsLocateFiles->new("--Recurse=1",
4015
                                       "--FilterIn=makefile.pl",
4016
                                       );
4017
    my @makefiles = $search->search($data->{ViewPath});
4018
    foreach my $file ( @makefiles )
4019
    {
4020
        $file =~ tr~/~/~s;
4021
        my $max_up = ($file =~ tr~/~/~);
4022
        my $shownPath;
4023
#print "---Reading: $workDir/$data->{ViewPath}/$file\n";
4024
        if ( open( my $fh, '<', "$data->{ViewPath}/$file" ) )
4025
        {
4026
            my $eof = 0;
4027
            my $line = '';
4028
 
4029
            until ( $eof )
4030
            {
4031
                my $in = <$fh>;
4032
                unless ( defined $in )
4033
                {
4034
                    $eof = 1;
4035
                }
4036
                else
4037
                {
4038
                $in =~ s~\s+$~~;
4039
                $in =~ s~^\s+~~;
4040
                $in =~ s~^#.*$~~;
4041
                $in =~ s~\s*[^\$]#.*$~~;
4042
                $line .= ' ' if ( $line );
4043
                $line .= $in;
4044
                $line =~ s~\s+~ ~g;
4045
#print "====== '$line'\n";
4046
                redo unless ( $line =~ m~;$~  );
4047
                }
4048
                if ( $line =~ m~^AddDir~ || $line =~ m~^AddSrcDir~ || $line =~ m~^AddIncDir~ || $line =~ m~^Src~ )
4049
                {
4050
                    #
4051
                    #   Extract out the arguments
4052
                    #
4053
                    my @myArgs;
4054
                    my $myProjectDir;
4055
                    my $myProject = "$data->{ViewRoot}/$file";
4056
                    $myProject =~ s~/[^/]+$~~;
4057
 
4058
                    unless ($line =~ m~\s*(\w+)\s*\((.*)\)\s*;\s*$~ )
4059
                    {
4060
                        Error("Could not detect arguments: $line");
4061
                    }
4062
                    my $args = $2;
4063
                    $args =~ tr~'" ~ ~s;
4064
                    @myArgs = split (/\s*,\s*/, $args);
4065
                    shift @myArgs;
4066
                    foreach ( @myArgs )
4067
                    {
4068
                        next if ( m~^--~ );
4069
                        next unless ( m~^\.\./~ );
4070
                        my $tmp = $_;
4071
                        $tmp =~ s~Z~z~g;
4072
                        $tmp =~ s~\.\./~Z~g;
4073
                        my $upCount = ( $tmp =~ tr~Z~Z~ );
4074
                        if ( $upCount > $max_up )
4075
                        {
4076
                            Warning ("Makefile Path: $file ") unless $shownPath;
4077
                            Warning ("Path escapes view: $max_up, $upCount, $_");
4078
                            $badPath++;
4079
                            $shownPath = 1;
4080
                        }
4081
#print "---x Path : $max_up, $upCount, $_\n";
4082
                    }
4083
                }
4084
                $line = '';
4085
            }
4086
            close $fh;
4087
        }
4088
        else
4089
        {
4090
            Warning ("detectBadMakePaths$eSuf - Cannot open makefile: $file");
4091
            $retval = 1;
4092
        }
4093
    }
4094
 
4095
    #
4096
    #   Used
4097
    #   May be improved latter
4098
    #
4099
    if ( $badPath )
4100
    {
4101
        Warning ("detectBadMakePaths$eSuf - Bad Path seen. Must check manually");
4102
        $retval = 1;
4103
    }
4104
 
4105
    return $retval;
4106
}
4107
 
4108
 
4109
#-------------------------------------------------------------------------------
1271 dpurdie 4110
# Function        : detectProjectBaseUsage
4111
#
4112
# Description     : Detect and report usage of the SetProjectBase directive
4113
#
4114
# Inputs          : $data               - Ref to a hash of bits
4115
#
4116
# Returns         : true    - Bad usage (Really good usage not detected)
4117
#                   false   - Good usage detected
4118
#
4119
sub detectProjectBaseUsage
4120
{
2764 dpurdie 4121
    my ($data) = @_;
1271 dpurdie 4122
    my $retval = 0;
4123
    my $eSuf = $opt_ignoreProjectBaseErrors ? '' : 'Error';
4124
 
4125
    #
4126
    #   Find makefile.pl
4127
    #
2764 dpurdie 4128
    Message ("Detect ProjectBase Usage");
1271 dpurdie 4129
    my $usesProjectBase = 0;
4130
    my $definesProjectBase = 0;
4131
    my $definitionError = 0;
4132
 
4133
    my $search = JatsLocateFiles->new("--Recurse=1",
4134
                                       "--FilterIn=makefile.pl",
4135
                                       );
2764 dpurdie 4136
    my @makefiles = $search->search($data->{ViewPath});
1271 dpurdie 4137
    foreach my $file ( @makefiles )
4138
    {
2764 dpurdie 4139
        if ( open( my $fh, '<', "$data->{ViewPath}/$file" ) )
1271 dpurdie 4140
        {
4141
            while ( <$fh> )
4142
            {
4143
                s~\s+$~~;
4144
                s~^\s+~~;
4145
                next if ( m~^#~ );
4146
 
4147
                if ( m~\$ProjectBase~ )
4148
                {
4149
                    $usesProjectBase++;
4150
                    Message ("Project Base Use: $_");
4151
                    $data->{UsesProjectBase}++;
4152
                }
4153
 
4154
                if ( m~^SetProjectBase~ )
4155
                {
4156
                    $definesProjectBase++;
4157
                    $data->{DefinesProjectBase}++;
2429 dpurdie 4158
                    Warning ("Package initialises SetProjectBase:",
2764 dpurdie 4159
                             "Line : " . $_,
4160
                             "Root : " . "$data->{ViewRoot}",
4161
                             "Path : " . "$data->{ViewPath}",
4162
                             "File : " . "$data->{ViewPath}/$file",
1271 dpurdie 4163
                            );
4164
 
4165
                    # The only problem is if the user attempts to escape
4166
                    # from the root of the view.
4167
                    #
4168
                    # Examine the depth of the makefile with the directive
4169
                    # Examine the depth of the view base
4170
                    #
4171
                    #
4172
                    # Locate the build.pl file
4173
                    # This is the basis for for the directive
4174
                    #
4175
                    my $blevel;
4176
                    my @bpaths = split ('/', $file );
2764 dpurdie 4177
                    my $buildFile;
1271 dpurdie 4178
                    while ( @bpaths )
4179
                    {
4180
                        $bpaths[-1] = 'build.pl';
4181
                        my $bfile = join '/', @bpaths ;
2764 dpurdie 4182
                        $buildFile = "$data->{ViewPath}/$bfile";
4183
                        if ( -f $buildFile )
1271 dpurdie 4184
                        {
4185
                            $blevel = scalar @bpaths;
4186
                            last;
4187
                        }
4188
                        pop @bpaths;
4189
                    }
4190
                    unless (defined $blevel)
4191
                    {
4192
                        Warning ("SetProjectBase$eSuf calculation failed - can't find build.pl");
2429 dpurdie 4193
#                        $retval = 1;
4194
                         $definitionError++;
1271 dpurdie 4195
                    }
4196
                    else
4197
                    {
4198
                        #
4199
                        #   Determine the depth of the view root
4200
                        #
2764 dpurdie 4201
                        Warning ("Build: $buildFile");
4003 dpurdie 4202
                        #
4203
                        #   Whats the file for
4204
                        #
4205
                        if (open (BF, '<', $buildFile ))
4206
                        {
4207
                            while ( <BF> )
4208
                            {
4209
                                s~\s+$~~;
4210
                                if ( m~\s*BuildName~ )
4211
                                {
4212
                                    Warning ("BuildName: $_");
4213
                                    last;
4214
                                }
4215
                            }
4216
                            close BF;
4217
                        }
4218
 
4219
 
4220
                        #
4221
                        #   Determine the depth of the view root
4222
                        #
2764 dpurdie 4223
                        my $countPath = ($data->{ViewPath} =~ tr~/~/~);
4224
                        my $countBuild = ($buildFile =~ tr~/~/~);
4225
                        my $max_up = $countBuild - $countPath -1;
1271 dpurdie 4226
 
4227
                        m~--Up=(\d+)~i;
4228
                        my $ulevel = $1;
4229
                        if ( defined $ulevel )
4230
                        {
4231
                            my @paths = split ('/', $file );
4232
                            my $plevel = scalar @paths;
4233
 
4234
#print "--- blevel: $blevel\n";
4235
#print "--- bpaths: @bpaths\n";
4236
#print "--- ulevel: $ulevel\n";
4237
#print "--- paths: @paths\n";
4238
#print "--- plevel: $plevel\n";
4239
#print "--- max_up: $max_up\n";
4240
 
4241
                            if ( $ulevel > $max_up )
4242
                            {
4243
                                Warning ("SetProjectBase escapes view. MaxUp: $max_up, Up: $ulevel");
4244
                                $definitionError++;
4245
                            }
4246
                        }
4247
                        else
4248
                        {
4249
                            $retval = 1;
4250
                            Warning ("SetProjectBase$eSuf MAY escape view - can't detect level")
4251
                        }
4252
                    }
4253
                }
4254
            }
4255
            close $fh;
4256
        }
4257
        else
4258
        {
4259
            Warning ("SetProjectBase$eSuf - Cannot open makefile: $file");
4260
            $retval = 1;
4261
        }
4262
    }
4263
 
4264
    #
4265
    #   Detect defined, but not used
4266
    #
4267
    if ( $usesProjectBase && ! $definesProjectBase )
4268
    {
4003 dpurdie 4269
        Warning ("SetProjectBase - Uses Default ProjectBase");
1271 dpurdie 4270
    }
4271
 
4272
    if ( ! $usesProjectBase && $definesProjectBase )
4273
    {
4274
        Warning ("SetProjectBase - Defines ProjectBase without using it");
4275
    }
4276
 
4277
    if ( $usesProjectBase && $definesProjectBase && $definitionError )
4278
    {
4279
        Warning ("SetProjectBase$eSuf - Problem detected");
4280
        $retval = 1;
4281
    }
4282
    return $retval;
4283
}
4284
 
1272 dpurdie 4285
#-------------------------------------------------------------------------------
4003 dpurdie 4286
# Function        : detectBuildFileClashes
4287
#
4288
# Description     : Scan a directory for multiple buildfiles and conflicts
4289
#                   Only works for Jats build.pl files - at the moment
4290
#
4291
# Inputs          : $data       - PackageVersion Data
4292
#                   $rootDir    - Directory to scan
4293
#
4294
# Returns         : 0                   - All is well
4295
#                   !0                  - Multiple build files found
4296
#
4297
sub detectBuildFileClashes
4298
{
4299
    my ($pvdata, $rootDir) = @_;
4300
    my %data;
4301
    my $rv = 0;
4302
Message ('Detect Build File Clashes');
4303
 
4304
    my $bscanner = BuildFileScanner ( $rootDir, 'build.pl' );
4305
    my $count = $bscanner->locate();
4306
 
4307
    #
4308
    #   None found - OK ( but not good )
4309
    #
4310
    return $rv unless ( $count );
4311
 
4312
    #
4313
    #   Process all the build files in the tree
4314
    #
4315
    $bscanner->scan();
4316
    my @buildfiles = $bscanner->getMatchList();
4317
#   DebugDumpData('$bscanner', $bscanner );
4318
#   DebugDumpData('@buildfiles', \@buildfiles );
4319
#   exit 99;
4320
 
4321
    foreach my $bf ( @buildfiles )
4322
    {
4323
        my $bdir = $bf->{dir};
4324
        my $bname = $bf->{name};
4325
        my $bversion = $bf->{version};
4326
        next unless ( defined($bname) );
4327
Information ("BuildFiles: $bname, $bversion : $bdir");
4328
 
4329
        if ( exists ($data{$bname}{count}) && ($data{$bname}{count} >= 1) )
4330
        {
4331
            Warning ("MultipleBuildFiles for $bname ($bversion)");
4332
            $rv = 1;
4333
        }
4334
        $data{$bname}{count}++;
4335
        push @{$data{$bname}{versions}}, $bversion;
4336
    }
4337
 
4338
    return $rv;
4339
}
4340
 
4341
#-------------------------------------------------------------------------------
1272 dpurdie 4342
# Function        : findDirWithStuff
4343
#
4344
# Description     : Find a directory that contains more than just another subdir
2429 dpurdie 4345
#                   Note: don't use 'glob' it doesn't work if the name has a space in it.
1272 dpurdie 4346
#
4347
# Inputs          : $base               - Start of the scan
4348
#
4349
# Returns         : Path to dir with more than just a single dir in it
4350
#
4351
sub findDirWithStuff
4352
{
4353
    my ($base) = @_;
1271 dpurdie 4354
 
1272 dpurdie 4355
    while ( $base )
4356
    {
4357
    my $fileCount = 0;
4358
    my $dirCount = 0;
2429 dpurdie 4359
    my $firstDir;
1272 dpurdie 4360
 
2429 dpurdie 4361
    opendir (my $dh, $base ) || Error ("Cannot opendir $base. $!");
4362
    my @list =readdir $dh;
4363
    closedir $dh;
1272 dpurdie 4364
    foreach ( @list )
4365
    {
4366
        next if ( $_ eq '.' );
4367
        next if ( $_ eq '..' );
2429 dpurdie 4368
 
4369
        $_ = $base . '/' . $_;
1272 dpurdie 4370
        if ( -d $_ )
4371
        {
4372
            $dirCount++;
2429 dpurdie 4373
            $firstDir = $_ unless ( defined $firstDir );
4374
            return $base
4375
                if ( $dirCount > 1  )
1272 dpurdie 4376
        }
2429 dpurdie 4377
        elsif ( -e $_ )
1272 dpurdie 4378
        {
4379
            return $base;
4380
        }
2429 dpurdie 4381
 
4382
        # else its probably a dead symlink
1272 dpurdie 4383
    }
2429 dpurdie 4384
 
4385
    return $base
4386
        unless ( $dirCount == 1  );
4387
    $base = $firstDir;
1272 dpurdie 4388
    }
4389
}
4390
 
1271 dpurdie 4391
#-------------------------------------------------------------------------------
4392
# Function        : JatsToolPrint
4393
#
4394
# Description     : Print and Execuate a JatsTool command
4395
#
4396
# Inputs          : 
4397
#
4398
# Returns         : 
4399
#
4400
 
4401
sub JatsToolPrint
4402
{
4403
    Information ("Command: @_");
4404
    JatsTool @_;
4405
}
4406
 
4407
sub GetVname
4408
{
4409
    my ($entry) = @_;
4410
    my $me = 'NONE';
4411
    if ( $entry )
4412
        {
4413
        $me = $versions{$entry}{vname};
4414
        unless ( $me )
4415
        {
4416
            $me = 'Unknown-' . $entry;
4417
        }
4418
    }
4419
    return $me;
4420
}
4421
 
2429 dpurdie 4422
#-------------------------------------------------------------------------------
4423
# Function        : saneLabel
4424
#
4425
# Description     : Generate a sane version label
4003 dpurdie 4426
#                   Handle duplicates (due to character squishing)
2429 dpurdie 4427
#                   Cache results for repeatability
4428
#
4429
# Inputs          : $entry          - Version info
4430
#                   $pkgname        - Alternate pkgname (branching)
4431
#
4432
# Returns         : Sane string
4433
#
1271 dpurdie 4434
sub saneLabel
4435
{
4436
    my ($entry, $pkgname) = @_;
4437
    my $me;
2429 dpurdie 4438
    $me = $versions{$entry}{vname};
4439
    $pkgname = $versions{$entry}{name} unless ( defined $pkgname );
1271 dpurdie 4440
 
2429 dpurdie 4441
    #
4442
    #   If we have calculated it, then reuse it.
4443
    #
4444
    if ( exists $versions{$entry}{saneLabel}{$pkgname} )
1271 dpurdie 4445
    {
2429 dpurdie 4446
        return $versions{$entry}{saneLabel}{$pkgname};
1271 dpurdie 4447
    }
4448
 
2429 dpurdie 4449
 
1271 dpurdie 4450
    Error ("Package does have a version string: pvid: $entry")
4451
        unless ( defined $me );
4452
 
4453
    #
4454
    #   Convert Wip format (xxxx) into a string that can be used for a label
4455
    #
4456
    if ( $me =~ m~^(.*)\((.*)\)(.*)$~ )
4457
    {
4458
        $me = $1 . '_' . $2 . '_' . $3 . '.WIP';
4459
        $me =~ s~_\.~.~;
4460
        $me =~ s~^_~~;
4461
    }
4462
 
4463
    #
4464
    #   Allow for WIPS
4465
    #   Get rid of multiple '_'
4466
    #   Replace space with -
4467
    #
4468
    $me = $pkgname . '_' . $me;
4469
    $me =~ tr~ ~-~s;
4470
    $me =~ tr~-~-~s;
4471
    $me =~ tr~_~_~s;
4472
 
2429 dpurdie 4473
    #
4474
    #   Due to some sillyness ( package version starting with _ )
4475
    #   we may get duplicates. Detect and allocate different numbers
4476
    #
4477
    if ( exists $saneLabels{$me} )
4478
    {
4479
        $saneLabels{$me}++;
4480
        $me = $me . '.' . $saneLabels{$me};
4481
        Message ("Duplicate SaneLabel resolved as: $me");
4482
    }
4483
    else
4484
    {
4485
        $saneLabels{$me} = 0;
4486
    }
4487
 
4488
    #
4489
    #   Cache value
4490
    #
4491
    $versions{$entry}{saneLabel}{$pkgname} = $me;
1271 dpurdie 4492
    return $me;
4493
}
4494
 
2429 dpurdie 4495
sub saneString
4496
{
4497
    my ($string) = @_;
4498
    #
4499
    #   Get rid of multiple '_'
4500
    #   Replace space with -
4501
    #
4502
    $string =~ s~\W~_~g;
4503
    $string =~ tr~ ~_~s;
4504
    $string =~ tr~_-~-~s;
4505
    $string =~ tr~-_~-~s;
4506
    $string =~ tr~-~-~s;
4507
    $string =~ tr~_~_~s;
4508
    $string =~ s~-$~~;
4509
    $string =~ s~_$~~;
1271 dpurdie 4510
 
2429 dpurdie 4511
    return $string;
4512
}
4513
 
4514
 
1271 dpurdie 4515
exit 0;
4516
 
4517
 
4518
#-------------------------------------------------------------------------------
4519
# Function        : GetPkgIdByName
4520
#
4521
# Description     :
4522
#
4523
# Inputs          : pkg_name
4524
#
4525
# Returns         : pkg_id
4526
#
4527
sub GetPkgIdByName
4528
{
4529
    my ( $pkg_name ) = @_;
4530
    my (@row);
4531
    my $pv_id;
4532
    my $pkg_id;
4533
 
4534
    #
4535
    #   Establish a connection to Release Manager
4536
    #
4537
    connectRM(\$RM_DB) unless ( $RM_DB );
4538
 
4539
    #
4540
    #   Extract data from Release Manager
4541
    #
4542
    my $m_sqlstr = "SELECT pkg.PKG_NAME, pkg.PKG_ID" .
4543
                   " FROM RELEASE_MANAGER.PACKAGES pkg" .
4544
                   " WHERE pkg.PKG_NAME = \'$pkg_name\'";
4545
 
4546
    my $sth = $RM_DB->prepare($m_sqlstr);
4547
    if ( defined($sth) )
4548
    {
4549
        if ( $sth->execute( ) )
4550
        {
4551
            if ( $sth->rows )
4552
            {
4553
                while ( @row = $sth->fetchrow_array )
4554
                {
4555
                    Verbose( "DATA: " . join(',', @row) );
4556
                    $pkg_id = $row[1] || 0;
4557
                    last;
4558
                }
4559
            }
4560
            else
4561
            {
4562
                Error ("GetPkgIdByName:No Data for package: $pkg_name");
4563
            }
4564
            $sth->finish();
4565
        }
4566
    }
4567
    else
4568
    {
4569
        Error("GetPkgIdByName:Prepare failure" );
4570
    }
4571
 
4572
    return $pkg_id;
4573
}
4574
 
4575
#-------------------------------------------------------------------------------
4576
# Function        : GetData_by_pkg_id
4577
#
4578
# Description     :
4579
#
4580
# Inputs          : pv_id
4581
#
4582
# Returns         :
4583
#
4584
sub GetData_by_pkg_id
4585
{
4586
    my ( $pkg_id, $packageName ) = @_;
4587
    my (@row);
4588
 
4589
    #
4590
    #   Establish a connection to Release Manager
4591
    #
4592
    Message ("Extract package versions from Release Manager: $packageName");
4593
    connectRM(\$RM_DB) unless ( $RM_DB );
4594
 
4595
    #
4596
    #   Extract data from Release Manager
4597
    #
2429 dpurdie 4598
    my $m_sqlstr = "SELECT " .
4599
                       "pkg.PKG_NAME, " .                                       # row[0]
4600
                       "pv.PKG_VERSION, " .                                     # row[1]
4601
                       "pkg.PKG_ID, " .                                         # row[2]
4602
                       "pv.PV_ID, " .                                           # row[3]
4603
                       "pv.LAST_PV_ID, " .                                      # row[4]
4604
                       "pv.MODIFIED_STAMP, " .                                  # row[5]
4605
                       "release_manager.PK_RMAPI.return_vcs_tag(pv.PV_ID), " .  # row[6]
4606
                       "amu.USER_NAME, " .                                      # row[7]
4607
                       "pv.COMMENTS, " .                                        # row[8]
4608
                       "pv.DLOCKED, " .                                         # row[9]
4609
                       "pv.CREATOR_ID, ".                                       # row[10]
4610
                       "pv.BUILD_TYPE ".                                        # row[11]
4611
                   " FROM " .
4612
                        "RELEASE_MANAGER.PACKAGES pkg, " .
4613
                        "RELEASE_MANAGER.PACKAGE_VERSIONS pv, " .
4614
                        "ACCESS_MANAGER.USERS amu" .
4615
                   " WHERE " .
4616
                        "pv.PKG_ID = \'$pkg_id\' " .
4617
                        "AND pkg.PKG_ID = pv.PKG_ID " .
4618
                        "AND amu.USER_ID (+) = pv.CREATOR_ID";
4619
 
1271 dpurdie 4620
    my $sth = $RM_DB->prepare($m_sqlstr);
4621
    if ( defined($sth) )
4622
    {
4623
        if ( $sth->execute( ) )
4624
        {
4625
            if ( $sth->rows )
4626
            {
4627
                while ( @row = $sth->fetchrow_array )
4628
                {
4629
                    Verbose( "DATA: " . join(',', @row) );
4630
                    my $pkg_name = $row[0] || 'Unknown';
4631
                    my $pkg_ver = $row[1] || 'Unknown';
4632
                       $pkg_ver =~ s~\s+$~~;
4633
                       $pkg_ver =~ s~^\s+~~;
4634
                    my $pv_id = $row[3] || 'Unknown';
4635
                    my $last_pv_id = $row[4];
4636
                    my $created =  $row[5] || 'Unknown';
4637
                    my $vcstag =  $row[6] || 'Unknown';
4638
 
4639
                    my $created_id =  $row[7] || ($row[10] ? "Userid_$row[10]" :'Unknown');
4640
                    my $comment =  $row[8] || '';
4641
                    my $locked =  $row[9] || 'N';
2429 dpurdie 4642
                    my $manual = $row[11] || 'M';
1271 dpurdie 4643
 
4644
                    #
4645
                    #   Some developers have a 'special' package version
4646
                    #   We really need to ignore them
4647
                    #
4648
                    next if ( $pkg_ver eq '23.23.23.ssw' );
4003 dpurdie 4649
 
1271 dpurdie 4650
                    #
4651
                    #   Add data to the hash
4652
                    #
4653
                    $versions{$pv_id}{name} = $pkg_name;
4654
                    $versions{$pv_id}{pvid} = $pv_id;
4655
                    $versions{$pv_id}{vname} = $pkg_ver;
4656
                    $versions{$pv_id}{vcsTag} = $vcstag;
4657
                    $versions{$pv_id}{created} = $created;
4658
                    $versions{$pv_id}{created_id} = $created_id;
4659
                    $versions{$pv_id}{comment} = $comment;
4660
                    $versions{$pv_id}{locked} = $locked;
4661
                    $versions{$pv_id}{TimeStamp} = str2time( $created );
4662
                    $versions{$pv_id}{Age} = ($now - $versions{$pv_id}{TimeStamp}) / (60 * 60 * 24);
4663
                    $versions{$pv_id}{TooOld} = 1 if ( $opt_age && $opt_age <= $versions{$pv_id}{Age} );
2429 dpurdie 4664
                    $versions{$pv_id}{BuildType} = $manual;
1271 dpurdie 4665
                    examineVcsTag($pv_id);
4666
 
4667
                    #
4668
                    #   Process version number
4669
                    #
4003 dpurdie 4670
                    my ($suffix, $version, $isaR, $isaWip, $buildVersion, $isaPatch ) = massageVersion($pkg_ver, $pkg_name);
1271 dpurdie 4671
 
4672
                    $versions{$pv_id}{version} = $version;
4673
                    $versions{$pv_id}{buildVersion} = $buildVersion;
4674
                    $versions{$pv_id}{isaWip} = 1 if ( $isaWip );
4003 dpurdie 4675
                    $versions{$pv_id}{isaPatch} = 1 if ( $isaPatch );
1271 dpurdie 4676
 
4003 dpurdie 4677
                    # Remove entries that address themselves
4678
                    push (@{$versions{$last_pv_id}{next}}, $pv_id) unless ($pv_id == $last_pv_id || $last_pv_id == 0 || $isaPatch) ;
4679
 
4680
 
1271 dpurdie 4681
                    #
4003 dpurdie 4682
                    #   New method for detecting a ripple
2429 dpurdie 4683
                    #       Don't look at the version number
4684
                    #       Use RM data
4685
                    #       Inlude the comment - there are some cases where the comment
4686
                    #       appears to have been user modified.
4687
                    #
4688
#                    $versions{$pv_id}{isaRipple} = 1 if ( $isaR );
4689
#                    $versions{$pv_id}{isaRipple} = 1 if ( uc($manual) eq 'Y' );
4690
                    $versions{$pv_id}{isaRipple} = ( $comment =~ m~^Rippled Build~i && ( uc($manual) eq 'Y' ));
4691
 
4692
                    #
1271 dpurdie 4693
                    #   Process suffix
4694
                    #
4695
                    $suffix = 'Unknown' unless ( $suffix );
4696
                    $suffix = lc ($suffix);
4697
                    $versions{$pv_id}{suffix} = $suffix;
4698
                    push @{$suffixes{$suffix}}, $pv_id;
4699
 
4700
#                    print "$pkg_name, $pkg_ver, $pv_id, $last_pv_id, $locked, $created, $created_id, $suffix\n";
4701
                }
4702
            }
4703
            else
4704
            {
4705
                Error ("GetData_by_pkg_id: No Data: $m_sqlstr");
4706
            }
4707
            $sth->finish();
4708
        }
4709
        else
4710
        {
4711
                Error ("GetData_by_pkg_id: Execute: $m_sqlstr");
4712
        }
4713
    }
4714
    else
4715
    {
4716
        Error("GetData_by_pkg_id:Prepare failure" );
4717
    }
4718
}
4719
 
4720
#-------------------------------------------------------------------------------
4721
# Function        : massageVersion
4722
#
4723
# Description     : Process a version number and return usful bits
4724
#
4725
# Inputs          : Version Number
4726
#                   Package Name - debug only
4727
#
4728
# Returns         : An array
4729
#                       suffix
4730
#                       multipart version string useful for text comparisons
4731
#
4732
sub massageVersion
4733
{
4734
    my ($version, $name) = @_;
4735
    my ($major, $minor, $patch, $build, $suffix);
4736
    my $result;
4737
    my $buildVersion;
4738
    my $isaRipple;
4739
    my $isaWIP;
4003 dpurdie 4740
    my $isaPatch;
1271 dpurdie 4741
    $build = 0;
4742
 
4743
#print "--- $name, $version\n";
4744
    $version =~ s~^_~~;
4745
    $version =~ s~^${name}_~~;
4746
 
4747
    #
4748
    #   xxxxxxxxx.nnnn.cots
4749
    #
4750
    if ( $version =~ m~(.*)\.cots$~ ) {
4751
        my $cots_base = $1;
4752
        $suffix = '.cots';
4003 dpurdie 4753
        if ( $version =~ m~(.*?)\.([0-9]{4,5})\.cots$~ )
1271 dpurdie 4754
        {
4755
            $result = $1 . sprintf (".%4.4d", $2) . $suffix;
4756
        }
4757
        else
4758
        {
4759
            $result = $cots_base . '.0000.cots';
4760
        }
4003 dpurdie 4761
        if ( $result =~ m~(.*)\.(\d+)(\d\d\d)\.cots$~ )
4762
        {
4763
            $buildVersion = [$1, 0 , $2, $3 ];
4764
        }
1271 dpurdie 4765
    }
4766
    #
4767
    #   Convert version into full form for comparisions
4768
    #       nnn.nnn.nnn.[p]nnn.xxx
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
    #   Don't flag as ripples - they are patches
4774
    #
4775
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-.p][p]?(\d+)([-.](.*))?$~ ) {
4776
        $major = $1;
4777
        $minor = $2;
4778
        $patch = $3;
4779
        $build = $4;
4780
        $suffix = defined $6 ? ".$6" : '';
4781
        $isaRipple = 0;
4003 dpurdie 4782
        $isaPatch = 1;
1271 dpurdie 4783
    }
4784
    #
4785
    #       nn.nnn.nnnnn.xxx
4786
    #       nn.nnn.nnnnn-xxx
4787
    #       nnn.nnn.nnnx.xxx
4788
    #   Don't flag as ripples - they are patches
4789
    #
4790
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)\w?([-.](.*))?$~ ) {
4791
        $major = $1;
4792
        $minor = $2;
4793
        $patch = $3;
4794
        if ( length( $patch) >= 4 )
4795
        {
4796
            $build = substr( $patch, -3 ,3);
4797
            $patch = substr( $patch,  0 ,length($patch)-3);
4798
        }
4799
        $suffix = defined $5 ? ".$5" : '';
4800
    }
4801
 
4802
    #
4803
    #       nnn.nnn.nnn
4804
    #       nnn.nnn-nnn
4805
    #       nnn.nnn_nnn
4806
    #
4807
    elsif ( $version =~ m~^(\d+)\.(\d+)[-._](\d+)$~ ) {
4808
        $major = $1;
4809
        $minor = $2;
4810
        $patch = $3;
4811
        $suffix = '';
4812
    }
4813
 
4814
    #
4815
    #       nnn.nnn.nnn.nnn
4816
    #       nnn.nnn.nnn-nnn
4817
    #       nnn.nnn.nnn_nnn
4818
    #
4819
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)[-._](\d+)$~ ) {
4820
        $major = $1;
4821
        $minor = $2;
4822
        $patch = $3;
4823
        $build = $4;
4824
        $suffix = '';
4825
        $isaRipple = 0;
4826
    }
4827
 
4828
 
4829
    #
4830
    #       nnn.nnn
4831
    #
4832
    elsif ( $version =~ m~^(\d+)\.(\d+)$~ ) {
4833
        $major = $1;
4834
        $minor = $2;
4835
        $patch = 0;
4836
        $suffix = '';
4837
    }
4838
    #
4839
    #       nnn.nnn.xxx
4840
    #
4841
    elsif ( $version =~ m~^(\d+)\.(\d+)(\.\w+)$~ ) {
4842
        $major = $1;
4843
        $minor = $2;
4844
        $patch = 0;
4845
        $suffix = $3;
4846
    }
4003 dpurdie 4847
 
4848
    #
4849
    #       nnn.nnn.c.xxx
4850
    #
4851
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\w)(\.\w+)$~ ) {
4852
        $major = $1;
4853
        $minor = $2;
4854
        $patch = ord($3);
4855
        $suffix = $4;
4856
    }
1271 dpurdie 4857
 
4003 dpurdie 4858
 
1271 dpurdie 4859
    #
4860
    #       nnn.nnn.nnnz
4861
    #
4862
    elsif ( $version =~ m~^(\d+)\.(\d+)\.(\d+)([a-z])$~ ) {
4863
        $major = $1;
4864
        $minor = $2;
4865
        $patch = $3;
4866
        $build = ord($4) - ord('a');
4867
        $suffix = '.cots';
4868
        $isaRipple = 0;
4869
    }
4870
    #
4871
    #       ???REV=???
4872
    #
4873
    elsif ( $version =~ m~REV=~ ) {
4874
        $suffix = '.cots';
4003 dpurdie 4875
        $result = $version . '.000000.cots';
1271 dpurdie 4876
    }
4877
 
4878
    #
4879
    #   Wip Packages
4880
    #   (nnnnnn).xxx
4881
    #   Should be essential, but want to sort very low
4882
    #
4883
    elsif ($version =~ m~\((.*)\)(\..*)?~) {
4884
        $suffix = $2 || '';
4003 dpurdie 4885
        $result = "000.000.000.00000$suffix";
1271 dpurdie 4886
        $isaWIP = 1;
4887
    }
4888
 
4889
    #
4890
    #   !current
4891
    #
4892
    elsif ($version eq '!current' || $version eq 'current_$USER' || $version eq 'current' || $version eq 'beta' || $version eq 'latest' || $version eq 'beta.cr' || $version eq 'CREATE') {
4893
        $suffix = '';
4003 dpurdie 4894
        $result = "000.000.000.00000$suffix";
1271 dpurdie 4895
        $isaWIP = 1;
4896
    }
4897
 
4898
    #
4899
    #   Also WIP: FINRUN.103649.BEI.WIP
4900
    elsif ($version =~ m~(\.[a-zA-Z]+)\.WIP$~) {
4901
        $suffix = lc($1);
4003 dpurdie 4902
        $result = "000.000.000.00000$suffix";
1271 dpurdie 4903
        $isaWIP = 1;
4904
    }
4905
 
4906
    #
4907
    #   Also ERGOFSSLS190100_015
4908
    #   Don't flag as a ripple
4909
    elsif ($version =~ m~^ERG[A-Z]+(\d\d)(\d\d)(\d\d)[-_](\d+)(\.\w+)?$~) {
4910
        $major = $1;
4911
        $minor = $2;
4912
        $patch = $3;
4913
        $build = $4;
4914
        $suffix = $5 || '.sls';
4915
        $isaRipple = 0;
4916
    }
4003 dpurdie 4917
 
1271 dpurdie 4918
    #
4003 dpurdie 4919
    #   nnnn
4920
    #
4921
    elsif ($version =~ m~[0-9]{4}~) {
4922
        $suffix = '';
4923
        $major = 0;
4924
        $minor = 0;
4925
        $patch = $version;
4926
        $build = 0;
4927
    }
4928
    #
1271 dpurdie 4929
    #   Stuff we don't yet handle
4930
    #
4931
    else  {
4932
        Warning ("Unknown version number: $name,$version");
4933
        $version =~ m~(\.\w+)$~;
4934
        $suffix = $1 || '';
4935
        $result = $version;
4936
    }
4937
 
4938
    $isaRipple = ($build > 0) unless defined $isaRipple;
4939
    unless ( $result )
4940
    {
4941
        # Major and minor of 99.99 are normally funy versions
4942
        # Don't make important desicions on them
4943
        #
4944
        if ( $major == 99 && $minor == 99 )
4945
        {
4946
            $major = 0;
4947
            $minor = 0;
4948
            $patch = 0;
4949
        }
4950
 
4003 dpurdie 4951
        $result = sprintf("%3.3d.%3.3d.%3.3d.%5.5d%s", $major,$minor,$patch,$build,$suffix || '.0000');
1271 dpurdie 4952
        $buildVersion = [ $major, $minor, $patch, $build ];
4953
    }
4954
 
4955
    $suffix = lc( $suffix );
4956
    if ( exists $suffixFixup{$suffix} )
4957
    {
4958
        $suffix = $suffixFixup{$suffix} ;
4959
    }
4960
 
4003 dpurdie 4961
    return ($suffix, $result, $isaRipple, $isaWIP, $buildVersion, $isaPatch );
1271 dpurdie 4962
}
4963
 
4964
#-------------------------------------------------------------------------------
4965
# Function        : vcsCleanup
4966
#
4967
# Description     : Cleanup and rewrite a vcstag
4968
#
4969
#                   DUPLICATED IN:
4970
#                       - cc2svn_procdata
4971
#                       - cc2svn_importpackage
4972
#
4973
# Inputs          : vcstag
4974
#
4975
# Returns         : Cleaned up vcs tag
4976
#
4977
sub vcsCleanup
4978
{
4979
    my ($tag) = @_;
2764 dpurdie 4980
    $tag =~ tr~\\/~/~;                              # Force use of /
4981
    $tag =~ s~/+$~~;                                # Trailing /
1271 dpurdie 4982
    if ( $tag =~ m~^CC::~ )
4983
    {
2764 dpurdie 4984
        $tag =~ s~CC::/VOB:/~CC::/~;                # Kill stuff
2429 dpurdie 4985
        $tag =~ s~CC::load\s+~CC::~;                # Load rule
4986
        $tag =~ s~CC::\s+~CC::~;                    # Leading white space
4987
        $tag =~ s~CC::[A-Za-z]\:/~CC::/~;           # Leading driver letter
4988
        $tag =~ s~CC::/+~CC::/~;                    # Multiple initial /'s
4989
        $tag =~ s~/build.pl::~::~i;
4990
        $tag =~ s~/src::~::~i;
1271 dpurdie 4991
        $tag =~ s~MASS_Dev_Bus/Cbp/~MASS_Dev_Bus/CBP/~i;
4992
        $tag =~ s~MASS_Dev_Bus~MASS_Dev_Bus~i;
4993
        $tag =~ s~/MASS_Dev/Infra~MASS_Dev_Infra~i;
4994
        $tag =~ s~/MASS_Dev/Bus/web~/MASS_Dev_Bus/web~i;
4995
 
4996
        $tag =~ s~/Vastraffik/~/Vasttrafik/~;
4997
        $tag =~ s~/MREF_Package/ergpostmongui$~/MREF_Package/ergpostmongui~i;
4998
        $tag =~ s~DPC_SWCode/~DPG_SWCode/~i;
4999
    }
5000
    return $tag;
5001
}
5002
 
5003
#-------------------------------------------------------------------------------
5004
# Function        : examineVcsTag
5005
#
5006
# Description     : Examine a VCS Tag and determine if it looks like rubbish
5007
#                   Give it a clean
5008
#
5009
# Inputs          : $entry
5010
#
5011
# Returns         : Will add Data to the $entry
5012
#
5013
sub examineVcsTag
5014
{
5015
    my ($entry) = @_;
5016
    my $bad = 0;
5017
 
5018
    $versions{$entry}{vcsTag} = vcsCleanup($versions{$entry}{vcsTag});
5019
    my $vcstag = $versions{$entry}{vcsTag};
5020
 
5021
    if ( $vcstag =~ m~^SVN::~ ) {
5022
        $versions{$entry}{isSvn} = 1;
5023
 
5024
    } elsif ( $vcstag =~ m~^CC::(.*?)(::(.+))?$~ ) {
5025
        my $path = $1  || '';
5026
        my $label = $2 || '';
5027
        $bad = 1 unless ( $label );
5028
        $bad = 1 if ( $label =~ m~^N/A$~i || $label  =~ m~^na$~i );
5029
 
5030
        $bad = 1 unless ( $path );
5031
        $bad = 1 if ( $path =~ m~^N/A$~i || $path  =~ m~^na$~i );
5032
        $bad = 1 if ( $path =~ m~^/dpkg_archive~ || $path  =~ m~^dpkg_archive~ );
5033
        $bad = 1 if ( $path =~ m~^/devl/~ || $path  =~ m~^devl/~ );
5034
        $bad = 1 if ( $path =~ m~^CVS~ );
5035
        $bad = 1 if ( $path =~ m~^http:~i );
5036
        $bad = 1 if ( $path =~ m~^[A-Za-z]\:~ );
5037
        $bad = 1 if ( $path =~ m~^//~ );
2764 dpurdie 5038
        $bad = 1 if ( $path =~ m~^/blade1/~ );
5039
        $bad = 1 if ( $path =~ m~^/devl/~ );
1271 dpurdie 5040
        $bad = 1 if ( $path =~ m~^/*none~i );
5041
        $bad = 1 if ( $path =~ m~^/*NoWhere~i );
5042
        $bad = 1 if ( $path =~ m~^-$~i );
5043
        $bad = 1 if ( $path =~ m~^cvsserver:~ );
5044
        $bad = 1 if ( $path =~ m~,\s*module:~ );
2764 dpurdie 5045
        $bad = 1 if ( $path =~ m~[()]~ );
1271 dpurdie 5046
#        $bad = 1 unless ( $path =~ m~^/~ );
5047
    }
5048
    else
5049
    {
5050
        $bad = 1;
5051
    }
5052
    $versions{$entry}{badVcsTag} = 1 if ( $bad );
5053
}
5054
 
5055
#-------------------------------------------------------------------------------
5056
# Function        : logToFile
5057
#
5058
# Description     : Log some data to a named file
5059
#                   Use file locking to allow multiple process to log
5060
#
5061
# Inputs          : $filename           - Name of file to log
5062
#                   ...                 - Data to log
5063
#
5064
# Returns         : Nothing
5065
#
5066
sub logToFile
5067
{
5068
    my ($file, @data) = @_;
5069
 
5070
    open  (LOGFILE, '>>', $file);
5071
    flock (LOGFILE, LOCK_EX);
5072
    print  LOGFILE "@data\n";
5073
    flock (LOGFILE, LOCK_UN);
5074
    close (LOGFILE);
5075
}
5076
 
5077
#-------------------------------------------------------------------------------
5078
# Function        : createImages
5079
#
5080
# Description     : Create nice images of the RM version tree
5081
#
5082
# Inputs          : 
5083
#
5084
# Returns         : 
5085
#
5086
sub createImages
5087
{
5088
 
5089
    my $filebase = "${packageNames}";
4003 dpurdie 5090
    my $openOk;
5091
    foreach my $ii ( 0 .. 5 )
5092
    {
5093
        if (open (FH, '>', $cwd . "/$filebase.dot" ))
5094
        {
5095
            $openOk = 1;
5096
            last;
5097
        }
5098
        sleep (2);
5099
    }
5100
    unless ( $openOk )
5101
    {
5102
        Warning ("Cannot open image output: $filebase.dot");
5103
        return;
5104
    }
5105
 
5106
 
1271 dpurdie 5107
    print FH "digraph \"${packageNames}\" {\n";
5108
    #print FH "rankdir=LR;\n";
5109
    print FH "node[fontsize=16];\n";
5110
    print FH "node[target=_graphviz];\n";
5111
#    print FH "subgraph cluster_A {\n";
5112
#    print FH "node[fontsize=12];\n";
5113
 
5114
    {
5115
        my @text;
5116
        push @text, $packageNames;
5117
        push @text, 'HyperLinked to Release Manager';
5118
        push @text, 'Created:' . localtime();
5119
        push @text, '|';
5120
 
5121
        push @text, 'Total RM versions: ' . $totalVersions;
5122
        push @text, 'Essential Entries: ' . scalar @EssentialPackages;
5123
        push @text, 'Initial trees: ' . $initialTrees;
5124
 
1272 dpurdie 5125
        push @text, 'Number of Entries: ' . $processTotal;
1271 dpurdie 5126
        push @text, 'Type : ' . $packageType;
5127
        push @text, 'All versions in Subversion' if ( $allSvn );
5128
 
5129
        push @text, '|';
5130
        push @text, 'Total Project Branches: ' . $ProjectCount;
5131
        foreach ( sort keys %knownProjects )
5132
        {
5133
            my $count = $knownProjects{$_}{count} || 0;
5134
            if ( $count )
5135
            {
5136
                my $text = 'Project Branch: ' . $_;
5137
                $text .= " (" . $count . ")" if ( $count > 1 );
5138
                push @text, $text;
5139
            }
5140
        }
5141
 
5142
        push @text, '|';
5143
        push @text, 'Bad VCS : ' . $badVcsCount;
5144
        push @text, 'Bad Singletions : ' . $badSingletonCount;
5145
        push @text, 'Deadwood entries : ' . $trimCount;
5146
        push @text, 'Walking Mode : Flat' if ($opt_flat);
5147
        push @text, 'Pruned Mode : ' . $pruneModeString;
5148
        push @text, 'Pruned entries : ' . $pruneCount;
2429 dpurdie 5149
        push @text, 'Recent entries : ' . $recentCount;
1271 dpurdie 5150
 
5151
        if ( @unknownProjects )
5152
        {
5153
            push @text, '|';
5154
            push @text, 'Unknown Projects';
5155
            push @text, 'Unknown Project: ' . $_ foreach (sort @unknownProjects );
5156
        }
5157
 
5158
        #
5159
        #   Multiple Paths
5160
        #
5161
        if ( scalar @multiplePaths > 1 )
5162
        {
5163
            push @text, '|';
5164
            push @text, 'Multiple Paths';
4003 dpurdie 5165
            if ( $opt_AllowMuliplePaths )
5166
            {
5167
                push @text, 'Multiple Paths allowed:' . scalar @multiplePaths . ' found';
5168
            }
5169
            else
5170
            {
5171
                push @text, @multiplePaths;
5172
            }
1271 dpurdie 5173
        }
5174
 
5175
        #
5176
        #   Bad essentials
5177
        #
5178
        if ( @badEssentials  )
5179
        {
5180
            push @text, '|';
5181
            push @text, 'Bad Essential Versions';
5182
            push @text, GetVname($_) foreach ( @badEssentials );
5183
        }
5184
 
5185
        #
5186
        #   Subversion Data
5187
        #
5188
        if ( %svnData )
5189
        {
5190
            push @text, '|';
5191
            push @text, 'Subversion';
5192
            push @text, 'Trunk used' if exists $svnData{branches}{trunk} ;
5193
            push @text, 'Labels: ' . scalar keys %{$svnData{tags}} ;
5194
            push @text, 'Branches: ' . scalar keys %{$svnData{branches}} ;
2429 dpurdie 5195
            push @text, 'Relabled Packages : ' . $packageReLabelCount;
1271 dpurdie 5196
        }
5197
 
5198
        push @text, '';
5199
        my $text = join '\l', @text;
5200
        $text =~ s~\|\\l~|~g;
5201
 
5202
        my @attributes;
5203
        push @attributes, "shape=record";
5204
        push @attributes, "label=\"{$text}\"";
5205
        push @attributes, "tooltip=\"$packageNames\"";
5206
        push (@attributes, "URL=\"" . $GBE_RM_URL . "/view_by_version.asp?pkg_id=$first_pkg_id" . "\"" )if $first_pkg_id;
5207
        push @attributes, "color=red";
5208
        my $attr = join( ' ', @attributes);
5209
 
5210
        my $tld_done = 'TitleBlock';
5211
        print FH "$tld_done [$attr]\n";
5212
    }
5213
 
5214
    #
5215
    #   Generate Legend
5216
    #
5217
    {
5218
        my @text;
5219
        push @text, 'Legend';
5220
        push @text, '|';
5221
        push @text, 'Node Content';
5222
        push @text, 'Package Version';
5223
#        push @text, 'Release Manager Ref (pvid)';
5224
        push @text, 'Creation Date: yyyy-mm-dd';
5225
        push @text, '(Coded information)';
5226
        push @text, '|{Code';
5227
        push @text, '|{N: Not Locked';
5228
        push @text, 'b: Bad Singleton';
5229
        push @text, 'B: Bad VCS Tag';
4003 dpurdie 5230
        push @text, 'd: Package in dpkg_archive';
1271 dpurdie 5231
        push @text, 'D: DeadWood';
5232
        push @text, 'E: Essential Release Version';
2429 dpurdie 5233
        push @text, 'F: Package directories labled';
1271 dpurdie 5234
        push @text, 'G: Glued into Version Tree';
2429 dpurdie 5235
        push @text, 'L: Label not in VOB';
4003 dpurdie 5236
        push @text, 'p: Is a Patch';
2429 dpurdie 5237
        push @text, 'r: Recent version';
5238
        push @text, 'R: Ripple';
1271 dpurdie 5239
        push @text, 'S: Splitpoint';
5240
        push @text, 't: Glued into Project Tree';
5241
        push @text, 'T: Tip version';
5242
        push @text, 'V: In SVN';
5243
        push @text, '+: In Subversion';
2429 dpurdie 5244
        push @text, '0: Zero files extracted';
1271 dpurdie 5245
        push @text, '}}';
5246
 
5247
        push @text, '|';
5248
        push @text, 'Outline';
5249
        push @text, 'Red: Dead or Bad VCS Tag';
5250
        push @text, 'Orange: Project Branch Root';
5251
        push @text, 'Green: Ripple Build Version';
5252
        push @text, 'Blue: Essential Version';
5253
        push @text, 'Darkmagenta: Entry Glued into tree';
5254
        push @text, 'Magenta: Entry added to project tree';
2429 dpurdie 5255
        push @text, 'DeepPink: Label not in VOB';
5256
        push @text, 'DarkViolet: Zero files extracted';
1271 dpurdie 5257
 
5258
 
5259
        push @text, '|';
5260
        push @text, 'Fill';
5261
        push @text, 'PowderBlue: Essential Version';
5262
        push @text, 'Red: Bad Essential Version';
5263
        push @text, 'Light Green: Migrated to SVN';
5264
#        push @text, 'Red: Entry Glued into tree';
5265
#        push @text, 'Green: Entry added to project tree';
5266
 
5267
        push @text, '|';
5268
        push @text, 'Shape';
5269
        push @text, 'Oval: Normal Package Version';
5270
        push @text, 'Invhouse: Project Branch Root';
5271
        push @text, 'Octagon: Branch Point';
5272
        push @text, 'Box: Bad Single version with no history';
5273
        push @text, 'Doublecircle: Tip of a Project Branch';
5274
 
5275
        push @text, '';
5276
        my $text = join '\l', @text;
5277
        $text =~ s~\|\\l~|~g;
5278
        $text =~ s~\}\\l~}~g;
5279
 
5280
        my @attributes;
5281
        push @attributes, "shape=record";
5282
        push @attributes, "label=\"{$text}\"";
5283
        push @attributes, "color=red";
5284
        my $attr = join( ' ', @attributes);
5285
 
5286
        my $tld_done = 'LegendBlock';
5287
        print FH "$tld_done [$attr]\n";
5288
    }
5289
 
5290
#    print FH "\n}\n";
5291
    print FH "TitleBlock -> LegendBlock [style=invis]\n";
5292
 
5293
    sub genLabelText
5294
    {
5295
        my ($entry) = @_;
5296
        my @label;
4003 dpurdie 5297
        if ( $opt_fileList ) {
5298
            push @label, $versions{$entry}{realLabel};
5299
        } else {
5300
            push @label, $versions{$entry}{name} if ( $multiPackages );
5301
            push @label, $versions{$entry}{vname};
5302
        }    
1271 dpurdie 5303
#        push @label, $entry;       # Add PVID
5304
        push @label, substr( $versions{$entry}{created}, 0, 10); #  2008-02-19
5305
#        push @label, 'V=' . $versions{$entry}{maxVersion};
5306
#        push @label, 'B=' . $versions{$entry}{svnBranchTip} if ( exists $versions{$entry}{svnBranchTip} );
5307
 
5308
 
5309
        my $stateText = '';
5310
        $stateText .= 'N' if ($versions{$entry}{locked} eq 'N');
5311
        $stateText .= 'b' if (exists $versions{$entry}{badSingleton});
5312
        $stateText .= 'B' if (exists $versions{$entry}{badVcsTag});
5313
        $stateText .= 'G' if (exists $versions{$entry}{GluedIn});
5314
        $stateText .= 't' if (exists $versions{$entry}{MakeTree});
4003 dpurdie 5315
        $stateText .= 'E' if (exists $versions{$entry}{Essential});
5316
        $stateText .= 'd' if (exists $versions{$entry}{dpkgArchive});
1271 dpurdie 5317
        $stateText .= 'D' if (exists $versions{$entry}{DeadWood});
4003 dpurdie 5318
        $stateText .= 'p' if ( $versions{$entry}{isaPatch} );
2429 dpurdie 5319
        $stateText .= 'R' if ( $versions{$entry}{isaRipple} );
5320
        $stateText .= 'r' if (exists $versions{$entry}{keepRecent} && $versions{$entry}{keepRecent} );
1271 dpurdie 5321
        $stateText .= 'S' if (exists $versions{$entry}{EssentialSplitPoint} && $versions{$entry}{EssentialSplitPoint} > 1 );
5322
        $stateText .= 'T' if (exists $versions{$entry}{Tip} );
5323
        $stateText .= 'V' if (exists $versions{$entry}{isSvn} );
5324
        $stateText .= '+' if (exists $versions{$entry}{svnVersion} );
2429 dpurdie 5325
        $stateText .= '0' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq '0');
5326
        $stateText .= 'L' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq 'L');
5327
        $stateText .= 'F' if ($versions{$entry}{data}{DirsLabled});
5328
 
5329
 
1271 dpurdie 5330
#        $stateText .= 's' if (exists $versions{$entry}{branchPoint} );
5331
#        $stateText .= ' T='. $versions{$entry}{threadId} if (exists $versions{$entry}{threadId});
5332
#        $stateText .= ' EssentalPath' if (exists $versions{$entry}{EssentialPath});
5333
#        $stateText .= ' Count='. $versions{$entry}{EssentialSplitPoint} if (exists $versions{$entry}{EssentialSplitPoint});
5334
#        $stateText .= ' M='. $versions{$entry}{maxVersion} if (exists $versions{$entry}{maxVersion});
5335
 
2429 dpurdie 5336
        push @label, "(${stateText})" if ( length($stateText) );
1271 dpurdie 5337
 
2429 dpurdie 5338
##       Insert Release Names
5339
        foreach my $rtag_id ( keys %{$versions{$entry}{Releases}}  ) {
5340
            next unless ( exists $ukHopsReleases{$rtag_id} );
5341
            push @label, "Release: $versions{$entry}{Releases}{$rtag_id}{rname}";
5342
        }
5343
 
1271 dpurdie 5344
        return join ('\n', @label );
5345
    }
5346
 
5347
    sub genAttributes
5348
    {
5349
        my ($entry) = @_;
5350
        my @attributes;
5351
        push @attributes, 'label="' . genLabelText($entry) . '"';
5352
        unless ( $opt_fileList )
5353
        {
5354
            push @attributes, 'URL="' . dotUrl($entry) . '"';
5355
            push @attributes, 'tooltip="' . "Goto: $versions{$entry}{vname}, PVID=$entry" ,'"';
5356
        }
2764 dpurdie 5357
        else
1271 dpurdie 5358
        {
5359
            push @attributes, 'URL="' . "Dummy" . '"';
5360
            push @attributes, 'tooltip="' . "Original Label: $versions{$entry}{realLabel}" ,'"';
5361
        }
5362
        my $shape;
5363
            $shape = 'box' if ($versions{$entry}{badSingleton});
5364
            $shape = 'octagon'  if ($versions{$entry}{branchPoint});
5365
            $shape = 'invhouse' if ($versions{$entry}{newSuffix});
5366
            $shape = 'doublecircle' if ($versions{$entry}{Tip});
5367
 
5368
 
5369
        push @attributes, 'shape=' . $shape if ( $shape );
5370
 
5371
        my $color;
5372
        my $fill;
5373
           $color = 'color=green style=bold' if ( $versions{$entry}{isaRipple} );
5374
           $color = 'color=orange style=bold' if ( $versions{$entry}{newSuffix} );
5375
           $color = 'color=red style=bold' if ( $versions{$entry}{DeadWood} || $versions{$entry}{badVcsTag} );
5376
           $color = 'color=blue style=bold' if ( $versions{$entry}{Essential} );
5377
           $color = 'color=darkmagenta style=bold' if ( $versions{$entry}{GluedIn} );
5378
           $color = 'color=magenta style=bold' if ( $versions{$entry}{MakeTree} );
2429 dpurdie 5379
           $color = 'color=DeepPink style=bold' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq 'L');
5380
           $color = 'color=DarkViolet style=bold' if (exists $versions{$entry}{data}{errCode} && $versions{$entry}{data}{errCode} eq '0');
1271 dpurdie 5381
 
5382
           $fill = 'style=filled fillcolor=powderblue' if ( $versions{$entry}{Essential} );
5383
           $fill = 'style=filled fillcolor=red' if ( $versions{$entry}{Essential} && $versions{$entry}{badVcsTag} );
5384
           $fill = 'style=filled fillcolor="#99FF99"' if ( exists $versions{$entry}{svnVersion} );
5385
 
5386
 
5387
        push @attributes, $color if ( $color );
5388
        push @attributes, $fill if ( $fill );
5389
 
5390
        return '[' . join( ' ', @attributes) . ']';
5391
    }
5392
 
5393
    sub genArrowAttributes
5394
    {
5395
        my ($not_first, $entry) = @_;
5396
        my @attributes;
5397
 
5398
        push @attributes, 'arrowhead=empty' if ( $not_first );
5399
        push ( @attributes, 'label="' . $versions{$entry}{svnBranchTip} .'"' ) if ( exists $versions{$entry}{svnBranchTip} );
5400
 
5401
        return ('[' . join( ' ', @attributes) . ']') if ( @attributes ) ;
5402
        return '';
5403
    }
5404
 
5405
    #
5406
    #   Flat
5407
    #
5408
    if ( $opt_flat )
5409
    {
5410
        my $last = 0;
5411
        foreach my $entry (@flatOrder )
5412
        {
5413
            if ( $last )
5414
            {
5415
                my $me = dotTag($last);
5416
 
5417
                print FH pentry($me)  ,' -> ', pentry(dotTag($entry)), genArrowAttributes(0, $entry) ,";\n";
5418
                print FH pentry($me)  ,genAttributes($last) . ";\n";
5419
            }
5420
            $last = $entry;
5421
        }
5422
        print FH pentry(dotTag($last))  ,genAttributes($last) . ";\n";
5423
 
5424
    }
5425
    else
5426
    {
5427
        foreach my $entry ( sort {$a <=> $b} keys(%versions) )
5428
        {
5429
            my $me = dotTag($entry);
5430
            my @versions = @{ $versions{$entry}{next}};
5431
            my $ii = 0;
5432
            foreach ( @versions )
5433
            {
5434
                print FH pentry($me)  ," -> ",pentry(dotTag($_)), genArrowAttributes($ii++, $_), ";\n";
5435
            }
5436
 
5437
            print FH pentry($me)  ,genAttributes($entry) . ";\n";
5438
        }
5439
    }
5440
 
5441
    print FH "\n};\n";
5442
    close FH;
5443
 
5444
    #
5445
    #   Convert DOT to a SVG
5446
    #
5447
    unless ( $UNIX )
5448
    {
5449
    print "Generating graphical images\n";
5450
#    system( "dot $filebase.dot -Tjpg -o$filebase.jpg" );  # -v
5451
    system( "dot $filebase.dot -Tsvg -o$filebase.svg" );  # -v
5452
#    unlink("$filebase.dot");
5453
 
5454
    #
5455
    #   Display a list of terminal packages
5456
    #   These are packages that are not used by any other package
5457
    #
5458
    print "\n";
5459
#    print "Generated: $filebase.dot\n";
5460
#    print "Generated: $filebase.jpg\n";
5461
    print "Generated: $filebase.svg\n";
5462
    }
5463
    else
5464
    {
5465
        print "Generated: $filebase.dot\n";
5466
    }
5467
}
5468
 
5469
sub dotTag
5470
{
5471
    my ($entry) = @_;
5472
 
5473
    my $label = '';
5474
    if ( $versions{$entry}{realLabel} )
5475
    {
5476
        $label .= $versions{$entry}{realLabel};
5477
    }
5478
    else
5479
    {
5480
        $label .= $versions{$entry}{name} if $multiPackages;
5481
        $label .= $versions{$entry}{vname};
5482
    }
5483
    $label =~ s~[-() ]~_~g;
5484
    return $label;
5485
}
5486
 
5487
sub dotUrl
5488
{
5489
    my ($entry) = @_;
5490
 
5491
    my $pv_base = $GBE_RM_URL . "/fixed_issues.asp?pv_id=$entry";
5492
}
5493
 
5494
#-------------------------------------------------------------------------------
5495
# Function        : pentry
5496
#
5497
# Description     : Generate an entry list as text
5498
#                   Replace "." with "_" since DOT doesn't like .'s
5499
#                   Seperate the arguments
5500
#
5501
# Inputs          : @_          - An array of entries to process
5502
#
5503
# Returns         : A string
5504
#
5505
sub pentry
5506
{
5507
    my ($data) = @_;
5508
    $data =~ s~\.~_~g;
5509
    $result = '"' . $data . '"' ;
5510
    return $result;
5511
}
5512
 
5513
#-------------------------------------------------------------------------------
5514
# Function        : getVobMapping
5515
#
5516
# Description     : Read in Package to Repository Mapping
5517
#
5518
# Inputs          : 
5519
#
5520
# Returns         : Populates %VobMapping
5521
#                             Mapping of PackageName to RepoName[/Subdir]
5522
#
5523
our %ScmRepoMap;
5524
sub getVobMapping
5525
{
5526
    Message ("Read in Vob Mapping");
5527
 
5528
    my $fname = 'cc2svn.repo.dat';
5529
    Error "Cannot locate $fname" unless ( -f $fname );
5530
    require $fname;
5531
 
5532
    Error "Data in $fname is not valid\n"
5533
        unless ( keys(%ScmRepoMap) >= 0 );
5534
 
5535
    $opt_vobMap = $ScmRepoMap{$packageNames}{repo}
5536
        if (exists $ScmRepoMap{$packageNames});
5537
 
2764 dpurdie 5538
    $opt_protected = $ScmRepoMap{$packageNames}{protected}
5539
        if (exists $ScmRepoMap{$packageNames}{protected});
4003 dpurdie 5540
 
5541
    $opt_vobMap = '' if ( $opt_repoSubdir );
5542
 
1271 dpurdie 5543
    #
5544
    #   Free the memory
5545
    #
5546
    %ScmRepoMap = ();
5547
 
5548
    #
5549
    #   Calculate Target Repo
5550
    #
5551
    Warning ("No VOB Mapping found")
4003 dpurdie 5552
        unless ($opt_vobMap || ($opt_repoSubdir && $opt_repo));
1271 dpurdie 5553
    Error("No repository specified. ie -repo=DevTools or -repo=COTS")
5554
        unless ( $opt_repo || $opt_vobMap );
2439 dpurdie 5555
    my $r1 = ($opt_repo || '') . '/' . ($opt_vobMap || '') . '/' . ($opt_repoSubdir || '') ;
4003 dpurdie 5556
    $r1 = 'Import_test/' . $r1 if ( $opt_useTestRepo );
2439 dpurdie 5557
    $r1 =~ s~//~/~g;
1271 dpurdie 5558
    $r1 =~ s~^/~~;
4003 dpurdie 5559
    $r1 =~ s~/\.$~~;
1271 dpurdie 5560
    $r1 =~ s~/$~~;
5561
    $svnRepo = $opt_repo_base . $r1;
5562
 
4003 dpurdie 5563
    Message( "Repo URL: $svnRepo");
1271 dpurdie 5564
}
5565
 
5566
 
5567
#-------------------------------------------------------------------------------
5568
# Function        : getEssenialPackageVersions
5569
#
5570
# Description     : Determine the 'Essental' Package Versions
5571
#                   Read the data in from an external file
5572
#
5573
# Inputs          : 
5574
#
5575
# Returns         : Populates @EssentialPackages
5576
#
5577
 
5578
our %ScmReleases;
5579
our %ScmPackages;
5580
our %ScmSuffixes;
5581
sub getEssenialPackageVersions
5582
{
5583
    Message ("Read in Essential Package Versions");
5584
 
5585
    my $fname = 'cc2svn.raw.txt';
5586
    Error "Cannot locate $fname" unless ( -f $fname );
5587
    require $fname;
5588
 
5589
    Error "Data in $fname is not valid\n"
5590
        unless ( keys(%ScmReleases) >= 0 );
5591
 
5592
#    DebugDumpData("ScmReleases", \%ScmReleases );
5593
#    DebugDumpData("ScmPackages", \%ScmPackages );
5594
#    DebugDumpData("ScmSuffixes", \%ScmSuffixes );
5595
 
5596
    #
5597
    #   Create a list of essential packages
5598
    #   Retain packages-versions used in this program
5599
    #
5600
    foreach ( keys %ScmPackages )
5601
    {
5602
        next unless ( exists  $pkg_ids{ $ScmPackages{$_}{pkgid} } );
5603
        push @EssentialPackages, $_;
5604
        Error ("Essential Package Version not in extracted Release Manager Data: $_")
5605
            unless ( exists $versions{$_} );
5606
        $versions{$_}{Essential} = 1;
2429 dpurdie 5607
 
5608
        # Retain which RM Release this package-version is the tip
5609
        # Release of
5610
        foreach my $rtag_id ( @{$ScmPackages{$_}{'release'}} )
5611
        {
5612
            $versions{$_}{Releases}{$rtag_id}{rname}   = $ScmReleases{$rtag_id}{name};
5613
            $versions{$_}{Releases}{$rtag_id}{pname}   = $ScmReleases{$rtag_id}{pName};
5614
            $versions{$_}{Releases}{$rtag_id}{proj_id} = $ScmReleases{$rtag_id}{proj_id};
5615
        }
5616
 
5617
        #print "ESSENTIAL: $versions{$_}{name} $versions{$_}{vname}\n";
1271 dpurdie 5618
    }
5619
 
5620
    #
5621
    #   Free memory
5622
    #
5623
    %ScmReleases = ();
5624
    %ScmPackages = ();
5625
    %ScmSuffixes = ();
5626
 
5627
#    DebugDumpData("Essential", \@EssentialPackages );
5628
    Message ("Essential Versions: " . scalar @EssentialPackages );
5629
}
5630
 
5631
#-------------------------------------------------------------------------------
5632
# Function        : ReportPathVariance
5633
#
5634
# Description     : Report variance in paths used by the versions
5635
#
5636
# Inputs          : 
5637
#
5638
# Returns         : 
5639
#
5640
my %VobPaths;
5641
sub ReportPathVariance
5642
{
5643
    Message ("Detect Multiple Paths");
5644
    foreach my $entry ( keys(%versions) )
5645
    {
5646
        my $e = $versions{$entry};
5647
        next if ( isSet ($e, 'DeadWood' ) );
5648
        next if ( isSet ($e, 'badVcsTag') );
5649
        next if ( isSet ($e, 'isSvn') );
5650
        my $tag = $e->{vcsTag};
5651
        next unless ( $tag );
5652
 
5653
        $tag =~ m~^(.+?)::(.*?)(::(.+))?$~;
5654
        my $vcsType = $1;
5655
        my $cc_label = $4;
5656
        my $cc_path = $2;
5657
        $cc_path = '/' . $cc_path;
5658
        $cc_path =~ tr~\\/~/~s;
2764 dpurdie 5659
        $cc_path =~ s~/+$~~;
1271 dpurdie 5660
 
5661
        $VobPaths{$cc_path}++;
5662
    }
5663
 
5664
    @multiplePaths = sort keys %VobPaths;
5665
    if ( scalar @multiplePaths > 1 )
5666
    {
5667
        Warning ("Multiple Paths:" . $_ ) foreach (@multiplePaths);
2764 dpurdie 5668
 
5669
        # Kill SVN import
5670
        # User will need to configure one path
5671
        unless ( $opt_AllowMuliplePaths )
5672
        {
5673
            Warning ("Multiple Paths detected: Import supressed");
5674
            $opt_useSvn = 0
5675
        }
5676
        else
5677
        {
5678
            Message ("Multiple Paths detected: Allowed");
5679
        }
1271 dpurdie 5680
    }
5681
}
5682
 
5683
sub isSet
5684
{
5685
    my ($base, $element) = @_;
5686
    return 0 unless ( exists $base->{$element} );
5687
    return $base->{$element};
5688
}
5689
 
5690
 
5691
#-------------------------------------------------------------------------------
5692
# Function        : recurseList
5693
#
5694
# Description     : Return a list of all element below a given head element
5695
#
5696
# Inputs          : $head               - Head element
5697
#
5698
# Returns         : A list, not in any particular order
5699
#
5700
 
5701
our @recurseList;
5702
sub recurseList
5703
{
5704
    @recurseList = ();
5705
    recurseListBody (@_);
5706
    return @recurseList;
5707
}
5708
sub recurseListBody
5709
{
5710
    foreach my $entry ( @_ )
5711
    {
5712
        push @recurseList, $entry;
5713
no warnings "recursion";
5714
        recurseListBody (@{$versions{$entry}{next}});
5715
    }
5716
}
5717
 
5718
#-------------------------------------------------------------------------------
5719
# Function        : getSvnData
5720
#
5721
# Description     : Read the SVN tree and see what we have
5722
#
5723
# Inputs          : 
5724
#
5725
# Returns         : 
5726
#
5727
my @svnDataItems;
5728
sub getSvnData
5729
{
5730
    Message ("Examine Subversion Tree");
5731
 
5732
    #
5733
    #   Re-init data
5734
    #
5735
    @svnDataItems = ();
5736
    %svnData = ();
5737
 
5738
    #
5739
    #   Create an SVN session
5740
    #
5741
    return unless ( $svnRepo );
5742
    my $svn = NewSessionByUrl ( "$svnRepo/$packageNames" );
5743
    return unless ( $svn );
5744
 
5745
    #
5746
    #   extract data
5747
    #
5748
#    DebugDumpData("SVN", $svn );
5749
    $svn->SvnCmd ( 'log', '-v', '--xml', '--stop-on-copy', $svn->Full()
5750
                    , { 'credentials' => 1,
5751
                        'process' => \&ProcessSvnLog,
5752
                         }
5753
                        );
5754
 
5755
    #
5756
    #   Process data
5757
    foreach my $entry ( @svnDataItems )
5758
    {
5759
        my $name;
4003 dpurdie 5760
        my $target = $entry->{'target'};
1271 dpurdie 5761
        if ( $target =~ m~/tags/(.*)~ ) {
5762
            $name = $1;
5763
            $svnData{tags}{$name} = 1;
5764
        } elsif ( $target =~ m~/branches/(.*)~ )  {
5765
            $name = $1;
5766
    #        $branches{$1} = 1;
5767
        } else {
5768
            $svnData{nonTag}{$target} = 1;
5769
        }
5770
 
5771
        my $fromBranch;
4003 dpurdie 5772
        if ( $entry->{'copyfrom-path'} =~ m~/trunk$~  ) {
1271 dpurdie 5773
            $fromBranch = 'trunk';
4003 dpurdie 5774
        } elsif ( $entry->{'copyfrom-path'} =~ m~/branches/(.*)~ ) {
1271 dpurdie 5775
            $fromBranch = $1;
5776
        }
5777
 
2429 dpurdie 5778
        # largest Rev number on branch
4003 dpurdie 5779
        if ( exists $svnData{max} && exists $svnData{max}{$fromBranch} )
1271 dpurdie 5780
        {
4003 dpurdie 5781
            if ( $svnData{max}{$fromBranch}{rev} <  $entry->{'copyfrom-rev'} )
1271 dpurdie 5782
            {
4003 dpurdie 5783
                $svnData{max}{$fromBranch}{rev} =  $entry->{'copyfrom-rev'};
2429 dpurdie 5784
                $svnData{max}{$fromBranch}{name} = $name;
1271 dpurdie 5785
            }
5786
        }
2429 dpurdie 5787
        else
5788
        {
4003 dpurdie 5789
            $svnData{max}{$fromBranch}{rev} =  $entry->{'copyfrom-rev'};
2429 dpurdie 5790
            $svnData{max}{$fromBranch}{name} = $name;
5791
        }
1271 dpurdie 5792
    }
2429 dpurdie 5793
 
5794
    foreach my $branch ( keys %{$svnData{max}} )
5795
    {
5796
        $svnData{tips}{$svnData{max}{$branch}{name}} = $branch;
5797
    }
5798
#    DebugDumpData("svnDataItems", \@svnDataItems);
1271 dpurdie 5799
#    DebugDumpData("SvnData", \%svnData);
5800
 
2429 dpurdie 5801
 
1271 dpurdie 5802
    foreach my $entry ( keys(%versions) )
5803
    {
5804
        my $import_label = saneLabel($entry);
5805
        delete $versions{$entry}{svnVersion};
5806
        delete $versions{$entry}{svnBranchTip};
5807
 
5808
        if ( exists $svnData{tags}{$import_label} )
5809
        {
5810
            $versions{$entry}{svnVersion} = 1;
5811
        }
5812
 
5813
        if ( exists $svnData{tips}{$import_label} )
5814
        {
5815
            $versions{$entry}{svnBranchTip} = $svnData{tips}{$import_label};
5816
        }
5817
    }
5818
 
2429 dpurdie 5819
    Message ( 'Trunk used: ' . (exists $svnData{'max'}{trunk} ? 'Yes' : 'No') );
1271 dpurdie 5820
    Message ( 'Labels    : ' . scalar keys %{$svnData{tags}} );
2429 dpurdie 5821
    Message ( 'Branches  : ' . scalar keys %{$svnData{'max'}} );
1271 dpurdie 5822
}
5823
 
5824
#-------------------------------------------------------------------------------
5825
# Function        : ProcessSvnLog
5826
#
5827
# Description     :
5828
#                   Parse
5829
#                       <logentry
5830
#                          revision="24272">
5831
#                       <author>bivey</author>
5832
#                       <date>2005-07-25T15:45:35.000000Z</date>
5833
#                       <paths>
5834
#                       <path
5835
#                          prop-mods="false"
5836
#                          text-mods="false"
5837
#                          kind="dir"
5838
#                          copyfrom-path="/enqdef/branches/Stockholm"
5839
#                          copyfrom-rev="24271"
5840
#                          action="A">/enqdef/tags/enqdef_24.0.1.sls</path>
5841
#                       </paths>
5842
#                       <msg>COTS/enqdef: Tagged by Jats Svn Import</msg>
5843
#                       </logentry>
5844
#
5845
# Inputs          : 
5846
#
5847
# Returns         : 
5848
#
5849
my $entryData;
4003 dpurdie 5850
my $entryActive;
1271 dpurdie 5851
sub  ProcessSvnLog
5852
{
5853
    my ($self, $line ) = @_;
4003 dpurdie 5854
    $entryActive = '' unless ( defined $entryActive );
5855
    return unless ( $line );
5856
#print "----- ($entryActive) $line\n";
5857
 
1271 dpurdie 5858
    if ( $line =~ m~^<logentry~ ) {
5859
        $entryData = ();
4003 dpurdie 5860
        $entryActive = 'A';
1271 dpurdie 5861
 
4003 dpurdie 5862
    } elsif ( ($line =~ s~\s*(.+?)="(.*)">(.*)</path>$~~) && ($entryActive eq 'A') ) {
5863
        #
5864
        #   Last entry has two items
5865
        #       Attribute
5866
        #       Data Item
5867
        #
5868
        $entryData->{$1} = $2;
5869
        $entryData->{target} = $3;
1271 dpurdie 5870
 
4003 dpurdie 5871
    } elsif ( ($line =~ m~\s*(.*?)="(.*)"~) && ($entryActive eq 'A') ) {
5872
        #
5873
        #   Attribute
5874
        #
5875
        $entryData->{$1} = $2;
1271 dpurdie 5876
 
5877
    } elsif ( $line =~ m~</logentry~ ) {
4003 dpurdie 5878
        $entryActive = '';
5879
        if ( exists $entryData->{'copyfrom-path'} )
1271 dpurdie 5880
        {
5881
#            DebugDumpData("Data", $entryData);
5882
            push @svnDataItems, $entryData;
5883
        }
5884
    }
5885
 
5886
    #
5887
    #   Return 0 to keep on going
5888
    return 0;
5889
}
5890
 
5891
#-------------------------------------------------------------------------------
5892
# Function        : saveData
5893
#
5894
# Description     : Save essential data
5895
#
5896
# Inputs          : 
5897
#
5898
# Returns         : 
5899
#
5900
sub saveData
5901
{
5902
    my $file = $cwd . "/${packageNames}.data";
5903
 
5904
    Message ("Create: $file");
5905
    my $fh = ConfigurationFile::New( $file );
5906
 
5907
    $fh->DumpData(
5908
        "\n# ScmVersions.\n#\n",
5909
        "ScmVersions", \%versions );
5910
 
5911
    #
5912
    #   Close out the file
5913
    #
5914
    $fh->Close();
5915
}
2764 dpurdie 5916
 
1271 dpurdie 5917
#-------------------------------------------------------------------------------
2764 dpurdie 5918
# Function        : restoreData
5919
#
5920
# Description     : Read in essential information
5921
#                   Used during a resume operation
5922
#
5923
# Inputs          : 
5924
#
5925
# Returns         : 
5926
#
5927
our %ScmVersions;
5928
sub restoreData
5929
{
5930
    my $file = $cwd . "/${packageNames}.data";
5931
    Message ("Restoring: $file");
5932
    Error "Cannot locate restoration file: $file" unless ( -f $file );
5933
    require $file;
5934
 
5935
    Error "Resume Data in $file is not valid\n"
5936
        unless ( keys(%ScmVersions) >= 0 );
5937
 
5938
    foreach  ( keys %ScmVersions )
5939
    {
5940
        $restoreData{$_} = $ScmVersions{$_}{data};
5941
        $restoreData{$_}{rmRef} = $ScmVersions{$_}{rmRef};
5942
    }
5943
    %ScmVersions = ();
5944
}
5945
 
5946
#-------------------------------------------------------------------------------
5947
# Function        : testSvnLabel
5948
#
5949
# Description     : Test existence of an SVN label
5950
#
5951
# Inputs          :     Package
5952
#                       Label to test
5953
#
5954
# Returns         : 0   - Tag in place
5955
#                   1   - Not in place
5956
#
5957
sub testSvnLabel
5958
{
5959
    my ($svnPkg, $svnTag) = @_;
5960
 
5961
    my $rv = JatsToolPrint ( 'jats_svnlabel',
5962
                    '-check',
5963
                    "-packagebase=$svnPkg",
5964
                    "$svnTag",
5965
                     );
5966
    Message ("testSvnLabel: $svnTag - $rv");
5967
    return $rv;
5968
}
5969
 
5970
 
5971
#-------------------------------------------------------------------------------
1271 dpurdie 5972
# Function        : GetData_by_filelist
5973
#
5974
# Description     : Read in source data from a file
5975
#
5976
# Inputs          : FileName
5977
#                   Format is 2002-03-05T17:13:50+08 rmussell MASS_DATAMAN_D1.0.0
5978
#
5979
# Returns         : 
5980
#
5981
sub GetData_by_filelist
5982
{
5983
    my ($fname) = @_;
5984
    my $pv_id = 0;
5985
#print "GetData_by_filelist\n";
5986
 
5987
    open (my $fh, '<', $fname ) || Error ("Cannot open Filelist");
5988
    while ( <$fh> )
5989
    {
5990
        next if ( m~^\s*\#~ );
5991
        my @data = split( /\s+/, $_);
5992
#print "@data\n";
5993
        if ( @data == 3 )
5994
        {
4003 dpurdie 5995
#print "--- $data[2]\n";
5996
            my $pkg_name;
5997
            my $pkg_ver;
5998
            if ($data[2] =~ m~^(.*)[_](.*)~ ) {
5999
                $pkg_name = $1;
6000
                $pkg_ver = $2;
6001
                if ( $pkg_ver =~ m~[0-9]+~ ) {
6002
                    $pkg_ver =~ s~^[a-zA-Z]\.*~~;
6003
                }
6004
            } else {
6005
                $pkg_name = $data[2];
6006
                $pkg_ver = '0.0.0';
6007
            }
1271 dpurdie 6008
print "$data[2] : $pkg_name, $pkg_ver\n";
6009
 
2429 dpurdie 6010
#           Expecting Clearcase format:
6011
#               2011-08-30T13:49:21+08
6012
#               2010-11-16T03:24:34Z
1271 dpurdie 6013
#           Need 'YYYY-MM-DDTHH:MM:SS.M'
6014
            my $cdate = $data[0];
6015
            $cdate =~ s~ ~T~;
6016
            $cdate =~ s~\+.*~~;
2429 dpurdie 6017
            $cdate =~ s~Z+.*~~;
1271 dpurdie 6018
            $cdate .= '.00';
6019
 
6020
            $pv_id++;
6021
#            $versions{$pv_id}{fileListEntry} = $_;
6022
            $versions{$pv_id}{name} = $pkg_name;
6023
            $versions{$pv_id}{pvid} = $pv_id;
6024
            $versions{$pv_id}{vname} = $pkg_ver;
2764 dpurdie 6025
            $versions{$pv_id}{vcsTag} = "CC::/${opt_ccbase}::$data[2]";
1271 dpurdie 6026
            $versions{$pv_id}{created} = $cdate;
6027
            $versions{$pv_id}{created_id} = $data[1];
6028
            $versions{$pv_id}{realLabel} = $data[2];
6029
            $versions{$pv_id}{comment} = "Label Import: $data[2]";
6030
            $versions{$pv_id}{locked} = 'Y';
6031
            $versions{$pv_id}{TimeStamp} = str2time( $versions{$pv_id}{created} );
6032
            $versions{$pv_id}{Age} = ($now - $versions{$pv_id}{TimeStamp}) / (60 * 60 * 24);
6033
            $versions{$pv_id}{TooOld} = 1 if ( $opt_age && $opt_age <= $versions{$pv_id}{Age} );
6034
            examineVcsTag($pv_id);
6035
 
6036
            #
6037
            #   Process version number
6038
            #
6039
            my ($suffix, $version, $isaR, $isaWip, $buildVersion ) = massageVersion($pkg_ver, $pkg_name);
6040
 
6041
            $versions{$pv_id}{version} = $version;
6042
            $versions{$pv_id}{buildVersion} = $buildVersion;
6043
            $versions{$pv_id}{isaRipple} = 1 if ( $isaR );
6044
            $versions{$pv_id}{isaWip} = 1 if ( $isaWip );
6045
 
6046
            #
6047
            #   Process suffix
6048
            #
6049
            $suffix = 'Unknown' unless ( $suffix );
6050
            $suffix = lc ($suffix);
6051
            $versions{$pv_id}{suffix} = $suffix;
6052
            push @{$suffixes{$suffix}}, $pv_id;
6053
 
6054
#DebugDumpData("PKG ", $versions{$pv_id} );
6055
 
6056
        }
6057
    }
6058
    close $fh;
6059
}
6060
 
6061
#-------------------------------------------------------------------------------
6062
#   Documentation
6063
#
6064
 
6065
=pod
6066
 
6067
=for htmltoc    SYSUTIL::cc2svn::
6068
 
6069
=head1 NAME
6070
 
6071
cc2svn_gendata - CC2SVN tool to import an entire package into SVN
6072
 
6073
=head1 SYNOPSIS
6074
 
6075
  jats cc2svn_importpackage [options] package_name
6076
 
6077
 Options:
6078
    -help              - brief help message
6079
    -help -help        - Detailed help message
6080
    -man               - Full documentation
6081
    -repository=name   - Specify target repository
6082
    -[no]flat          - Do not create project tree. Def: -noflat
6083
    -prunemode=mode    - Mode: none, ripple, retain, severe, Def=ripple
6084
    -retain=N          - Specify retain count for pruning. Def=2
6085
    -[no]test          - Do not create packages. Def:-notest
6086
    -[no]reuse         - Keep and reuse ClearCase views
6087
    -age=nnDays        - Only keep recent package
6088
    -dump[=n]          - Dump raw data. N=0,1,2
6089
    -images[=n]        - Create SVG of version tree. N=0,1,2
6090
    -name=aaa          - Alternate output package name. Test Only
6091
    -[no]log           - Write output to log file. Def: -nolog
6092
    -[no]postimage     - Create image after transger: Def: -post
6093
    -workdir=path      - Use for temp storage (def:/work)
1272 dpurdie 6094
    -delete            - Delete SVN package before test
2429 dpurdie 6095
    -[no]relabel       - Attempt to relabel dirs in packages that don't extract
6096
    -filelist=path     - Use named list of files
4003 dpurdie 6097
    -ccbase=VOB        - Clearcase Vob to use for filelist
2764 dpurdie 6098
    -testRmDatabase    - Use test database
6099
    -[no]fromSvn       - Also extract packages from SVN
4003 dpurdie 6100
    -[no]testRepo      - Force use of a test repository.
6101
    -resume            - Resume aborted import (dangerous)
1271 dpurdie 6102
 
6103
=head1 OPTIONS
6104
 
6105
=over 8
6106
 
6107
=item B<-help>
6108
 
6109
Print a brief help message and exits.
6110
 
6111
=item B<-help -help>
6112
 
6113
Print a detailed help message with an explanation for each option.
6114
 
6115
=item B<-man>
6116
 
6117
Prints the manual page and exits.
6118
 
6119
=item B<-prunemode=mode>
6120
 
6121
This option control the manner in which excess versions will be pruned. Valid
6122
modes are:
6123
 
6124
=over 8
6125
 
6126
=item   none
6127
 
6128
No pruning will be performed
6129
 
6130
=item   ripple
6131
 
6132
Non-Essential packages that are ripple builds will be removed.
6133
 
6134
=item   retain
6135
 
6136
Versions that preceed an Essential version will be retained.
6137
 
6138
=item   severe
6139
 
6140
Only Essential Versions, and Branching points will be retained.
6141
 
6142
=back
6143
 
6144
=back
6145
 
6146
=head1 DESCRIPTION
6147
 
6148
This program is a tool used in the conversion of ClearCase VOBS to subversion.
6149
It will take a complete package and all relevent versions from ClearCase and
6150
insert them into subversion in a sessible manner. It will attempt to retain
6151
file change order and history.
6152
 
6153
It will:
6154
 
6155
=over 8
6156
 
6157
=item *
6158
 
6159
Read in the Essential Package Version list.
6160
 
6161
=item *
6162
 
6163
Extract, from Release Manager, all known versions of the specified package.
6164
 
6165
=item *
6166
 
6167
It will attempt to determine the type of package: COTS, TOOL, CORE, PROJECT
6168
and alter the processing accordingly.
6169
 
6170
=item *
6171
 
6172
It will create a version dependency tree and determine 'new' project branch
6173
points. It will remove (prune) versions that are excess to requirements.
6174
 
6175
=item *
6176
 
6177
It will extract source from ClearCase and insert it into SVN, creating
6178
branches and tags as it goes.
6179
 
6180
=back
6181
 
6182
The program can also be used to create a SVG image of the version dependency
6183
tree. This does not work on Linux; only Windows with 'dot' installed.
6184
 
6185
=cut
6186