1 #!/bin/bash
   2 #
   3 # Java Packager tool execution script for Linux and MacOS.
   4 #
   5 
   6 # Default values.
   7 DEBUG=""
   8 MEMORY="-Xmx512M"
   9 JAVA_ARGS=""
  10 DEBUG_ARG="-J-Xdebug:";
  11 
  12 # Argument parsing.
  13 args=
  14 narg=1
  15 for i in "$@"; do
  16     if [[ "$i" == "-J-Xmx"* ]]; then
  17         ARGUMENT=${i:2}
  18         MEMORY=${ARGUMENT}
  19     elif [[ "$i" == ${DEBUG_ARG}* ]]; then
  20         ADDRESS=${i:${#DEBUG_ARG}}
  21         DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${ADDRESS}"
  22     elif [[ "$i" == "-J-"* ]]; then
  23         ARGUMENT=${i:2}
  24         JAVA_ARGS="${JAVA_ARGS} ${ARGUMENT}"
  25     else
  26         args="$args \"$""{"$narg"}\""
  27     fi
  28     narg=`expr $narg + 1`
  29 done
  30 
  31 # resolve symlinks
  32 PRG=$0
  33 while [ -h "$PRG" ]; do
  34     ls=`ls -ld "$PRG"`
  35     link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
  36     if expr "$link" : '^/' 2> /dev/null >/dev/null; then
  37         PRG="$link"
  38     else
  39         PRG="`dirname "$PRG"`/$link"
  40     fi
  41 done
  42 
  43 # detect Darwin and Cygwin environments
  44 darwin=false;
  45 cygwin=false;
  46 case "`uname`" in
  47   Darwin*) darwin=true;
  48            if [ -z "$JAVA_HOME" ] ; then
  49                BIN_DIR=`dirname $PRG`
  50                JAVA_HOME=`cd $BIN_DIR > /dev/null; pwd`/..
  51            fi
  52            ;;
  53   CYGWIN*) cygwin=true;;
  54 esac
  55 
  56 JAVA_JPACKAGER_PATH=$(cd $(dirname $0) ; pwd -P)
  57 JAVA_CMD="${JAVA_JPACKAGER_PATH}/java"
  58 
  59 if [[ ! -f ${JAVA_CMD} ]]; then
  60   if [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/javac" ] ; then
  61       JAVA_CMD="$JAVA_HOME/bin/java"
  62       export JAVA_HOME
  63   else
  64     JAVAC_CMD=`which javac 2> /dev/null `
  65     while [ -h "$JAVAC_CMD" ]; do
  66       ls=`ls -ld "$JAVAC_CMD"`
  67       link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
  68       if expr "$link" : '^/' 2> /dev/null >/dev/null; then
  69         JAVAC_CMD="$link"
  70       else
  71         JAVAC_CMD="`dirname "$JAVAC_CMD"`/$link"
  72       fi
  73     done
  74 
  75     BIN_DIR=`dirname "$JAVAC_CMD"`
  76     JAVA_HOME=`dirname "$BIN_DIR"`
  77     if [ "m$JAVA_HOME" != "m." ]; then
  78       JAVA_CMD="$JAVA_HOME/bin/java"
  79       export JAVA_HOME
  80     else
  81       unset JAVA_HOME
  82       JAVA_CMD=`which java 2> /dev/null `
  83       if [ -z "$JAVA_CMD" ]; then
  84         JAVA_CMD="java"
  85       fi
  86     fi
  87   fi
  88 fi
  89 
  90 if [ ! -x "$JAVA_CMD" ] ; then
  91   echo 'Error: JAVA_HOME is not defined, cannot find "java" command.'
  92   exit 1
  93 fi
  94 
  95 if $cygwin ; then
  96     JAVA_CMD=`cygpath --unix "$JAVA_CMD"`
  97 fi
  98 
  99 # This is similar to "$@" except we had to strip out some arguments
 100 # that we don't want to be passed to the Java Packager.
 101 eval exec "$JAVA_CMD" ${DEBUG} ${MEMORY} ${JAVA_ARGS} \
 102     -m jdk.jpackager/jdk.jpackager.main.Main $args
 103