Skip to content

Commit

Permalink
Allow different interpreters for SubCreator build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jan 14, 2019
1 parent 9b01aeb commit df159f7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 42 deletions.
Expand Up @@ -122,7 +122,7 @@ private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate
e.printStackTrace();
}

if (template.getBuildOptions().contains("Shell-Location")) {
if (template.getBuildOptions().contains("Executable")) {
File cache;
if (template.getBuildOptions().getBoolean("Use-Cache", true)) {
cache = new UniversalFile(host.plugin.dir, "SubServers:Cache:Templates:" + template.getName());
Expand All @@ -132,22 +132,9 @@ private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate
cache = null;
}

if (!System.getProperty("os.name").toLowerCase().startsWith("windows") && template.getBuildOptions().contains("Permission")) {
try {
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
Thread.sleep(500);
if (process.exitValue() != 0) {
System.out.println(name + File.separator + "Creator > Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location"));
}
} catch (Exception e) {
System.out.println(name + File.separator + "Creator > Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location"));
e.printStackTrace();
}
}

try {
System.out.println(name + File.separator + "Creator > Launching " + template.getBuildOptions().getRawString("Shell-Location"));
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, "bash \"" + template.getBuildOptions().getRawString("Shell-Location") + '\"')).directory(dir);
System.out.println(name + File.separator + "Creator > Launching Build Script...");
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, template.getBuildOptions().getRawString("Executable"))).directory(dir);
pb.environment().putAll(var);
process = pb.start();
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString() + ".log");
Expand Down
3 changes: 1 addition & 2 deletions SubServers.Creator/src/Forge/template.yml
Expand Up @@ -5,7 +5,6 @@ Template:
Build:
Server-Type: 'Forge'
Use-Cache: false
Shell-Location: 'build.sh'
Permission: '+x'
Executable: 'bash build.sh'
Settings:
Executable: 'java -Xmx2048M -jar Forge.jar'
3 changes: 1 addition & 2 deletions SubServers.Creator/src/Spigot/template.yml
Expand Up @@ -4,7 +4,6 @@ Template:
Icon: 'lava_bucket'
Build:
Server-Type: 'Spigot'
Shell-Location: 'build.sh'
Permission: '+x'
Executable: 'bash build.sh'
Settings:
Executable: 'java -Xmx1024M -Dorg.bukkit.craftbukkit.libs.jline.terminal=unix -Djansi.passthrough=true -jar Spigot.jar -p $port$'
3 changes: 1 addition & 2 deletions SubServers.Creator/src/Sponge/template.yml
Expand Up @@ -5,7 +5,6 @@ Template:
Build:
Server-Type: 'Sponge'
Use-Cache: false
Shell-Location: 'build.sh'
Permission: '+x'
Executable: 'bash build.sh'
Settings:
Executable: 'java -Xmx1024M -jar Sponge.jar'
3 changes: 1 addition & 2 deletions SubServers.Creator/src/Vanilla/template.yml
Expand Up @@ -4,7 +4,6 @@ Template:
Icon: 'bukkit:grass'
Build:
Server-Type: 'Vanilla'
Shell-Location: 'build.sh'
Permission: '+x'
Executable: 'bash build.sh'
Settings:
Executable: 'java -Xmx1024M -jar Vanilla.jar nogui'
Expand Up @@ -280,25 +280,10 @@ private YAMLSection build(File dir, ServerTemplate template, List<ServerTemplate
cache = null;
}

if (!System.getProperty("os.name").toLowerCase().startsWith("windows") && template.getBuildOptions().contains("Permission")) {
try {
Process process = Runtime.getRuntime().exec("chmod " + template.getBuildOptions().getRawString("Permission") + ' ' + template.getBuildOptions().getRawString("Shell-Location"), null, dir);
Thread.sleep(500);
if (process.exitValue() != 0) {
log.logger.info.println("Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location"));
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location")));
}
} catch (Exception e) {
log.logger.info.println("Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location"));
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Couldn't set " + template.getBuildOptions().getRawString("Permission") + " permissions to " + template.getBuildOptions().getRawString("Shell-Location")));
log.logger.error.println(e);
}
}

try {
log.logger.info.println("Launching " + template.getBuildOptions().getRawString("Shell-Location"));
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching " + template.getBuildOptions().getRawString("Shell-Location")));
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), "bash \"" + template.getBuildOptions().getRawString("Shell-Location") + '\"')).directory(dir);
log.logger.info.println("Launching Build Script...");
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Launching Build Script..."));
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getRawString("Git-Bash"), template.getBuildOptions().getRawString("Executable"))).directory(dir);
pb.environment().putAll(var);
process = pb.start();
log.file = new File(dir, "SubCreator-" + template.getName() + "-" + version.toString().replace(" ", "@") + ".log");
Expand Down

0 comments on commit df159f7

Please sign in to comment.