Only set application specific environment variables if this is being launched by 1.5 or later and the existing environment can be passed on as well

This commit is contained in:
Charlie Groves
2009-02-23 22:39:58 +00:00
parent 81e4a792fd
commit 4018636aa1
@@ -23,6 +23,8 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.threerings.getdown.data; package com.threerings.getdown.data;
import static com.threerings.getdown.Log.log;
import java.awt.Color; import java.awt.Color;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -54,6 +56,7 @@ 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 java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -75,8 +78,6 @@ import com.threerings.getdown.util.LaunchUtil;
import com.threerings.getdown.util.MetaProgressObserver; import com.threerings.getdown.util.MetaProgressObserver;
import com.threerings.getdown.util.ProgressObserver; import com.threerings.getdown.util.ProgressObserver;
import static com.threerings.getdown.Log.log;
/** /**
* Parses and provide access to the information contained in the <code>getdown.txt</code> * Parses and provide access to the information contained in the <code>getdown.txt</code>
* configuration file. * configuration file.
@@ -767,25 +768,50 @@ public class Application
args.add(processArg(string)); args.add(processArg(string));
} }
String[] envp = createEnvironment ();
String[] sargs = new String[args.size()]; String[] sargs = new String[args.size()];
args.toArray(sargs); args.toArray(sargs);
log.info("Running " + StringUtil.join(sargs, "\n "));
return Runtime.getRuntime().exec(sargs, envp);
}
// Look for environmental variables. Pass through envp as null if no environmental /**
// variables were specified so we keep the current environment * If the application provided environment variables, combine those with the current
String[] envp = null; * environment and return that in a style usable for {@link Runtime#exec(String, String[])}.
* If the application didn't provide any environment variables, null is returned to just use
* the existing environment. If the application provided environment variables and this is
* running on Java 1.4 which can't find the existing environment, null is returned so the
* existing environment is used and things have a chance of running.
*/
protected String[] createEnvironment ()
{
List<String> envvar = new ArrayList<String>(); List<String> envvar = new ArrayList<String>();
fillAssignmentListFromPairs("environment.txt", envvar); fillAssignmentListFromPairs("environment.txt", envvar);
if (envvar.size() > 0) { if (envvar.isEmpty()) {
envp = new String[envvar.size()]; log.info("Didn't find any custom environment variables, not setting any.");
for (int ii = 0; ii < envp.length; ii++) { return null;
envp[ii] = processArg(envvar.get(ii));
}
log.info("Environment " + StringUtil.join(envp, "\n "));
} }
Map<String, String> existing;
log.info("Running " + StringUtil.join(sargs, "\n ")); try {
return Runtime.getRuntime().exec(sargs, envp); existing = System.getenv();
} catch (NoSuchMethodError nsme) {
log.warning("Unable to access the existing environment, most likely due to being on "
+ "Java 1.4. Not setting application specific environment.", "applicationEnv",
envvar, nsme);
return null;
}
List<String> envAssignments = new ArrayList<String>();
for (String assignment : envvar) {
envAssignments.add(processArg(assignment));
}
for (Entry<String, String> environmentEntry : existing.entrySet()) {
envAssignments.add(environmentEntry.getKey() + "=" + environmentEntry.getValue());
}
String[] envp = envAssignments.toArray(new String[envAssignments.size()]);
log.info("Environment " + StringUtil.join(envp, "\n "));
return envp;
} }
/** /**