From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3297 invoked from network); 24 Aug 2002 19:12:27 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 24 Aug 2002 19:12:27 -0000 Received: (qmail 15090 invoked by alias); 24 Aug 2002 19:12:20 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17577 Received: (qmail 15073 invoked from network); 24 Aug 2002 19:12:19 -0000 X-VirusChecked: Checked cc: zsh-workers@sunsite.dk In-reply-to: <20020820194141.9912.qmail@web10410.mail.yahoo.com> From: Oliver Kiddle References: <20020820194141.9912.qmail@web10410.mail.yahoo.com> To: Felix Rosencrantz Subject: Re: [SUBMIT] _ant completion function MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16721.1030216294.1@logica.com> Date: Sat, 24 Aug 2002 20:11:48 +0100 Sender: kiddleo@logica.com Message-Id: On 20 Aug, Felix wrote: > > > For cacheing the contents of jar files, it might be wise to use the same > > cache used by _zip and allow jar completion to also use it. > > I'm not quite sure I understand exactly how that would work. The _zip > cache assumes that there is a single zip file that is being cached. Well, _zip would have to change. As you say, we'd need a per-file cache and use the full filename. > Also, feel free to fix _java_class, I don't have much time. This patch fixes it and gets it to take a -classpath option. I've also got zip to complete all of .jar, .ear and .war files. I've not done any of the caching though. Oliver Index: Completion/Unix/Command/_ant =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ant,v retrieving revision 1.2 diff -u -r1.2 _ant --- Completion/Unix/Command/_ant 19 Aug 2002 14:54:13 -0000 1.2 +++ Completion/Unix/Command/_ant 24 Aug 2002 19:07:27 -0000 @@ -2,8 +2,9 @@ typeset -A opt_args local buildfile tmp state line curcontext="$curcontext" -local target='*:target:->target' -#local CLASSPATH="$ANT_HOME/lib/*.jar" +local c target='*:target:->target' + +c=( $ANT_HOME/lib/*.jar ) if [[ $service = *ANT_ARGS* ]]; then compset -q @@ -22,12 +23,12 @@ '-debug[print debugging information]' \ '-emacs[produce logging information without adornments]' \ '(-l -logfile)'{-l,-logfile}'[use specified file for log]:logfile:_files' \ - '-logger[the class which is to perform logging]:classname:_java_class' \ - '*-listener[add an instance of class as a project listener]:classname:_java_class' \ + '-logger[the class which is to perform logging]:classname:_java_class -cp ${(j.:.)c}' \ + '*-listener[add an instance of class as a project listener]:classname:_java_class -cp ${(j.:.)c}' \ '(-f -file -buildfile -find)'{-f,-file,-buildfile}'[use specified build file]:build file:_files' \ '*-D[specify property with value to use]:property:->property' \ '-propertyfile[load properties from specfied file]:property file:_files' \ - '-inputhandler[specify class which will handle input requests]:class:_java_class' \ + '-inputhandler[specify class which will handle input requests]:class:_java_class -cp ${(j.\:.)c}' \ '(-f -file -buildfile)-find[search for build file towards the root of filesystem]:build file:(build.xml)' \ $target && return Index: Completion/Unix/Command/_java =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_java,v retrieving revision 1.7 diff -u -r1.7 _java --- Completion/Unix/Command/_java 16 Apr 2002 14:15:37 -0000 1.7 +++ Completion/Unix/Command/_java 24 Aug 2002 19:07:27 -0000 @@ -34,8 +34,7 @@ java) _arguments -C \ "$jdb_args[@]" \ - '(-cp)-classpath[specify path for user class files]:class path:->classpath' \ - '(-classpath)-cp[specify path for user class files]:class path:->classpath' \ + '(-cp -classpath)'{-cp,-classpath}'[specify path for user class files]:class path:->classpath' \ '-D-[specify a property]:property:->property' \ '(-verbose:class)-verbose[print class information]' \ '(-verbose)-verbose\:class[print class information]' \ @@ -44,7 +43,7 @@ '-version[print version]' \ '-help[print help message]' \ '(- 1)-jar[specify a program capsulated as jar]:jar:_files -g \*.jar' \ - '(-):class:_java_class -m main' \ + '(-):class:_java_class -m main ${(kv)opt_args[(i)(-classpath|-cp)]}' \ '*::args: _normal' \ && return 0 ;; @@ -57,7 +56,7 @@ '-package[display packages, public/protected classes and members only]' \ '-private[display all classes and members]' \ '-help[print help message]' \ - '-doclet[specify a doclet]:doclet:_java_class -t doclet' \ + '-doclet[specify a doclet]:doclet:_java_class -t doclet ${(kv)opt_args[(i)-classpath]}' \ '-docletpath[specify a path to search doclet]:doclet path:->docletpath' \ '-1.1[Javadoc 1.1 compatible output]' \ '-sourcepath[specify path for source files]:source path:->sourcepath' \ @@ -118,7 +117,7 @@ jar_cmd="${words[2]#-}" tmpassoc=( m ':manifest file:_files' - f ':archive file:_files -g \*.\(jar\|zip\)' + f ':archive file:_files -g \*.\([ejw]ar\|zip\)' ) _arguments -C \ "${jar_cmd/[^-]*/:dummy:}" \ @@ -140,7 +139,7 @@ '-bootclasspath[specify path for bootstrap class files]:bootstrap class path:->bootstrapclasspath' \ '-old[generate old JDK1.0-style header files]' \ '-force[force output]' \ - '*:fully qualified classname:_java_class -m main' && return 0 + '*:fully qualified classname:_java_class -m main ${(kv)opt_args[(i)-classpath]}' && return 0 ;; javap) @@ -159,7 +158,7 @@ '-classpath[specify path for user class files]:class path:->classpath' \ '-bootclasspath[specify path for bootstrap class files]:bootstrap class path:->bootstrapclasspath' \ '-extdirs[specify directories for extensions]:extensions directories:->extdirs' \ - '*:class:_java_class' && return 0 + '*:class:_java_class ${(kv)opt_args[(i)-classpath]}' && return 0 ;; extcheck) @@ -182,7 +181,7 @@ '-verbose[print verbose messages]' \ '-v1.1[JDK 1.1 stub protocol]' \ '-v1.2[JDK 1.2 stub protocol]' \ - '*:package qualified class name:_java_class' && return 0 + '*:package qualified class name:_java_class ${(kv)opt_args[(i)-classpath]}' && return 0 ;; rmiregistry) Index: Completion/Unix/Command/_zip =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_zip,v retrieving revision 1.5 diff -u -r1.5 _zip --- Completion/Unix/Command/_zip 2 Jan 2002 17:14:09 -0000 1.5 +++ Completion/Unix/Command/_zip 24 Aug 2002 19:07:27 -0000 @@ -50,7 +50,7 @@ '(-0 -1 -2 -3 -4 -5 -6 -7 -8 )-9[compress better]' \ '-x[exclude the following names]' \ '-i[include only the following names]' \ - "(-f -d -R -q -c -b -@ -F -FF -A -T -y -e -h -u -m -g -j -l -ll -L -v -z -t -tt -o -D -J -X -n -0 -1 -2 -3 -4 -5 -6 -7 -8 -9):zip file:_files -g '(#i)*.(zip|[jw]ar)'" \ + "(-f -d -R -q -c -b -@ -F -FF -A -T -y -e -h -u -m -g -j -l -ll -L -v -z -t -tt -o -D -J -X -n -0 -1 -2 -3 -4 -5 -6 -7 -8 -9):zip file:_files -g '(#i)*.(zip|[ejw]ar)'" \ '*:file:->files' && return 0 ;; unzip) @@ -75,7 +75,7 @@ '-M[page output]' \ '-x[exclude the following names]' \ '-Z[zipinfo mode]:zipinfomode:->zipinfo' \ - "(-p -f -u -l -t -z -n -o -j -C -X -q -qq -a -aa -v -L -M)1:zip file:_files -g '(#i)*.(zip|[jw]ar)'" \ + "(-p -f -u -l -t -z -n -o -j -C -X -q -qq -a -aa -v -L -M)1:zip file:_files -g '(#i)*.(zip|[ejw]ar)'" \ '*:file:->files' && return 0 ;; esac @@ -98,7 +98,7 @@ '(-1 -2)-T[use sortable decimal format for file times]' \ '-M[page output]' \ '-x[exclude the following names]' \ - "(-1 -2 -s -m -l -v -h -z -C -t -T -M)1:zip file:_files -g '(#i)*.(zip|[jw]ar)'" \ + "(-1 -2 -s -m -l -v -h -z -C -t -T -M)1:zip file:_files -g '(#i)*.(zip|[ejw]ar)'" \ '*:file:->files' && return 0 fi @@ -112,7 +112,7 @@ ;; files) if [[ $service = zip ]] && (( ! ${+opt_args[-d]} )); then - _files -g '^(#i)*.(zip|[jw]ar)' && return 0 + _files -g '^(#i)*.(zip|[ejw]ar)' && return 0 else zipfile=( $~line[1](|.zip|.ZIP) ) [[ -z $zipfile[1] ]] && return 1 Index: Completion/Unix/Type/_java_class =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_java_class,v retrieving revision 1.2 diff -u -r1.2 _java_class --- Completion/Unix/Type/_java_class 26 Jul 2002 13:54:41 -0000 1.2 +++ Completion/Unix/Type/_java_class 24 Aug 2002 19:07:27 -0000 @@ -1,16 +1,24 @@ #autoload -local classpath -#Should probably add some sort of cache. -#First use -classpath/-cp, then CLASSPATH, then assume . -classpath=${opt_args[-classpath]:-${opt_args[-cp]:-${CLASSPATH:-.}}} -local c i -#Should we call _multipart insteads of compadd -for i in ${(z)classpath//:/ }; do - if [ -f $i ] && [[ "$i" == *.(jar|zip|war|ear) ]]; then - c=(${${${(M)$(_call_program jar_classes jar -tf $i)##*.class}%%.class}:gs#/#.#}) - compadd -M 'r:|.=* r:|=*' -- $c - elif [ -d $i ]; then - c=(**/*.class(.:r:s/.class//:gs#/#.#)) - compadd -M 'r:|.=* r:|=*' -- $c - fi + +# Should probably add some sort of cache. +# Should we call _multi_parts insteads of compadd? + +local classpath i expl +local -a c +local method type + +zparseopts -D -E -a classpath t:=type m:=method cp: classpath: +: "$classpath[@]" +classpath="${${classpath[2]:-${CLASSPATH:-.}}//\\:/:}" +: "$classpath[@]" + +for i in "${(s.:.)classpath}"; do + if [ -f $i ] && [[ "$i" == *.(jar|zip|war|ear) ]]; then + c+=( ${${${(M)$(_call_program jar_classes jar -tf $i)##*.class}%%.class}:gs#/#.#} ) + elif [ -d $i ]; then + c+=( $i/**/*.class(.:r:s/.class//:s#$i/##:gs#/#.#) ) + fi done + +_wanted classes expl 'java class' compadd "$@" -M 'r:|.=* r:|=*' -a c + This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.