<?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:ant="jelly:ant"
         xmlns:license="license" 
         xmlns:util="jelly:util"
         xmlns:artifact="artifact">

  <!--==================================================================-->
  <!-- Default goal : Builds a ejb file                                 -->
  <!--==================================================================-->
  <goal name="ejb" prereqs="ejb:ejb" description="Build an ejb file"/>

  <!--==================================================================-->
  <!-- Initializations                                                  -->
  <!--==================================================================-->
  <goal name="ejb:init" 
    description="Initialize filesystem and other resources for an ejb build">

   <j:set var="maven.ejb.final.name" 
      value="${maven.build.dir}/${maven.final.name}.jar"/>

    <j:if test="${sourcesPresent == 'true'}">
      <attainGoal name="test:test"/>
    </j:if>

  </goal>
  
  <!--==================================================================-->
  <!-- Builds an ejb file                                               -->
  <!--==================================================================-->
  <goal name="ejb:ejb" prereqs="ejb:init" description="Build an ejb file">

    <ant:echo>Building ejb ${maven.final.name}</ant:echo>

    <ant:available property="maven.ejb.manifest.available"
      file="${maven.ejb.manifest}"/>

    <j:forEach var="dep" items="${pom.dependencies}">
      <j:if test="${dep.getProperty('ejb.manifest.classpath')=='true'}">
        <j:set var="maven.ejb.classpath" value="${maven.ejb.classpath} ${dep.artifact}"/>
      </j:if>
    </j:forEach>

    <!-- jar task used for now due to problems with ejb jar not including 
         files other than class files -->
    <ant:jar
      jarfile="${maven.ejb.final.name}"
      index="${maven.ejb.index}">
      
      <!-- include marked dependencies -->
      <j:forEach var="lib" items="${pom.artifacts}">
        <j:set var="dep" value="${lib.dependency}"/>     

        <!-- Just include jars-->
        <!-- Probably we should also include uberjars -->
        <j:if test="${dep.getProperty('ejb.bundle')=='true' and dep.type=='jar'}">          
          <ant:echo>Bundling: ${dep.type} - ${dep.id}</ant:echo>                                             
          <ant:fileset dir="${lib.file.parent}">
            <ant:include name="${lib.file.name}"/>
          </ant:fileset>
        </j:if>   
        
        <!-- TO BE REMOVED -->
        <j:if test="${dep.getProperty('ejb.bundle.jar')=='true'}">
          <ant:echo> 
           <ant:echo>Bundling: ${dep.type} - ${dep.id}</ant:echo>        
            DEPRECATION WARNING:            
            Use : ejb.bundle instead of ejb.bundle.jar
          </ant:echo>
          <ant:fileset dir="${lib.file.parent}">
            <ant:include name="${lib.file.name}"/>
          </ant:fileset>
        </j:if>  
        <!-- END OF TO BE REMOVED -->        
      </j:forEach>
 

      <j:if test="${maven.ejb.manifest.available}">
        <ant:setProperty name="manifest" value="${maven.ejb.manifest}" />
      </j:if>

      <j:set var="licenseFileName"><license:fileName/></j:set>
      <util:file name="${licenseFileName}" var="licenseFile"/>
      <ant:metainf dir="${licenseFile.canonicalFile.parent}">
        <ant:include name="${licenseFile.canonicalFile.name}"/>
      </ant:metainf>

      <ant:manifest>
        <ant:attribute name="Built-By" value="${user.name}"/>
        <ant:attribute name="Created-By" value="Apache Jakarta Maven"/>
        <ant:attribute name="Package" value="${pom.package}"/>
        <j:set var="classPath" value="${maven.ejb.classpath}"/>
        <j:if test="${!empty(classPath)}">
          <ant:attribute name="Class-Path" value="${maven.ejb.classpath}"/>
        </j:if>
        <ant:section name="${pom.package}">
          <ant:attribute name="Specification-Title" value="${pom.artifactId}"/>
          <ant:attribute name="Specification-Vendor" value="${pom.organization.name}"/>
          <!--
          <ant:attribute name="Specification-Version" value="${pom.currentVersion}"/>
          -->
          <ant:attribute name="Implementation-Title" value="${pom.package}"/>
          <ant:attribute name="Implementation-Vendor" value="${pom.organization.name}"/>
          <ant:attribute name="Implementation-Version" value="${pom.currentVersion}"/>
        </ant:section>
      </ant:manifest>
    
      <util:available file="${maven.ejb.src}">
        <ant:fileset dir="${maven.ejb.src}"/>
      </util:available>
      <ant:fileset dir="${maven.build.dest}"
        includes="${maven.ejb.includes}"
        excludes="${maven.ejb.excludes}">
      </ant:fileset>

    </ant:jar>

  </goal>
     
  <!--==================================================================-->
  <!-- Builds an ejb client jar file                                    -->
  <!--==================================================================-->
  <goal name="ejb:ejb-client" prereqs="ejb:ejb" description="Build a client ejb file">
    <ant:jar jarfile="${maven.build.dir}/${maven.final.name}-client.jar"
             basedir="${maven.build.dest}"
             excludes="${maven.ejb.client.base.excludes},${maven.ejb.client.excludes}"
             index="${maven.ejb.client.index}"
             >
    </ant:jar>
  </goal>
  
  <!--==================================================================-->
  <!-- Install the ejb in the local repository                          -->
  <!--==================================================================-->    
  <goal name="ejb:install"
        prereqs="ejb:ejb"
        description="Install the ejb in the local repository">
     
     <artifact:install
        artifact="${maven.ejb.final.name}"
        type="ejb"
        project="${pom}"/> 
  
  </goal>
  
  <!--==================================================================-->
  <!-- Install the snapshot version of the ejb in the local repository  -->
  <!--==================================================================-->      
  <goal name="ejb:install-snapshot"
        prereqs="ejb:ejb" 
        description="Install the snapshot version of the ejb in the local repository">
        
      <artifact:install-snapshot
        artifact="${maven.ejb.final.name}"
        type="ejb"
        project="${pom}"/> 
        
  </goal>

  <!--==================================================================-->
  <!-- Deploys the ejb to the remote repository                         -->
  <!--==================================================================-->      
  <goal name="ejb:deploy" 
        prereqs="ejb:ejb" 
        description="Deploys the ejb to the remote repository">

     <artifact:deploy
        artifact="${maven.ejb.final.name}"
        type="ejb"
        project="${pom}"/>   
        
  </goal>      
        
  <!--==================================================================-->
  <!-- Deploys the snapshot of the ejb to the remote repository         -->
  <!--==================================================================-->      
  <goal name="ejb:deploy-snapshot" 
        prereqs="ejb:ejb"
        description="Deploys the snapshot version of the ejb to remote repository">  

     <artifact:deploy-snapshot
        artifact="${maven.ejb.final.name}"
        type="ejb"
        project="${pom}"/>    
        
  </goal>
  
  

</project>
