#!/usr/bin/perl -w ##------------------------------------------------------------------------## ## File: ## $Id: find-jpkgs,v 1.4 2002/07/31 04:20:14 ehood Exp $ ## Author: ## Earl Hood earl@earlhood.com ## Description: ## Find java package names from source tree. ##------------------------------------------------------------------------## ## Copyright (C) 2001-2002 Earl Hood, earl@earlhood.com ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA ##------------------------------------------------------------------------## package Devtools::find_jpkgs; use FindBin; use lib "$FindBin::Bin/../lib"; # Add relative lib to search path use File::Basename; use File::Find; use Getopt::Long; use CommandUtil; my @dirs = ( ); my %pkgs = ( ); MAIN: { ## Command-line parsing my %opt = (); my $status = GetOptions(\%opt, 'help|?', # Brief help message 'man' ); if (!$status || (!$opt{'help'} && !@ARGV)) { die qq/Use -help for usage information\n/; } usage(1,0) if ($opt{'help'}); usage(2,0) if ($opt{'man'}); @dirs = sort { length($b) <=> length($a) } @ARGV; find( { wanted => \&wanted, no_chdir => 1 }, @dirs ); print join("\n", (sort keys %pkgs)), "\n"; } # END: MAIN ############################################################################ ## Routines ############################################################################ sub wanted { if (/\.java$/) { my $dirname = dirname($_); my $dir; foreach $dir (@dirs) { last if ($dirname =~ s/^\Q$dir\E[\\\/]?//); } $dirname =~ s/[\\\/]/./g; $pkgs{$dirname} = $_; } } ############################################################################ __END__ =head1 NAME find-jpkgs - Find java package names from source tree. =head1 SYNOPSIS find-jpkgs directory ... =head1 DESCRIPTION This program searches from the top of the specified source directories, and any directory that contains a C<.java> file, is identified as a Java package. The package name is determined by translating 'C's to 'C<.>'s. This list of java package names are sent to stdout with each package name printed on a separate line. =head1 OPTIONS =over =item C<-help> Display help message. =item C<-man> Display manpage. =back =head1 EXAMPLE This program is best used within project makefiles to set a make variable representing all the applicable java packages to generate javadoc for. For example: JDOC_PKGS = $(shell $(DEVTOOLS)/bin/find-jpkgs $(SRC_TOP)) This prevents the need to manually maintain the package list when new packages are added to a project. =head1 VERSION C<$Id: find-jpkgs,v 1.4 2002/07/31 04:20:14 ehood Exp $> =head1 AUTHOR Earl Hood, earl@earlhood.com This program comes with ABSOLUTELY NO WARRANTY and may be copied only under the terms of the GNU General Public License. =cut