Makes the jar building finally work
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2021-08-02 11:38:43 +02:00
parent 123a8eddda
commit 51ceac69da
2 changed files with 26 additions and 33 deletions

View File

@ -8,17 +8,13 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class JarBuilder {
private String downloadedBuildToolsVersion = "#124";
private String buildDirectory;
private String jarDirectory;
private final String buildDirectory;
private final String jarDirectory;
public JarBuilder(String buildDirectory, String jarDirectory) {
this.buildDirectory = buildDirectory;
@ -30,7 +26,7 @@ public class JarBuilder {
*/
public void buildSpigotJar() {
downloadBuildTools();
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev",
ProcessBuilder processBuilder = new ProcessBuilder("C:\\Program Files\\Java\\jdk-16.0.1\\bin\\java.exe", "-jar", "BuildTools.jar", "--rev",
"latest", "--output-dir", jarDirectory);
executeBuildProcess(processBuilder);
System.out.println("Finished building spigot .jar. Moving it to the correct location");
@ -43,7 +39,7 @@ public class JarBuilder {
*/
public void buildBukkitJar() {
downloadBuildTools();
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", "BuildTools.jar", "--compile",
ProcessBuilder processBuilder = new ProcessBuilder("C:\\Program Files\\Java\\jdk-16.0.1\\bin\\java.exe", "-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");
@ -100,31 +96,21 @@ public class JarBuilder {
Process process = processBuilder.start();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
ScheduledExecutorService builderOutputExecutor = Executors.newSingleThreadScheduledExecutor();
builderOutputExecutor.scheduleAtFixedRate(() -> {
try {
String readText = CommonFunctions.readBufferedReader(reader);
if (!readText.equals("")) {
writer.write(readText);
do {
writer.write(CommonFunctions.readBufferedReader(reader));
} while (process.isAlive());
writer.flush();
}
if (!process.isAlive()) {
writer.write("Closing process");
writer.flush();
builderOutputExecutor.shutdown();
writer.close();
reader.close();
process.destroyForcibly();
if (process.exitValue() == 0) {
System.out.println("Jar building process finished successfully.");
} else {
throw new RuntimeException("Jar building process failed with exit code " + process.exitValue() + ".");
}
} catch (IOException e) {
e.printStackTrace();
}
}, 1000, 5000, TimeUnit.MILLISECONDS);
process.waitFor();
System.out.println("Stopped waiting for process");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
/**

View File

@ -1,7 +1,6 @@
package net.knarcraft.minecraftserverlauncher.utility;
import net.knarcraft.minecraftserverlauncher.Main;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@ -34,13 +33,21 @@ public class JarBuilderTest {
@Test
@Order(3)
public void buildLatestSpigotJarTest() {
File spigotFile = new File(jarDirectory + "SpigotLatest.jar");
if (spigotFile.exists() && !spigotFile.delete()) {
throw new IllegalArgumentException("Unable to remove existing spigot .jar");
}
jarBuilder.buildSpigotJar();
assertTrue(new File(jarDirectory + "SpigotLatest.jar").exists());
assertTrue(spigotFile.exists());
}
@Test
@Order(4)
public void buildLatestBukkitJarTest() {
File bukkitFile = new File(jarDirectory + "BukkitLatest.jar");
if (bukkitFile.exists() && !bukkitFile.delete()) {
throw new IllegalArgumentException("Unable to remove existing bukkit .jar");
}
jarBuilder.buildBukkitJar();
assertTrue(new File(jarDirectory + "BukkitLatest.jar").exists());
}