Improves writing speed when not using a GUI
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
Uses buffered writers instead of System.out Uses a GUI for writing JarBuilder messages Adds some missing comments to the jar builder
This commit is contained in:
parent
52eacb9980
commit
32c17c6005
@ -1,6 +1,9 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
/**
|
||||
* This class handles displaying messages to the user
|
||||
@ -8,6 +11,7 @@ import javax.swing.*;
|
||||
public abstract class MessageHandler implements GUI {
|
||||
|
||||
private final boolean silent;
|
||||
private final BufferedWriter writer;
|
||||
|
||||
/***
|
||||
* Initializes a new message handler
|
||||
@ -16,12 +20,18 @@ public abstract class MessageHandler implements GUI {
|
||||
*/
|
||||
public MessageHandler(boolean silent) {
|
||||
this.silent = silent;
|
||||
this.writer = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String title, String message) {
|
||||
if (silent) {
|
||||
try {
|
||||
writer.write(message);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println(message);
|
||||
}
|
||||
} else {
|
||||
showJOptionPane(title, message, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
@ -35,7 +45,12 @@ public abstract class MessageHandler implements GUI {
|
||||
@Override
|
||||
public void showMessage(String title, String message) {
|
||||
if (silent) {
|
||||
try {
|
||||
writer.write(message);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println(message);
|
||||
}
|
||||
} else {
|
||||
showJOptionPane(title, message, JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package net.knarcraft.minecraftserverlauncher.utility;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
|
||||
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@ -11,16 +12,27 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* The jar builder is responsible for building the newest Spigot and CraftBukkit .jar files using BuildTools
|
||||
*/
|
||||
public class JarBuilder {
|
||||
|
||||
private final String buildDirectory;
|
||||
private final String jarDirectory;
|
||||
private final ServerVersionContainer versionContainer;
|
||||
private final GUI gui;
|
||||
|
||||
public JarBuilder(String buildDirectory, String jarDirectory, ServerVersionContainer versionContainer) {
|
||||
/**
|
||||
* Instantiates a new jar builder
|
||||
* @param buildDirectory <p>The directory containing BuildTool files</p>
|
||||
* @param jarDirectory <p>The directory containing downloaded .jar files</p>
|
||||
* @param gui <p>The GUI to write messages to</p>
|
||||
*/
|
||||
public JarBuilder(String buildDirectory, String jarDirectory, GUI gui) {
|
||||
this.buildDirectory = buildDirectory;
|
||||
this.jarDirectory = jarDirectory;
|
||||
this.versionContainer = versionContainer;
|
||||
this.gui = gui;
|
||||
this.versionContainer = ServerVersionContainer.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,9 +43,9 @@ public class JarBuilder {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev",
|
||||
"latest", "--output-dir", jarDirectory);
|
||||
executeBuildProcess(processBuilder);
|
||||
System.out.println("Finished building spigot .jar. Moving it to the correct location");
|
||||
gui.setStatus("Finished building spigot .jar. Moving it to the correct location");
|
||||
moveBuiltJar("spigot-", "SpigotLatest.jar");
|
||||
System.out.println("Finished moving spigot .jar");
|
||||
gui.setStatus("Finished moving spigot .jar");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,9 +56,9 @@ public class JarBuilder {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--compile",
|
||||
"craftbukkit", "--rev", "latest", "--output-dir", jarDirectory);
|
||||
executeBuildProcess(processBuilder);
|
||||
System.out.println("Finished building craftbukkit .jar. Moving it to the correct location");
|
||||
gui.setStatus("Finished building craftbukkit .jar. Moving it to the correct location");
|
||||
moveBuiltJar("craftbukkit-", "BukkitLatest.jar");
|
||||
System.out.println("Finished moving craftbukkit .jar");
|
||||
gui.setStatus("Finished moving craftbukkit .jar");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +123,7 @@ public class JarBuilder {
|
||||
writer.flush();
|
||||
|
||||
if (process.exitValue() == 0) {
|
||||
System.out.println("Jar building process finished successfully.");
|
||||
gui.setStatus("Jar building process finished successfully.");
|
||||
} else {
|
||||
throw new RuntimeException("Jar building process failed with exit code " + process.exitValue() + ".");
|
||||
}
|
||||
|
@ -1,20 +1,31 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
public class FakeGUI extends MessageHandler implements GUI {
|
||||
|
||||
private final BufferedWriter writer;
|
||||
|
||||
/***
|
||||
* Initializes a new fake gui
|
||||
*/
|
||||
public FakeGUI() {
|
||||
super(true);
|
||||
this.writer = new BufferedWriter(new OutputStreamWriter(System.out));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(String message) {
|
||||
try {
|
||||
writer.write(message);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File askForDirectory(String prompt) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.minecraftserverlauncher.utility;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
|
||||
import net.knarcraft.minecraftserverlauncher.userinterface.FakeGUI;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@ -27,7 +27,7 @@ public class JarBuilderTest {
|
||||
"BuildTools" + File.separator;
|
||||
jarDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator +
|
||||
"testjars" + File.separator;
|
||||
jarBuilder = new JarBuilder(targetDirectory, jarDirectory, ServerVersionContainer.getInstance());
|
||||
jarBuilder = new JarBuilder(targetDirectory, jarDirectory, new FakeGUI());
|
||||
removeBuildToolsFiles();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user