Fidgeting while the world burns 🔥🔥🔥🔥🔥🔥

This commit is contained in:
cpw 2018-06-10 21:36:50 -04:00 committed by LexManos
parent f942eb184a
commit 3b78e97ad8
24 changed files with 72 additions and 79 deletions

View file

@ -21,7 +21,7 @@ package net.minecraftforge.fml;
import com.electronwill.nightconfig.core.path.PathConfig;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import java.net.URISyntaxException;

View file

@ -60,7 +60,6 @@ import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourcePack;
import net.minecraft.client.resources.SimpleResource;
import net.minecraft.crash.CrashReport;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.CrashReportExtender;
import net.minecraftforge.fml.common.EnhancedRuntimeException;

View file

@ -21,7 +21,7 @@ package net.minecraftforge.fml.common;
import net.minecraftforge.fml.LifecycleEventProvider;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.language.IModInfo;
import java.util.HashMap;
import java.util.Map;

View file

@ -19,11 +19,10 @@
package net.minecraftforge.fml.javafmlmod;
import net.minecraftforge.fml.javafmlmod.FMLModContainer;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.loading.IModLanguageProvider;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ScanResult;
import net.minecraftforge.fml.language.IModLanguageProvider;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.language.ModFileScanData;
import org.objectweb.asm.Type;
import java.util.Map;
@ -52,9 +51,9 @@ public class FMLJavaModLanguageProvider implements IModLanguageProvider
}
@Override
public ModContainer loadMod(final IModInfo info, final ClassLoader modClassLoader, final ScanResult scanResults)
public ModContainer loadMod(final IModInfo info, final ClassLoader modClassLoader, final ModFileScanData modFileScanResults)
{
return new FMLModContainer(info, className, modClassLoader, scanResults);
return new FMLModContainer(info, className, modClassLoader, modFileScanResults);
}
}
@ -67,7 +66,7 @@ public class FMLJavaModLanguageProvider implements IModLanguageProvider
}
@Override
public Consumer<ScanResult> getFileVisitor() {
public Consumer<ModFileScanData> getFileVisitor() {
return scanResult -> {
final Map<String, FMLModTarget> modTargetMap = scanResult.getAnnotations().stream()
.filter(ad -> ad.getAnnotationType().equals(MODANNOTATION))

View file

@ -27,8 +27,8 @@ import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ScanResult;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.language.ModFileScanData;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
@ -43,14 +43,14 @@ import static net.minecraftforge.fml.Logging.LOADING;
public class FMLModContainer extends ModContainer
{
private static final Logger LOGGER = LogManager.getLogger("FML");
private final ScanResult scanResults;
private final ModFileScanData scanResults;
private Object modInstance;
private final Class<?> modClass;
public FMLModContainer(IModInfo info, String className, ClassLoader modClassLoader, ScanResult scanResults)
public FMLModContainer(IModInfo info, String className, ClassLoader modClassLoader, ModFileScanData modFileScanResults)
{
super(info);
this.scanResults = scanResults;
this.scanResults = modFileScanResults;
triggerMap.put(ModLoadingStage.BEGIN, this::constructMod);
triggerMap.put(ModLoadingStage.PREINIT, this::preinitMod);

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
package net.minecraftforge.fml.language;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.common.versioning.VersionRange;

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
package net.minecraftforge.fml.language;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
@ -61,7 +61,7 @@ public interface IModInfo
private final Ordering ordering;
private final DependencySide side;
ModVersion(final IModInfo owner, final UnmodifiableConfig config) {
public ModVersion(final IModInfo owner, final UnmodifiableConfig config) {
this.owner = owner;
this.modId = config.get("modId");
this.versionRange = config.getOptional("versionRange").map(String.class::cast).

View file

@ -17,11 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading;
package net.minecraftforge.fml.language;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ScanResult;
import java.util.function.Consumer;
@ -35,9 +33,9 @@ public interface IModLanguageProvider
{
String name();
Consumer<ScanResult> getFileVisitor();
Consumer<ModFileScanData> getFileVisitor();
interface IModLanguageLoader {
ModContainer loadMod(IModInfo info, ClassLoader modClassLoader, ScanResult scanResults);
ModContainer loadMod(IModInfo info, ClassLoader modClassLoader, ModFileScanData modFileScanResults);
}
}

View file

@ -17,40 +17,32 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
package net.minecraftforge.fml.language;
import net.minecraftforge.fml.loading.IModLanguageProvider;
import org.objectweb.asm.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
public class ScanResult {
private final ModFile file;
private final List<ScanResult.AnnotationData> annotations = new ArrayList<>();
private final List<ScanResult.ClassData> classes = new ArrayList<>();
public class ModFileScanData
{
private final List<ModFileScanData.AnnotationData> annotations = new ArrayList<>();
private final List<ModFileScanData.ClassData> classes = new ArrayList<>();
private Map<String,? extends IModLanguageProvider.IModLanguageLoader> modTargets;
public ScanResult(final ModFile file) {
this.file = file;
public static Predicate<Type> interestingAnnotations() {
return t->true;
}
public ModFile getFile() {
return file;
}
public static boolean interestingAnnotations(final ModAnnotation annotation) {
return true;
}
public List<ScanResult.ClassData> getClasses() {
public List<ModFileScanData.ClassData> getClasses() {
return classes;
}
public List<ScanResult.AnnotationData> getAnnotations() {
public List<ModFileScanData.AnnotationData> getAnnotations() {
return annotations;
}
@ -105,8 +97,5 @@ public class ScanResult {
public Map<String, Object> getAnnotationData() {
return annotationData;
}
public static ScanResult.AnnotationData fromModAnnotation(final Type clazz, final ModAnnotation annotation) {
return new AnnotationData(annotation.asmType, clazz, annotation.member, annotation.values);
}
}
}

View file

@ -44,7 +44,7 @@ public class FMLDevClientLaunchProvider extends FMLCommonLaunchHandler implement
private static final List<String> SKIPPACKAGES = Arrays.asList(
"joptsimple.", "org.lwjgl.", "com.mojang.", "com.google.",
"org.apache.commons.", "io.netty.", "net.minecraftforge.fml.loading.",
"org.apache.commons.", "io.netty.", "net.minecraftforge.fml.loading.", "net.minecraftforge.fml.language.",
"net.minecraftforge.eventbus.", "it.unimi.dsi.fastutil.", "net.minecraftforge.api.",
"paulscode.sound.", "com.ibm.icu.", "sun.", "gnu.trove.", "com.electronwill.nightconfig."
);

View file

@ -23,6 +23,7 @@ import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.language.IModLanguageProvider;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import java.nio.file.Path;

View file

@ -23,8 +23,6 @@ import net.minecraftforge.fml.LifecycleEventProvider;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.loading.moddiscovery.BackgroundScanHandler;
import net.minecraftforge.fml.loading.moddiscovery.IModFileInfo;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;

View file

@ -25,7 +25,7 @@ import net.minecraftforge.fml.common.DuplicateModsFoundException;
import net.minecraftforge.fml.common.MissingModsException;
import net.minecraftforge.fml.common.toposort.TopologicalSort;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.loading.moddiscovery.IModInfo;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import org.apache.logging.log4j.LogManager;
@ -35,7 +35,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;

View file

@ -19,7 +19,7 @@
package net.minecraftforge.fml.loading.moddiscovery;
import com.google.common.util.concurrent.MoreExecutors;
import net.minecraftforge.fml.language.ModFileScanData;
import net.minecraftforge.fml.loading.ModList;
import java.util.ArrayList;
@ -27,7 +27,6 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import static net.minecraftforge.fml.Logging.SCAN;
@ -58,13 +57,13 @@ public class BackgroundScanHandler
}
allFiles.add(file);
pendingFiles.add(file);
final CompletableFuture<ScanResult> future = CompletableFuture.supplyAsync(file::compileContent, modContentScanner)
final CompletableFuture<ModFileScanData> future = CompletableFuture.supplyAsync(file::compileContent, modContentScanner)
.whenComplete(file::setScanResult)
.whenComplete((r,t)-> this.addCompletedFile(file,r,t));
file.setFutureScanResult(future);
}
private void addCompletedFile(final ModFile file, final ScanResult scanResult, final Throwable throwable) {
private void addCompletedFile(final ModFile file, final ModFileScanData modFileScanData, final Throwable throwable) {
if (throwable != null) {
fmlLog.error(SCAN,"An error occurred scanning file {}", file, throwable);
}

View file

@ -19,6 +19,8 @@
package net.minecraftforge.fml.loading.moddiscovery;
import net.minecraftforge.fml.language.IModFileInfo;
public class InvalidModFileException extends RuntimeException
{
private final IModFileInfo modFileInfo;

View file

@ -23,6 +23,7 @@ import java.lang.annotation.ElementType;
import java.util.ArrayList;
import java.util.Map;
import net.minecraftforge.fml.language.ModFileScanData;
import org.objectweb.asm.Type;
import com.google.common.base.MoreObjects;
@ -31,6 +32,10 @@ import com.google.common.collect.Maps;
public class ModAnnotation
{
public static ModFileScanData.AnnotationData fromModAnnotation(final Type clazz, final ModAnnotation annotation) {
return new ModFileScanData.AnnotationData(annotation.asmType, clazz, annotation.member, annotation.values);
}
public static class EnumHolder
{
private final String desc;

View file

@ -19,6 +19,7 @@
package net.minecraftforge.fml.loading.moddiscovery;
import net.minecraftforge.fml.language.ModFileScanData;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
@ -74,10 +75,11 @@ public class ModClassVisitor extends ClassVisitor
return new ModMethodVisitor(name, desc, annotations);
}
public void buildData(final List<ScanResult.ClassData> classes, final List<ScanResult.AnnotationData> annotations) {
classes.add(new ScanResult.ClassData(this.asmType, this.asmSuperType, this.interfaces));
final List<ScanResult.AnnotationData> collect = this.annotations.stream().filter(ScanResult::interestingAnnotations).
map(a -> ScanResult.AnnotationData.fromModAnnotation(this.asmType, a)).collect(Collectors.toList());
public void buildData(final List<ModFileScanData.ClassData> classes, final List<ModFileScanData.AnnotationData> annotations) {
classes.add(new ModFileScanData.ClassData(this.asmType, this.asmSuperType, this.interfaces));
final List<ModFileScanData.AnnotationData> collect = this.annotations.stream().
filter(ma->ModFileScanData.interestingAnnotations().test(ma.asmType)).
map(a -> ModAnnotation.fromModAnnotation(this.asmType, a)).collect(Collectors.toList());
annotations.addAll(collect);
}

View file

@ -21,8 +21,11 @@ package net.minecraftforge.fml.loading.moddiscovery;
import com.google.common.collect.ImmutableMap;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.language.IModFileInfo;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.language.ModFileScanData;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.IModLanguageProvider;
import net.minecraftforge.fml.language.IModLanguageProvider;
import net.minecraftforge.fml.loading.ModLoadingClassLoader;
import java.nio.file.Files;
@ -86,8 +89,8 @@ public class ModFile
private final IModLocator locator;
private IModFileInfo modFileInfo;
private Map<String, IModInfo> modInfoMap;
private ScanResult fileScanResult;
private CompletableFuture<ScanResult> futureScanResult;
private ModFileScanData fileModFileScanData;
private CompletableFuture<ModFileScanData> futureScanResult;
private List<CoreModFile> coreMods;
private Path accessTransformer;
@ -142,19 +145,19 @@ public class ModFile
/**
* Run in an executor thread to harvest the class and annotation list
*/
public ScanResult compileContent() {
public ModFileScanData compileContent() {
return new Scanner(this).scan();
}
public void scanFile(Consumer<Path> pathConsumer) {
locator.scanFile(this, pathConsumer);
}
public void setFutureScanResult(CompletableFuture<ScanResult> future)
public void setFutureScanResult(CompletableFuture<ModFileScanData> future)
{
this.futureScanResult = future;
}
public ScanResult getScanResult() {
public ModFileScanData getScanResult() {
if (this.futureScanResult != null) {
try {
this.futureScanResult.get();
@ -162,12 +165,12 @@ public class ModFile
e.printStackTrace();
}
}
return this.fileScanResult;
return this.fileModFileScanData;
}
public void setScanResult(final ScanResult scanResult, final Throwable throwable) {
public void setScanResult(final ModFileScanData modFileScanData, final Throwable throwable) {
this.futureScanResult = null;
this.fileScanResult = scanResult;
this.fileModFileScanData = modFileScanData;
}
@Override

View file

@ -21,6 +21,8 @@ package net.minecraftforge.fml.loading.moddiscovery;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.language.IModFileInfo;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.loading.StringUtils;
import java.net.URL;

View file

@ -22,6 +22,7 @@ package net.minecraftforge.fml.loading.moddiscovery;
import com.electronwill.nightconfig.core.path.PathConfig;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.minecraftforge.fml.language.IModFileInfo;
import java.io.IOException;
import java.lang.reflect.Type;

View file

@ -20,10 +20,10 @@
package net.minecraftforge.fml.loading.moddiscovery;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.language.IModInfo;
import net.minecraftforge.fml.loading.StringSubstitutor;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionRange;
import java.util.Arrays;
import java.util.Collections;
@ -31,7 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class ModInfo implements IModInfo {
public class ModInfo implements IModInfo
{
private static final DefaultArtifactVersion DEFAULT_VERSION = new DefaultArtifactVersion("1");
private final ModFileInfo owningFile;
private final String modId;

View file

@ -19,19 +19,14 @@
package net.minecraftforge.fml.loading.moddiscovery;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.IModLanguageProvider;
import net.minecraftforge.fml.loading.LanguageLoadingProvider;
import net.minecraftforge.fml.language.IModLanguageProvider;
import net.minecraftforge.fml.language.ModFileScanData;
import org.objectweb.asm.ClassReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static net.minecraftforge.fml.Logging.LOADING;
import static net.minecraftforge.fml.Logging.SCAN;
import static net.minecraftforge.fml.Logging.fmlLog;
@ -42,8 +37,8 @@ public class Scanner {
this.fileToScan = fileToScan;
}
public ScanResult scan() {
ScanResult result = new ScanResult(fileToScan);
public ModFileScanData scan() {
ModFileScanData result = new ModFileScanData();
fileToScan.scanFile(p -> fileVisitor(p, result));
final IModLanguageProvider loader = fileToScan.getLoader();
fmlLog.debug(SCAN, "Scanning {} with language loader {}", fileToScan.getFilePath(), loader.name());
@ -51,7 +46,7 @@ public class Scanner {
return result;
}
private void fileVisitor(final Path path, final ScanResult result) {
private void fileVisitor(final Path path, final ModFileScanData result) {
try {
fmlLog.debug(SCAN,"Scanning {} path {}", fileToScan, path);
ModClassVisitor mcv = new ModClassVisitor();

View file

@ -1,6 +1,6 @@
package net.minecraftforge.fml.test;
import net.minecraftforge.fml.loading.moddiscovery.IModFileInfo;
import net.minecraftforge.fml.language.IModFileInfo;
import net.minecraftforge.fml.loading.moddiscovery.ModFileParser;
import org.junit.Test;