#! /bin/bash

# parameter example: testjar/alljava1.jar $INTROOT/lib $ACSROOT/lib
# Todo: use default parameters, e.g. a certain name 
#       for the output jar, and $INTROOT/lib 
#       as the input directory

#
# First argument can be the option -g (for generated)
# This would consider on Jar files generated by ACS
# and containing the special attribute:
#      ACS-Generated-FromFile: <filename>
# in their manifest file
#
JAVA_PROPERTIES=""
if [ "$1" == "-g" ]
then
    JAVA_PROPERTIES="-DjarExtract.onlyGeneratedJars=true"
    shift
fi

#
# Check if there is the destination jar file as first parameter
#
if [ $# = 0 ]
then
    #
    # Is INTROOT defined?
    #
    if [ "X$INTROOT" == X ]
    then
       if [ "X$INTLIST" == "X" ]
       then
          echo INTROOT/INTLIST not defined. Cannot write default file!
          exit 1
       else
          # Intlist is defined. First left dir is taken
          intlist_first_dir=`echo $INTLIST | awk -F: '{print $1}'`
          JARFILE="$intlist_first_dir/Sources/introotJavaSrc.jar"
          JARDIR1="$intlist_first_dir/lib"
       fi
    fi
    JARFILE="$INTROOT/Sources/introotJavaSrc.jar"
    JARDIR1="$INTROOT/lib"
else
    JARFILE=$1
    JARDIR1=$2
fi

if (( $# > 5 )) 
then
   echo "Too many parameters (max is 4 jar file directories)!"
   exit 1
fi 


acsStartJava --noDirectory $JAVA_PROPERTIES alma.acs.makesupport.JarSourceExtractorRunner $JARFILE $JARDIR1 $3 $4 $5
exit 0
#
# ___oOo___

