Fidgeting while the world burns 🔥🔥🔥🔥🔥🔥

This commit is contained in:
cpw authored and LexManos committed 2018-09-05 11:40:48 -07:00
1 parent f942eb184a
commit 3b78e97ad8
24 files changed
+72 -79

No files matched your search

@@ -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."
);
@@ -1,43 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading;
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;
/**
* Loaded as a ServiceLoader, from the classpath. Extensions are loaded from
* the mods directory, with the FMLType META-INF of LANGPROVIDER.
*
* Version data is read from the manifest's implementation version.
*/
public interface IModLanguageProvider
{
String name();
Consumer<ScanResult> getFileVisitor();
interface IModLanguageLoader {
ModContainer loadMod(IModInfo info, ClassLoader modClassLoader, ScanResult scanResults);
}
}
@@ -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;
@@ -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;
@@ -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;
@@ -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);
}
@@ -1,39 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.common.versioning.VersionRange;
import java.net.URL;
import java.util.List;
public interface IModFileInfo
{
List<IModInfo> getMods();
UnmodifiableConfig getConfig();
URL getUpdateURL(IModFileInfo modFileInfo);
String getModLoader();
VersionRange getModLoaderVersion();
}
@@ -1,107 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
import net.minecraftforge.fml.common.versioning.VersionRange;
import net.minecraftforge.fml.loading.FMLEnvironment;
import java.util.List;
public interface IModInfo
{
VersionRange UNBOUNDED = VersionRange.createFromVersionSpec("");
IModFileInfo getOwningFile();
String getModId();
ArtifactVersion getVersion();
List<ModVersion> getDependencies();
UnmodifiableConfig getModConfig();
enum Ordering {
BEFORE, AFTER, NONE
}
enum DependencySide {
CLIENT, SERVER, BOTH;
public boolean isCorrectSide()
{
return this == BOTH || FMLEnvironment.side.name().equals(this.name());
}
}
class ModVersion {
private IModInfo owner;
private final String modId;
private final VersionRange versionRange;
private final boolean mandatory;
private final Ordering ordering;
private final DependencySide side;
ModVersion(final IModInfo owner, final UnmodifiableConfig config) {
this.owner = owner;
this.modId = config.get("modId");
this.versionRange = config.getOptional("versionRange").map(String.class::cast).
map(VersionRange::createFromVersionSpec).orElse(UNBOUNDED);
this.mandatory = config.get("mandatory");
this.ordering = config.getOptional("ordering").map(String.class::cast).
map(Ordering::valueOf).orElse(Ordering.NONE);
this.side = config.getOptional("side").map(String.class::cast).
map(DependencySide::valueOf).orElse(DependencySide.BOTH);
}
public String getModId()
{
return modId;
}
public VersionRange getVersionRange()
{
return versionRange;
}
public boolean isMandatory()
{
return mandatory;
}
public Ordering getOrdering()
{
return ordering;
}
public DependencySide getSide()
{
return side;
}
public void setOwner(final IModInfo owner)
{
this.owner = owner;
}
}
}
@@ -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;
@@ -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;
@@ -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);
}
@@ -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
@@ -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;
@@ -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;
@@ -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;
@@ -1,112 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.fml.loading.moddiscovery;
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;
public class ScanResult {
private final ModFile file;
private final List<ScanResult.AnnotationData> annotations = new ArrayList<>();
private final List<ScanResult.ClassData> classes = new ArrayList<>();
private Map<String,? extends IModLanguageProvider.IModLanguageLoader> modTargets;
public ScanResult(final ModFile file) {
this.file = file;
}
public ModFile getFile() {
return file;
}
public static boolean interestingAnnotations(final ModAnnotation annotation) {
return true;
}
public List<ScanResult.ClassData> getClasses() {
return classes;
}
public List<ScanResult.AnnotationData> getAnnotations() {
return annotations;
}
public void addLanguageLoader(Map<String,? extends IModLanguageProvider.IModLanguageLoader> modTargetMap)
{
modTargets = modTargetMap;
}
public Map<String, ? extends IModLanguageProvider.IModLanguageLoader> getTargets()
{
return modTargets;
}
public static class ClassData {
private final Type clazz;
private final Type parent;
private final Set<Type> interfaces;
public ClassData(final Type clazz, final Type parent, final Set<Type> interfaces) {
this.clazz = clazz;
this.parent = parent;
this.interfaces = interfaces;
}
}
public static class AnnotationData {
private final Type annotationType;
private final Type clazz;
private final String memberName;
private final Map<String,Object> annotationData;
public AnnotationData(final Type annotationType, final Type clazz, final String memberName, final Map<String, Object> annotationData) {
this.annotationType = annotationType;
this.clazz = clazz;
this.memberName = memberName;
this.annotationData = annotationData;
}
public Type getAnnotationType() {
return annotationType;
}
public Type getClassType() {
return clazz;
}
public String getMemberName() {
return memberName;
}
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);
}
}
}
@@ -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();