Subversion Repositories DevTools

Rev

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