Use the same java version for child processes

This commit is contained in:
ME1312 2019-12-18 14:15:02 -05:00
parent 51d3c31220
commit 6e116763c1
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
13 changed files with 43 additions and 13 deletions

View File

@ -19,6 +19,10 @@ public class Executable {
* @return
*/
public static String[] parse(String gitbash, String exec) {
if (exec.startsWith("java ")) {
exec = '\"' + System.getProperty("java.home") + File.separator + "bin" + File.separator + "java" + '\"' + exec.substring(4);
}
String[] cmd;
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
if (gitbash != null && (exec.toLowerCase().startsWith("bash ") || exec.toLowerCase().startsWith("sh ")))

View File

@ -203,14 +203,15 @@ public class ExternalHost extends Host implements ClientHandler {
}
@Override
public boolean forceRemoveSubServer(UUID player, String name) {
public boolean forceRemoveSubServer(UUID player, String name) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
String server = servers.get(name.toLowerCase()).getName();
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
plugin.getPluginManager().callEvent(event);
if (getSubServer(server).isRunning()) {
getSubServer(server).terminate();
getSubServer(server).stop();
getSubServer(server).waitFor();
}
queue(new PacketExRemoveServer(server, data -> {
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {

View File

@ -131,13 +131,14 @@ public class InternalHost extends Host {
}
@Override
public boolean forceRemoveSubServer(UUID player, String name) {
public boolean forceRemoveSubServer(UUID player, String name) throws InterruptedException {
if (Util.isNull(name)) throw new NullPointerException();
String server = servers.get(name.toLowerCase()).getName();
SubRemoveServerEvent event = new SubRemoveServerEvent(player, this, getSubServer(server));
plugin.getPluginManager().callEvent(event);
if (getSubServer(server).isRunning()) {
getSubServer(server).terminate();
getSubServer(server).stop();
getSubServer(server).waitFor();
}
if (UPnP.isUPnPAvailable() && UPnP.isMappedTCP(getSubServer(server).getAddress().getPort()))
UPnP.closePortTCP(getSubServer(server).getAddress().getPort());

View File

@ -111,6 +111,7 @@ public class InternalSubCreator extends SubCreator {
try {
Logger.get(prefix).info("Loading Template: " + template.getDisplayName());
Util.copyDirectory(template.getDirectory(), dir);
var.put("java", System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
var.put("mode", (update == null)?"CREATE":"UPDATE");
var.put("name", name);
var.put("host", host.getName());

View File

@ -144,9 +144,11 @@ public class InternalSubLogger extends SubLogger {
@Override
public void stop() {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
destroy();
try {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
destroy();
} catch (NullPointerException e) {}
}
@Override

View File

@ -122,6 +122,7 @@ public class InternalSubServer extends SubServerContainer {
started = false;
try {
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.getCreator().getBashDirectory(), executable)).directory(directory);
pb.environment().put("java", System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
pb.environment().put("name", getName());
pb.environment().put("host", host.getName());
pb.environment().put("address", host.getAddress().getHostAddress());

View File

@ -7,6 +7,10 @@ if [[ -z "$mcf_version" ]] || [[ -z "$sp_version" ]]
rm -Rf "$0"
exit 1
fi
if [[ -z "$java" ]]
then
export java="java"
fi
function __DL() {
if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $?
@ -18,7 +22,7 @@ echo Downloading the Minecraft Forge Installer...
__DL "forge-$mcf_version-installer.jar" "http://files.minecraftforge.net/maven/net/minecraftforge/forge/$mcf_version/forge-$mcf_version-installer.jar"; __RETURN=$?
if [[ $__RETURN -eq 0 ]]; then
echo Installing Minecraft Forge...
java -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$?
"$java" -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$?
if [[ $__RETURN -eq 0 ]]; then
echo Cleaning Up...
if [[ -f "Forge.jar" ]]; then

View File

@ -7,6 +7,10 @@ if [[ -z "$version" ]]
rm -Rf "$0"
exit 1
fi
if [[ -z "$java" ]]
then
export java="java"
fi
function __DL() {
if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $?
@ -29,7 +33,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" ==
export HOME="$cache"
fi
export MAVEN_OPTS="-Xms2G"
java -Xms2G -jar ../Buildtools.jar --rev "$version"; __RETURN=$?
"$java" -Xms2G -jar ../Buildtools.jar --rev "$version"; __RETURN=$?
if [[ ! -z "$cache" ]] && [[ ! -z "$__HOME" ]] && [[ "$cache" == "$HOME" ]]; then
export HOME="$__HOME"
fi

View File

@ -7,6 +7,10 @@ if [[ -z "$version" ]]
rm -Rf "$0"
exit 1
fi
if [[ -z "$java" ]]
then
export java="java"
fi
function __DL() {
if [[ -x "$(command -v wget)" ]]; then
wget -O "$1" "$2"; return $?
@ -24,7 +28,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then
if [[ $__RETURN -eq 0 ]]; then
cd VanillaCord
echo Launching VanillaCord
java -jar VanillaCord.jar "$version"; __RETURN=$?;
"$java" -jar VanillaCord.jar "$version"; __RETURN=$?;
if [[ $__RETURN -eq 0 ]]; then
echo Copying Finished Jar...
cd ../

View File

@ -20,6 +20,10 @@ public class Executable {
* @return
*/
public static String[] parse(String gitbash, String exec) {
if (exec.startsWith("java ")) {
exec = '\"' + System.getProperty("java.home") + File.separator + "bin" + File.separator + "java" + '\"' + exec.substring(4);
}
String[] cmd;
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
if (gitbash != null && (exec.toLowerCase().startsWith("bash ") || exec.toLowerCase().startsWith("sh ")))

View File

@ -260,6 +260,7 @@ public class SubCreatorImpl {
log.logger.info.println("Loading Template: " + template.getDisplayName());
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
Util.copyDirectory(template.getDirectory(), dir);
var.put("java", System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
var.put("mode", (update == null)?"CREATE":"UPDATE");
var.put("name", name);
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) var.put("host", SubAPI.getInstance().getName());

View File

@ -178,9 +178,11 @@ public class SubLoggerImpl {
* Stop Logger
*/
public void stop() {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
destroy();
try {
if (out != null) out.interrupt();
if (err != null) err.interrupt();
destroy();
} catch (NullPointerException e) {}
}
private void destroy() {

View File

@ -109,6 +109,7 @@ public class SubServerImpl {
allowrestart = true;
try {
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), executable)).directory(directory);
pb.environment().put("java", System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
pb.environment().put("name", getName());
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) pb.environment().put("host", SubAPI.getInstance().getName());
pb.environment().put("address", host.config.get().getMap("Settings").getRawString("Server-Bind"));