mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
11.15.2006 7926b4fde36b76848d123186eeea60a075984c44
Update the Java Web Start, GUI, and CLI setup modes to write a shell script or
batch file that can be used to set JAVA_HOME. Update all of the tools and
administrative scripts provided with OpenDS so that they will use this to set
JAVA_HOME unless it's already set in the user's environment.

OpenDS Issue Number: 1082
1 files deleted
1 files added
13 files modified
570 ■■■■■ changed files
opends/build.xml 4 ●●●● patch | view | raw | blame | history
opends/resource/bin/_client-script.bat 10 ●●●● patch | view | raw | blame | history
opends/resource/bin/_client-script.sh 39 ●●●●● patch | view | raw | blame | history
opends/resource/bin/_server-script.bat 11 ●●●● patch | view | raw | blame | history
opends/resource/bin/_server-script.sh 39 ●●●●● patch | view | raw | blame | history
opends/resource/bin/start-ds 39 ●●●●● patch | view | raw | blame | history
opends/resource/bin/start-ds.bat 10 ●●●● patch | view | raw | blame | history
opends/resource/bin/stop-ds 39 ●●●●● patch | view | raw | blame | history
opends/resource/setup.bat 4 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 4 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java 8 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java 8 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/InstallDS.java 32 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/CreateTemplate.java 119 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/SetupUtils.java 204 ●●●●● patch | view | raw | blame | history
opends/build.xml
@@ -319,7 +319,7 @@
    </copy>
    <copy todir="${quicksetup.classes.dir}">
      <fileset dir="${classes.dir}"
               includes="**/DynamicConstants.class **/CreateTemplate.class" />
               includes="**/DynamicConstants.class **/SetupUtils.class" />
    </copy>
  </target>
@@ -395,7 +395,7 @@
    <copy todir="${quicksetup.classes.dir}">
        <fileset dir="${classes.dir}"
            includes="**/DynamicConstants.class **/CreateTemplate.class"/>
            includes="**/DynamicConstants.class **/SetupUtils.class"/>
    </copy>
    <!-- Generate the quicksetup.jar file -->
opends/resource/bin/_client-script.bat
@@ -47,10 +47,16 @@
:noJavaBin
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_BIN="%JAVA_HOME%\bin\java.exe"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noJavaHome
if not exist "%DIR_HOME%\bin\set-java-home.bat" goto noSetJavaHome
call "%DIR_HOME%\bin\set-java-home.bat"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noSetJavaHome
echo Error: JAVA_HOME environment variable is not set.
echo        Please set it to a valid Java 5 installation.
goto end
@@ -61,7 +67,7 @@
set PATH=%SystemRoot%
%JAVA_BIN% %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% %*
"%JAVA_BIN%" %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% %*
:end
opends/resource/bin/_client-script.sh
@@ -35,12 +35,33 @@
fi
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# See if JAVA_HOME is set.  If not, then see if there is a java executable in
# the path and try to figure it out.
if test -z "${JAVA_BIN}"
then
  if test -z "${JAVA_HOME}"
  then
    if test -f "${INSTANCE_ROOT}/bin/set-java-home"
    then
      . "${INSTANCE_ROOT}/bin/set-java-home"
      JAVA_BIN="${JAVA_HOME}/bin/java"
      export JAVA_BIN
    else
    JAVA_BIN=`which java 2> /dev/null`
    if test ${?} -eq 0
    then
@@ -49,8 +70,9 @@
      echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
      exit 1
    fi
    fi
  else
    JAVA_BIN=${JAVA_HOME}/bin/java
    JAVA_BIN="${JAVA_HOME}/bin/java"
    export JAVA_BIN
  fi
fi
@@ -69,21 +91,6 @@
       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# Configure the appropriate CLASSPATH.
