Using public API for SemanticVersion
(paulevsGitch/BCLib#146)
This commit is contained in:
parent
69a4583d57
commit
c1b5b7c01b
1 changed files with 409 additions and 433 deletions
|
@ -1,21 +1,12 @@
|
||||||
package ru.bclib.util;
|
package ru.bclib.util;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.*;
|
||||||
|
import net.fabricmc.loader.api.metadata.*;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
|
||||||
import net.fabricmc.loader.api.SemanticVersion;
|
|
||||||
import net.fabricmc.loader.api.Version;
|
|
||||||
import net.fabricmc.loader.api.VersionParsingException;
|
|
||||||
import net.fabricmc.loader.api.metadata.ContactInformation;
|
|
||||||
import net.fabricmc.loader.api.metadata.CustomValue;
|
|
||||||
import net.fabricmc.loader.api.metadata.ModDependency;
|
|
||||||
import net.fabricmc.loader.api.metadata.ModEnvironment;
|
|
||||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
|
||||||
import net.fabricmc.loader.api.metadata.Person;
|
|
||||||
import net.fabricmc.loader.util.version.SemanticVersionImpl;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
|
|
||||||
|
@ -28,12 +19,7 @@ import java.nio.file.FileSystem;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -68,15 +54,14 @@ public class ModUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException {
|
private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException {
|
||||||
try (com.google.gson.stream.JsonReader reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
|
try (com.google.gson.stream.JsonReader reader = new JsonReader(new InputStreamReader(is,
|
||||||
|
StandardCharsets.UTF_8))) {
|
||||||
JsonObject data = new JsonParser().parse(reader)
|
JsonObject data = new JsonParser().parse(reader)
|
||||||
.getAsJsonObject();
|
.getAsJsonObject();
|
||||||
Version ver;
|
Version ver;
|
||||||
try {
|
try {
|
||||||
ver = new SemanticVersionImpl(data.get("version")
|
ver = SemanticVersion.parse(data.get("version").getAsString());
|
||||||
.getAsString(), false);
|
} catch (VersionParsingException e) {
|
||||||
}
|
|
||||||
catch (VersionParsingException e) {
|
|
||||||
BCLib.LOGGER.error("Unable to parse Version in " + sourceFile);
|
BCLib.LOGGER.error("Unable to parse Version in " + sourceFile);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +108,8 @@ public class ModUtil {
|
||||||
final String environment = env == null ? "" : env.getAsString()
|
final String environment = env == null ? "" : env.getAsString()
|
||||||
.toLowerCase(Locale.ROOT);
|
.toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
if (environment.isEmpty() || environment.equals("*") || environment.equals("\"*\"") || environment.equals("common")) {
|
if (environment.isEmpty() || environment.equals("*") || environment.equals("\"*\"") || environment.equals(
|
||||||
|
"common")) {
|
||||||
JsonElement entrypoints = data.get("entrypoints");
|
JsonElement entrypoints = data.get("entrypoints");
|
||||||
boolean hasClient = true;
|
boolean hasClient = true;
|
||||||
|
|
||||||
|
@ -134,11 +120,9 @@ public class ModUtil {
|
||||||
if (client != null && client.isJsonArray()) {
|
if (client != null && client.isJsonArray()) {
|
||||||
hasClient = client.getAsJsonArray()
|
hasClient = client.getAsJsonArray()
|
||||||
.size() > 0;
|
.size() > 0;
|
||||||
}
|
} else if (client == null || !client.isJsonPrimitive()) {
|
||||||
else if (client == null || !client.isJsonPrimitive()) {
|
|
||||||
hasClient = false;
|
hasClient = false;
|
||||||
}
|
} else if (!client.getAsJsonPrimitive()
|
||||||
else if (!client.getAsJsonPrimitive()
|
|
||||||
.isString()) {
|
.isString()) {
|
||||||
hasClient = false;
|
hasClient = false;
|
||||||
}
|
}
|
||||||
|
@ -146,14 +130,11 @@ public class ModUtil {
|
||||||
|
|
||||||
//if (hasClient == false) return ModEnvironment.SERVER;
|
//if (hasClient == false) return ModEnvironment.SERVER;
|
||||||
return ModEnvironment.UNIVERSAL;
|
return ModEnvironment.UNIVERSAL;
|
||||||
}
|
} else if (environment.equals("client")) {
|
||||||
else if (environment.equals("client")) {
|
|
||||||
return ModEnvironment.CLIENT;
|
return ModEnvironment.CLIENT;
|
||||||
}
|
} else if (environment.equals("server")) {
|
||||||
else if (environment.equals("server")) {
|
|
||||||
return ModEnvironment.SERVER;
|
return ModEnvironment.SERVER;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
BCLib.LOGGER.error("Unable to read environment in " + sourceFile);
|
BCLib.LOGGER.error("Unable to read environment in " + sourceFile);
|
||||||
return ModEnvironment.UNIVERSAL;
|
return ModEnvironment.UNIVERSAL;
|
||||||
}
|
}
|
||||||
|
@ -328,8 +309,7 @@ public class ModUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,8 +357,7 @@ public class ModUtil {
|
||||||
// boolean doClose = false;
|
// boolean doClose = false;
|
||||||
try {
|
try {
|
||||||
fs = FileSystems.getFileSystem(uri);
|
fs = FileSystems.getFileSystem(uri);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
// doClose = true;
|
// doClose = true;
|
||||||
fs = FileSystems.newFileSystem(file);
|
fs = FileSystems.newFileSystem(file);
|
||||||
}
|
}
|
||||||
|
@ -394,14 +373,12 @@ public class ModUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
BCLib.LOGGER.error("Error for " + uri + ": " + e.toString());
|
BCLib.LOGGER.error("Error for " + uri + ": " + e.toString());
|
||||||
}
|
}
|
||||||
//if (doClose) fs.close();
|
//if (doClose) fs.close();
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
BCLib.LOGGER.error("Error for " + file.toUri() + ": " + e.toString());
|
BCLib.LOGGER.error("Error for " + file.toUri() + ": " + e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -430,8 +407,7 @@ public class ModUtil {
|
||||||
for (int i = 0; i < cCount; i++) {
|
for (int i = 0; i < cCount; i++) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
stringBuilder.append('.');
|
stringBuilder.append('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue