This commit is contained in:
TheBrokenRail 2020-06-24 21:54:28 -04:00
parent c3c45a033e
commit 4199aa02bb
7 changed files with 49 additions and 37 deletions

View File

@ -1,5 +1,8 @@
# Changelog
**1.0.6**
* Fix Crash (Again)
**1.0.5**
* Fix Crash

View File

@ -34,6 +34,7 @@ dependencies {
shadowJar {
configurations = [project.configurations.shadow]
classifier 'shadow-dev'
mergeServiceFiles()
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation

View File

@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G
fabric_loader_version = 0.8.8+build.202
# Mod Properties
mod_version = 1.0.5
mod_version = 1.0.6
maven_group = com.thebrokenrail
# Dependencies

View File

@ -33,18 +33,21 @@ class CurseForgeStrategy implements ModUpdateStrategy {
return null;
}
String data = Util.urlToString("https://addons-ecs.forgesvc.net/api/v2/addon/" + projectID + "/files");
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<CurseForgeFile[]> jsonAdapter = moshi.adapter(CurseForgeFile[].class);
CurseForgeFile[] files;
String data;
try {
files = jsonAdapter.fromJson(data);
data = Util.urlToString("https://addons-ecs.forgesvc.net/api/v2/addon/" + projectID + "/files");
} catch (IOException e) {
ModUpdater.getLogger().warn("Unable To Access CurseForge: " + name);
return null;
} catch (JsonDataException e) {
}
CurseForgeFile[] files;
try {
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<CurseForgeFile[]> jsonAdapter = moshi.adapter(CurseForgeFile[].class);
files = jsonAdapter.fromJson(data);
} catch (JsonDataException | IOException e) {
ModUpdater.getLogger().warn("CurseForge Sent Invalid Data: ", e);
return null;
}

View File

@ -37,19 +37,22 @@ public class GitHubReleasesStrategy implements ModUpdateStrategy {
return null;
}
String data = Util.urlToString(String.format("https://api.github.com/repos/%s/%s/releases", owner, repo));
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<GitHubRelease[]> jsonAdapter = moshi.adapter(GitHubRelease[].class);
GitHubRelease[] releases;
String data;
try {
// GitHub's API never omits values, they're always null
releases = jsonAdapter.nonNull().fromJson(data);
data = Util.urlToString(String.format("https://api.github.com/repos/%s/%s/releases", owner, repo));
} catch (IOException e) {
ModUpdater.getLogger().warn("Unable To Access GitHub: " + name);
return null;
} catch (JsonDataException e) {
}
GitHubRelease[] releases;
try {
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<GitHubRelease[]> jsonAdapter = moshi.adapter(GitHubRelease[].class);
// GitHub's API never omits values, they're always null
releases = jsonAdapter.nonNull().fromJson(data);
} catch (JsonDataException | IOException e) {
ModUpdater.getLogger().warn("GitHub Sent Invalid Data: ", e);
return null;
}

View File

@ -12,8 +12,7 @@ import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.IOException;
import java.util.List;
public class MavenStrategy implements ModUpdateStrategy {
@ -33,11 +32,19 @@ public class MavenStrategy implements ModUpdateStrategy {
String mavenRoot = String.format("%s/%s/%s", repository, group.replaceAll("\\.", "/"), artifact);
String data;
try {
data = Util.urlToString(mavenRoot + "/maven-metadata.xml");
} catch (IOException e) {
ModUpdater.getLogger().warn("Unable To Access Maven Repository: " + name);
return null;
}
Document doc;
try {
SAXReader reader = new SAXReader();
doc = reader.read(new URL(mavenRoot + "/maven-metadata.xml"));
} catch (MalformedURLException | DocumentException e) {
doc = reader.read(data);
} catch (DocumentException e) {
ModUpdater.getLogger().warn("Unable To Access Maven Repository: " + name);
return null;
}

View File

@ -12,24 +12,19 @@ import java.net.URL;
import java.util.Optional;
public class Util {
public static String urlToString(String urlStr) {
try {
StringBuilder stringBuilder = new StringBuilder();
URL url = new URL(urlStr);
public static String urlToString(String urlStr) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
URL url = new URL(urlStr);
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()))) {
String line;
while ((line = in.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append('\n');
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()))) {
String line;
while ((line = in.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append('\n');
}
return stringBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
return "";
}
return stringBuilder.toString();
}
public static final String JAR_EXTENSION = ".jar";