Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: fix import parsing in Completion/Unix/Command/_ant



Hi,

In our ant build we do some import of some build.xml file which are relative to the ANT_HOME:
<import file="${ant.home}/../common-build.xml"/>

So first the completion blows off as sed is not able to find the imported file. See when I write "ant <tab>" : $ ant find_targets:1: no such file or directory: ${ant.home}/../common- build.xml
sed: ${ant.home}/../common-build.xml: No such file or directory
find_targets:1: no such file or directory: ${ant.home}/../common- build.xml
sed: ${ant.home}/../common-build.xml: No such file or directory

So I have fixed it with a little test. And then I made the completion understand the ant.home property reference.

I think at least the check of the existence of the file should be done so the completion doesn't break. For the ant.home, I know I have a particular use case, but I don't think it will harm the completion script to have that feature.

Here is the patch:

Index: Completion/Unix/Command/_ant
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ant,v
retrieving revision 1.18
diff -u -8 -p -r1.18 _ant
--- Completion/Unix/Command/_ant	24 Jan 2009 15:07:21 -0000	1.18
+++ Completion/Unix/Command/_ant	27 Jun 2009 17:03:13 -0000
@@ -7,20 +7,26 @@ typeset -A opt_args
local buildfile classpath cp userjars importedfiles target='*:target:->target' targets tmp

 find_targets() {
importedfiles=( $(sed -n "s/ *<import[^>]* file=[\"']\([^\"']*\) [\"'].*/\1/p" < $1) )
     # Tweaked to omit targets beginning with "-" that can't
     # be invoked from the command line; see zsh-workers/24129.
     sed -n "s/ *<target[^>]* name=[\"']\([^-][^\"']*\)[\"'].*/\1/p" $1
     if (( $#importedfiles )) ; then
-	( cd $1:h
-    	for file in $importedfiles ; do
-	    find_targets $file
-	done )
+        ( cd $1:h
+            for file in $importedfiles ; do
+ expanded=( $(echo $file | sed -n "s|\${ant.home}| $ANT_HOME|p") )
+                if [[ ! "bla$expanded" = "bla" ]]; then
+                    file=$expanded
+                fi
+                if [[ -f $file ]]; then
+                    find_targets $file
+                fi
+        done )
     fi
 }

 if [[ $service = *ANT_ARGS* ]]; then
   compset -q
   words=( fake "$words[@]" )
   (( CURRENT++ ))
   unset target



cheers,
Nicolas



Messages sorted by: Reverse Date, Date, Thread, Author