implement improvements and simplifications

This commit is contained in:
moehreag 2024-05-28 15:12:52 +02:00
parent dd8b87a1cf
commit 0bc8d555d0
8 changed files with 24 additions and 8076 deletions

View file

@ -1,7 +1,7 @@
[versions]
remapper = "1.0.0-SNAPSHOT"
nightconfig = "3.7.1"
nightconfig = "3.7.2"
mixin = "0.13.4+mixin.0.8.5"
annotations = "24.1.0"

View file

@ -1,60 +0,0 @@
package org.ecorous.esnesnon.nonsense.loader.api.mod;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.JsonObject;
import org.ecorous.esnesnon.nonsense.loader.impl.LoaderImpl;
import org.slf4j.LoggerFactory;
public final class License {
private static final Map<String, String> idToName = new HashMap<>();
private static final Map<String, License> idToLicense = new HashMap<>();
static {
loadList();
}
private static void loadList(){
try (InputStream in = License.class.getResourceAsStream("/assets/nonsense-loader/licenses.json")){
if (in == null){
throw new IllegalStateException("in == null");
}
JsonObject object = LoaderImpl.getInstance().getGson().fromJson(new InputStreamReader(in), JsonObject.class);
object.getAsJsonArray("licenses").forEach(element -> {
JsonObject entry = element.getAsJsonObject();
idToName.put(entry.get("licenseId").getAsString(), entry.get("name").getAsString());
});
} catch (Exception e){
LoggerFactory.getLogger(License.class).warn("Failed to load license list!", e);
}
idToName.put("ARR", "All rights reserved");
idToName.put("", "Unknown License");
}
public static License fromId(String id){
return idToLicense.computeIfAbsent(id, ignored -> new License(idToName.getOrDefault(id, id), id));
}
public static License custom(String id, String name){
return idToLicense.computeIfAbsent(id, ignored -> new License(idToName.computeIfAbsent(id, s -> name), id));
}
private final String name, id;
private License(String name, String id) {
this.name = name;
this.id = id;
}
public String name() {
return name;
}
public String id() {
return id;
}
}

View file

@ -1,5 +1,8 @@
package org.ecorous.esnesnon.nonsense.loader.api.mod;
import java.util.Collection;
import java.util.Map;
public interface ModProperties {
String id();
@ -8,9 +11,9 @@ public interface ModProperties {
SemVer version();
License license();
String license();
ModCredits credits();
Map<String, Collection<String>> credits();
ModDependencies dependencies();

View file

@ -1,8 +1,14 @@
package org.ecorous.esnesnon.nonsense.loader.impl.mod;
import org.ecorous.esnesnon.nonsense.loader.api.mod.*;
import java.util.Collection;
import java.util.Map;
public record ModPropertiesImpl(String id, String name, SemVer version, License license,
ModCredits credits, ModDependencies dependencies,
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModDependencies;
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModExtensions;
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModProperties;
import org.ecorous.esnesnon.nonsense.loader.api.mod.SemVer;
public record ModPropertiesImpl(String id, String name, SemVer version, String license,
Map<String, Collection<String>> credits, ModDependencies dependencies,
ModExtensions extensions) implements ModProperties {
}

View file

@ -94,7 +94,7 @@ public class ModPropertiesReader {
extensionsConfig.entrySet().forEach(entry -> extensions.put(entry.getKey(), entry.getValue()));
}
return new ModPropertiesImpl(id, name, SemVerImpl.parse(version), License.fromId(license), ModCredits.of(credits), new ModDependencies(depends, breaks, suggests, provides), ModExtensions.of(extensions));
return new ModPropertiesImpl(id, name, SemVerImpl.parse(version), license, Collections.unmodifiableMap(credits), new ModDependencies(depends, breaks, suggests, provides), ModExtensions.of(extensions));
});
private final String version;

View file

@ -28,7 +28,6 @@ class AWProcessor {
private static final String AW_EXTENSION_NAME = BuiltinExtensions.ACCESSWIDENER;
private static final Predicate<String> HEADER = Pattern.compile("accessWidener\\s+v[12]\\s+.*").asMatchPredicate();
private static final Predicate<String> COMMENT = Pattern.compile("^#.*").asMatchPredicate();
private static final String SEPARATOR = "[\\t ]+";
private static final Logger LOGGER = LoggerFactory.getLogger("AccessWidener");
@ -40,10 +39,11 @@ class AWProcessor {
Map<String, Map<String, Entry>> mutations = new ConcurrentHashMap<>();
Set<String> classNames = new ConcurrentSkipListSet<>();
mods.parallelStream().map(ModProperties::extensions).map(e -> (String) e.get(AW_EXTENSION_NAME))
mods.stream().map(ModProperties::extensions).map(e -> (String) e.get(AW_EXTENSION_NAME))
.filter(Objects::nonNull).map(s -> "/" + s).map(AWProcessor.class::getResourceAsStream).filter(Objects::nonNull)
.map(InputStreamReader::new).map(BufferedReader::new).flatMap(BufferedReader::lines)
.filter(l -> !l.isBlank()).filter(l -> !COMMENT.test(l)).filter(l -> !HEADER.test(l)).distinct()
.map(l -> l.contains("#") ? l.split("#")[0] : l).filter(l -> !l.isBlank())
.filter(l -> !HEADER.test(l)).distinct()
.map(l -> l.replace("transitive-", "")) // ignore all transitive declarations (just make them normal) as they're only relevant for dev envs
.map(l -> l.split(SEPARATOR)).filter(l -> l.length > 0).map(Entry::new).forEach(e -> {
classNames.add(e.className);
@ -101,13 +101,9 @@ class AWProcessor {
if (!classNames.isEmpty()) {
try (FileSystem out = FileSystems.newFileSystem(output)) {
classNames.parallelStream().forEach(name -> {
try {
for (String name : classNames) {
processFile(name, out.getPath("/" + name + ".class"), classMap, fields, methods, mutations);
} catch (IOException e) {
throw new Error(e);
}
});
}
}
LOGGER.info(String.format("Applied AccessWideners in %.2fs", (System.currentTimeMillis() - startTime) / 1000f));

View file

@ -60,8 +60,8 @@ public class Minecraft implements NonsensePlugin {
}
modProperties.add(new ModPropertiesImpl("minecraft", "Minecraft",
new MinecraftSemVerImpl(version), License.custom("MC-EULA", "Minecraft EULA"),
ModCredits.of(Map.of("Mojang AB", Collections.singleton("Author"))),
new MinecraftSemVerImpl(version), "MC-EULA",
Map.of("Mojang AB", Collections.singleton("Author")),
new ModDependencies(Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()),
ModExtensions.of(Collections.emptyMap())));

File diff suppressed because it is too large Load diff