Improves console and GUI messages
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Adds newlines when writing to console Add Error: on lines containing an error Makes it clearer when a jar build is successful Makes failures show errors rather than throwing exceptions
This commit is contained in:
parent
d61239c417
commit
6ec44f1f92
@ -27,7 +27,9 @@ public abstract class MessageHandler implements GUI {
|
|||||||
public void showError(String title, String message) {
|
public void showError(String title, String message) {
|
||||||
if (silent) {
|
if (silent) {
|
||||||
try {
|
try {
|
||||||
|
writer.write("Error: ");
|
||||||
writer.write(message);
|
writer.write(message);
|
||||||
|
writer.newLine();
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
@ -47,6 +49,7 @@ public abstract class MessageHandler implements GUI {
|
|||||||
if (silent) {
|
if (silent) {
|
||||||
try {
|
try {
|
||||||
writer.write(message);
|
writer.write(message);
|
||||||
|
writer.newLine();
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
@ -42,10 +42,9 @@ public class JarBuilder {
|
|||||||
downloadBuildTools();
|
downloadBuildTools();
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev",
|
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev",
|
||||||
"latest", "--output-dir", jarDirectory);
|
"latest", "--output-dir", jarDirectory);
|
||||||
executeBuildProcess(processBuilder);
|
if (executeBuildProcess(processBuilder) && moveBuiltJar("spigot-", "SpigotLatest.jar")) {
|
||||||
gui.setStatus("Finished building spigot .jar. Moving it to the correct location");
|
gui.setStatus("Finished moving spigot.jar");
|
||||||
moveBuiltJar("spigot-", "SpigotLatest.jar");
|
}
|
||||||
gui.setStatus("Finished moving spigot .jar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,10 +54,9 @@ public class JarBuilder {
|
|||||||
downloadBuildTools();
|
downloadBuildTools();
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--compile",
|
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--compile",
|
||||||
"craftbukkit", "--rev", "latest", "--output-dir", jarDirectory);
|
"craftbukkit", "--rev", "latest", "--output-dir", jarDirectory);
|
||||||
executeBuildProcess(processBuilder);
|
if (executeBuildProcess(processBuilder) && moveBuiltJar("craftbukkit-", "BukkitLatest.jar")) {
|
||||||
gui.setStatus("Finished building craftbukkit .jar. Moving it to the correct location");
|
gui.setStatus("Finished moving craftbukkit.jar");
|
||||||
moveBuiltJar("craftbukkit-", "BukkitLatest.jar");
|
}
|
||||||
gui.setStatus("Finished moving craftbukkit .jar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,27 +86,32 @@ public class JarBuilder {
|
|||||||
* Moves a built .jar file to its target file
|
* Moves a built .jar file to its target file
|
||||||
* @param searchString <p>The start of the name of the built file used to find it</p>
|
* @param searchString <p>The start of the name of the built file used to find it</p>
|
||||||
* @param newName <p>The new name of the built file</p>
|
* @param newName <p>The new name of the built file</p>
|
||||||
|
* @return <p>True if the .jar file was moved successfully</p>
|
||||||
*/
|
*/
|
||||||
private void moveBuiltJar(String searchString, String newName) {
|
private boolean moveBuiltJar(String searchString, String newName) {
|
||||||
File[] foundFiles = new File(jarDirectory).listFiles((file) -> file.isFile() && file.getName().startsWith(searchString));
|
File[] foundFiles = new File(jarDirectory).listFiles((file) -> file.isFile() && file.getName().startsWith(searchString));
|
||||||
if (foundFiles != null && foundFiles.length == 1) {
|
if (foundFiles != null && foundFiles.length == 1) {
|
||||||
File newFileLocation = new File(jarDirectory + File.separator + newName);
|
File newFileLocation = new File(jarDirectory + File.separator + newName);
|
||||||
if (newFileLocation.exists()) {
|
if (newFileLocation.exists()) {
|
||||||
if (!newFileLocation.delete()) {
|
if (!newFileLocation.delete()) {
|
||||||
throw new IllegalArgumentException("Unable to delete previously built .jar");
|
gui.showError("Unable to delete previously built .jar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!foundFiles[0].renameTo(newFileLocation)) {
|
if (!foundFiles[0].renameTo(newFileLocation)) {
|
||||||
throw new IllegalArgumentException("Unable to move built .jar");
|
gui.showError("Unable to move built .jar");
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the build process and initializes
|
* Starts the build process and initializes
|
||||||
* @param processBuilder <p>The process builder to execute</p>
|
* @param processBuilder <p>The process builder to execute</p>
|
||||||
|
* @return <p>True if the process exited successfully</p>
|
||||||
*/
|
*/
|
||||||
private void executeBuildProcess(ProcessBuilder processBuilder) {
|
private boolean executeBuildProcess(ProcessBuilder processBuilder) {
|
||||||
processBuilder.directory(new File(buildDirectory));
|
processBuilder.directory(new File(buildDirectory));
|
||||||
processBuilder.redirectErrorStream(true);
|
processBuilder.redirectErrorStream(true);
|
||||||
try {
|
try {
|
||||||
@ -120,16 +123,20 @@ public class JarBuilder {
|
|||||||
writer.write(CommonFunctions.readBufferedReader(reader));
|
writer.write(CommonFunctions.readBufferedReader(reader));
|
||||||
} while (process.isAlive());
|
} while (process.isAlive());
|
||||||
|
|
||||||
|
writer.newLine();
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
if (process.exitValue() == 0) {
|
if (process.exitValue() == 0) {
|
||||||
gui.setStatus("Jar building process finished successfully.");
|
gui.showMessage("Jar building process finished successfully.");
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Jar building process failed with exit code " + process.exitValue() + ".");
|
gui.showError("Jar building process failed with exit code " + process.exitValue() +
|
||||||
|
". Please check the BuildTools log for errors.");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,4 +150,4 @@ public class JarBuilder {
|
|||||||
return CommonFunctions.stringBetween(versionDocument, "BuildTools #", " [");
|
return CommonFunctions.stringBetween(versionDocument, "BuildTools #", " [");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -21,6 +21,7 @@ public class FakeGUI extends MessageHandler implements GUI {
|
|||||||
public void setStatus(String message) {
|
public void setStatus(String message) {
|
||||||
try {
|
try {
|
||||||
writer.write(message);
|
writer.write(message);
|
||||||
|
writer.newLine();
|
||||||
writer.flush();
|
writer.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
Loading…
Reference in New Issue
Block a user