Merge pull request #206 from sergiorussia/feature/java_local_dir
enable custom java local dir instead of hardcoded "java_vm"
This commit is contained in:
@@ -244,7 +244,7 @@ public class Application
|
|||||||
*/
|
*/
|
||||||
public Application (EnvConfig envc) {
|
public Application (EnvConfig envc) {
|
||||||
_envc = envc;
|
_envc = envc;
|
||||||
_config = getLocalPath(envc.appDir, CONFIG_FILE);
|
_config = new File(envc.appDir, CONFIG_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,7 +435,15 @@ public class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a resource for a zip file containing a Java VM that can be downloaded to use in
|
* @return directory into which a local VM installation should be unpacked.
|
||||||
|
*/
|
||||||
|
public File getJavaLocalDir ()
|
||||||
|
{
|
||||||
|
return _javaLocalDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a resource for a zip file containing a Java VM that can be downloaded to use in
|
||||||
* place of the installed VM (in the case where the VM that launched Getdown does not meet the
|
* place of the installed VM (in the case where the VM that launched Getdown does not meet the
|
||||||
* application's version requirements) or null if no VM is available for this platform.
|
* application's version requirements) or null if no VM is available for this platform.
|
||||||
*/
|
*/
|
||||||
@@ -445,7 +453,9 @@ public class Application
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String vmfile = LaunchUtil.LOCAL_JAVA_DIR + ".jar";
|
// take extension from java location
|
||||||
|
String vmfileExt = _javaLocation.substring(_javaLocation.lastIndexOf('.'));
|
||||||
|
String vmfile = _javaLocalDir.getName() + vmfileExt;
|
||||||
try {
|
try {
|
||||||
URL remote = new URL(createVAppBase(_targetVersion), encodePath(_javaLocation));
|
URL remote = new URL(createVAppBase(_targetVersion), encodePath(_javaLocation));
|
||||||
return new Resource(vmfile, remote, getLocalPath(vmfile),
|
return new Resource(vmfile, remote, getLocalPath(vmfile),
|
||||||
@@ -645,6 +655,9 @@ public class Application
|
|||||||
_javaLocation = (String)javaloc;
|
_javaLocation = (String)javaloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used only in conjunction with java_location
|
||||||
|
_javaLocalDir = getLocalPath(config.getString("java_local_dir", LaunchUtil.LOCAL_JAVA_DIR));
|
||||||
|
|
||||||
// determine whether we have any tracking configuration
|
// determine whether we have any tracking configuration
|
||||||
_trackingURL = config.getString("tracking_url");
|
_trackingURL = config.getString("tracking_url");
|
||||||
|
|
||||||
@@ -788,7 +801,7 @@ public class Application
|
|||||||
*/
|
*/
|
||||||
public File getLocalPath (String path)
|
public File getLocalPath (String path)
|
||||||
{
|
{
|
||||||
return getLocalPath(getAppDir(), path);
|
return new File(getAppDir(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -811,8 +824,7 @@ public class Application
|
|||||||
// if we have an unpacked VM, check the 'release' file for its version
|
// if we have an unpacked VM, check the 'release' file for its version
|
||||||
Resource vmjar = getJavaVMResource();
|
Resource vmjar = getJavaVMResource();
|
||||||
if (vmjar != null && vmjar.isMarkedValid()) {
|
if (vmjar != null && vmjar.isMarkedValid()) {
|
||||||
File vmdir = new File(getAppDir(), LaunchUtil.LOCAL_JAVA_DIR);
|
File relfile = new File(_javaLocalDir, "release");
|
||||||
File relfile = new File(vmdir, "release");
|
|
||||||
if (!relfile.exists()) {
|
if (!relfile.exists()) {
|
||||||
log.warning("Unpacked JVM missing 'release' file. Assuming valid version.");
|
log.warning("Unpacked JVM missing 'release' file. Assuming valid version.");
|
||||||
return true;
|
return true;
|
||||||
@@ -930,7 +942,7 @@ public class Application
|
|||||||
ArrayList<String> args = new ArrayList<>();
|
ArrayList<String> args = new ArrayList<>();
|
||||||
|
|
||||||
// reconstruct the path to the JVM
|
// reconstruct the path to the JVM
|
||||||
args.add(LaunchUtil.getJVMPath(getAppDir(), _windebug || optimum));
|
args.add(LaunchUtil.getJVMBinaryPath(_javaLocalDir, _windebug || optimum));
|
||||||
|
|
||||||
// check whether we're using -jar mode or -classpath mode
|
// check whether we're using -jar mode or -classpath mode
|
||||||
boolean dashJarMode = MANIFEST_CLASS.equals(_class);
|
boolean dashJarMode = MANIFEST_CLASS.equals(_class);
|
||||||
@@ -1717,11 +1729,6 @@ public class Application
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File getLocalPath (File appdir, String path)
|
|
||||||
{
|
|
||||||
return new File(appdir, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final EnvConfig _envc;
|
protected final EnvConfig _envc;
|
||||||
protected File _config;
|
protected File _config;
|
||||||
protected Digest _digest;
|
protected Digest _digest;
|
||||||
@@ -1753,6 +1760,7 @@ public class Application
|
|||||||
protected long _javaMinVersion, _javaMaxVersion;
|
protected long _javaMinVersion, _javaMaxVersion;
|
||||||
protected boolean _javaExactVersionRequired;
|
protected boolean _javaExactVersionRequired;
|
||||||
protected String _javaLocation;
|
protected String _javaLocation;
|
||||||
|
protected File _javaLocalDir;
|
||||||
|
|
||||||
protected List<Resource> _codes = new ArrayList<>();
|
protected List<Resource> _codes = new ArrayList<>();
|
||||||
protected List<Resource> _resources = new ArrayList<>();
|
protected List<Resource> _resources = new ArrayList<>();
|
||||||
@@ -1772,9 +1780,6 @@ public class Application
|
|||||||
|
|
||||||
protected List<String> _txtJvmArgs = new ArrayList<>();
|
protected List<String> _txtJvmArgs = new ArrayList<>();
|
||||||
|
|
||||||
/** If a warning has been issued about not being able to set modtimes. */
|
|
||||||
protected boolean _warnedAboutSetLastModified;
|
|
||||||
|
|
||||||
/** Locks gettingdown.lock in the app dir. Held the entire time updating is going on.*/
|
/** Locks gettingdown.lock in the app dir. Held the entire time updating is going on.*/
|
||||||
protected FileLock _lock;
|
protected FileLock _lock;
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static com.threerings.getdown.Log.log;
|
|||||||
*/
|
*/
|
||||||
public class LaunchUtil
|
public class LaunchUtil
|
||||||
{
|
{
|
||||||
/** The directory into which a local VM installation should be unpacked. */
|
/** The default directory into which a local VM installation should be unpacked. */
|
||||||
public static final String LOCAL_JAVA_DIR = "java_vm";
|
public static final String LOCAL_JAVA_DIR = "java_vm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +32,7 @@ public class LaunchUtil
|
|||||||
* probably <code>getdown-pro.jar</code> or <code>getdown-retro-pro.jar</code> if you are using
|
* probably <code>getdown-pro.jar</code> or <code>getdown-retro-pro.jar</code> if you are using
|
||||||
* the results of the standard build.
|
* the results of the standard build.
|
||||||
* @param newVersion the new version to which Getdown will update when it is executed.
|
* @param newVersion the new version to which Getdown will update when it is executed.
|
||||||
|
* @param javaLocalDir JRE location within appdir, falls back to {@link #LOCAL_JAVA_DIR} in case if null is passed
|
||||||
*
|
*
|
||||||
* @return true if the relaunch succeeded, false if we were unable to relaunch due to being on
|
* @return true if the relaunch succeeded, false if we were unable to relaunch due to being on
|
||||||
* Windows 9x where we cannot launch subprocesses without waiting around for them to exit,
|
* Windows 9x where we cannot launch subprocesses without waiting around for them to exit,
|
||||||
@@ -45,7 +46,7 @@ public class LaunchUtil
|
|||||||
* resort to telling the user that it is in a bad way.
|
* resort to telling the user that it is in a bad way.
|
||||||
*/
|
*/
|
||||||
public static boolean updateVersionAndRelaunch (
|
public static boolean updateVersionAndRelaunch (
|
||||||
File appdir, String getdownJarName, String newVersion)
|
File appdir, String getdownJarName, String newVersion, String javaLocalDir)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// create the file that instructs Getdown to upgrade
|
// create the file that instructs Getdown to upgrade
|
||||||
@@ -61,8 +62,9 @@ public class LaunchUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the deed
|
// do the deed
|
||||||
String[] args = new String[] {
|
String[] args = {
|
||||||
getJVMPath(appdir), "-jar", pro.toString(), appdir.getPath()
|
getJVMBinaryPath(new File(appdir, StringUtil.isBlank(javaLocalDir) ? LOCAL_JAVA_DIR : javaLocalDir), false),
|
||||||
|
"-jar", pro.toString(), appdir.getPath()
|
||||||
};
|
};
|
||||||
log.info("Running " + StringUtil.join(args, "\n "));
|
log.info("Running " + StringUtil.join(args, "\n "));
|
||||||
try {
|
try {
|
||||||
@@ -75,22 +77,14 @@ public class LaunchUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reconstructs the path to the JVM used to launch this process.
|
* @param javaLocalDir JRE location within appdir
|
||||||
*/
|
|
||||||
public static String getJVMPath (File appdir)
|
|
||||||
{
|
|
||||||
return getJVMPath(appdir, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reconstructs the path to the JVM used to launch this process.
|
|
||||||
*
|
|
||||||
* @param windebug if true we will use java.exe instead of javaw.exe on Windows.
|
* @param windebug if true we will use java.exe instead of javaw.exe on Windows.
|
||||||
|
* @return the path to the JVM binary used to launch this process.
|
||||||
*/
|
*/
|
||||||
public static String getJVMPath (File appdir, boolean windebug)
|
public static String getJVMBinaryPath(File javaLocalDir, boolean windebug)
|
||||||
{
|
{
|
||||||
// first look in our application directory for an installed VM
|
// first look in our application directory for an installed VM
|
||||||
String vmpath = checkJVMPath(new File(appdir, LOCAL_JAVA_DIR).getAbsolutePath(), windebug);
|
String vmpath = checkJVMPath(javaLocalDir.getAbsolutePath(), windebug);
|
||||||
|
|
||||||
// then fall back to the VM in which we're already running
|
// then fall back to the VM in which we're already running
|
||||||
if (vmpath == null) {
|
if (vmpath == null) {
|
||||||
@@ -99,7 +93,7 @@ public class LaunchUtil
|
|||||||
|
|
||||||
// then throw up our hands and hope for the best
|
// then throw up our hands and hope for the best
|
||||||
if (vmpath == null) {
|
if (vmpath == null) {
|
||||||
log.warning("Unable to find java [appdir=" + appdir +
|
log.warning("Unable to find java [javaLocalDir=" + javaLocalDir +
|
||||||
", java.home=" + System.getProperty("java.home") + "]!");
|
", java.home=" + System.getProperty("java.home") + "]!");
|
||||||
vmpath = "java";
|
vmpath = "java";
|
||||||
}
|
}
|
||||||
@@ -150,7 +144,7 @@ public class LaunchUtil
|
|||||||
if (newgd.renameTo(curgd)) {
|
if (newgd.renameTo(curgd)) {
|
||||||
FileUtil.deleteHarder(oldgd); // yay!
|
FileUtil.deleteHarder(oldgd); // yay!
|
||||||
try {
|
try {
|
||||||
// copy the moved file back to getdown-dop-new.jar so that we don't end up
|
// copy the moved file back to newgd so that we don't end up
|
||||||
// downloading another copy next time
|
// downloading another copy next time
|
||||||
FileUtil.copy(curgd, newgd);
|
FileUtil.copy(curgd, newgd);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -507,13 +507,13 @@ public abstract class Getdown extends Thread
|
|||||||
vmjar.install(true);
|
vmjar.install(true);
|
||||||
|
|
||||||
// these only run on non-Windows platforms, so we use Unix file separators
|
// these only run on non-Windows platforms, so we use Unix file separators
|
||||||
String localJavaDir = LaunchUtil.LOCAL_JAVA_DIR + "/";
|
File javaLocalDir = _app.getJavaLocalDir();
|
||||||
FileUtil.makeExecutable(_app.getLocalPath(localJavaDir + "bin/java"));
|
FileUtil.makeExecutable(new File(javaLocalDir, "bin/java"));
|
||||||
FileUtil.makeExecutable(_app.getLocalPath(localJavaDir + "lib/jspawnhelper"));
|
FileUtil.makeExecutable(new File(javaLocalDir, "lib/jspawnhelper"));
|
||||||
FileUtil.makeExecutable(_app.getLocalPath(localJavaDir + "lib/amd64/jspawnhelper"));
|
FileUtil.makeExecutable(new File(javaLocalDir, "lib/amd64/jspawnhelper"));
|
||||||
|
|
||||||
// lastly regenerate the .jsa dump file that helps Java to start up faster
|
// lastly regenerate the .jsa dump file that helps Java to start up faster
|
||||||
String vmpath = LaunchUtil.getJVMPath(_app.getLocalPath(""));
|
String vmpath = LaunchUtil.getJVMBinaryPath(javaLocalDir, false);
|
||||||
try {
|
try {
|
||||||
log.info("Regenerating classes.jsa for " + vmpath + "...");
|
log.info("Regenerating classes.jsa for " + vmpath + "...");
|
||||||
Runtime.getRuntime().exec(vmpath + " -Xshare:dump");
|
Runtime.getRuntime().exec(vmpath + " -Xshare:dump");
|
||||||
|
|||||||
Reference in New Issue
Block a user