Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 dpurdie 1
#! perl
2
########################################################################
3
# Copyright (C) 2006 ERG Limited, All rights reserved
4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description   : Covert an entire directory of package snadboxes from
11
#                 one project to another project
12
#
13
#                 * Locate all the sandboxes
14
#                 * In each view do:
15
#                       * Locate build files
16
#                       * Determine label and calcularte new label
17
#                       * Rewrite the build file
18
#                       * Check the new build file in
19
#
20
# Usage:
21
#
22
# Version   Who      Date        Description
23
#
24
#......................................................................#
25
 
26
require 5.006_001;
27
use strict;
28
use warnings;
29
use Cwd;
30
 
31
use JatsError;
32
use JatsSystem;
33
use Pod::Usage;
34
use Getopt::Long;
35
use File::Find;
36
 
37
 
38
my $VERSION = "1.0.0";                      # Update this
39
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
40
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
41
my $opt_help = 0;
42
my $opt_manual = 0;
43
my $opt_newproject;
44
my $opt_oldproject;
45
 
46
 
47
#-------------------------------------------------------------------------------
48
# Function        : Mainline Entry Point
49
#
50
# Description     :
51
#
52
# Inputs          :
53
#
54
my $result = GetOptions (
55
                "help+"         => \$opt_help,              # flag, multiple use allowed
56
                "manual"        => \$opt_manual,            # flag, multiple use allowed
57
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
58
                "newproject=s"  => \$opt_newproject,
59
                "oldproject=s"  => \$opt_oldproject,
60
                );
61
 
62
                #
63
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
64
                #
65
 
66
#
67
#   Process help and manual options
68
#
69
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
70
pod2usage(-verbose => 1)  if ($opt_help == 2 );
71
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
72
 
73
#
74
#   Configure the error reporting process now that we have the user options
75
#
76
ErrorConfig( 'name'    =>'ConvertRelease',
77
             'verbose' => $opt_verbose,
78
             'debug'   => $opt_debug );
79
 
80
Error ("Must specify both old and new project suffixes")
81
    unless ( $opt_newproject && $opt_oldproject );
82
 
83
#
84
#   Process all top level directories
85
#
86
my $Cwd = getcwd();                          # Current working dir
87
foreach my $dir ( glob ('*') )
88
{
89
    Verbose2("Scanning: $dir" );
90
    next if ( $dir =~ m/^\./ );
91
    next unless ( -d $dir  );
92
    process_dir ( $dir );
93
    chdir $Cwd || Error ("Cannot CD to original directory");
94
    Message ("End of processing for: $dir" );
95
}
96
 
97
exit 0;
98
 
99
#-------------------------------------------------------------------------------
100
# Function        : process_dir
101
#
102
# Description     : Process one directory
103
#
104
# Inputs          : $dir                - The name of the directory
105
#
106
# Returns         :
107
#
108
sub process_dir
109
{
110
    my ($dir) = @_;
111
    Message ("Processing: $dir");
112
 
113
    chdir $dir || Error ("Cannot CD to $dir");
114
 
115
    #
116
    #   Locate the ONE buildfile within the current directory tree
117
    #
118
    my @build_list = locate_build_files( getcwd() );
119
    if ( $#build_list > 0 )
120
    {
121
        foreach my $fe ( @build_list )
122
        {
123
            Message( "Build file: $fe->[0] Name: $fe->[1]");
124
        }
125
        Error ("Multiple Build Files located" );
126
    }
127
 
128
    #
129
    #   CD to the build directory
130
    #
131
    my $build_dir = $build_list[0]->[0];
132
    my $build_file = $build_list[0]->[1];
133
    Message ("Found Build files: $build_dir");
134
    chdir ( $build_dir ) || Error("Cannot CD to: $build_dir" );
135
 
136
    #
137
    #   Determine the label on which the view is based
138
    #   This will allow us to calculate a 'new' label
139
    #
140
    my @elements;
141
    my $cmd = "cleartool catcs";
142
    open(CMD, "$cmd 2>&1 |") || Error( "can't run command: $!");
143
    while (<CMD>)
144
    {
145
        #
146
        #   Filter output from the user
147
        #
148
        chomp;
149
        Verbose2("catcs: $_");
150
        next unless ( m/element/ );
151
        next if ( m/-none/ );
152
        next if ( m/CHECKEDOUT/ );
153
        my @bits = split ( ' ', $_ );
154
        Verbose("LABEL: $bits[2]");
155
        push @elements, $bits[2];
156
    }
157
    close(CMD);
158
 
159
    Error ("No labels found")if ( $#elements < 0 );
160
    Error ("Multiple labels found")if ( $#elements > 0 );
161
 
162
    #
163
    #   Calculate NEW label
164
    #
165
    my $new_label = $elements[0];
166
    $new_label =~ s~\.$opt_oldproject$~.$opt_newproject~;
167
    Message("New label: $new_label");
168
 
169
    #
170
    #   Rewrite the build file
171
    #
172
    JatsTool ("jats_rewrite.pl ",
173
                    "-old=$opt_oldproject",
174
                    "-new=$opt_newproject",
175
                    "-infile=$build_file",
176
                    "-outfile=xxxxxx.pl" );
177
 
178
}
179
 
180
#-------------------------------------------------------------------------------
181
# Function        : locate_build_files
182
#
183
# Description     : Locate all potential buildfiles in the view
184
#
185
# Inputs          : base_dir     - Start directory
186
#
187
# Returns         : An array of build files
188
#                   Each entry in the array conatins
189
#                       Directory
190
#                       Filename
191
#
192
my @located_files;
193
my $locate_files_base;
194
sub locate_build_files
195
{
196
    my ( $base_dir) = @_;
197
 
198
    #
199
    #   Locate build files ( JATS and ANT )
200
    #
201
    sub locate_build_files_wanted
202
    {
203
 
204
        my $dir = "$File::Find::dir";
205
        my $file = $_;
206
        my $arg = "$dir/$file";
207
 
208
        return if ( -d $arg );
209
#        print "$arg\n";
210
 
211
        #
212
        #   Detect a JATS build file
213
        #
214
        if ( $file eq "build.pl"  )
215
        {
216
            push @located_files, [ $dir, $file ];
217
            return;
218
        }
219
 
220
        #
221
        #   Detect ANT {packagename}depends.xml file
222
        #
223
        if ( $file =~ m/(.+)depends.xml$/ )
224
        {
225
            if ( -f $1 . ".xml" )
226
            {
227
                push @located_files, [ $dir, $file ];
228
                return;
229
            }
230
        }
231
    }
232
 
233
    @located_files = ();
234
    $locate_files_base = $base_dir;
235
    File::Find::find ( \&locate_build_files_wanted, $base_dir );
236
    return @located_files;
237
}
238
 
239