<?xml version="1.0"?>

<project 
  xmlns:j="jelly:core"
  xmlns:define="jelly:define"
  xmlns:maven="jelly:maven">

  <!-- ================================================================== -->
  <!-- S E L F  C O N T A I N E D  A R C H I V E                          -->
  <!-- ================================================================== -->
  <!-- Create a self contained archive for Unix systems which understand  -->
  <!-- the tar and gzip commands.                                         -->
  <!--                                                                    -->
  <!-- NOTE: This is a first attempt so I'm sure some adjustments will    -->
  <!-- have to be made for other Unices. I only use Linux.                -->
  <!-- ================================================================== -->

  <!--
   |
   | Usage:
   |
   | <sea:create
   |   sourceDirectory="/path/to/contents"
   |   seaName="foo"
   | />
   |
   | This will produce a self extracting file called foo.sh in
   | ${maven.build.dir} which contains the contents of ${sourceDirectory}.
   |
   -->

  <define:taglib uri="sea">
    <!--
     |
     | @sourceDirectory
     | @seaName
     | @workdir
     | @notice
     |
     -->
    <define:tag name="create">
    
      <mkdir dir="${maven.build.dir}"/>
      
      <!-- 
       |
       | Work around for Ant requiring specifics on which files get
       | special perm treatment. When including the JRE the Ant tar task makes
       | it very difficult to get the perms correct in the include JRE
       | directory.
       |
       -->
      
      <chmod
        file="${pom.getPluginContext('maven-sea-plugin').getVariable('plugin.dir')}/sea-tar"
        perm="+x"/>
      
      <exec
        executable="${pom.getPluginContext('maven-sea-plugin').getVariable('plugin.dir')}/sea-tar">
        <arg value="${seaName}"/>
        <arg value="${sourceDirectory}"/>
        <arg value="${maven.build.dir}"/>
      </exec>
      
      <filter token="NOTICE" value="${pom.name} v${pom.currentVersion} - starting installation... please wait"/>
      <filter token="WORK_DIR" value="${pom.artifactId}-${pom.currentVersion}"/>
      
      <copy 
        file="${pom.getPluginContext('maven-sea-plugin').getVariable('plugin.resources')}/sea-header"
        tofile="${maven.build.dir}/project-sea-header"
        overwrite="true"
        filtering="true"
      />
      
      <!--
       |
       | Concatenate the sea-header with the tarball we just made.
       |
       -->
      <maven:concat outputFile="${maven.build.dir}/${seaName}.sh">
        <maven:input file="${maven.build.dir}/project-sea-header"/>
        <maven:input file="${maven.build.dir}/${seaName}.tar.gz"/>
      </maven:concat>
      
      <!--
       |
       | Flip on the +x bit so all users have to do is run it!
       |
       -->
      <chmod file="${maven.build.dir}/${seaName}.sh" perm="+x"/>
      
      <!--
       |
       | The archive has been packaged up in a self-extracting ball
       | so we don't need the originals anymore.
       |
       -->
      <delete file="${maven.build.dir}/${seaName}.tar"/>
      <delete file="${maven.build.dir}/${seaName}.tar.gz"/>
      <delete file="${maven.build.dir}/project-sea-header"/>

    </define:tag>
  </define:taglib>
  
</project>
