From 57abe2cac73187010d2fce0825ed003adb200def Mon Sep 17 00:00:00 2001 From: Julian Hyde Date: Wed, 7 Mar 2012 19:24:42 +0000 Subject: [PATCH] Update buildOnJdk.sh similar to those on mondrian. No longer need to edit the script in a build environment, provided that you set environment variables JAVA_HOME_xx. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@521 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- buildOnJdk.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/buildOnJdk.sh b/buildOnJdk.sh index e8a5b35..2c12f17 100755 --- a/buildOnJdk.sh +++ b/buildOnJdk.sh @@ -1,3 +1,4 @@ +#!/bin/bash # # $Id$ # @@ -30,17 +31,82 @@ jdkVersion=$1 shift -# If you are building olap4j for a single JDK (most likely the -# case), leave the following lines commented. +# Version number without jdk prefix. E.g. '1.6'. +versionSansJdk=`echo "${jdkVersion}" | sed 's/jdk\([0-9]\.[0-9]\)/\1/'` + +# Chooses a JAVA_HOME to match the required JDK version. +# +# If you are building olap4j for a single JDK (most likely the case), it +# doesn't matter if this method cannot find a valid JAVA_HOME for the JDK +# version. It will keep the existing JAVA_HOME, ant will report that the JDK +# version is not the one required, and will not compile any files. You will +# still end up with a valid build for all the classes needed by your JDK +# version. +# +# If you are building a release, you must compile different parts of olap4j's +# source code under different JDKs. You will need to do one of the following: +# +# 1. Specify environment variables JAVA_HOME_15, JAVA_HOME_16 and JAVA_HOME_17 +# before invoking 'ant'. +# +# 2. Install a JDK in (or create a symbolic link as) one of the standard +# locations: /usr/lib/jvm/jdk1.x on Linux/Unix/Cygwin; or +# /System/Library/Frameworks/JavaVM.framework/Versions/1.x/Home on MacOS. # -# If you are building a release, you will need to compile different -# parts of Mondrian's source code under different JDKs. Uncomment the -# following lines to ensure that JAVA_HOME is assigned correctly for -# each JDK version. +# 3. Customize this method with the correct JDK location. # -#case "$jdkVersion" in -#(*) export JAVA_HOME=/usr/lib/jvm/${jdkVersion};; -#esac +chooseJavaHome() { + # If JAVA_HOME_xx is specified in the environment, use it. + case "$jdkVersion" in + (jdk1.5) + if [ -d "$JAVA_HOME_15" ]; then + export JAVA_HOME="$JAVA_HOME_15" + return + fi + ;; + (jdk1.6) + if [ -d "$JAVA_HOME_16" ]; then + export JAVA_HOME="$JAVA_HOME_16" + return + fi + ;; + (jdk1.7) + if [ -d "$JAVA_HOME_17" ]; then + export JAVA_HOME="$JAVA_HOME_17" + return + fi + ;; + esac + + # 2. Look in default location based on the operating system and JDK + # version. If the directory exists, we presume that it is a valid JDK, and + # override JAVA_HOME. + defaultJavaHome= + case $(uname) in + (Darwin) + defaultJavaHome=/System/Library/Frameworks/JavaVM.framework/Versions/${versionSansJdk}/Home;; + (*) + defaultJavaHome=/usr/lib/jvm/${jdkVersion};; + esac + + if [ -d "$defaultJavaHome" ]; then + export JAVA_HOME="$defaultJavaHome" + return + fi + + # 3. If JDK is installed in a non-standard location, customize here. + # + #case ${jdkVersion} in + #(jdk1.5) export JAVA_HOME=...; return ;; + #(jdk1.6) export JAVA_HOME=...; return ;; + #(jdk1.7) export JAVA_HOME=...; return ;; + #esac + + # 4. Leave JAVA_HOME unchanged. If it does not match the required version, + # ant will no-op. +} + +chooseJavaHome if [ ! -d "$JAVA_HOME" ]; then echo "$0: Invalid JAVA_HOME $JAVA_HOME; skipping compile."