<?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="RarImport" basedir="." default="usage">

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

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

    <!--
        The ts.rar task allows users to build connector 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.rar descriptor="ejb_sam_Hello_connector.xml" 
                archivename="ejb_sam_Hello"/>

        This example builds an EJB archive named ejb_sam_Hello.rar.  The deployment
        descriptor in the connector archive, ra.xml, is specified using the descriptor
        attribute.  Note, the ejb_sam_Hello_connector.xml file ends up in the connector archive as
        the META-INF/ra.xml with no diffs.  The jars added to the archive are the
        default jars, TS_HOME/dist/<pkg.dir>/**/*.jar.  Where <pkg.dir> is the
        package name of the test being built.
 

        <ts.rar descriptor="ejb_sam_Hello_connector.xml" 
                archivename="ejb_sam_Hello"/>
          <fileset dir="TS_HOME/classes" includes="<some-package>/*.class"/>
          <fileset dir="TS_HOME/classes" includes="<some-other-package>/*.class"/>
        </ts.rar>

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


        <ts.rar descriptor="ejb_sam_Hello_connector.xml" 
                archivename="ejb_sam_Hello"/>
                includedefaultfiles="false">
          <fileset dir="TS_HOME/classes" includes="<some-package>/*.class"/>
          <fileset dir="TS_HOME/classes" includes="<some-other-package>/*.class"/>
        </ts.rar>

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


        <ts.rar descriptor="ejb_sam_Hello_connector.xml" 
                archivename="ejb_sam_Hello"/>
                excludedfiles="B*.jar>
        </ts.rar>

        This example excludes all jar files that start with "B" that live in the
        TS_HOME/dist/${pkg.dir}.  If the TS_HOME/dist/${pkg.dir} contained the jars A.jar,
        B1.jar, B2.jar and C.jar, only jars 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.rar descriptor="ejb_sam_Hello_connector.xml" 
                archivename="ejb_sam_Hello"/>
                includedefaultfiles="false">
          <fileset dir="TS_HOME/classes" includes="${pkg.dir}/A.class, ${pkg.dir}/C.class"/>
        </ts.rar>

      -->

        <attribute name="descriptor"
                   default=""        
                   description="Deployment descriptor added to the archive if the archive requires a deployment descriptor"/>
                              
        <attribute name="permissionsdescriptor"
                   default=""        
                   description="Permisssions 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="permissionsdescriptordir"
                   default="${src.dir}/${pkg.dir}"
                   description="Directory containing the permissions descriptor"/>           
        
        <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 ${dist.dir}/${pkg.dir} 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.rar">
            <_component descriptor="@{descriptor}"
                        permissionsdescriptor="@{permissionsdescriptor}"
                       manifest="@{manifest}"
                       archivename="@{archivename}"
                       archivesuffix=".rar"
                       descriptordir="@{descriptordir}"
                       permissionsdescriptordir="@{permissionsdescriptordir}"
                       internaldescriptorname="META-INF/ra.xml">
            </_component>
        </presetdef>
        
        <if>
          <istrue value="@{includedefaultfiles}"/>
        <then>
          <component.rar>
              <fileset dir="${dist.dir}/${pkg.dir}"
                       includes="**/*.jar"
                       excludes="@{excludedfiles}"/>
              <jar-elements/>
          </component.rar>
        </then>
        <else>
          <component.rar>
            <jar-elements/>
          </component.rar>
        </else>
        </if>
        </sequential>
    </macrodef>
    
    <!-- PRESETS -->
    
    <!-- TARGETS -->
     
</project>
