#!/bin/bash

#=============================================================================
#  Launcher for @@FULL_PRODUCT_NAME@@
# Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
#=============================================================================

#-----------------------------------------------------------------------------
#  toAbsPath() takes two arguments
#    1) a pathname (assumed to point to a file)
#    2) a directory that the pathname is relative to
#
#  and converts the pathname to an absolute path (if necessary), resolving
#  any "." or ".." in the absolute path.  The result is echoed to STDOUT.
#-----------------------------------------------------------------------------
toAbsPath()
{
    local pathname="$1"
    local rawAbsPath

    #  Test if $arg starts with '/'.
    if [ "X`expr \"${pathname}\" : '\(/\).*'`" = "X/" ]
    then
    rawAbsPath="${pathname}"
    else
        local relativeTo="$2"
        rawAbsPath="${relativeTo}/${pathname}"
    fi

    #  Resolve any "." and ".." in $rawAbsPath.
    local cwd=`pwd`
    local rawAbsDir=`dirname "$rawAbsPath"`
    local basename=`basename "$rawAbsPath"`
    cd "${rawAbsDir}"
    local dir=`pwd -P`
    cd "${cwd}"
    echo "${dir}/${basename}"
}

#-----------------------------------------------------------------------------
#  getSymlinkTarget() takes one argument
#    1) a pathname
#
#  If the pathname is a symlink, the symlink target is echoed to STDOUT.
#  If the pathname is not a symlink, the pathname itself is echoed.
#-----------------------------------------------------------------------------
getSymlinkTarget()
{
    local pathname="$1"
    while [ -h "$pathname" ] ; do
        local ls=`ls -ld "$pathname"`
        local link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '.*/.*' > /dev/null
        then
            pathname="$link"
        else
            pathname="`dirname \"$pathname\"`/$link"
        fi
    done
    echo "$pathname"
}

#-----------------------------------------------------------------------------
#  main
#-----------------------------------------------------------------------------
STARTING_CWD=`pwd`
readonly STARTING_CWD

#  INVOKED_AS contains the absolute path of the script invocation.
INVOKED_AS=`toAbsPath "$0" "\`pwd\`"`
readonly INVOKED_AS

#  SCRIPT contains the absolute path of the actual (symlink-resolved) script.
SCRIPT=`toAbsPath "\`getSymlinkTarget \"${INVOKED_AS}\"\`" "\`dirname \"${INVOKED_AS}\"\`"`
readonly SCRIPT

#  PRODUCT_HANDLES_HELP should be 1 if the java part of this product handles help argument
PRODUCT_HANDLES_HELP=0

#  PRODUCT_HANDLES_VERBOSE should be 1 if the java part of this product handles verbose argument
PRODUCT_HANDLES_VERBOSE=0

#  PRODUCT_DISPLAYS_BANNER should be 1 if the java part of this product displays the banner
PRODUCT_DISPLAYS_BANNER=0

# PRODUCT_CAN_RESTART should be 0 if the product cannot be restarted
PRODUCT_CAN_RESTART=1

. "`dirname "${SCRIPT}"`/../../ide/bin/launcher.sh"

#  A segmentation fault or other core dump at startup can occur if
#  the shell's stack size limit is too small.  Uncomment the following
#  line to raise the stack size to 4MB or more.
#ulimit -s 4096

# Uncomment the following line if escaped wildcards should not be expanded by this shell
# set -o noglob

#-----------------------------------------------------------------------------
#  product-specific function overrides
#-----------------------------------------------------------------------------
GetFullProductName()
{
    echo "@@FULL_PRODUCT_NAME@@"
}

GetShortProductName()
{
    echo "@@SHORT_PRODUCT_NAME@@"
}

GetProductVersion()
{
    echo "13.0.0.1.0"
}

# The name of the root directory of the user .conf files
GetUserConfRootDirName()
{
    local confDirName="@@USER_CONF_ROOT_DIR_NAME@@"
    if [ "`echo $confDirName | sed -e 's/@//g'`" = "USER_CONF_ROOT_DIR_NAME" ]
    then
        echo ".`GetShortProductName | sed -e 's/ /_/g' | tr [:upper:] [:lower:]`"
    else
        echo "$confDirName"
    fi
}

# Get the contents of the tool specific override of the user .conf file in
# case a tool is using a user .conf file that is shared with other tools
GetToolSpecificUserConfFileContents()
{
    local content="@@TOOL_SPECIFIC_USER_CONF_FILE_CONTENTS@@"
    if [ "`echo $content | sed -e 's/@//g'`" = "TOOL_SPECIFIC_USER_CONF_FILE_CONTENTS" ]
    then
        echo ""
    else
        echo "$content"
    fi
}

LaunchIDE "$@"
