Subversion Repositories DevTools

Rev

Rev 5709 | Rev 6177 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5709 Rev 6133
Line 81... Line 81...
81
#                   options         - Options to be processed
81
#                   options         - Options to be processed
82
#
82
#
83
#                   Options are:
83
#                   Options are:
84
#                   --ScanDependencies  - Collect information on dependent packages
84
#                   --ScanDependencies  - Collect information on dependent packages
85
#                   --LocateAll         - Scan for ANT and JATS build files
85
#                   --LocateAll         - Scan for ANT and JATS build files
-
 
86
#                   --LimitDepth=n      - Limit the depth of the scan
86
#
87
#
87
#
88
#
88
# Returns         : A reference to class.
89
# Returns         : A reference to class.
89
#
90
#
90
sub BuildFileScanner {
91
sub BuildFileScanner {
Line 93... Line 94...
93
    $self->{root} = shift;
94
    $self->{root} = shift;
94
    $self->{file}  = shift;
95
    $self->{file}  = shift;
95
    $self->{info} = [];
96
    $self->{info} = [];
96
    $self->{scandeps} = 0;
97
    $self->{scandeps} = 0;
97
    $self->{locateAll} = 0;             # Scan Jats and Ant files
98
    $self->{locateAll} = 0;             # Scan Jats and Ant files
-
 
99
    $self->{LimitDepth} = 0;            # Skim the tree
98
 
100
 
99
    bless ($self);
101
    bless ($self);
100
 
102
 
101
    Error ("Locating Build files. Root directory not found",
103
    Error ("Locating Build files. Root directory not found",
102
           "Path: $self->{root}" ) unless ( -d $self->{root} );
104
           "Path: $self->{root}" ) unless ( -d $self->{root} );
Line 137... Line 139...
137
        $self->{scandeps} = 2;
139
        $self->{scandeps} = 2;
138
 
140
 
139
    } elsif ( $opt =~ m/^--LocateAll/ ) {
141
    } elsif ( $opt =~ m/^--LocateAll/ ) {
140
        $self->{locateAll} = 1;
142
        $self->{locateAll} = 1;
141
 
143
 
-
 
144
    } elsif ( $opt =~ m/^--LimitDepth=(\d+)/ ) {
-
 
145
        $self->{LimitDepth} = $1;
-
 
146
 
142
    } else {
147
    } else {
143
        $result = 0;
148
        $result = 0;
144
 
149
 
145
    }
150
    }
146
    return $result;
151
    return $result;
147
}
152
}
148
 
153
 
149
#-------------------------------------------------------------------------------
154
#-------------------------------------------------------------------------------
-
 
155
# Function        : getLocation 
-
 
156
#
-
 
157
# Description     : Serialize location data such that it can be used by the
-
 
158
#                   setLocation function.    
-
 
159
#
-
 
160
# Inputs          :  $self
-
 
161
#
-
 
162
# Returns         :  Text string of serailised data
-
 
163
#
-
 
164
sub getLocation
-
 
165
{
-
 
166
    my ($self) = shift;
-
 
167
    my @locationData;
-
 
168
    push @locationData,  $self->{root};
-
 
169
    push @locationData,  scalar  @{$self->{info}};
-
 
170
    foreach my $be ( @{$self->{info}} )
-
 
171
    {
-
 
172
        push @locationData,  $be->{dir}, $be->{file}, $be->{type};
-
 
173
    }
-
 
174
    return (join($;, @locationData));
-
 
175
}
-
 
176
 
-
 
177
 
-
 
178
#-------------------------------------------------------------------------------
-
 
179
# Function        : setLocation 
-
 
180
#
-
 
181
# Description     : Insert location data
-
 
182
#                   Bypass the need to perform a 'locate' operation
-
 
183
#                   Used to cache location data in large systems 
-
 
184
#                   
-
 
185
#                   Will detect missing build files and allow the user to
-
 
186
#                   handle the error.
-
 
187
#
-
 
188
# Inputs          : $self
-
 
189
#                   ...     Location data as returned by getLocation
-
 
190
#
-
 
191
# Returns         : 1   - All Build files exist
-
 
192
#                   0   - At least one of the build files does not exist
-
 
193
#
-
 
194
sub setLocation
-
 
195
{
-
 
196
    my ($self, $data) = @_;
-
 
197
    my @locationData =  split($;, $data);
-
 
198
    my $rv = 1;
-
 
199
 
-
 
200
    my $root = shift @locationData;
-
 
201
    my $count = shift @locationData;
-
 
202
 
-
 
203
    while ($count-- > 0)
-
 
204
    {
-
 
205
        my $buildfile = join('/',$locationData[0], $locationData[1]);
-
 
206
        $rv = 0 unless -f $buildfile;    
-
 
207
 
-
 
208
        push @{$self->{info}}, BuildEntry( @locationData);
-
 
209
        splice @locationData, 0, 3;
-
 
210
    }
-
 
211
 
-
 
212
    $self->{locate_done} = 1;
-
 
213
    return $rv;
-
 
214
}
-
 
215
 
-
 
216
#-------------------------------------------------------------------------------
150
# Function        : locate
217
# Function        : locate
151
#
218
#
152
# Description     : Locate all build files within a given directory tree
219
# Description     : Locate all build files within a given directory tree
153
#                   Collects the data and builds up a data structure
220
#                   Collects the data and builds up a data structure
154
#
221
#
Line 165... Line 232...
165
 
232
 
166
    #
233
    #
167
    #   Locate all the build files that match the users request
234
    #   Locate all the build files that match the users request
168
    #   Use 'our' to avoid closure issues
