Subversion Repositories DevTools

Rev

Rev 3890 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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