about summary refs log tree commit diff
path: root/Completion/Unix/Command/_ant
blob: 6ef0e733df7f8bc617a642034a9b45872fa2b66a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#compdef ant -value-,ANT_ARGS,-default-

typeset -A opt_args
local buildfile tmp state line curcontext="$curcontext" ret=1
local targets importedfiles
local c target='*:target:->target'

c=( $ANT_HOME/lib/*.jar )

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

_arguments -C \
  '-help[display usage information]' \
  '-projecthelp[print project help information]' \
  '-version[display version information]' \
  '-diagnostics[display info useful to problem diagnosis]' \
  '(-q -quiet)'{-q,-quiet}'[be extra quiet]' \
  '(-v -verbose)'{-v,-verbose}'[be more verbose]' \
  '-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 -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 specified file]:property file:_files' \
  '-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 && ret=0

case $state in
  property)
    if compset -P '*='; then
      _default
    else
      _message -e properties 'property name'
    fi
  ;;
  target)
    if zstyle -t ":completion:${curcontext}:targets" call-command; then
      # Run ant -projecthelp also passing any of -find, -buildfile or -f options.
      # Parse output into an array of the format "target:description".
      # For the array to be set with correct argument boundaries, the entire
      # set statement needs to be eval'd.  On Cygwin, need to kill \r's output
      # from Java or parsing will fail.
      eval set -A tmp "${$(_call_program targets "$words[1]" $buildxml -projecthelp |
	while read target desc
	do
          # This loop reads ant -projecthelp output from versions 1.3 to 1.5
          ln="${target}${desc:+:$desc}"
          [[ $target = "" ]] && continue  # skip blank lines
          case $ln in
              (Buildfile:*)
                  buildfile=$desc
              ;;
              (Default:target:*)
                  # with version 1.5, target is on the same line
                  default_target="${${desc/target:/}# }"
                  # versions 1.3 and 1.4 with default target on a separate line
                  if [[ -z $default_target ]]; then
                      read junk
                      read default_target junk
                  fi
                  # Output target again indicating its the default one.
                  print -n "'${default_target}:(Default target) ' "
              ;;
              (Searching:*|Main:targets:|Subtargets:|BUILD:SUCCESSFUL|Total:time:
	      *)
              ;;
              (*)
                  # Return target and description
                  print -n "'$ln' "
              ;;
          esac
	done
      )//$'\015'}"
      _describe 'target' tmp && ret=0
    else
      if [[ -n $opt_args[-find] ]]; then
	buildfile=( (../)#${opt_args[-find]:-build.xml}(N[-1]) )
      else
	buildfile=${(v)opt_args[(I)(-f|-file|-buildfile)]:-build.xml}
      fi
      if [[ -f $buildfile ]]; then
        importedfiles=( $(sed -n "s/ *<import[^>]* file=[\"']\([^\"']*\)[\"'].*/\1/p" < $buildfile) )
        targets=( $(sed -n "s/ *<target[^>]* name=[\"']\([^\"']*\)[\"'].*/\1/p" $buildfile) )
        (( $#importedfiles )) && targets+=( $(cd $buildfile:h;
	    sed -n "s/ *<target[^>]* name=[\"']\([^\"']*\)[\"'].*/\1/p" $importedfiles) )
	_wanted targets expl target compadd -a targets && ret=0
      else
	_message -e targets target
      fi
    fi
  ;;
esac

return ret