From 0735b01b58278441aef6ea4284f583f391366bad Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Fri, 9 Nov 2001 11:15:14 +0000 Subject: [PATCH] Add in a completiong script for nt build files. Submitted by: Mike Williams git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269889 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 7 ++- src/script/complete-ant-cmd.pl | 99 ++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 src/script/complete-ant-cmd.pl diff --git a/build.xml b/build.xml index 002bb26d6..6ab6b7377 100644 --- a/build.xml +++ b/build.xml @@ -368,7 +368,7 @@ - + @@ -376,7 +376,7 @@ - + @@ -506,6 +506,7 @@ + @@ -550,11 +551,13 @@ + + + +my $cmdLine = $ENV{'COMP_LINE'}; +my $antCmd = $ARGV[0]; +my $word = $ARGV[1]; + +my @completions; +if ($word =~ /^-/) { + list( restrict( $word, getArguments() )); +} elsif ($cmdLine =~ /-(f|buildfile)\s+\S*$/) { + list( getBuildFiles($word) ); +} else { + list( restrict( $word, getTargets() )); +} + +exit(0); + +sub list { + for (@_) { + print "$_\n"; + } +} + +sub restrict { + my ($word, @completions) = @_; + grep( /^\Q$word\E/, @completions ); +} + +sub getArguments { + qw(-buildfile -debug -emacs -f -find -help -listener -logfile + -logger -projecthelp -quiet -verbose -version); +} + + +sub getBuildFiles { + my ($word) = @_; + grep( /\.xml$/, glob( "$word*" )); +} + +sub getTargets { + + # Look for build-file + my $buildFile = 'build.xml'; + if ($cmdLine =~ /-(f|buildfile)\s+(\S+)/) { + $buildFile = $2; + } + return () unless (-f $buildFile); + + # Run "ant -projecthelp" to list targets. Keep a cache of results in a + # cache-file. + my $cacheFile = $buildFile; + $cacheFile =~ s|(.*/)?(.*)|${1}.ant-targets-${2}|; + if ((!-e $cacheFile) || (-M $buildFile) < (-M $cacheFile)) { + open( CACHE, '>'.$cacheFile ) || die "can\'t write $cacheFile: $!\n"; + open( HELP, "$antCmd -projecthelp -f '$buildFile'|" ) || return(); + my %targets; + while( ) { + if (/^\s+(\S+)/) { + $targets{$1}++; + } + } + my @targets = sort keys %targets; + for (@targets) { print CACHE "$_\n"; } + return @targets; + } + + # Read the target-cache + open( CACHE, $cacheFile ) || die "can\'t read $cacheFile: $!\n"; + my @targets; + while () { + chop; + s/\r$//; # for Cygwin + push( @targets, $_ ); + } + close( CACHE ); + @targets; + +} + + +