<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->


<project xmlns:j="jelly:core"
  xmlns:test="test">

  <goal name="shell" prereqs="shell:zsh"
    description="Generate Zsh files"
    />

  <goal name="shell:zsh"
    description="Generate Zsh files">

    <j:set var="outputDir" value="${maven.shell.zsh.dir}"/>
    <j:if test="${empty outputDir}">
      <j:set var="outputDir" value="${maven.build.dir}"/>
    </j:if>

  <j:file name="${maven.build.dir}/_mavenzsh.tmp" omitXmlDeclaration="true" xmlns="dummy">
  <![CDATA[
       #compdef maven
       case "$service" in
       
maven)
 _arguments -s \
    '-D[Define a system property]' \
    '-E[Produce logging information without adornments]' \
    '-X[Produce execution debug output]' \
    '-b[Suppress logo banner]' \
    '-d[Set effective working directory]' \
    '-e[Produce exception stack traces]' \
    '-f[Set project file and effective working directory by finding the project file]' \
    '-g[Display available goals]' \
    '-h[Display help information]' \
    '-i[Display system information]' \
    '-o[Build is happening offline]' \
    '-p[Set project file]:Project File:_files -g \*.xml' \
    '-v[Display version information]' \
    ':Maven Goals:-@GREATER_THAN@mavengoals' \
    ':destination directory:_files -/' @AMBERSAND@@AMBERSAND@ return 0 
    ;;
  *)
esac
[[ -n "$state" ]] @AMBERSAND@@AMBERSAND@
case "$state" in

  mavengoals)
  tmp=(
  
  ]]>
  
  <j:set var="mavenSession" value="${context.getMavenSession()}"/>
  <j:set var="allGoals" value="${mavenSession.getAllGoalNames()}"/>
  <j:new var="modList" className="java.util.ArrayList"/>
  <j:set var="dummy" value="${modList.addAll(allGoals)}"/>
        <j:invokeStatic method="sort" className="java.util.Collections" var="dummy">
            <j:arg type="java.util.List" value="${modList}" />
        </j:invokeStatic>

    <j:forEach var="goal" items="${modList.iterator()}">
     <j:set var="escgoal" value='${goal.replaceAll(":","\\:")}'/> 


      <j:choose>
        <j:when test="${context.getVariable('maven.shell.zsh.nodesc') == 'false'}">
           <j:set var="desc" value="${mavenSession.getGoalDescription(goal)}"/>
           <j:set var="escdesc" value='${desc.replaceAll(":","\\:")}'/>
           <j:set var="point" value="'"/>
           <j:set var="pointesc" value='"'/>
           <j:set var="escdesc" value='${escdesc.replaceAll(point,pointesc)}'/>
        '${escgoal}:${escdesc}'
        </j:when>
        <j:otherwise>
        '${escgoal}'
        </j:otherwise>
      </j:choose><j:whitespace> </j:whitespace></j:forEach>


  <![CDATA[
   )
     _describe 'Maven Goals' tmp --
  ;;
  
  esac
  ]]>
   </j:file>
   
  <echo>Now start a new zsh shell</echo>
  
    <filter token="AMBERSAND" value="&amp;"/>
    <filter token="LESSER_THAN" value="&lt;"/>
    <filter token="GREATER_THAN" value="&gt;"/>
    <copy file="${maven.build.dir}/_mavenzsh.tmp" tofile="${outputDir}/_maven" filtering="true"/>
    <delete file="${maven.build.dir}/_mavenzsh.tmp"/>


  
  </goal>

</project>