CLASSPATH=${INSTANCE_ROOT}/classes
for JAR in ${INSTANCE_ROOT}/lib/*.jar
opends/resource/bin/_server-script.bat
@@ -47,21 +47,26 @@
:noJavaBin
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_BIN="%JAVA_HOME%\bin\java.exe"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noJavaHome
if not exist "%DIR_HOME%\bin\set-java-home.bat" goto noSetJavaHome
call "%DIR_HOME%\bin\set-java-home.bat"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noSetJavaHome
echo Error: JAVA_HOME environment variable is not set.
echo        Please set it to a valid Java 5 installation.
goto end
:setClassPath
FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\bin\setcp.bat" %%x
set PATH=%SystemRoot%
%JAVA_BIN% %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
"%JAVA_BIN%" %JAVA_ARGS% %SCRIPT_NAME_ARG% %OPENDS_INVOKE_CLASS% --configClass org.opends.server.extensions.ConfigFileHandler --configFile "%DIR_HOME%\config\config.ldif" %*
:end
opends/resource/bin/_server-script.sh
@@ -35,12 +35,33 @@
fi
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# See if JAVA_HOME is set.  If not, then see if there is a java executable in
# the path and try to figure it out.
if test -z "${JAVA_BIN}"
then
  if test -z "${JAVA_HOME}"
  then
    if test -f "${INSTANCE_ROOT}/bin/set-java-home"
    then
      . "${INSTANCE_ROOT}/bin/set-java-home"
      JAVA_BIN="${JAVA_HOME}/bin/java"
      export JAVA_BIN
    else
    JAVA_BIN=`which java 2> /dev/null`
    if test ${?} -eq 0
    then
@@ -49,8 +70,9 @@
      echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
      exit 1
    fi
    fi
  else
    JAVA_BIN=${JAVA_HOME}/bin/java
    JAVA_BIN="${JAVA_HOME}/bin/java"
    export JAVA_BIN
  fi
fi
@@ -69,21 +91,6 @@
       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# Configure the appropriate CLASSPATH.
CLASSPATH=${INSTANCE_ROOT}/classes
for JAR in ${INSTANCE_ROOT}/lib/*.jar
opends/resource/bin/start-ds
@@ -26,12 +26,33 @@
#      Portions Copyright 2006 Sun Microsystems, Inc.
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# See if JAVA_HOME is set.  If not, then see if there is a java executable in
# the path and try to figure it out.
if test -z "${JAVA_BIN}"
then
  if test -z "${JAVA_HOME}"
  then
    if test -f "${INSTANCE_ROOT}/bin/set-java-home"
    then
      . "${INSTANCE_ROOT}/bin/set-java-home"
      JAVA_BIN="${JAVA_HOME}/bin/java"
      export JAVA_BIN
    else
    JAVA_BIN=`which java 2> /dev/null`
    if test ${?} -eq 0
    then
@@ -40,8 +61,9 @@
      echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
      exit 1
    fi
    fi
  else
    JAVA_BIN=${JAVA_HOME}/bin/java
    JAVA_BIN="${JAVA_HOME}/bin/java"
    export JAVA_BIN
  fi
fi
@@ -60,21 +82,6 @@
       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# Configure the appropriate CLASSPATH.
CLASSPATH=${INSTANCE_ROOT}/classes
for JAR in ${INSTANCE_ROOT}/lib/*.jar
opends/resource/bin/start-ds.bat
@@ -30,6 +30,7 @@
set DIR_HOME=%~dP0..
set INSTANCE_ROOT=%DIR_HOME%
:checkJavaBin
if "%JAVA_BIN%" == "" goto noJavaBin
goto setClassPath
@@ -40,17 +41,22 @@
goto setClassPath
:noJavaHome
if not exist "%DIR_HOME%\bin\set-java-home.bat" goto noSetJavaHome
call "%DIR_HOME%\bin\set-java-home.bat"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noSetJavaHome
echo Error: JAVA_HOME environment variable is not set.
echo        Please set it to a valid Java 5 installation.
goto end
:setClassPath
FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\bin\setcp.bat" %%x
set PATH=%SystemRoot%
set SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
set SCRIPT_NAME_ARG=-Dorg.opends.server.scriptName=start-ds
set NODETACH=0
for %%x in (%*) DO if "%%x" == "-N" set NODETACH=1
opends/resource/bin/stop-ds
@@ -35,12 +35,33 @@
# to stop the server using an LDAP request.
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# See if JAVA_HOME is set.  If not, then see if there is a java executable in
# the path and try to figure it out.
if test -z "${JAVA_BIN}"
then
  if test -z "${JAVA_HOME}"
  then
    if test -f "${INSTANCE_ROOT}/bin/set-java-home"
    then
      . "${INSTANCE_ROOT}/bin/set-java-home"
      JAVA_BIN="${JAVA_HOME}/bin/java"
      export JAVA_BIN
    else
    JAVA_BIN=`which java 2> /dev/null`
    if test ${?} -eq 0
    then
@@ -49,8 +70,9 @@
      echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
      exit 1
    fi
    fi
  else
    JAVA_BIN=${JAVA_HOME}/bin/java
    JAVA_BIN="${JAVA_HOME}/bin/java"
    export JAVA_BIN
  fi
fi
@@ -69,21 +91,6 @@
       LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
# Capture the current working directory so that we can change to it later.
# Then capture the location of this script and the Directory Server instance
# root so that we can use them to create appropriate paths.
WORKING_DIR=`pwd`
cd `dirname "${0}"`
SCRIPT_DIR=`pwd`
cd ..
INSTANCE_ROOT=`pwd`
export INSTANCE_ROOT
cd "${WORKING_DIR}"
# Configure the appropriate CLASSPATH.
CLASSPATH=${INSTANCE_ROOT}/classes
for JAR in ${INSTANCE_ROOT}/lib/*.jar
opends/resource/setup.bat
@@ -36,7 +36,7 @@
:noJavaBin
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_BIN="%JAVA_HOME%\bin\java.exe"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
:noJavaHome
echo Error: JAVA_HOME environment variable is not set.
@@ -49,7 +49,7 @@
set PATH=%SystemRoot%
%JAVA_BIN% %JAVA_ARGS% org.opends.quicksetup.SetupLauncher -P setup.bat %*
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.SetupLauncher -P setup.bat %*
:end
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -41,7 +41,7 @@
import org.opends.quicksetup.i18n.ResourceProvider;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.CreateTemplate;
import org.opends.server.util.SetupUtils;
/**
 * This is an abstract class that is in charge of actually performing the
@@ -391,7 +391,7 @@
  {
    try
    {
      return CreateTemplate.createTemplateFile(
      return SetupUtils.createTemplateFile(
                  getUserData().getDataOptions().getBaseDn(),
                  getUserData().getDataOptions().getNumberEntries());
    }
opends/src/quicksetup/org/opends/quicksetup/installer/offline/OfflineInstaller.java
@@ -38,6 +38,7 @@
import org.opends.quicksetup.installer.UserInstallData;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.SetupUtils;
/**
 * This is an implementation of the Installer class that is used to install
@@ -174,6 +175,13 @@
        break;
      }
      try
      {
        // This isn't likely to happen, and it's not a serious problem even if
        // it does.
        SetupUtils.writeSetJavaHome(FULL_INSTALL_PATH);
      } catch (Exception e) {}
      if (getUserData().getStartServer())
      {
        notifyListeners(getTaskSeparator());
opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
@@ -43,6 +43,7 @@
import org.opends.quicksetup.installer.UserInstallData;
import org.opends.quicksetup.util.ProgressMessageFormatter;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.SetupUtils;
/**
 * This is an implementation of the Installer class that is used to install
@@ -169,6 +170,13 @@
        break;
      }
      try
      {
        // This isn't likely to happen, and it's not a serious problem even if
        // it does.
        SetupUtils.writeSetJavaHome(getUserData().getServerLocation());
      } catch (Exception e) {}
      if (getUserData().getStartServer())
      {
        notifyListeners(getTaskSeparator());
opends/src/server/org/opends/server/tools/InstallDS.java
@@ -41,7 +41,7 @@
import org.opends.server.types.DN;
import org.opends.server.types.ExistingFileBehavior;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.util.CreateTemplate;
import org.opends.server.util.SetupUtils;
import org.opends.server.util.LDIFWriter;
import org.opends.server.util.PasswordReader;
import org.opends.server.util.args.ArgumentException;
@@ -81,7 +81,7 @@
  /**
   * Indicates whether we think we're running on a Windows system.
   */
  private static boolean isWindows = false;
  private static final boolean isWindows = SetupUtils.isWindows();
