ant: Rewrite build target parsing in plain bash, add build file test case.

There's no alternation (\|) in POSIX basic regexps which is what POSIX
sed supports.
This commit is contained in:
Ville Skyttä 2011-05-08 14:46:12 +03:00
parent 727fa3adfd
commit 2d23a3f47c
3 changed files with 30 additions and 6 deletions

View File

@ -50,11 +50,13 @@ _ant()
[ ! -f $buildfile ] && return 0
# parse buildfile for targets
# some versions of sed complain if there's no trailing linefeed,
# hence the 2>/dev/null
COMPREPLY=( $( compgen -W "$( tr "'\t\n>" "\" \n" < $buildfile | \
sed -ne 's/.*<\(target\|extension-point\) .*name="\([^"]*\).*/\2/p' 2>/dev/null )" \
-- "$cur" ) )
local line targets
while read -rd '>' line; do
[[ $line =~ \
\<(targe|extension-poin)t[[:space:]].*name=[\"\']([^\"\']+) ]] \
&& targets+=" ${BASH_REMATCH[2]}"
done < $buildfile
COMPREPLY=( $( compgen -W '$targets' -- "$cur" ) )
fi
} &&
have ant && { have complete-ant-cmd.pl && \

17
test/fixtures/ant/build.xml vendored Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build" name="bash-completion">
<target name="clean">
<!-- ... -->
</target>
<target
name="realclean" depends="clean">
<!-- ... -->
</target>
<target foo="bar" name="init"></target>
<target
foo="bar"
name='bashcomp' >
<!-- ... -->
</target>
</project>

View File

@ -4,7 +4,10 @@ proc setup {} {
proc teardown {} {
assert_env_unmodified
assert_env_unmodified {
/OLDPWD=/d
/BASH_REMATCH=/d
}
}
@ -12,8 +15,10 @@ setup
assert_complete_any "ant -"
sync_after_int
assert_complete_dir "bashcomp clean init realclean" "ant " $::srcdir/fixtures/ant
sync_after_int