#!/bin/sh ############################################################################## # __ # # ________ ___ / / ___ Scala Tools Launch Script # # / __/ __// _ | / / / _ | (c) 2002-2005, LAMP/EPFL # # __\ \/ /__/ __ |/ /__/ __ | # # /____/\___/_/ |_/____/_/ | | # # |/ # ############################################################################## # $Id$ ############################################################################## # Configuration # The configure function contains all the configurable variables of # this script. Each of these variables may be overridden by defining # an environment variable with the same but where the "default_" has # been replaced by "SCALA_". For example, to start scalaint with a big # initial heap size, one may run the following command: # # env SCALA_SCALA_ARGS=-Xms1024m scalaint". # # These variables must use the Unix form for paths and path lists # (i.e. use '/' as file separator and ':' as path separator). There # are two exceptions: JAVA_ARGS and SCALA_ARGS which must use the # paltform-specific form. # # The following environment variables are also read by this script: # # - SCALA_CLASSPATH: if defined, it is used as the default classpath # by all Scala tools. # # - CLASSPATH: if defined and SCALA_CLASSPATH is undefined, it is used # as the default classpath by all Scala tools. # # - SCALA_SOURCEPATH: if defined, it is used as the default sourcepath # by all Scala tools. # # - SCALA_BOOTCLASSPATH: if defined, it is used as the default # bootclasspath by all Scala tools. # # - SCALA_EXTDIRS: if defined, it is used as the default extdirs by # all Scala tools. # # These variables must use the platform-specific form for paths and # path lists. configure() { # Location of the Scala library sources. default_LIBRARY_SOURCES={#LIBRARY_SOURCES#}; # Location of the Scala library. default_LIBRARY_CLASSES={#LIBRARY_CLASSES#}; # Location of the Scala tools library. default_TOOLS_CLASSES={#TOOLS_CLASSES#}; # Location of the FJBG library. default_FJBG_CLASSES={#FJBG_CLASSES#}; # Location of the MSIL library. default_MSIL_CLASSES={#MSIL_CLASSES#}; # Command to start the Java VM. default_JAVA_CMD={#JAVA_CMD#}; # Additional arguments to pass to the Java VM. default_JAVA_ARGS={#JAVA_ARGS#}; # Command to start the Scala VM. default_SCALA_CMD={#SCALA_CMD#}; # Additional arguments to pass to the Scala VM. default_SCALA_ARGS={#SCALA_ARGS#}; # Command to start subprocesses. This is mainly for debugging # purposes. For example, one may display the Java command that is # started by "scala", by running "env SCALA_EXEC=echo scala". default_EXEC="exec"; } ############################################################################## # Error functions # Prints a warning message on stderr. warning() { echo "$0: warning:" "$@" 1>&2; } # Prints an error message on stderr. error() { echo "$0:" "$@" 1>&2; } # Prints an error message on stderr and exits with a non-zero status. abort() { error "$@"; exit 1; } ############################################################################## # Printing functions # Initializes the printf functions printf_initialization() { case "$1" in many ) printf_font_outline="printf \\033[1;39m"; printf_font_success="printf \\033[1;32m"; printf_font_failure="printf \\033[1;31m"; printf_font_warning="printf \\033[1;33m"; printf_font_default="printf \\033[0;39m"; ;; some ) printf_font_outline="printf \\033[1m"; printf_font_success="printf \\033[0m"; printf_font_failure="printf \\033[1m"; printf_font_warning="printf \\033[1m"; printf_font_default="printf \\033[0m"; ;; none ) printf_font_outline=""; printf_font_success=""; printf_font_failure=""; printf_font_warning=""; printf_font_default=""; ;; * ) abort "unknown color mode \`$1'"; ;; esac; } # Prints formated text in outline font. printf_outline() { $printf_font_outline; printf "$@"; $printf_font_default; } # Prints formated text in success font. printf_success() { $printf_font_success; printf "$@"; $printf_font_default; } # Prints formated text in failure font. printf_failure() { $printf_font_failure; printf "$@"; $printf_font_default; } # Prints formated text in warning font. printf_warning() { $printf_font_warning; printf "$@"; $printf_font_default; } ############################################################################## # File name and path list conversion functions # Prints the OS-specific form of the specified Unix form file name. get_os_filename() { [ $# = 1 ] || abort "internal error"; case "$UNAME" in CYGWIN* ) cygpath --windows "$1";; * ) echo "$@";; esac; } # Prints the Unix form of the specified OS-specific form file name. get_unix_filename() { [ $# = 1 ] || abort "internal error"; case "$UNAME" in CYGWIN* ) cygpath --unix "$1";; * ) echo "$@";; esac; } # Prints the OS-specific form of the specified Unix form path list. get_os_pathlist() { [ $# = 1 ] || abort "internal error"; case "$UNAME" in CYGWIN* ) cygpath --window --path "$1";; * ) echo "$@";; esac; } # Prints the Unix form of the specified OS-specific form path list. get_unix_pathlist() { [ $# = 1 ] || abort "internal error"; case "$UNAME" in CYGWIN* ) cygpath --unix --path "$1";; * ) echo "$@";; esac; } ############################################################################## # Path list construction functions # Prints the concatenation of two path lists. append_pathlists() { [ $# = 2 ] || abort "internal error"; if [ -z "$1" ]; then echo "$2"; elif [ -z "$2" ]; then echo "$1"; else echo "$1:$2"; fi; } ############################################################################## # Value computation functions # Computes and stores the value "$1" in the variable "current_$1". If # the variable "SCALA_$1" is defined, its content is used. Otherwise, # the content of the variable "default_$1" is used. compute_value() { [ $# = 1 ] || abort "internal error"; eval current_$1=\"\$default_$1\"; case "$1" in LIBRARY_SOURCES | \ LIBRARY_CLASSES | \ TOOLS_CLASSES | \ NLIBRARY_CLASSES | \ NTOOLS_CLASSES | \ FJBG_CLASSES | \ MSIL_CLASSES ) if eval [ -n \"\$SCALA_$1\" ]; then if eval [ -f \"\$SCALA_$1\" -o -d \"\$SCALA_$1\" ]; then eval current_$1=\"\$SCALA_$1\"; else eval warning \""File referred by SCALA_$1 (\$SCALA_$1)" \ "does not exist, using default value instead."\"; unset SCALA_$1; fi; fi; if eval [ -f \"\$current_$1\" -o -d \"\$current_$1\" ]; then :; else eval abort \""File referred by default_$1 (\$default_$1)" \ "does not exist. Please, fix definition of default_$1 in" \ "file $SOURCE or define environment variable SCALA_$1."\"; fi; ;; JAVA_CMD | \ JAVA_ARGS | \ SCALA_CMD | \ SCALA_ARGS | \ EXEC ) if eval [ -n \"\$SCALA_$1\" ]; then eval current_$1=\"\$SCALA_$1\"; fi; ;; * ) abort "internal error: $1"; ;; esac; } ############################################################################## # Default paths # Prints the default scala classpath or nothing if it's unspecified. get_scala_classpath() { if [ -n "$SCALA_CLASSPATH" ]; then get_unix_pathlist "$SCALA_CLASSPATH"; elif [ -n "$CLASSPATH" ]; then get_unix_pathlist "$CLASSPATH"; fi; } # Prints the default scala sourcepath or nothing if it's unspecified. get_scala_sourcepath() { if [ -n "$SCALA_SOURCEPATH" ]; then get_unix_pathlist "$SCALA_SOURCEPATH"; fi; } # Prints the default scala bootclasspath or nothing if it's unspecified. get_scala_bootclasspath() { if [ -n "$SCALA_BOOTCLASSPATH" ]; then get_unix_pathlist "$SCALA_BOOTCLASSPATH"; fi; } # Prints the default scala extdirs or nothing if it's unspecified. get_scala_extdirs() { if [ -n "$SCALA_EXTDIRS" ]; then get_unix_pathlist "$SCALA_EXTDIRS"; fi; } ############################################################################## # VM invocation functions # Prints the VM script-suffix-specific arguments. vm_get_script_suffix_args() { case "$SCRIPT" in *-debug* ) echo "-Djava.compiler=NONE -ea";; esac; } # Starts a Java VM with the specified arguments. vm_start_java() { # compute values compute_value EXEC; compute_value JAVA_CMD; compute_value JAVA_ARGS; # start Java VM $current_EXEC $current_JAVA_CMD $current_JAVA_ARGS \ `vm_get_script_suffix_args` "$@"; } # Starts a Scala VM with the specified arguments. vm_start_scala() { # compute values compute_value EXEC; compute_value SCALA_CMD; compute_value SCALA_ARGS; # start Java VM $current_EXEC $current_SCALA_CMD $current_SCALA_ARGS \ `vm_get_script_suffix_args` "$@"; } ############################################################################## # Scala invocation functions # Returns true if the given arguments contain a flag -Xbootclasspath. scala_has_bootclasspath() { while [ $# != 0 ]; do case "$1" in -Xbootclasspath:* ) return 0;; -cp | -classpath ) shift 1; [ $# != 0 ] && shift 1;; -jar ) return 1;; -* ) shift 1;; * ) return 1;; esac; done; return 1; } # Implements "scala [