# HG changeset patch # User Jie Kang # Date 1482265811 18000 # Node ID f04119b95df6ce1150c8606524858dfa000375f3 # Parent 83ded2b9af311ebcf30d38b8e92ddef4050185f4 Allow for custom JAVA_HOME when Thermostat runs. Backport of: http://icedtea.classpath.org/hg/thermostat/rev/598461e53926 PR3238 Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-December/021885.html diff -r 83ded2b9af31 -r f04119b95df6 distribution/config/thermostatrc --- a/distribution/config/thermostatrc Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/config/thermostatrc Tue Dec 20 15:30:11 2016 -0500 @@ -47,7 +47,7 @@ # Extra jar files which need to be on the classpath when # Thermostat boots. # -THERMOSTAT_EXT_BOOT_CLASSPATH="@java.home@/../lib/tools.jar" +THERMOSTAT_EXT_BOOT_CLASSPATH="${JAVA_HOME}/lib/tools.jar" # FIXME: Remove once jfreechart is a real OSGi bundle upstream THERMOSTAT_EXT_BOOT_CLASSPATH="${THERMOSTAT_EXT_BOOT_CLASSPATH}:${THERMOSTAT_HOME}/libs/jfreechart-@jfreechart.version@.jar" THERMOSTAT_EXT_BOOT_CLASSPATH="${THERMOSTAT_EXT_BOOT_CLASSPATH}:${THERMOSTAT_HOME}/libs/jcommon-@jcommon.version@.jar" @@ -65,4 +65,4 @@ # Extra options passed on to the Thermostat main class # #THERMOSTAT_EXT_OPTS="--ignore-bundle-versions" -#export THERMOSTAT_EXT_OPTS +#export THERMOSTAT_EXT_OPTS \ No newline at end of file diff -r 83ded2b9af31 -r f04119b95df6 distribution/packaging/fedora/fedora-thermostatrc --- a/distribution/packaging/fedora/fedora-thermostatrc Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/packaging/fedora/fedora-thermostatrc Tue Dec 20 15:30:11 2016 -0500 @@ -44,10 +44,15 @@ ##################################################################### # +# Use a different JDK for running thermostat +# +#JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk + +# # Extra jar files which need to be on the classpath when # Thermostat boots. # -THERMOSTAT_EXT_BOOT_CLASSPATH="__TOOLS_PATH__" +THERMOSTAT_EXT_BOOT_CLASSPATH="${JAVA_HOME}/lib/tools.jar" THERMOSTAT_EXT_BOOT_CLASSPATH="${THERMOSTAT_EXT_BOOT_CLASSPATH}:${THERMOSTAT_HOME}/plugins/embedded-web-endpoint/jetty-schemas-3.1.M0.jar" export THERMOSTAT_EXT_BOOT_CLASSPATH diff -r 83ded2b9af31 -r f04119b95df6 distribution/packaging/fedora/thermostat.spec --- a/distribution/packaging/fedora/thermostat.spec Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/packaging/fedora/thermostat.spec Tue Dec 20 15:30:11 2016 -0500 @@ -468,6 +468,8 @@ %patch1 -p1 %patch2 -p1 +# Replace thermostatrc with Fedora's version +cp %{SOURCE4} distribution/config/thermostatrc # Fix up artifact names which have different name upstream # lucene @@ -645,6 +647,7 @@ # install javadoc:aggregate # Everything after '--' is passed to plain xmvn/mvn %mvn_build -f -- -Dthermostat.home=%{thermostat_home} \ + -Dthermostat.jdk.home=%{jdk_base} \ -Dthermostat.system.user=thermostat \ -Dthermostat.system.group=thermostat \ -Dthermostat.desktop.app.name=%{thermostat_desktop_app_name} \ @@ -672,18 +675,6 @@ -Djetty.javax.servlet.osgi.version=%{javax_servlet_bundle_version} \ -Djavax.servlet.bsn=%{javax_servlet_bsn} \ -Djetty.version=%{jetty_version} - -# Make path to java so that it keeps working after updates. -# We require java >= 1.7.0 -sed -i 's|^JAVA=.*|JAVA="%{jdk_base}/bin/java"|' distribution/target/image/bin/thermostat-agent-proxy -sed -i 's|^JAVA=.*|JAVA="%{jdk_base}/bin/java"|' distribution/target/image/bin/thermostat-webservice -sed -i 's|^JAVA=.*|JAVA="%{jdk_base}/bin/java"|' distribution/target/image/bin/thermostat-command-channel -sed -i 's|^JAVA=.*|JAVA="%{jdk_base}/bin/java"|' distribution/target/image/bin/thermostat -# Fix path to tools.jar, replace system thermostatrc -sed 's|__TOOLS_PATH__|%{jdk_base}/lib/tools.jar|' %{SOURCE4} > distribution/target/image/etc/thermostatrc -sed -i 's|^TOOLS_JAR=.*|TOOLS_JAR="%{jdk_base}/lib/tools.jar"|' distribution/target/image/bin/thermostat-agent-proxy -sed -i 's|^TOOLS_JAR=.*|TOOLS_JAR="%{jdk_base}/lib/tools.jar"|' distribution/target/image/bin/thermostat-command-channel -sed -i 's|^TOOLS_JAR=.*|TOOLS_JAR="%{jdk_base}/lib/tools.jar"|' distribution/target/image/bin/thermostat %{?scl:EOF} @@ -949,15 +940,10 @@ %{?scl:EOF} %check -# Perform some sanity checks on paths to JAVA/TOOLS_JAR -# in important boot scripts. See RHBZ#1052992 and -# RHBZ#1053123 -TOOLS_JAR="$(grep -E THERMOSTAT_EXT_BOOT_CLASSPATH='.*tools.jar' %{buildroot}/%{_sysconfdir}/%{pkg_name}/thermostatrc | cut -d= -f2 | cut -d\" -f2)" -test "${TOOLS_JAR}" = "%{jdk_base}/lib/tools.jar" -TOOLS_JAR="$(grep 'TOOLS_JAR=' %{buildroot}/%{thermostat_home}/bin/thermostat-agent-proxy | cut -d= -f2 | cut -d\" -f2)" -test "${TOOLS_JAR}" = "%{jdk_base}/lib/tools.jar" -JAVA="$(grep 'JAVA=' %{buildroot}/%{thermostat_home}/bin/thermostat | cut -d= -f2 | cut -d\" -f2)" -test "${JAVA}" = "%{jdk_base}/bin/java" +# Perform a sanity check so as to ensure that JAVA_HOME will point to a +# stable path (across OpenJDK package updates). +JDK_HOME_CANDIDATE=$(grep 'jdk_home_candidate=' %{buildroot}/%{thermostat_home}/bin/thermostat-common | cut -d= -f2 | cut -d\" -f2) +test "${JDK_HOME_CANDIDATE}" = "%{jdk_base}" %pre %{?scl: diff -r 83ded2b9af31 -r f04119b95df6 distribution/scripts/thermostat --- a/distribution/scripts/thermostat Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/scripts/thermostat Tue Dec 20 15:30:11 2016 -0500 @@ -39,13 +39,6 @@ # Source thermostat-common from same directory as this script . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-common -# Source system thermostat profile -. ${THERMOSTAT_HOME}/etc/thermostatrc -# Source user thermostat profile (if any) -if [ -f ${USER_THERMOSTAT_HOME}/etc/thermostatrc ]; then - . ${USER_THERMOSTAT_HOME}/etc/thermostatrc -fi - # NOTE: The following variables come from the system/user # profiles (if any) # @@ -65,7 +58,6 @@ BOOT_CLASSPATH="${BOOT_CLASSPATH}:${THERMOSTAT_EXT_BOOT_CLASSPATH}" fi - JLINE_LOG_ARG="-Djline.log.jul=true" function usage() { diff -r 83ded2b9af31 -r f04119b95df6 distribution/scripts/thermostat-agent-proxy --- a/distribution/scripts/thermostat-agent-proxy Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/scripts/thermostat-agent-proxy Tue Dec 20 15:30:11 2016 -0500 @@ -44,7 +44,7 @@ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/thermostat-common # Need tools from the JVM -TOOLS_JAR="@java.home@/../lib/tools.jar" +TOOLS_JAR="${JAVA_HOME}/lib/tools.jar" # JARs necessary for the server SERVICE_CLASSPATH="${THERMOSTAT_LIBS}/thermostat-common-core-@project.version@.jar" diff -r 83ded2b9af31 -r f04119b95df6 distribution/scripts/thermostat-command-channel --- a/distribution/scripts/thermostat-command-channel Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/scripts/thermostat-command-channel Tue Dec 20 15:30:11 2016 -0500 @@ -35,24 +35,20 @@ # to do so, delete this exception statement from your version. # ##################################################################### -# -# Some necessary variables. -JAVA_DIR="@java.dir@" -JAVA="@java.home@/bin/java" + +# Source thermostat-common from same directory as this script +CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +. "$CWD"/thermostat-common -if [ x"$THERMOSTAT_INSTALL_DIR" = x ] ; then - THERMOSTAT_INSTALL_DIR="@thermostat.home@" -fi -# Not always are installation directory and thermostat home one and -# the same location. -if [ x"$THERMOSTAT_HOME" = x ] ; then - THERMOSTAT_HOME=${THERMOSTAT_INSTALL_DIR} - export THERMOSTAT_HOME -fi -THERMOSTAT_LIBS="${THERMOSTAT_HOME}/libs" +# NOTE: The following variables come from the system/user +# profiles (if any) +# +# THERMOSTAT_EXT_BOOT_CLASSPATH +# THERMOSTAT_EXT_JAVA_OPTS +# THERMOSTAT_EXT_OPTS -# need tools from the JVM -TOOLS_JAR="@java.home@/../lib/tools.jar" +# Need tools from the JVM +TOOLS_JAR="${JAVA_HOME}/lib/tools.jar" # JARs necessary for the server BOOT_CLASSPATH="${THERMOSTAT_LIBS}/thermostat-common-core-@project.version@.jar" @@ -63,6 +59,12 @@ BOOT_CLASSPATH="${BOOT_CLASSPATH}:${THERMOSTAT_LIBS}/netty-@netty.version@.jar" BOOT_CLASSPATH="${TOOLS_JAR}:${BOOT_CLASSPATH}" +# Append extra class path entries coming from the profiles +if [ ! -z "${THERMOSTAT_EXT_BOOT_CLASSPATH}" ]; then + BOOT_CLASSPATH="${BOOT_CLASSPATH}:${THERMOSTAT_EXT_BOOT_CLASSPATH}" +fi + + # Duplicated in ThermostatVmMainLabelDecorator CMD_CHANNEL_CLASS="com.redhat.thermostat.agent.command.server.internal.CommandChannelServerMain" diff -r 83ded2b9af31 -r f04119b95df6 distribution/scripts/thermostat-common --- a/distribution/scripts/thermostat-common Tue Dec 20 15:28:47 2016 -0500 +++ b/distribution/scripts/thermostat-common Tue Dec 20 15:30:11 2016 -0500 @@ -67,5 +67,31 @@ THERMOSTAT_MAIN="com.redhat.thermostat.main.Thermostat" -JAVA="@java.home@/bin/java" +if [[ "${JAVA_HOME}" = "" ]]; then + jdk_home_candidate="@thermostat.jdk.home@" + if [[ -e "${jdk_home_candidate}/bin/javac" ]]; then + JAVA_HOME="${jdk_home_candidate}" + else + # Got likely a JRE, but thermostat expects a full JDK, try + # one level up and hope this will work. We check + # if JAVA_HOME is a valid value below. + JAVA_HOME="${jdk_home_candidate}/.." + fi +fi +# Source system thermostat profile +. ${THERMOSTAT_HOME}/etc/thermostatrc +# Source user thermostat profile (if any) +if [[ -f ${USER_THERMOSTAT_HOME}/etc/thermostatrc ]]; then + . ${USER_THERMOSTAT_HOME}/etc/thermostatrc +fi + +# Verify that JAVA_HOME is a real JDK +if [[ ! -e "${JAVA_HOME}/bin/javac" ]]; then + echo "JAVA_HOME does not seem to be a JDK. Thermostat needs a JDK to run." 1>&2 + echo "JAVA_HOME was set to '${JAVA_HOME}'" 1>&2 + exit 2 +fi + +JAVA="${JAVA_HOME}/bin/java" + diff -r 83ded2b9af31 -r f04119b95df6 pom.xml --- a/pom.xml Tue Dec 20 15:28:47 2016 -0500 +++ b/pom.xml Tue Dec 20 15:30:11 2016 -0500 @@ -134,6 +134,7 @@ UTF-8 target 1.7 + ${java.home} ${user.dir}/distribution/target/image/ $HOME/.thermostat-1.6