aboutsummaryrefslogtreecommitdiff
path: root/build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl
diff options
context:
space:
mode:
authorgregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2003-07-07 15:46:46 +0000
committergregor <gregor@d688527b-c9ab-4aba-bd8d-4036d912da1d>2003-07-07 15:46:46 +0000
commit7a433b7053eea6bd2270bdb42bc22bfb5ab8e815 (patch)
treedb0a42a3cd4deaf7968c24ae3a877e7bef1f1ecf /build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl
parentd5bfcf5666a3c0502abc028800e3d0f43ae6d985 (diff)
downloadmoa-id-spss-7a433b7053eea6bd2270bdb42bc22bfb5ab8e815.tar.gz
moa-id-spss-7a433b7053eea6bd2270bdb42bc22bfb5ab8e815.tar.bz2
moa-id-spss-7a433b7053eea6bd2270bdb42bc22bfb5ab8e815.zip
Initial commit
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@4 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl')
-rw-r--r--build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl102
1 files changed, 102 insertions, 0 deletions
diff --git a/build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl b/build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl
new file mode 100644
index 000000000..58d7b2367
--- /dev/null
+++ b/build/tools/jakarta-ant-1.5.1/bin/complete-ant-cmd.pl
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+#
+# Copyright (c) 2001 The Apache Software Foundation. All rights
+# reserved.
+#
+# A script to allow Bash or Z-Shell to complete an Ant command-line.
+#
+# To install for Bash 2.0 or better, add the following to ~/.bashrc:
+#
+# $ complete -C complete-ant-cmd ant build.sh
+#
+# To install for Z-Shell 2.5 or better, add the following to ~/.zshrc:
+#
+# function ant_complete () {
+# local args_line args
+# read -l args_line
+# set -A args $args_line
+# set -A reply $(COMP_LINE=$args_line complete-ant-cmd ${args[1]} $1)
+# }
+# compctl -K ant_complete ant build.sh
+#
+# @author Mike Williams <mikew@cortexebusiness.com.au>
+
+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( <HELP> ) {
+ 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 (<CACHE>) {
+ chop;
+ s/\r$//; # for Cygwin
+ push( @targets, $_ );
+ }
+ close( CACHE );
+ @targets;
+
+}
+
+
+