@@ -156,14 +156,6 @@
   */
  public static int installMain(String[] args)
  {
    // Determine whether we think we're running on Windows.
    String osName = System.getProperty("os.name");
    if ((osName != null) && (osName.toLowerCase().indexOf("windows") >= 0))
    {
      isWindows = true;
    }
    // Construct the product version string and the setup filename.
    versionString = DirectoryServer.getVersionString();
@@ -784,7 +776,7 @@
    {
      try
      {
        File templateFile = CreateTemplate.createTemplateFile(
        File templateFile = SetupUtils.createTemplateFile(
                                 baseDNs.getFirst().toString(), numUsers);
        if (ldifFiles == null)
        {
@@ -861,6 +853,24 @@
    }
    // Try to write a file that can be used to set the JAVA_HOME environment
    // variable for the administrative scripts and client tools provided with
    // the server.  If this fails, then it's not a big deal.
    try
    {
      String serverRoot = System.getenv("INSTANCE_ROOT");
      if ((serverRoot == null) || (serverRoot.length() == 0))
      {
        File f = new File(configFileName);
        serverRoot = f.getParentFile().getParentFile().getAbsolutePath();
      }
      // This isn't likely to happen, and it's not a serious problem even if it
      // does.
      SetupUtils.writeSetJavaHome(serverRoot);
    } catch (Exception e) {}
    // If we've gotten here, then everything seems to have gone smoothly.
    if (! silentInstall.isPresent())
    {
opends/src/server/org/opends/server/util/CreateTemplate.java
File was deleted
opends/src/server/org/opends/server/util/SetupUtils.java
New file
@@ -0,0 +1,204 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006 Sun Microsystems, Inc.
 */
package org.opends.server.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
/**
 * This class provides a number of utility methods that may be used during the
 * graphical or command-line setup process.
 */
public class SetupUtils
{
  /**
   * Creates a MakeLDIF template file using the provided information.
   *
   * @param  baseDN      The base DN for the data in the template file.
   * @param  numEntries  The number of user entries the template file should
   *                     create.
   *
   * @return  The {@code File} object that references the created template file.
   *
   * @throws  IOException  If a problem occurs while writing the template file.
   */
  public static File createTemplateFile(String baseDN, int numEntries)
         throws IOException
  {
    File templateFile = File.createTempFile("opends-install", ".template");
    templateFile.deleteOnExit();
    LinkedList<String> lines = new LinkedList<String>();
    lines.add("define suffix=" + baseDN);
    if (numEntries > 0)
    {
      lines.add("define numusers=" + numEntries);
    }
    lines.add("");
    lines.add("branch: [suffix]");
    lines.add("");
    lines.add("branch: ou=People,[suffix]");
    if (numEntries > 0)
    {
      lines.add("subordinateTemplate: person:[numusers]");
      lines.add("");
      lines.add("template: person");
      lines.add("rdnAttr: uid");
      lines.add("objectClass: top");
      lines.add("objectClass: person");
      lines.add("objectClass: organizationalPerson");
      lines.add("objectClass: inetOrgPerson");
      lines.add("givenName: <first>");
      lines.add("sn: <last>");
      lines.add("cn: {givenName} {sn}");
      lines.add("initials: {givenName:1}" +
                "<random:chars:ABCDEFGHIJKLMNOPQRSTUVWXYZ:1>{sn:1}");
      lines.add("employeeNumber: <sequential:0>");
      lines.add("uid: user.{employeeNumber}");
      lines.add("mail: {uid}@maildomain.net");
      lines.add("userPassword: password");
      lines.add("telephoneNumber: <random:telephone>");
      lines.add("homePhone: <random:telephone>");
      lines.add("pager: <random:telephone>");
      lines.add("mobile: <random:telephone>");
      lines.add("street: <random:numeric:5> <file:streets> Street");
      lines.add("l: <file:cities>");
      lines.add("st: <file:states>");
      lines.add("postalCode: <random:numeric:5>");
      lines.add("postalAddress: {cn}${street}${l}, {st}  {postalCode}");
      lines.add("description: This is the description for {cn}.");
    }
    BufferedWriter writer = new BufferedWriter(new FileWriter(templateFile));
    for (String line : lines)
    {
      writer.write(line);
      writer.newLine();
    }
    writer.flush();
    writer.close();
    return templateFile;
  }
  /**
   * Indicates whether the underlying operating system is a Windows variant.
   *
   * @return  {@code true} if the underlying operating system is a Windows
   *          variant, or {@code false} if not.
   */
  public static boolean isWindows()
  {
    String osName = System.getProperty("os.name");
    return ((osName != null) && (osName.toLowerCase().indexOf("windows") >= 0));
  }
  /**
   * Write a set-java-home file appropriate for the underlying platform that may
   * be used to set the JAVA_HOME environment variable in a form suitable for
   * the underlying operating system.  If a JAVA_HOME environment variable is
   * currently set, then its value will be used.  Otherwise, it will be
   * dynamically determined from the JVM properties.
   * <BR><BR>
   * Note that if the target file that would be written already exists, then
   * this method will exit without doing anything and leaving the existing file
   * intact.
   *
   *
   * @param  serverRoot  The path to the root of the Directory Server instance
   *                     for which the file will be written.
   *
   * @return  A handle to the {@code File} object that has been written.
   *
   * @throws  IOException  If a problem occurs while creating or writing to the
   *                       specified file.
   */
  public static File writeSetJavaHome(String serverRoot)
         throws IOException
  {
    String javaHome = System.getenv("JAVA_HOME");
    if ((javaHome == null) || (javaHome.length() == 0))
    {
      javaHome = System.getProperty("java.home");
    }
    File binDirectory = new File(serverRoot, "bin");
    File setJavaHomeFile;
    if (isWindows())
    {
      setJavaHomeFile = new File(binDirectory, "set-java-home.bat");
      if (setJavaHomeFile.exists())
      {
        return setJavaHomeFile;
      }
      BufferedWriter writer =
           new BufferedWriter(new FileWriter(setJavaHomeFile));
      writer.write("set JAVA_HOME=" + javaHome);
      writer.newLine();
      writer.close();
    }
    else
    {
      setJavaHomeFile = new File(binDirectory, "set-java-home");
      if (setJavaHomeFile.exists())
      {
        return setJavaHomeFile;
      }
      BufferedWriter writer =
           new BufferedWriter(new FileWriter(setJavaHomeFile));
      writer.write("#!/bin/sh");
      writer.newLine();
      writer.newLine();
      writer.write("JAVA_HOME=" + javaHome);
      writer.newLine();
      writer.write("export JAVA_HOME");
      writer.newLine();
      writer.close();
    }
    return setJavaHomeFile;
  }
}