235
    #   Use 'our' to avoid closure issues
169
 
236
 
170
    our  $ff_datap = \@{$self->{info}};
237
    my $ff_datap = \@{$self->{info}};
171
    our  $ff_file = $self->{file};
238
    my $ff_file = $self->{file};
172
    our  $ff_all = $self->{locateAll};
239
    my $ff_all = $self->{locateAll};
173
    our  $ff_self = $self;
240
    my $ff_self = $self;
174
    our  $ff_ant = ( $ff_file =~ m~(.+)\.xml$~i ) ? $1 : '';
241
    my $ff_ant = ( $ff_file =~ m~(.+)\.xml$~i ) ? $1 : '';
175
 
242
 
-
 
243
    #
-
 
244
    #   Anonymous sub for the file::find wanted function
-
 
245
    #       Use closure to allow access to local variables
-
 
246
    #       Use no_chdir to allow very deep (windows) structures
-
 
247
    #
176
    sub find_file_wanted
248
    my $wanted = sub 
177
    {
249
    {
-
 
250
        # Using no_chdir - extract just the filename
-
 
251
        my $file = $_;
-
 
252
        $file =~ s~.*/~~;
178
        Verbose3( "find_file_wanted: $_");
253
        Verbose3( "locateBuildFile: $file");
-
 
254
 
-
 
255
        if ( -d $_)
-
 
256
        {
-
 
257
            #
-
 
258
            #   Skip known dirs
-
 
259
            #   
-
 
260
            if ($file eq '.git' || $file eq '.svn')
-
 
261
            {
-
 
262
                $File::Find::prune = 1;
-
 
263
                Verbose3( "locateBuildFile: PRUNE: $file");
-
 
264
                return;
-
 
265
            }
-
 
266
 
-
 
267
            #
-
 
268
            #   Limit the depth of the scan
-
 
269
            #       Suggestion 3 below the package base
-
 
270
            #
-
 
271
            if ($self->{LimitDepth})
-
 
272
            {
-
 
273
                my $depth = $File::Find::name =~ tr~/~/~;
-
 
274
                if ($depth >= $self->{LimitDepth})
-
 
275
                {
-
 
276
                    $File::Find::prune = 1;
-
 
277
                    Verbose3( "locateBuildFile: LimitDepth: $_");
-
 
278
                    return;
-
 
279
                }
-
 
280
            }
-
 
281
        }
-
 
282
 
179
        if ( $_ eq $ff_file  )
283
        if ( $file eq $ff_file  )
180
        {
284
        {
181
            if ( $ff_ant )
285
            if ( $ff_ant )
182
            {
286
            {
183
                if ( -f (${ff_ant} . 'depends.xml') )
287
                if ( -f ( $File::Find::dir . '/' . ${ff_ant} . 'depends.xml') )
184
                {
288
                {
185
                    Verbose ("find_file_wanted: FOUND $File::Find::dir, $_");
289
                    Verbose ("locateBuildFile: FOUND $File::Find::dir, $file");
186
                    push @{$ff_datap}, BuildEntry( $File::Find::dir, $_, 2);
290
                    push @{$ff_datap}, BuildEntry( $File::Find::dir, $file, 2);
187
                }
291
                }
188
            }
292
            }
189
            else
293
            else
190
            {
294
            {
191
                $_ = 'auto.pl' if ( $ff_self->{scandeps} && -f 'auto.pl' );
295
                $file = 'auto.pl' if ( $ff_self->{scandeps} && -f 'auto.pl' );
192
                Verbose ("find_file_wanted: FOUND $File::Find::dir, $_");
296
                Verbose ("locateBuildFile: FOUND $File::Find::dir, $file");
193
                push @{$ff_datap}, BuildEntry( $File::Find::dir, $_, 1);
297
                push @{$ff_datap}, BuildEntry( $File::Find::dir, $file, 1);
194
            }
298
            }
195
            return;    
299
            return;    
196
        }
300
        }
197
 
301
 
198
        #
302
        #
199
        #   Detect ANT {packagename}depends.xml file
303
        #   Detect ANT {packagename}depends.xml file
200
        #   These are file pairs (mostly)
304
        #       These are file pairs (mostly)
201
        #
305
        #
202
        if ( $ff_all && $_ =~ m/(.+)depends.xml$/ )
306
        if ( $ff_all && $file =~ m/(.+)depends.xml$/ )
203
        {
307
        {
204
            if ( -f $1 . '.xml' )
308
            if ( -f ($File::Find::dir . '/' . $1 . '.xml') )
205
            {
309
            {
206
                Verbose ("find_file_wanted: FOUND $File::Find::dir, $_");
310
                Verbose ("locateBuildFile: FOUND $File::Find::dir, $file");
207
                push @{$ff_datap}, BuildEntry( $File::Find::dir, $_, 2);
311
                push @{$ff_datap}, BuildEntry( $File::Find::dir, $file, 2);
208
            }
312
            }
209
        }
313
        }
210
    }
314
    };
211
 
315
 
212
    #
316
    #
213
    #   Find all matching files
317
    #   Find all matching files
214
    #   Call helper rouine to populate the data strcutures
318
    #   Call helper rouine to populate the data strcutures
215
    #
319
    #
216
    File::Find::find ( \&find_file_wanted, $self->{root} );
320
    File::Find::find ( { wanted => $wanted, no_chdir => 1 }, $self->{root} );
217
 
321
 
218
    #
322
    #
219
    #   Flag that the directories have been scanned
323
    #   Flag that the directories have been scanned
220
    #
324
    #
221
    $self->{locate_done} = 1;
325
    $self->{locate_done} = 1;