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;
|
||||
|
||||
import net.fabricmc.loader.api.*;
|
||||
import net.fabricmc.loader.api.metadata.*;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
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 ru.bclib.BCLib;
|
||||
|
||||
|
@ -28,12 +19,7 @@ import java.nio.file.FileSystem;
|
|||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -68,15 +54,14 @@ public class ModUtil {
|
|||
}
|
||||
|
||||
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)
|
||||
.getAsJsonObject();
|
||||
Version ver;
|
||||
try {
|
||||
ver = new SemanticVersionImpl(data.get("version")
|
||||
.getAsString(), false);
|
||||
}
|
||||
catch (VersionParsingException e) {
|
||||
ver = SemanticVersion.parse(data.get("version").getAsString());
|
||||
} catch (VersionParsingException e) {
|
||||
BCLib.LOGGER.error("Unable to parse Version in " + sourceFile);
|
||||
return null;
|
||||
}
|
||||
|
@ -123,7 +108,8 @@ public class ModUtil {
|
|||
final String environment = env == null ? "" : env.getAsString()
|
||||
.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");
|
||||
boolean hasClient = true;
|
||||
|
||||
|
@ -134,11 +120,9 @@ public class ModUtil {
|
|||
if (client != null && client.isJsonArray()) {
|
||||
hasClient = client.getAsJsonArray()
|
||||
.size() > 0;
|
||||
}
|
||||
else if (client == null || !client.isJsonPrimitive()) {
|
||||
} else if (client == null || !client.isJsonPrimitive()) {
|
||||
hasClient = false;
|
||||
}
|
||||
else if (!client.getAsJsonPrimitive()
|
||||
} else if (!client.getAsJsonPrimitive()
|
||||
.isString()) {
|
||||
hasClient = false;
|
||||
}
|
||||
|
@ -146,14 +130,11 @@ public class ModUtil {
|
|||
|
||||
//if (hasClient == false) return ModEnvironment.SERVER;
|
||||
return ModEnvironment.UNIVERSAL;
|
||||
}
|
||||
else if (environment.equals("client")) {
|
||||
} else if (environment.equals("client")) {
|
||||
return ModEnvironment.CLIENT;
|
||||
}
|
||||
else if (environment.equals("server")) {
|
||||
} else if (environment.equals("server")) {
|
||||
return ModEnvironment.SERVER;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
BCLib.LOGGER.error("Unable to read environment in " + sourceFile);
|
||||
return ModEnvironment.UNIVERSAL;
|
||||
}
|
||||
|
@ -328,8 +309,7 @@ public class ModUtil {
|
|||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -377,8 +357,7 @@ public class ModUtil {
|
|||
// boolean doClose = false;
|
||||
try {
|
||||
fs = FileSystems.getFileSystem(uri);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
// doClose = true;
|
||||
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());
|
||||
}
|
||||
//if (doClose) fs.close();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
BCLib.LOGGER.error("Error for " + file.toUri() + ": " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -430,8 +407,7 @@ public class ModUtil {
|
|||
for (int i = 0; i < cCount; i++) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stringBuilder.append('.');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue