Skip to content

Commit

Permalink
MONDRIAN: fix for CM-88, CM-102, contributed by Mat Lowery:
Browse files Browse the repository at this point in the history
Made changes to bat and sh files so that:
       * use a common set of steps to find a suitable java launcher
       * can be lauched from outside of their home folder
       * can be launched from folders with spaces
       * are compatible with solaris (use of backquotes instead of dollar parathesis)

[git-p4: depot-paths = "//open/mondrian/": change = 13042]
  • Loading branch information
Will Gorman committed Sep 15, 2009
1 parent 9c003d0 commit 0b45c8c
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 7 deletions.
81 changes: 81 additions & 0 deletions workbench/set-pentaho-java.bat
@@ -0,0 +1,81 @@
rem ---------------------------------------------------------------------------
rem Finds a suitable Java
rem
rem Looks in well-known locations to find a suitable Java then sets two
rem environment variables for use in other bat files. The two environment
rem variables are:
rem
rem * _PENTAHO_JAVA_HOME - absolute path to Java home
rem * _PENTAHO_JAVA - absolute path to Java launcher (e.g. java.exe)
rem
rem The order of the search is as follows:
rem
rem 1. environment variable PENTAHO_JAVA_HOME - path to Java home
rem 2. environment variable JAVA_HOME - path to Java home
rem 3. environment variable JRE_HOME - path to Java home
rem 4. argument #1 - path to Java home
rem
rem If a suitable Java is found at one of these locations, then
rem _PENTAHO_JAVA_HOME is set to that location and _PENTAHO_JAVA is set to the
rem absolute path of the Java launcher at that location. If none of these
rem locations are suitable, then _PENTAHO_JAVA_HOME is set to empty string and
rem _PENTAHO_JAVA is set to java.exe.
rem
rem Finally, there is one final optional environment variable: PENTAHO_JAVA.
rem If set, this value is used in the construction of _PENTAHO_JAVA. If not
rem set, then the value java.exe is used.
rem ---------------------------------------------------------------------------

if not "%PENTAHO_JAVA%" == "" goto gotPentahoJava
set __LAUNCHER=java.exe
goto checkPentahoJavaHome

:gotPentahoJava
set __LAUNCHER=%PENTAHO_JAVA%
goto checkPentahoJavaHome

:checkPentahoJavaHome
if not "%PENTAHO_JAVA_HOME%" == "" goto gotPentahoJavaHome
if not "%JAVA_HOME%" == "" goto gotJdkHome
if not "%JRE_HOME%" == "" goto gotJreHome
goto tryValueFromCaller

:gotPentahoJavaHome
echo DEBUG: Using PENTAHO_JAVA_HOME
set _PENTAHO_JAVA_HOME=%PENTAHO_JAVA_HOME%
set _PENTAHO_JAVA=%_PENTAHO_JAVA_HOME%\bin\%__LAUNCHER%
goto end

:gotJdkHome
echo DEBUG: Using JAVA_HOME
set _PENTAHO_JAVA_HOME=%JAVA_HOME%
set _PENTAHO_JAVA=%_PENTAHO_JAVA_HOME%\bin\%__LAUNCHER%
goto end

:gotJreHome
echo DEBUG: Using JRE_HOME
set _PENTAHO_JAVA_HOME=%JRE_HOME%
set _PENTAHO_JAVA=%_PENTAHO_JAVA_HOME%\bin\%__LAUNCHER%
goto end

:tryValueFromCaller
if not !%1!==!! goto gotValueFromCaller
goto :gotPath

:gotValueFromCaller
echo DEBUG: Using value (%~1) from calling script
set _PENTAHO_JAVA_HOME=%~1
set _PENTAHO_JAVA=%_PENTAHO_JAVA_HOME%\bin\%__LAUNCHER%
goto end

:gotPath
echo WARNING: Using java from path
set _PENTAHO_JAVA_HOME=
set _PENTAHO_JAVA=%__LAUNCHER%

goto end

:end

echo DEBUG: _PENTAHO_JAVA_HOME=%_PENTAHO_JAVA_HOME%
echo DEBUG: _PENTAHO_JAVA=%_PENTAHO_JAVA%
59 changes: 59 additions & 0 deletions workbench/set-pentaho-java.sh
@@ -0,0 +1,59 @@
#!/bin/sh
# -----------------------------------------------------------------------------
# Finds a suitable Java
#
# Looks in well-known locations to find a suitable Java then sets two
# environment variables for use in other script files. The two environment
# variables are:
#
# * _PENTAHO_JAVA_HOME - absolute path to Java home
# * _PENTAHO_JAVA - absolute path to Java launcher (e.g. java)
#
# The order of the search is as follows:
#
# 1. environment variable PENTAHO_JAVA_HOME - path to Java home
# 2. environment variable JAVA_HOME - path to Java home
# 3. environment variable JRE_HOME - path to Java home
# 4. argument #1 - path to Java home
#
# If a suitable Java is found at one of these locations, then
# _PENTAHO_JAVA_HOME is set to that location and _PENTAHO_JAVA is set to the
# absolute path of the Java launcher at that location. If none of these
# locations are suitable, then _PENTAHO_JAVA_HOME is set to empty string and
# _PENTAHO_JAVA is set to java.
#
# Finally, there is one final optional environment variable: PENTAHO_JAVA.
# If set, this value is used in the construction of _PENTAHO_JAVA. If not
# set, then the value java is used.
# -----------------------------------------------------------------------------

setPentahoJava() {
if [ -n "$PENTAHO_JAVA" ]; then
__LAUNCHER="$PENTAHO_JAVA"
else
__LAUNCHER="java"
fi
if [ -n "$PENTAHO_JAVA_HOME" ]; then
echo "DEBUG: Using PENTAHO_JAVA_HOME"
_PENTAHO_JAVA_HOME="$PENTAHO_JAVA_HOME"
_PENTAHO_JAVA="$_PENTAHO_JAVA_HOME"/bin/$__LAUNCHER
elif [ -n "$JAVA_HOME" ]; then
echo "DEBUG: Using JAVA_HOME"
_PENTAHO_JAVA_HOME="$JAVA_HOME"
_PENTAHO_JAVA="$_PENTAHO_JAVA_HOME"/bin/$__LAUNCHER
elif [ -n "$JRE_HOME" ]; then
echo "DEBUG: Using JRE_HOME"
_PENTAHO_JAVA_HOME="$JRE_HOME"
_PENTAHO_JAVA="$_PENTAHO_JAVA_HOME"/bin/$__LAUNCHER
elif [ -n "$1" ] && [ -x "$1"/bin/$__LAUNCHER ]; then
echo "DEBUG: Using value ($1) from calling script"
_PENTAHO_JAVA_HOME="$1"
_PENTAHO_JAVA="$_PENTAHO_JAVA_HOME"/bin/$__LAUNCHER
else
echo "WARNING: Using java from path"
_PENTAHO_JAVA_HOME=
_PENTAHO_JAVA=$__LAUNCHER
fi
echo "DEBUG: _PENTAHO_JAVA_HOME=$_PENTAHO_JAVA_HOME"
echo "DEBUG: _PENTAHO_JAVA=$_PENTAHO_JAVA"
}
5 changes: 4 additions & 1 deletion workbench/workbench.bat
Expand Up @@ -49,6 +49,9 @@ rem add all needed plugin jars to the classpath

for %%i in ("plugins\*.jar") do call cpappend %%i

java -Xms100m -Xmx500m -cp "%CP%" -Dlog4j.configuration=file:///%ROOT%\.schemaWorkbench\log4j.xml mondrian.gui.Workbench
set PENTAHO_JAVA=java
call "%~dp0set-pentaho-java.bat"

"%_PENTAHO_JAVA%" -Xms100m -Xmx500m -cp "%CP%" -Dlog4j.configuration=file:///%ROOT%\.schemaWorkbench\log4j.xml mondrian.gui.Workbench

rem End workbench.bat
15 changes: 9 additions & 6 deletions workbench/workbench.sh
Expand Up @@ -7,14 +7,14 @@
# first look in directory of the script for lib, then
# look up one folder if lib does not exist

MONDRIAN_HOME=$(cd $(dirname $0); pwd)
if test ! -d $MONDRIAN_HOME/lib; then
MONDRIAN_HOME=$(cd $(dirname $0)/..; pwd)
MONDRIAN_HOME=`cd \`dirname $0\`; pwd`
if test ! -d "$MONDRIAN_HOME/lib"; then
MONDRIAN_HOME="`cd \`dirname $0\`/..; pwd`"
fi
case $(uname) in
case `uname` in
Windows_NT|CYGWIN*)
export PS=";"
export MONDRIAN_HOME=$(cygpath -m $MONDRIAN_HOME)
export MONDRIAN_HOME=`cygpath -m $MONDRIAN_HOME`
;;
*)
export PS=":"
Expand Down Expand Up @@ -78,6 +78,9 @@ done
JAVA_FLAGS="-Xms100m -Xmx500m"
#JAVA_FLAGS="-verbose $JAVA_FLAGS"

exec java $JAVA_FLAGS -cp "$CP" mondrian.gui.Workbench
. "$MONDRIAN_HOME/set-pentaho-java.sh"
setPentahoJava

exec "$_PENTAHO_JAVA" $JAVA_FLAGS -cp "$CP" mondrian.gui.Workbench

# End workbench.sh

0 comments on commit 0b45c8c

Please sign in to comment.