<?xml version="1.0"?>
<!--

    Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<project name="ClientjarImport" basedir=".">

    <!-- IMPORTS -->
    <import file="./ts.common.xml"/>

    <!-- LOCAL PROPERTY DEFINITIONS -->
    
    <!-- MACROS -->
    <macrodef name="ts.clientjar">

    <!--
        The ts.clientjar task allows users to build application client archives.
        By default all classes under TS_HOME/classes/<pkg.dir> are included in the
        generated archive.  Users may specify additional content using nested fileset
        and zipfileset elements.  User may also tweak the contents of the generated
        archive by specifying various attribute values, see the attribute and element
        tables for details.

        Examples:

        <ts.clientjar descriptor="ejb_sam_Hello_client.xml" 
                      archivename="ejb_sam_Hello"
                      mainclass="com.sun.ts.tests.samples.ejb.ee.simpleHello.HelloClient"/>

        This example builds a client archive named ejb_sam_Hello_client.jar.  The deployment
        descriptor in the application client archive, application-client.xml, is specified
        using the descriptor attribute.  Note, the ejb_sam_Hello_client.xml file ends up in
        the application client archive as the META-INF/application-client.xml with no diffs.
        The mainclass attribute specifies the main-class entry added to the application
        client's MANIFEST file.  The classes added to the archive are the default classes,
        TS_HOME/classes/<pkg.dir>/**/*.class.  Where <pkg.dir> is the package name of the
        test being built.
 

        <ts.clientjar descriptor="ejb_sam_Hello_client.xml" 
                      archivename="ejb_sam_Hello"
                      mainclass="com.sun.ts.tests.samples.ejb.ee.simpleHello.HelloClient">
          <fileset dir="TS_HOME/classes" includes="<some-package>/*.class"/>
          <fileset dir="TS_HOME/classes" includes="<some-other-package>/*.class"/>
        </ts.clientjar>

        This example is the same as the previous example except the user has opted to add
        additional classes in addition to the default classes.  The additional classes are
        specified using nested fileset elements.  Note, users may specify additional classes
        using nested fileset or zipfileset elements.


        <ts.clientjar descriptor="ejb_sam_Hello_client.xml" 
                      archivename="ejb_sam_Hello"
                      mainclass="com.sun.ts.tests.samples.ejb.ee.simpleHello.HelloClient"
                      includedefaultfiles="false">
          <fileset dir="TS_HOME/classes" includes="<some-package>/*.class"/>
          <fileset dir="TS_HOME/classes" includes="<some-other-package>/*.class"/>
        </ts.clientjar>

        This example is the same as the previous example except the user has opted
        to add additional classes instead of the default classes.  The additional classes
        are specified using nested fileset elements.  Note, users may specify additional
        classes using nested fileset or zipfileset elements.


        <ts.clientjar descriptor="ejb_sam_Hello_client.xml" 
                      archivename="ejb_sam_Hello"
                      mainclass="com.sun.ts.tests.samples.ejb.ee.simpleHello.HelloClient"
                      excludedfiles="${pkg.dir}/B*.class>
        </ts.clientjar>

        This example excludes all class files that start with "B" that live in the
        TS_HOME/classes/${pkg.dir}.  If the TS_HOME/classes/${pkg.dir} contained the classes A.class,
        B1.class, B2.class and C.class only classes A and C would end up in the archive.  Using the
        excludedfiles attribute is another way of customizing the content of the archive by excluding
        some of the default content.  Users can also use the includedefaultfiles attribute to exclude
        all default content but the user must then use nested filesets and or zipfilesets to include
        the appropriate content.  Using the excludedfiles attribute may be simpler in some cases.

        To continue this example, the following XML does the exact same thing as the example above
        but it uses the includedefaultfiles attribute and a nested fileset element.

        <ts.clientjar descriptor="ejb_sam_Hello_client.xml" 
                      archivename="ejb_sam_Hello"
                      mainclass="com.sun.ts.tests.samples.ejb.ee.simpleHello.HelloClient"
                      includedefaultfiles="false">
          <fileset dir="TS_HOME/classes" includes="${pkg.dir}/A.class, ${pkg.dir}/C.class"/>
        </ts.clientjar>

      -->

        <attribute name="descriptor"
                   default=""        
                   description="Deployment descriptor added to the archive if the archive requires a deployment descriptor"/>
                              
        <attribute name="manifest"
                   default=""
                   description="Manifest to be used within the archive"/>
        
        <attribute name="archivename"   
                   description="Archive name minus the file suffix"/>
                   
        <attribute name="descriptordir"
                   default="${src.dir}/${pkg.dir}"
                   description="Directory containing the deployment descriptor"/>           
        
        <attribute name="mainclass"
                   default=""    
                   description="main-class MANIFEST entry for the appclient archive"/>

        <attribute name="includedefaultfiles"
                   default="true"
                   description="Include default files in the component archive"/>
                  
        <attribute name="excludedfiles"
                   default=""
                   description="A comma separated list of file expressions to exclude from the set of default included files.  This list of file expressions is relative to the TS_HOME/classes directory."/>

        <element name="jar-elements" implicit="yes" optional="true" 
                 description="The content to be added to the archive"/>
        
        <sequential>
        
        <!-- Define commmon preset regardless of includedefaultfiles value-->
        <presetdef name="component.clientjar">
            <_component descriptor="@{descriptor}"
                       manifest="@{manifest}"
                       archivename="@{archivename}"
                       archivesuffix="_client.jar"
                       descriptordir="@{descriptordir}"
                       mainclass="@{mainclass}"
                       internaldescriptorname="META-INF/application-client.xml">
                <fileset dir="${class.dir}"
                         includes="${test.base.classes}"/>
            </_component>
        </presetdef>
        
        <if>
          <istrue value="@{includedefaultfiles}"/>
        <then>
          <component.clientjar>
              <fileset dir="${class.dir}"
                       includes="${pkg.dir}/**/*.class"
                       excludes="@{excludedfiles}"/>
              <jar-elements/>
          </component.clientjar>
        </then>
        <else>
          <component.clientjar>
            <jar-elements/>            
          </component.clientjar>
        </else>
        </if>
        </sequential>
    </macrodef>
    
    <!-- PRESETS -->
    
    <!-- TARGETS -->
   
</project>
