System properties prefixed with "app." are passed through to the application

(with the prefix removed).
This commit is contained in:
Ray Greenwell
2005-03-17 20:42:37 +00:00
parent 08b7e9dbba
commit 01e0dafdd9
@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import com.samskivert.io.NestableIOException; import com.samskivert.io.NestableIOException;
import com.samskivert.io.StreamUtil; import com.samskivert.io.StreamUtil;
@@ -49,6 +50,10 @@ public class Application
/** The name of our target version file. */ /** The name of our target version file. */
public static final String VERSION_FILE = "version.txt"; public static final String VERSION_FILE = "version.txt";
/** System properties that are prefixed with this string will be
* passed through to our application (minus this prefix). */
public static final String PROP_PASSTHROUGH_PREFIX = "app.";
/** Used to communicate information about the UI displayed when /** Used to communicate information about the UI displayed when
* updating the application. */ * updating the application. */
public static class UpdateInterface public static class UpdateInterface
@@ -383,73 +388,66 @@ public class Application
cpbuf.append(rsrc.getLocal().getAbsolutePath()); cpbuf.append(rsrc.getLocal().getAbsolutePath());
} }
int exargs = 0; ArrayList args = new ArrayList();
// reconstruct the path to the JVM
args.add(LaunchUtil.getJVMPath());
// add the classpath arguments
args.add("-classpath");
args.add(cpbuf.toString());
// we love our Mac users, so we do nice things to preserve our // we love our Mac users, so we do nice things to preserve our
// application identity // application identity
if (RunAnywhere.isMacOS()) { if (RunAnywhere.isMacOS()) {
exargs += 2; args.add("-Xdock:icon=" + _appdir.getAbsolutePath() +
"/../desktop.icns");
args.add("-Xdock:name=" + _name);
} }
// pass along our proxy settings // pass along our proxy settings
String proxyHost, proxyPort = null; String proxyHost;
if ((proxyHost = System.getProperty("http.proxyHost")) != null) { if ((proxyHost = System.getProperty("http.proxyHost")) != null) {
exargs += 2; args.add("-Dhttp.proxyHost=" + proxyHost);
proxyPort = System.getProperty("http.proxyPort"); args.add("-Dhttp.proxyPort=" + System.getProperty("http.proxyPort"));
} }
// we'll need the JVM, classpath, JVM args, class name and app args // pass along any pass-through arguments
String[] args = new String[ for (Iterator itr = System.getProperties().entrySet().iterator();
4 + _jvmargs.size() + exargs + _appargs.size()]; itr.hasNext(); ) {
int idx = 0; Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
// reconstruct the path to the JVM if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) {
args[idx++] = LaunchUtil.getJVMPath(); key = key.substring(PROP_PASSTHROUGH_PREFIX.length());
args.add("-D" + key + "=" + entry.getValue());
// add the classpath arguments }
args[idx++] = "-classpath";
args[idx++] = cpbuf.toString();
// do our Mac identity business
if (RunAnywhere.isMacOS()) {
args[idx++] = "-Xdock:icon=" + _appdir.getAbsolutePath() +
"/../desktop.icns";
args[idx++] = "-Xdock:name=" + _name;
}
// if we have a proxy configuration, add those
if (proxyHost != null) {
args[idx++] = "-Dhttp.proxyHost=" + proxyHost;
args[idx++] = "-Dhttp.proxyPort=" + proxyPort;
} }
// add the JVM arguments // add the JVM arguments
for (Iterator iter = _jvmargs.iterator(); iter.hasNext(); ) { for (Iterator iter = _jvmargs.iterator(); iter.hasNext(); ) {
args[idx++] = processArg((String)iter.next()); args.add(processArg((String)iter.next()));
} }
// add the application class name // add the application class name
args[idx++] = _class; args.add(_class);
// finally add the application arguments // finally add the application arguments
for (Iterator iter = _appargs.iterator(); iter.hasNext(); ) { for (Iterator iter = _appargs.iterator(); iter.hasNext(); ) {
args[idx++] = processArg((String)iter.next()); args.add(processArg((String)iter.next()));
} }
Log.info("Running " + StringUtil.join(args, "\n ")); String[] sargs = new String[args.size()];
return Runtime.getRuntime().exec(args, null); args.toArray(sargs);
Log.info("Running " + StringUtil.join(sargs, "\n "));
return Runtime.getRuntime().exec(sargs, null);
} }
/** Replaces the application directory and version in any argument. */ /** Replaces the application directory and version in any argument. */
protected String processArg (String arg) protected String processArg (String arg)
{ {
if (arg.indexOf("%APPDIR%") != -1) { arg = StringUtil.replace(arg, "%APPDIR%", _appdir.getAbsolutePath());
arg = StringUtil.replace( arg = StringUtil.replace(arg, "%VERSION%", String.valueOf(_version));
arg, "%APPDIR%", _appdir.getAbsolutePath());
}
if (arg.indexOf("%VERSION%") != -1) {
arg = StringUtil.replace(arg, "%VERSION%", "" + _version);
}
return arg; return arg;
} }