diff --git a/build.gradle b/build.gradle index 4152554..7702421 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,8 @@ dependencies { compile group: 'org.yaml', name: 'snakeyaml', version: '1.21' compile group: 'commons-io', name: 'commons-io', version: '2.6' - compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9' + compile 'com.squareup.okhttp3:okhttp:3.10.0' + compile group: 'com.google.code.gson', name: 'gson', version: '2.8.4' // https://mvnrepository.com/artifact/org.fusesource.jansi/jansi @@ -93,4 +94,26 @@ static String getGithubKey(){ Properties props = new Properties() props.load(new FileInputStream(new File('secrets.properties'))) return props['GITHUB_TOKEN'] +} + +task depsize { + group = "help" + doLast { + def size = 0 + def formatStr = "%,10.2f" + configurations.default.collect { it.length() / (1024 * 1024) }.each { size += it } + + def out = new StringBuffer() + out << 'Total dependencies size:'.padRight(45) + out << "${String.format(formatStr, size)} Mb\n\n" + + configurations + .default + .sort { -it.length() } + .each { + out << "${it.name}".padRight(45) + out << "${String.format(formatStr, (it.length() / 1024))} kb\n" + } + println(out) + } } \ No newline at end of file diff --git a/serverstarter.lock b/serverstarter.lock index c876caa..52a5e53 100644 --- a/serverstarter.lock +++ b/serverstarter.lock @@ -1,3 +1,4 @@ #Auto genereated file, DO NOT EDIT! {forgeInstalled: true, forgeVersion: 14.23.3.2682, mcVersion: 1.12.2, packInstalled: true, - packUrl: 'https://minecraft.curseforge.com/projects/all-the-mods-3/files/2556240'} + packUrl: 'https://minecraft.curseforge.com/projects/all-the-mods-3/files/2556240', + spongeBootstrapper: NONE} diff --git a/src/main/java/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.java b/src/main/java/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.java index f677849..ee45193 100644 --- a/src/main/java/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.java +++ b/src/main/java/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.java @@ -7,16 +7,15 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; import java.io.*; import java.net.URISyntaxException; @@ -36,18 +35,22 @@ import static atm.bloodworkxgaming.serverstarter.ServerStarter.LOGGER; public class CursePackType implements IPackType { + private final OkHttpClient httpClient; private ConfigFile configFile; private String basePath; private String forgeVersion; private String mcVersion; private File oldFiles; + public CursePackType(ConfigFile configFile) { this.configFile = configFile; basePath = configFile.install.baseInstallPath; forgeVersion = configFile.install.forgeVersion; mcVersion = configFile.install.mcVersion; oldFiles = new File(basePath + "OLD_TO_DELETE/"); + + httpClient = new OkHttpClient(); } @Override @@ -80,9 +83,17 @@ public void installPack() { } else if (configFile.install.formatSpecific.containsKey("packid") && configFile.install.formatSpecific.containsKey("fileid")) { try { - HttpResponse res = Unirest.get("/api/v2/direct/GetAddOnFile/" + configFile.install.formatSpecific.get("packid") + "/" + configFile.install.formatSpecific.get("fileid")).asJson(); - LOGGER.info("PackID request response: " + res); - } catch (UnirestException e) { + Request request = new Request.Builder() + .url("/api/v2/direct/GetAddOnFile/" + configFile.install.formatSpecific.get("packid") + "/" + configFile.install.formatSpecific.get("fileid")) + .build(); + Response response = httpClient.newCall(request).execute(); + ResponseBody body = response.body(); + if (body != null) { + LOGGER.info("PackID request response: " + body.string()); + } else { + LOGGER.info("PackID request response returned with a null body"); + } + } catch (IOException e) { e.printStackTrace(); } } @@ -284,23 +295,26 @@ private void downloadMods(List mods) { LOGGER.info("Download url is: " + url, true); try { - HttpResponse res = Unirest - .get(url) + Request request = new Request.Builder() + .url(url) .header("User-Agent", "All the mods server installer.") .header("Content-Type", "application/json") - .asJson(); + .build(); + Response res = httpClient.newCall(request).execute(); - if (res.getStatus() != 200) - throw new UnirestException("Response was not OK"); + if (!res.isSuccessful()) + throw new IOException("Request to " + url + " was not successful."); + ResponseBody body = res.body(); + if (body == null) + throw new IOException("Request to " + url + " returned a null body."); - JsonObject jsonRes = new JsonParser().parse(res.getBody().toString()).getAsJsonObject(); + JsonObject jsonRes = new JsonParser().parse(body.string()).getAsJsonObject(); LOGGER.info("Response from manifest query: " + jsonRes, true); urls.add(jsonRes .getAsJsonObject() .getAsJsonPrimitive("DownloadURL").getAsString()); - - } catch (UnirestException e) { + } catch (IOException e) { LOGGER.error("Error while trying to get URL from cursemeta for mod " + mod.projectID, e); } });