Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions src/main/java/cam72cam/universalmodcore/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class Mod {
public final String id;
public final String version;
public final List<Dependency> dependencies;
public final List<Library> libraries = new ArrayList<>();

public static class Dependency {
public final String id;
Expand All @@ -49,6 +50,9 @@ public Mod(JsonObject data) {
this.dependencies = data.get("dependencies").getAsJsonObject().entrySet().stream()
.map((e) -> new Dependency(e.getKey(), e.getValue().getAsJsonObject()))
.collect(Collectors.toList());
if (data.has("libraries")) {
data.get("libraries").getAsJsonArray().forEach(e -> libraries.add(new Library(e.getAsJsonObject())));
}
}
}

Expand All @@ -74,6 +78,49 @@ public UMC(JsonObject data) {
}
}

public static class Library {
public final boolean isDir;
public final String id;
public final String repo;
public final boolean hasRelocation;
public String relocateFrom;
public String relocateTo;
public final String type;
public final List<String> onlyIn = new ArrayList<>();

public Library(JsonObject data) {
this.id = data.get("artifact").getAsString();

String repoType = data.get("repositoryType").getAsString();

switch (repoType) {
case "URL": this.isDir = false; break;
case "Dir": this.isDir = true; break;
default: throw new IllegalArgumentException("The repository Type needs to be either \"URL\" or \"Dir\"");
}


this.hasRelocation = data.has("relocate");

this.type = data.get("type").getAsString();

if (data.has("onlyIn")) {
data.get("onlyIn").getAsJsonArray().forEach(e -> onlyIn.add(e.getAsString()));
}

if (hasRelocation) {
String[] path = data.get("relocate").getAsString().replaceAll(" ", "").split("\\|");
if (path.length != 2) {
throw new IllegalArgumentException("Relocate needs needs two paths separated by a '|'");
}
relocateFrom = path[0];
relocateTo = path[1];
}

this.repo = data.get("repository").getAsString();
}
}

public Config(JsonObject data, String mcVersion, Loader brand) throws GitAPIException, IOException {
mod = new Mod(data.get("mod").getAsJsonObject());
integration = data.has("integration") ? new Integration(data.get("integration").getAsJsonObject()) : null;
Expand All @@ -91,6 +138,42 @@ public Config(JsonObject data, String mcVersion, Loader brand) throws GitAPIExce
vars.put("MINECRAFT", mcVersion);
vars.put("LOADER", brand.toString());

List<String> repoLines = new ArrayList<>();
List<String> depLines = new ArrayList<>();
List<String> relLines = new ArrayList<>();
List<String> flatDirs = new ArrayList<>();

for (Library library : mod.libraries) {
if (!library.onlyIn.isEmpty() && !library.onlyIn.contains(minecraftLoader)) {
continue;
}

if (library.isDir) {
flatDirs.add("'" + library.repo + "'");
} else {
repoLines.add("\tmaven { url = \"" + library.repo + "\"");
}

if (library.hasRelocation) {
relLines.add("\trelocate'" + library.relocateFrom + "', \"" + library.relocateTo + "\"");
}

depLines.add("\t" + library.type + " '" + library.id + "'");
}

if (!flatDirs.isEmpty()) {
String flatDirBlock =
"\tflatDir {\n" +
"\t\tdirs " + String.join(", ", flatDirs) + "\n" +
"\t}";

repoLines.add(0, flatDirBlock);
}

vars.put("LIB_REPOS", String.join("\n", repoLines));
vars.put("MOD_DEPENDENCIES", String.join("\n", depLines));
vars.put("RELOCATION", String.join("\n", relLines));

String version = require("umc.version", umc.version);

if (version.equals("latest")) {
Expand Down Expand Up @@ -131,11 +214,11 @@ public Config(JsonObject data, String mcVersion, Loader brand) throws GitAPIExce
if (!jar.exists()) {
throw new RuntimeException(String.format("Unable to find UMC jar: %s", jar));
}
vars.put("UMC_REPO", String.format("repositories { flatDir { dirs '%s' } }", jar.getParent()));
vars.put("UMC_REPO", String.format("flatDir { dirs '%s' }", jar.getParent()));
vars.put("UMC_DEPENDENCY", String.format("name: '%s'", jar.getName().replace(".jar", "")));
vars.put("UMC_FILE", jar.getPath());
} else {
vars.put("UMC_REPO", "repositories { maven { url = \"https://teamopenindustry.cc/maven\" }}");
vars.put("UMC_REPO", "maven { url = \"https://teamopenindustry.cc/maven\" }");
vars.put("UMC_DEPENDENCY", String.format("'cam72cam.universalmodcore:UniversalModCore:%s-%s'", minecraftLoader, version));
vars.put("UMC_DOWNLOAD", String.format("https://teamopenindustry.cc/maven/cam72cam/universalmodcore/UniversalModCore/%s-%s/UniversalModCore-%s-%s.jar", minecraftLoader, version, minecraftLoader, version));
}
Expand Down