Another Elias patch to work around an -Xdock:name bug.
This commit is contained in:
@@ -29,9 +29,10 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import com.samskivert.util.RunAnywhere;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.getdown.Log;
|
import static com.threerings.getdown.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful routines for launching Java applications from within other Java
|
* Useful routines for launching Java applications from within other Java
|
||||||
@@ -84,12 +85,12 @@ public class LaunchUtil
|
|||||||
String[] args = new String[] {
|
String[] args = new String[] {
|
||||||
getJVMPath(appdir), "-jar", pro.toString(), appdir.getPath()
|
getJVMPath(appdir), "-jar", pro.toString(), appdir.getPath()
|
||||||
};
|
};
|
||||||
Log.info("Running " + StringUtil.join(args, "\n "));
|
log.info("Running " + StringUtil.join(args, "\n "));
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(args, null);
|
Runtime.getRuntime().exec(args, null);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.log.log(Level.WARNING, "Failed to run getdown", ioe);
|
log.log(Level.WARNING, "Failed to run getdown", ioe);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,20 +112,35 @@ public class LaunchUtil
|
|||||||
{
|
{
|
||||||
// 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).getPath(), windebug);
|
String vmpath = checkJVMPath(new File(appdir, LOCAL_JAVA_DIR).getPath(), windebug);
|
||||||
if (vmpath != null) {
|
|
||||||
return vmpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// then fall back to the VM in which we're already running
|
// then fall back to the VM in which we're already running
|
||||||
vmpath = checkJVMPath(System.getProperty("java.home"), windebug);
|
if (vmpath == null) {
|
||||||
if (vmpath != null) {
|
vmpath = checkJVMPath(System.getProperty("java.home"), windebug);
|
||||||
return vmpath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// then throw up our hands and hope for the best
|
// then throw up our hands and hope for the best
|
||||||
Log.warning("Unable to find java [appdir=" + appdir +
|
if (vmpath == null) {
|
||||||
", java.home=" + System.getProperty("java.home") + "]!");
|
log.warning("Unable to find java [appdir=" + appdir +
|
||||||
return "java";
|
", java.home=" + System.getProperty("java.home") + "]!");
|
||||||
|
vmpath = "java";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Oddly, the Mac OS X specific java flag -Xdock:name will only work if java is launched
|
||||||
|
// from /usr/bin/java, and not if launched by directly referring to <java.home>/bin/java,
|
||||||
|
// even though the former is a symlink to the latter! To work around this, see if the
|
||||||
|
// desired jvm is in fact pointed to by /usr/bin/java and, if so, use that instead.
|
||||||
|
if (RunAnywhere.isMacOS()) {
|
||||||
|
try {
|
||||||
|
File localVM = new File("/usr/bin/java").getCanonicalFile();
|
||||||
|
if (localVM.equals(new File(vmpath).getCanonicalFile())) {
|
||||||
|
vmpath = "/usr/bin/java";
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
log.log(Level.WARNING, "Failed to check Mac OS canonical VM path.", ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vmpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,7 +159,7 @@ public class LaunchUtil
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info("Updating Getdown with " + newgd + "...");
|
log.info("Updating Getdown with " + newgd + "...");
|
||||||
|
|
||||||
// clear out any old getdown
|
// clear out any old getdown
|
||||||
if (oldgd.exists()) {
|
if (oldgd.exists()) {
|
||||||
@@ -159,25 +175,24 @@ public class LaunchUtil
|
|||||||
// downloading another copy next time
|
// downloading another copy next time
|
||||||
IOUtils.copy(new FileInputStream(curgd), new FileOutputStream(newgd));
|
IOUtils.copy(new FileInputStream(curgd), new FileOutputStream(newgd));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.warning("Error copying updated Getdown back: " + e);
|
log.warning("Error copying updated Getdown back: " + e);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.warning("Unable to renameTo(" + oldgd + ").");
|
log.warning("Unable to renameTo(" + oldgd + ").");
|
||||||
// try to unfuck ourselves
|
// try to unfuck ourselves
|
||||||
if (!oldgd.renameTo(curgd)) {
|
if (!oldgd.renameTo(curgd)) {
|
||||||
Log.warning("Oh God, why dost thee scorn me so.");
|
log.warning("Oh God, why dost thee scorn me so.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// that didn't work, let's try copying it
|
// that didn't work, let's try copying it
|
||||||
Log.info("Attempting to upgrade by copying over " + curgd + "...");
|
log.info("Attempting to upgrade by copying over " + curgd + "...");
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(new FileInputStream(newgd), new FileOutputStream(curgd));
|
IOUtils.copy(new FileInputStream(newgd), new FileOutputStream(curgd));
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.warning("Mayday! Brute force copy method also failed.");
|
log.log(Level.WARNING, "Mayday! Brute force copy method also failed.", ioe);
|
||||||
Log.logStackTrace(ioe);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user