From 82e97bef11565de30b1e3f6342cb2d5a70359b3e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 3 Aug 2004 03:29:58 +0000 Subject: [PATCH] Refactored some things to allow us to use them in externally. --- .../threerings/getdown/data/Application.java | 18 ++----- .../threerings/getdown/launcher/Getdown.java | 15 +++--- .../threerings/getdown/util/LaunchUtil.java | 48 +++++++++++++++++++ 3 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/java/com/threerings/getdown/util/LaunchUtil.java diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 85b4389..b5729b4 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -1,5 +1,5 @@ // -// $Id: Application.java,v 1.27 2004/08/03 00:10:34 mdb Exp $ +// $Id: Application.java,v 1.28 2004/08/03 03:29:58 mdb Exp $ package com.threerings.getdown.data; @@ -33,6 +33,7 @@ import org.apache.commons.io.CopyUtils; import com.threerings.getdown.Log; import com.threerings.getdown.util.ConfigUtil; +import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.MetaProgressObserver; import com.threerings.getdown.util.ProgressObserver; @@ -379,20 +380,7 @@ public class Application int idx = 0; // reconstruct the path to the JVM - String apbase = System.getProperty("java.home") + - File.separator + "bin" + File.separator; - String apath = apbase + "java"; - if (!new File(apath).exists()) { - apath = apbase + "javaw.exe"; - if (!new File(apath).exists()) { - apath = apbase + "java.exe"; - if (!new File(apath).exists()) { - Log.warning("Unable to find java! [jhome=" + apbase + "]."); - apath = apbase + "java"; - } - } - } - args[idx++] = apath; + args[idx++] = LaunchUtil.getJVMPath(); // add the classpath arguments args[idx++] = "-classpath"; diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 565a81e..a0581c6 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -1,5 +1,5 @@ // -// $Id: Getdown.java,v 1.32 2004/08/02 20:07:33 mdb Exp $ +// $Id: Getdown.java,v 1.33 2004/08/03 03:29:58 mdb Exp $ package com.threerings.getdown.launcher; @@ -45,6 +45,7 @@ import com.threerings.getdown.data.Application; import com.threerings.getdown.data.Resource; import com.threerings.getdown.tools.Patcher; import com.threerings.getdown.util.ConfigUtil; +import com.threerings.getdown.util.LaunchUtil; import com.threerings.getdown.util.ProgressObserver; /** @@ -462,19 +463,17 @@ public class Getdown extends Thread try { Process proc = _app.createProcess(); - // on Windows 98 we need to stick around and read the output - // of stdout lest the process fills its output buffer and - // chokes, yay! - String osname = System.getProperty("os.name").toLowerCase(); - if (osname.indexOf("windows 98") != -1 || - osname.indexOf("windows me") != -1) { + // on Windows 98 and ME we need to stick around and read the + // output of stderr lest the process fill its output buffer + // and choke, yay! + if (LaunchUtil.mustMonitorChildren()) { // close our window if it's around if (_frame != null) { _frame.dispose(); _status = null; _frame = null; } - Log.info("Sticking around to read stderr on " + osname + "..."); + Log.info("Sticking around to read stderr..."); InputStream stderr = proc.getErrorStream(); BufferedReader reader = new BufferedReader( new InputStreamReader(stderr)); diff --git a/src/java/com/threerings/getdown/util/LaunchUtil.java b/src/java/com/threerings/getdown/util/LaunchUtil.java new file mode 100644 index 0000000..0efde85 --- /dev/null +++ b/src/java/com/threerings/getdown/util/LaunchUtil.java @@ -0,0 +1,48 @@ +// +// $Id: LaunchUtil.java,v 1.1 2004/08/03 03:29:58 mdb Exp $ + +package com.threerings.getdown.util; + +import java.io.File; + +import com.threerings.getdown.Log; + +/** + * Useful routines for launching Java applications from within other Java + * applications. + */ +public class LaunchUtil +{ + /** + * Reconstructs the path to the JVM used to launch this process. + */ + public static String getJVMPath () + { + String apbase = System.getProperty("java.home") + + File.separator + "bin" + File.separator; + String apath = apbase + "java"; + if (!new File(apath).exists()) { + apath = apbase + "javaw.exe"; + if (!new File(apath).exists()) { + apath = apbase + "java.exe"; + if (!new File(apath).exists()) { + Log.warning("Unable to find java! [jhome=" + apbase + "]."); + apath = apbase + "java"; + } + } + } + return apath; + } + + /** + * Returns true if, on this operating system, we have to stick around + * and read the stderr from our children processes to prevent them + * from filling their output buffers and hanging. + */ + public static boolean mustMonitorChildren () + { + String osname = System.getProperty("os.name").toLowerCase(); + return (osname.indexOf("windows 98") != -1 || + osname.indexOf("windows me") != -1); + } +}