use strict; ############################################################ # # depend.pl # # Under the current directory, check all Java files # and see who is used by whom. # # Caveat Emptor: this code calls DOS system commands # (I was being lazy in a bad way). # ############################################################ # # I assume the workspace begins here. # my %uses = (); my %user = (); my %allkeys = (); # # Here's one DOS system command. Sorry 'bout that. # system( 'dir /b /s > files.tmp' ); open( IN, 'files.tmp' ); my @files = grep( /\.java$/, ); close IN; chomp( @files ); # # Here's the other DOS system command. No biggie to # just change it to 'unlink', I suppose. # system( 'del files.tmp' ); print "Processing files.\n"; my $file; foreach $file (@files) { # # Glob the file # open( IN, $file ) || die "ERROR: cannot open $file\n"; my @dat = ; close IN; # # Pull out the file name # my $filename = $file; $filename =~ s/^.*\\(\w+\.java).*$/$1/; # # Pull out the package name # my ($pkg) = grep( /^package/, @dat ); $pkg =~ s/^package (\S*);.*$/$1\.$filename/; chomp( $pkg ); # # Add the import dependency to our list. # foreach (grep( /^import/, @dat )) { /import (\S*);/; $uses{ $pkg }->{ $1 } ++; $user{ $1 }->{ $pkg } ++; $allkeys{ $pkg } ++; $allkeys{ $1 } ++; } } print "Writing uses.log file.\n"; open( OUT, ">uses.log" ); foreach ( sort keys %allkeys ) { if ( $uses{ $_ } ) { print OUT "$_ uses:\n " , join( "\n ", keys %{$uses{$_}} ) , "\n\n"; } if ( $user{ $_ } ) { print OUT "$_ is used by:\n " , join( "\n ", keys %{$user{$_}} ) , "\n\n"; } } close OUT;