Allow environmental variables for the launched application to be specified as pairs in
environment.txt from the app
This commit is contained in:
@@ -542,8 +542,8 @@ public class Application
|
|||||||
// transfer our JVM arguments
|
// transfer our JVM arguments
|
||||||
String[] jvmargs = ConfigUtil.getMultiValue(cdata, "jvmarg");
|
String[] jvmargs = ConfigUtil.getMultiValue(cdata, "jvmarg");
|
||||||
if (jvmargs != null) {
|
if (jvmargs != null) {
|
||||||
for (int ii = 0; ii < jvmargs.length; ii++) {
|
for (String jvmarg : jvmargs) {
|
||||||
_jvmargs.add(jvmargs[ii]);
|
_jvmargs.add(jvmarg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,24 +555,13 @@ public class Application
|
|||||||
// transfer our application arguments
|
// transfer our application arguments
|
||||||
String[] appargs = ConfigUtil.getMultiValue(cdata, prefix + "apparg");
|
String[] appargs = ConfigUtil.getMultiValue(cdata, prefix + "apparg");
|
||||||
if (appargs != null) {
|
if (appargs != null) {
|
||||||
for (int ii = 0; ii < appargs.length; ii++) {
|
for (String apparg : appargs) {
|
||||||
_appargs.add(appargs[ii]);
|
_appargs.add(apparg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for custom arguments
|
// look for custom arguments
|
||||||
File file = getLocalPath("extra.txt");
|
fillAssignmentListFromPairs("extra.txt", _jvmargs);
|
||||||
if (file.exists()) {
|
|
||||||
try {
|
|
||||||
List<String[]> args = ConfigUtil.parsePairs(file, false);
|
|
||||||
for (Iterator<String[]> iter = args.iterator(); iter.hasNext();) {
|
|
||||||
String[] pair = iter.next();
|
|
||||||
_jvmargs.add(pair[0] + "=" + pair[1]);
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
log.warning("Failed to parse '" + file + "': " + t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine whether or not we should be using bit torrent
|
// determine whether or not we should be using bit torrent
|
||||||
_useTorrent = (cdata.get("torrent") != null) || (System.getProperty("torrent") != null);
|
_useTorrent = (cdata.get("torrent") != null) || (System.getProperty("torrent") != null);
|
||||||
@@ -613,6 +602,24 @@ public class Application
|
|||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds strings of the form pair0=pair1 to collector for each pair parsed out of pairLocation.
|
||||||
|
*/
|
||||||
|
protected void fillAssignmentListFromPairs (String pairLocation, List<String> collector)
|
||||||
|
{
|
||||||
|
File pairFile = getLocalPath(pairLocation);
|
||||||
|
if (pairFile.exists()) {
|
||||||
|
try {
|
||||||
|
List<String[]> args = ConfigUtil.parsePairs(pairFile, false);
|
||||||
|
for (String[] pair : args) {
|
||||||
|
collector.add(pair[0] + "=" + pair[1]);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.warning("Failed to parse '" + pairFile + "': " + t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a URL from which the specified path can be fetched. Our application base URL is
|
* Returns a URL from which the specified path can be fetched. Our application base URL is
|
||||||
* properly versioned and combined with the supplied path.
|
* properly versioned and combined with the supplied path.
|
||||||
@@ -709,11 +716,10 @@ public class Application
|
|||||||
{
|
{
|
||||||
// create our classpath
|
// create our classpath
|
||||||
StringBuilder cpbuf = new StringBuilder();
|
StringBuilder cpbuf = new StringBuilder();
|
||||||
for (Iterator<Resource> iter = _codes.iterator(); iter.hasNext(); ) {
|
for (Resource rsrc : _codes) {
|
||||||
if (cpbuf.length() > 0) {
|
if (cpbuf.length() > 0) {
|
||||||
cpbuf.append(File.pathSeparator);
|
cpbuf.append(File.pathSeparator);
|
||||||
}
|
}
|
||||||
Resource rsrc = iter.next();
|
|
||||||
cpbuf.append(rsrc.getLocal().getAbsolutePath());
|
cpbuf.append(rsrc.getLocal().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,23 +755,37 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add the JVM arguments
|
// add the JVM arguments
|
||||||
for (Iterator<String> iter = _jvmargs.iterator(); iter.hasNext(); ) {
|
for (String string : _jvmargs) {
|
||||||
args.add(processArg(iter.next()));
|
args.add(processArg(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the application class name
|
// add the application class name
|
||||||
args.add(_class);
|
args.add(_class);
|
||||||
|
|
||||||
// finally add the application arguments
|
// finally add the application arguments
|
||||||
for (Iterator<String> iter = _appargs.iterator(); iter.hasNext(); ) {
|
for (String string : _appargs) {
|
||||||
args.add(processArg(iter.next()));
|
args.add(processArg(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] sargs = new String[args.size()];
|
String[] sargs = new String[args.size()];
|
||||||
args.toArray(sargs);
|
args.toArray(sargs);
|
||||||
|
|
||||||
|
|
||||||
|
// Look for environmental variables. Pass through envp as null if no environmental
|
||||||
|
// variables were specified so we keep the current environment
|
||||||
|
String[] envp = null;
|
||||||
|
List<String> envvar = new ArrayList<String>();
|
||||||
|
fillAssignmentListFromPairs("environment.txt", envvar);
|
||||||
|
if (envvar.size() > 0) {
|
||||||
|
envp = new String[envvar.size()];
|
||||||
|
for (int ii = 0; ii < envp.length; ii++) {
|
||||||
|
envp[ii] = processArg(envvar.get(ii));
|
||||||
|
}
|
||||||
|
log.info("Environment " + StringUtil.join(envp, "\n "));
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Running " + StringUtil.join(sargs, "\n "));
|
log.info("Running " + StringUtil.join(sargs, "\n "));
|
||||||
return Runtime.getRuntime().exec(sargs, null);
|
return Runtime.getRuntime().exec(sargs, envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user