#!/bin/sh
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright 1997-2013 Oracle and/or its affiliates. All rights reserved.
#
# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
# Other names may be trademarks of their respective owners.
#
# The contents of this file are subject to the terms of either the GNU General Public
# License Version 2 only ("GPL") or the Common Development and Distribution
# License("CDDL") (collectively, the "License"). You may not use this file except in
# compliance with the License. You can obtain a copy of the License at
# http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
# License for the specific language governing permissions and limitations under the
# License. When distributing the software, include this License Header Notice in
# each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle
# designates this particular file as subject to the "Classpath" exception as provided
# by Oracle in the GPL Version 2 section of the License file that accompanied this code.
# If applicable, add the following below the License Header, with the fields enclosed
# by brackets [] replaced by your own identifying information:
# "Portions Copyrighted [year] [name of copyright owner]"
#
# Contributor(s):
#
# The Original Software is NetBeans. The Initial Developer of the Original Software
# is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
# Rights Reserved.
#
# If you wish your version of this file to be governed by only the CDDL or only the
# GPL Version 2, indicate your decision by adding "[Contributor] elects to include
# this software in this distribution under the [CDDL or GPL Version 2] license." If
# you do not indicate a single choice of license, a recipient has the option to
# distribute your version of this file under either the CDDL, the GPL Version 2 or
# to extend the choice of license to its licensees as provided above. However, if you
# add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the
# option applies only if the new code is made subject to such option by the copyright
# holder.
#
ARG_JAVAHOME="--javahome"
ARG_VERBOSE="--verbose"
ARG_OUTPUT="--output"
ARG_EXTRACT="--extract"
ARG_JAVA_ARG_PREFIX="-J"
ARG_TEMPDIR="--tempdir"
ARG_CLASSPATHA="--classpath-append"
ARG_CLASSPATHP="--classpath-prepend"
ARG_HELP="--help"
ARG_SILENT="--silent"
ARG_NOSPACECHECK="--nospacecheck"
ARG_LOCALE="--locale"
USE_DEBUG_OUTPUT=0
PERFORM_FREE_SPACE_CHECK=1
SILENT_MODE=0
EXTRACT_ONLY=0
SHOW_HELP_ONLY=0
LOCAL_OVERRIDDEN=0
APPEND_CP=
PREPEND_CP=
LAUNCHER_APP_ARGUMENTS=
LAUNCHER_JVM_ARGUMENTS=
ERROR_OK=0
ERROR_TEMP_DIRECTORY=2
ERROR_TEST_JVM_FILE=3
ERROR_JVM_NOT_FOUND=4
ERROR_JVM_UNCOMPATIBLE=5
ERROR_EXTRACT_ONLY=6
ERROR_INPUTOUPUT=7
ERROR_FREESPACE=8
ERROR_INTEGRITY=9
ERROR_MISSING_RESOURCES=10
ERROR_JVM_EXTRACTION=11
ERROR_JVM_UNPACKING=12
ERROR_VERIFY_BUNDLED_JVM=13
VERIFY_OK=1
VERIFY_NOJAVA=2
VERIFY_UNCOMPATIBLE=3
MSG_ERROR_JVM_NOT_FOUND="nlu.jvm.notfoundmessage"
MSG_ERROR_USER_ERROR="nlu.jvm.usererror"
MSG_ERROR_JVM_UNCOMPATIBLE="nlu.jvm.uncompatible"
MSG_ERROR_INTEGRITY="nlu.integrity"
MSG_ERROR_FREESPACE="nlu.freespace"
MSG_ERROP_MISSING_RESOURCE="nlu.missing.external.resource"
MSG_ERROR_TMPDIR="nlu.cannot.create.tmpdir"
MSG_ERROR_EXTRACT_JVM="nlu.cannot.extract.bundled.jvm"
MSG_ERROR_UNPACK_JVM_FILE="nlu.cannot.unpack.jvm.file"
MSG_ERROR_VERIFY_BUNDLED_JVM="nlu.error.verify.bundled.jvm"
MSG_RUNNING="nlu.running"
MSG_STARTING="nlu.starting"
MSG_EXTRACTING="nlu.extracting"
MSG_PREPARE_JVM="nlu.prepare.jvm"
MSG_JVM_SEARCH="nlu.jvm.search"
MSG_ARG_JAVAHOME="nlu.arg.javahome"
MSG_ARG_VERBOSE="nlu.arg.verbose"
MSG_ARG_OUTPUT="nlu.arg.output"
MSG_ARG_EXTRACT="nlu.arg.extract"
MSG_ARG_TEMPDIR="nlu.arg.tempdir"
MSG_ARG_CPA="nlu.arg.cpa"
MSG_ARG_CPP="nlu.arg.cpp"
MSG_ARG_DISABLE_FREE_SPACE_CHECK="nlu.arg.disable.space.check"
MSG_ARG_LOCALE="nlu.arg.locale"
MSG_ARG_SILENT="nlu.arg.silent"
MSG_ARG_HELP="nlu.arg.help"
MSG_USAGE="nlu.msg.usage"
isSymlink=
entryPoint() {
initSymlinkArgument
CURRENT_DIRECTORY=`pwd`
LAUNCHER_NAME=`echo $0`
parseCommandLineArguments "$@"
initializeVariables
setLauncherLocale
debugLauncherArguments "$@"
if [ 1 -eq $SHOW_HELP_ONLY ] ; then
showHelp
fi
message "$MSG_STARTING"
createTempDirectory
checkFreeSpace "$TOTAL_BUNDLED_FILES_SIZE" "$LAUNCHER_EXTRACT_DIR"
extractJVMData
if [ 0 -eq $EXTRACT_ONLY ] ; then
searchJava
fi
extractBundledData
verifyIntegrity
if [ 0 -eq $EXTRACT_ONLY ] ; then
executeMainClass
else
exitProgram $ERROR_OK
fi
}
initSymlinkArgument() {
testSymlinkErr=`test -L / 2>&1 > /dev/null`
if [ -z "$testSymlinkErr" ] ; then
isSymlink=-L
else
isSymlink=-h
fi
}
debugLauncherArguments() {
debug "Launcher Command : $0"
argCounter=1
while [ $# != 0 ] ; do
debug "... argument [$argCounter] = $1"
argCounter=`expr "$argCounter" + 1`
shift
done
}
isLauncherCommandArgument() {
case "$1" in
$ARG_VERBOSE | $ARG_NOSPACECHECK | $ARG_OUTPUT | $ARG_HELP | $ARG_JAVAHOME | $ARG_TEMPDIR | $ARG_EXTRACT | $ARG_SILENT | $ARG_LOCALE | $ARG_CLASSPATHP | $ARG_CLASSPATHA)
echo 1
;;
*)
echo 0
;;
esac
}
parseCommandLineArguments() {
while [ $# != 0 ]
do
case "$1" in
$ARG_VERBOSE)
USE_DEBUG_OUTPUT=1;;
$ARG_NOSPACECHECK)
PERFORM_FREE_SPACE_CHECK=0
parseJvmAppArgument "$1"
;;
$ARG_OUTPUT)
if [ -n "$2" ] ; then
OUTPUT_FILE="$2"
if [ -f "$OUTPUT_FILE" ] ; then
# clear output file first
rm -f "$OUTPUT_FILE" > /dev/null 2>&1
touch "$OUTPUT_FILE"
fi
shift
fi
;;
$ARG_HELP)
SHOW_HELP_ONLY=1
;;
$ARG_JAVAHOME)
if [ -n "$2" ] ; then
LAUNCHER_JAVA="$2"
shift
fi
;;
$ARG_TEMPDIR)
if [ -n "$2" ] ; then
LAUNCHER_JVM_TEMP_DIR="$2"
shift
fi
;;
$ARG_EXTRACT)
EXTRACT_ONLY=1
if [ -n "$2" ] && [ `isLauncherCommandArgument "$2"` -eq 0 ] ; then
LAUNCHER_EXTRACT_DIR="$2"
shift
else
LAUNCHER_EXTRACT_DIR="$CURRENT_DIRECTORY"
fi
;;
$ARG_SILENT)
SILENT_MODE=1
parseJvmAppArgument "$1"
;;
$ARG_LOCALE)
SYSTEM_LOCALE="$2"
LOCAL_OVERRIDDEN=1
parseJvmAppArgument "$1"
;;
$ARG_CLASSPATHP)
if [ -n "$2" ] ; then
if [ -z "$PREPEND_CP" ] ; then
PREPEND_CP="$2"
else
PREPEND_CP="$2":"$PREPEND_CP"
fi
shift
fi
;;
$ARG_CLASSPATHA)
if [ -n "$2" ] ; then
if [ -z "$APPEND_CP" ] ; then
APPEND_CP="$2"
else
APPEND_CP="$APPEND_CP":"$2"
fi
shift
fi
;;
*)
parseJvmAppArgument "$1"
esac
shift
done
}
setLauncherLocale() {
if [ 0 -eq $LOCAL_OVERRIDDEN ] ; then
SYSTEM_LOCALE="$LANG"
debug "Setting initial launcher locale from the system : $SYSTEM_LOCALE"
else
debug "Setting initial launcher locale using command-line argument : $SYSTEM_LOCALE"
fi
LAUNCHER_LOCALE="$SYSTEM_LOCALE"
if [ -n "$LAUNCHER_LOCALE" ] ; then
# check if $LAUNCHER_LOCALE is in UTF-8
if [ 0 -eq $LOCAL_OVERRIDDEN ] ; then
removeUTFsuffix=`echo "$LAUNCHER_LOCALE" | sed "s/\.UTF-8//"`
isUTF=`ifEquals "$removeUTFsuffix" "$LAUNCHER_LOCALE"`
if [ 1 -eq $isUTF ] ; then
#set launcher locale to the default if the system locale name doesn`t containt UTF-8
LAUNCHER_LOCALE=""
fi
fi
localeChanged=0
localeCounter=0
while [ $localeCounter -lt $LAUNCHER_LOCALES_NUMBER ] ; do
localeVar="$""LAUNCHER_LOCALE_NAME_$localeCounter"
arg=`eval "echo \"$localeVar\""`
if [ -n "$arg" ] ; then
# if not a default locale
# $comp length shows the differe