Improves output logging and fixes some bugs

Fixes an error caused by the BuildTools directory not being created
Creates functions for writing to files in CommonFunctions
Adds some more error info to the log when BuildTools fails to download
Fixes some typos
Makes sure all visible text is logged
This commit is contained in:
2021-08-03 15:22:04 +02:00
parent 28291cf4c3
commit e47b34a472
9 changed files with 109 additions and 32 deletions

View File

@ -4,10 +4,12 @@ import net.knarcraft.minecraftserverlauncher.Main;
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@ -37,6 +39,11 @@ public class JarBuilder {
this.gui = gui;
this.versionContainer = ServerVersionContainer.getInstance();
this.javaCommand = ServerLauncherController.getInstance().getJavaCommand();
try {
CommonFunctions.createFolder(new File(buildDirectory));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
/**
@ -75,6 +82,7 @@ public class JarBuilder {
* Downloads the latest BuildTools version
*/
public void downloadBuildTools() {
ServerLauncherGUI gui = Main.getController().getGUI();
try {
String latestVersion = getLatestBuildToolsVersion();
boolean exists = new File(buildDirectory + "BuildTools.jar").exists();
@ -84,13 +92,16 @@ public class JarBuilder {
String buildToolsURL = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar";
boolean success = CommonFunctions.downloadFile(buildToolsURL, Paths.get(buildDirectory + "BuildTools.jar"));
if (!success) {
Main.getController().getGUI().setStatus("Unable to download the latest BuildTools");
gui.setStatus("Unable to download the latest BuildTools");
gui.logError("Target: " + buildDirectory + "BuildTools.jar");
gui.logError("URL: " + buildToolsURL);
} else {
versionContainer.setDownloadedBuildToolsVersion(latestVersion);
}
}
} catch (IOException e) {
Main.getController().getGUI().setStatus("Unable to download the latest BuildTools");
gui.setStatus("Unable to download the latest BuildTools");
gui.logMessage(e.getMessage());
}
}