Created
October 21, 2022 22:18
-
-
Save WizardlyBump17/50be6d97fc27361e527cb8c75b226922 to your computer and use it in GitHub Desktop.
Simple Java utility class to download and run BuildTools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.nio.file.Files; | |
public class BuildToolsExecutor { | |
//java -Dversion=1.19.2 BuildToolsExecutor.java | |
//java -Djava=custom_path -Dversion=1.19.2 BuildToolsExecutor.java | |
public static void main(String[] args) { | |
String java = System.getProperties().getProperty("java", "java"); | |
File folder = new File(System.getProperty("user.dir")); | |
String version = System.getProperty("version"); | |
boolean remapped = System.getProperties().containsKey("remapped"); | |
File targetFolder = new File(folder, remapped ? version + "-remapped" : version); | |
File buildToolsFile = new File(targetFolder, "BuildTools.jar"); | |
checkBuildTools(buildToolsFile); | |
try { | |
ProcessBuilder builder = new ProcessBuilder(java, "-jar", buildToolsFile.getName(), "--rev", version); | |
if (remapped) | |
builder.command().add("--remapped"); | |
builder.directory(targetFolder); | |
builder.inheritIO(); | |
Process process = builder.start(); | |
process.waitFor(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
private static void checkBuildTools(File file) { | |
if (!file.exists()) { | |
System.out.println("BuildTools.jar not found, downloading..."); | |
downloadBuildTools(file); | |
} | |
} | |
private static void downloadBuildTools(File targetFile) { | |
try { | |
if (!targetFile.getParentFile().exists()) | |
targetFile.getParentFile().mkdirs(); | |
InputStream stream = new URL("https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar").openStream(); | |
Files.copy(stream, targetFile.toPath()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
System.exit(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment