Allow specification of appbase via system property.

This allows one to bootstrap a Getdown install with no files at all. You don't
get a very sexy UI during the first install, but you can make something
non-horrible with a background color and a small window.
This commit is contained in:
Michael Bayne
2014-02-11 10:53:50 -08:00
parent c1d2946747
commit faece11e11
2 changed files with 33 additions and 21 deletions
@@ -261,7 +261,7 @@ public class Application
try { try {
return createResource(CONFIG_FILE, false); return createResource(CONFIG_FILE, false);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Invalid appbase '" + _vappbase + "'."); throw new RuntimeException("Invalid appbase '" + _vappbase + "'.", e);
} }
} }
@@ -472,10 +472,10 @@ public class Application
} }
/** /**
* Instructs the application to parse its <code>getdown.txt</code> configuration and prepare * Instructs the application to parse its {@code getdown.txt} configuration and prepare itself
* itself for operation. The application base URL will be parsed first so that if there are * for operation. The application base URL will be parsed first so that if there are errors
* errors discovered later, the caller can use the application base to download a new * discovered later, the caller can use the application base to download a new {@code
* <code>config.txt</code> file and try again. * getdown.txt} file and try again.
* *
* @return a configured UpdateInterface instance that will be used to configure the update UI. * @return a configured UpdateInterface instance that will be used to configure the update UI.
* *
@@ -485,26 +485,36 @@ public class Application
public UpdateInterface init (boolean checkPlatform) public UpdateInterface init (boolean checkPlatform)
throws IOException throws IOException
{ {
// parse our configuration file
Map<String,Object> cdata = null; Map<String,Object> cdata = null;
File config = _config;
try { try {
cdata = ConfigUtil.parseConfig(_config, checkPlatform); // if we have a configuration file, read the data from it
} catch (FileNotFoundException fnfe) { if (config.exists()) {
// thanks to funny windows bullshit, we have to do this backup file fiddling in case we cdata = ConfigUtil.parseConfig(_config, checkPlatform);
// got screwed while updating our very critical getdown config file
File cbackup = getLocalPath(CONFIG_FILE + "_old");
if (cbackup.exists()) {
cdata = ConfigUtil.parseConfig(cbackup, checkPlatform);
} else {
throw fnfe;
} }
// otherwise, try reading data from our backup config file; thanks to funny windows
// bullshit, we have to do this backup file fiddling in case we got screwed while
// updating getdown.txt during normal operation
else if ((config = getLocalPath(CONFIG_FILE + "_old")).exists()) {
cdata = ConfigUtil.parseConfig(config, checkPlatform);
}
} catch (Exception e) {
log.warning("Failure reading config file", "file", config, e);
}
// if we failed to read our config file, check for an appbase specified via a system
// property; we can use that to bootstrap ourselves back into operation
if (cdata == null) {
log.info("Found no getdown.txt file. Falling back to appbase system prop",
"appbase", SysProps.appBase());
cdata = new HashMap<String,Object>();
cdata.put("appbase", SysProps.appBase());
} }
// first determine our application base, this way if anything goes wrong later in the // first determine our application base, this way if anything goes wrong later in the
// process, our caller can use the appbase to download a new configuration file // process, our caller can use the appbase to download a new configuration file
_appbase = (String)cdata.get("appbase"); _appbase = (String)cdata.get("appbase");
if (_appbase == null) { if (_appbase == null) {
throw new IOException("m.missing_appbase"); throw new RuntimeException("m.missing_appbase");
} }
// make sure there's a trailing slash // make sure there's a trailing slash
if (!_appbase.endsWith("/")) { if (!_appbase.endsWith("/")) {
@@ -524,11 +534,7 @@ public class Application
// if we are a versioned deployment, create a versioned appbase // if we are a versioned deployment, create a versioned appbase
try { try {
if (_version < 0) { _vappbase = (_version < 0) ? new URL(_appbase) : createVAppBase(_version);
_vappbase = new URL(_appbase);
} else {
_vappbase = createVAppBase(_version);
}
} catch (MalformedURLException mue) { } catch (MalformedURLException mue) {
String err = MessageUtil.tcompose("m.invalid_appbase", _appbase); String err = MessageUtil.tcompose("m.invalid_appbase", _appbase);
throw (IOException) new IOException(err).initCause(mue); throw (IOException) new IOException(err).initCause(mue);
@@ -23,6 +23,12 @@ public class SysProps
return System.getProperty("appid"); return System.getProperty("appid");
} }
/** Configures the appbase (in lieu of providing a skeleton getdown.txt, and as a last resort
* fallback). Usage: {@code -Dappbase=someurl}. */
public static String appBase () {
return System.getProperty("appbase");
}
/** If true, disables redirection of logging into {@code launcher.log}. /** If true, disables redirection of logging into {@code launcher.log}.
* Usage: {@code -Dno_log_redir}. */ * Usage: {@code -Dno_log_redir}. */
public static boolean noLogRedir () { public static boolean noLogRedir () {