mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
Holy Moly, it's a big fat commit of broken code!
This commit is contained in:
1 parent
5b05e103f4
commit
c1f0e1b68f
63 files changed
+2027
-542
No files matched your search
@@ -20,6 +20,8 @@
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import cpw.mods.modlauncher.api.IEnvironment;
|
||||
import cpw.mods.modlauncher.api.ITransformingClassLoader;
|
||||
import net.minecraftforge.api.Side;
|
||||
|
||||
public abstract class FMLCommonLaunchHandler
|
||||
{
|
||||
@@ -27,4 +29,11 @@ public abstract class FMLCommonLaunchHandler
|
||||
{
|
||||
// We need to check for deobf and patched jar here and if not, build one.
|
||||
}
|
||||
|
||||
public abstract Side getSidedness();
|
||||
|
||||
protected void beforeStart(ITransformingClassLoader launchClassLoader)
|
||||
{
|
||||
FMLLoader.beforeStart(launchClassLoader);
|
||||
}
|
||||
}
|
||||
+15
-4
@@ -21,7 +21,9 @@ package net.minecraftforge.fml.loading;
|
||||
|
||||
import cpw.mods.modlauncher.api.IEnvironment;
|
||||
import cpw.mods.modlauncher.api.ILaunchHandlerService;
|
||||
import cpw.mods.modlauncher.api.ITransformingClassLoader;
|
||||
import net.minecraft.client.main.Main;
|
||||
import net.minecraftforge.api.Side;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
@@ -31,12 +33,12 @@ import java.util.concurrent.Callable;
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class FMLDevLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService
|
||||
public class FMLDevClientLaunchProvider extends FMLCommonLaunchHandler implements ILaunchHandlerService
|
||||
{
|
||||
@Override
|
||||
public String name()
|
||||
{
|
||||
return "devfml";
|
||||
return "devfmlclient";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,10 +57,13 @@ public class FMLDevLaunchProvider extends FMLCommonLaunchHandler implements ILau
|
||||
}
|
||||
|
||||
@Override
|
||||
public Callable<Void> launchService(String[] arguments, ClassLoader launchClassLoader)
|
||||
public Callable<Void> launchService(String[] arguments, ITransformingClassLoader launchClassLoader)
|
||||
{
|
||||
return () -> {
|
||||
Main.main(arguments);
|
||||
fmlLog.debug(CORE, "Launching minecraft in {} with arguments {}", launchClassLoader, arguments);
|
||||
super.beforeStart(launchClassLoader);
|
||||
launchClassLoader.setTargetPackageFilter(cn -> !cn.startsWith("net.minecraftforge.fml.loading."));
|
||||
Class.forName("net.minecraft.client.main.Main", true, launchClassLoader.getInstance()).getMethod("main", String[].class).invoke(null, (Object)arguments);
|
||||
return null;
|
||||
};
|
||||
}
|
||||
@@ -68,4 +73,10 @@ public class FMLDevLaunchProvider extends FMLCommonLaunchHandler implements ILau
|
||||
{
|
||||
fmlLog.debug(CORE, "No jar creation necessary. Launch is dev environment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side getSidedness()
|
||||
{
|
||||
return Side.CLIENT;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLModContainer;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
@@ -52,9 +53,9 @@ public class FMLJavaModLanguageProvider implements IModLanguageProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModContainer loadMod(ModFile file, ClassLoader modClassLoader)
|
||||
public ModContainer loadMod(final ModInfo info, final ClassLoader modClassLoader)
|
||||
{
|
||||
return null;
|
||||
return new FMLModContainer(info, className, modClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,13 +75,7 @@ public class FMLJavaModLanguageProvider implements IModLanguageProvider
|
||||
.peek(ad -> fmlLog.debug(SCAN, "Found @Mod class {} with id {}", ad.getClassType().getClassName(), ad.getAnnotationData().get("modid")))
|
||||
.map(ad -> new FMLModTarget(ad.getClassType().getClassName(), (String)ad.getAnnotationData().get("modid")))
|
||||
.collect(Collectors.toMap(FMLModTarget::getModId, Function.identity()));
|
||||
modTargetMap.forEach((key, value) -> scanResult.getFile().claimLanguage(key, value));
|
||||
scanResult.addLanguageLoader(modTargetMap);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModContainer> buildModContainers(List<ModInfo> modFiles, ClassLoader modClassLoader)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,9 @@
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
import cpw.mods.modlauncher.api.ILaunchHandlerService;
|
||||
import cpw.mods.modlauncher.api.ITransformingClassLoader;
|
||||
import net.minecraft.client.main.Main;
|
||||
import net.minecraftforge.api.Side;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -40,10 +42,16 @@ public class FMLLaunchProvider extends FMLCommonLaunchHandler implements ILaunch
|
||||
}
|
||||
|
||||
@Override
|
||||
public Callable<Void> launchService(String[] arguments, ClassLoader launchClassLoader)
|
||||
public Callable<Void> launchService(String[] arguments, ITransformingClassLoader launchClassLoader)
|
||||
{
|
||||
return () -> {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side getSidedness()
|
||||
{
|
||||
return Side.CLIENT;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,14 @@ package net.minecraftforge.fml.loading;
|
||||
import cpw.mods.modlauncher.api.IEnvironment;
|
||||
import cpw.mods.modlauncher.api.ILaunchHandlerService;
|
||||
import cpw.mods.modlauncher.api.ITransformationService;
|
||||
import cpw.mods.modlauncher.api.ITransformingClassLoader;
|
||||
import cpw.mods.modlauncher.api.IncompatibleEnvironmentException;
|
||||
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
||||
import net.minecraftforge.api.Side;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.BackgroundScanHandler;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.forgespi.ICoreModProvider;
|
||||
@@ -51,6 +55,10 @@ public class FMLLoader
|
||||
private static ModDiscoverer modDiscoverer;
|
||||
private static ICoreModProvider coreModProvider;
|
||||
private static LanguageLoadingProvider languageLoadingProvider;
|
||||
private static Side side;
|
||||
private static ModList modList;
|
||||
private static ClassLoader launchClassLoader;
|
||||
private static ModLoader modLoader;
|
||||
|
||||
static void onInitialLoad(IEnvironment environment, Set<String> otherServices) throws IncompatibleEnvironmentException
|
||||
{
|
||||
@@ -90,29 +98,31 @@ public class FMLLoader
|
||||
languageLoadingProvider = new LanguageLoadingProvider();
|
||||
}
|
||||
|
||||
static void setupLaunchHandler(final IEnvironment environment) throws IncompatibleEnvironmentException
|
||||
static void setupLaunchHandler(final IEnvironment environment)
|
||||
{
|
||||
final String launchTarget = environment.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).orElse("MISSING");
|
||||
final Optional<ILaunchHandlerService> launchHandler = environment.findLaunchHandler(launchTarget);
|
||||
fmlLog.debug(CORE, "Using {} as launch service", launchTarget);
|
||||
if (!launchHandler.isPresent()) {
|
||||
fmlLog.error(CORE,"Missing LaunchHandler {}, cannot continue", launchTarget);
|
||||
throw new IncompatibleEnvironmentException("Missing launch handler");
|
||||
throw new RuntimeException("Missing launch handler");
|
||||
}
|
||||
|
||||
if (!(launchHandler.get() instanceof FMLCommonLaunchHandler)) {
|
||||
fmlLog.error(CORE, "Incompatible Launch handler found - type {}, cannot continue", launchHandler.get().getClass().getName());
|
||||
throw new IncompatibleEnvironmentException("Incompatible launch handler found");
|
||||
throw new RuntimeException("Incompatible launch handler found");
|
||||
}
|
||||
|
||||
FMLCommonLaunchHandler commonLaunchHandler = (FMLCommonLaunchHandler)launchHandler.get();
|
||||
commonLaunchHandler.setup(environment);
|
||||
side = commonLaunchHandler.getSidedness();
|
||||
}
|
||||
public static void beginModScan()
|
||||
{
|
||||
fmlLog.debug(SCAN,"Scanning for Mod Locators");
|
||||
modDiscoverer = new ModDiscoverer();
|
||||
modDiscoverer.discoverMods();
|
||||
final BackgroundScanHandler backgroundScanHandler = modDiscoverer.discoverMods();
|
||||
modList = backgroundScanHandler.getModList();
|
||||
}
|
||||
|
||||
public static ICoreModProvider getCoreModProvider() {
|
||||
@@ -147,4 +157,20 @@ public class FMLLoader
|
||||
fmlLog.debug(SCAN, "Adding Access Transformer in {}", modName.getFilePath());
|
||||
accessTransformer.addResource(atPath, modName.getFileName());
|
||||
}
|
||||
|
||||
public static Side getSide()
|
||||
{
|
||||
return side;
|
||||
}
|
||||
|
||||
public static void beforeStart(ITransformingClassLoader launchClassLoader)
|
||||
{
|
||||
modLoader = new ModLoader(launchClassLoader.getInstance(), modList);
|
||||
modLoader.classloadModFiles();
|
||||
}
|
||||
|
||||
public static ModLoader getModLoader()
|
||||
{
|
||||
return modLoader;
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ public class FMLServiceProvider implements ITransformationService
|
||||
FMLPaths.setup(environment);
|
||||
fmlLog.debug(CORE,"Loading configuration");
|
||||
FMLConfig.load();
|
||||
fmlLog.debug(CORE, "Preparing launch handler");
|
||||
FMLLoader.setupLaunchHandler(environment);
|
||||
fmlLog.debug(CORE,"Initiating mod scan");
|
||||
FMLLoader.beginModScan();
|
||||
fmlLog.debug(CORE, "Loading access transformers");
|
||||
|
||||
@@ -40,8 +40,6 @@ public interface IModLanguageProvider
|
||||
Consumer<ScanResult> getFileVisitor();
|
||||
|
||||
interface IModLanguageLoader {
|
||||
ModContainer loadMod(ModFile file, ClassLoader modClassLoader);
|
||||
ModContainer loadMod(ModInfo info, ClassLoader modClassLoader);
|
||||
}
|
||||
|
||||
List<ModContainer> buildModContainers(List<ModInfo> modFiles, ClassLoader modClassLoader);
|
||||
}
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
package net.minecraftforge.fml.loading;
|
||||
|
||||
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.loading.moddiscovery.ModFile;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -36,18 +40,41 @@ public class LanguageLoadingProvider
|
||||
{
|
||||
private final List<IModLanguageProvider> languageProviders = new ArrayList<>();
|
||||
private final ServiceLoader<IModLanguageProvider> serviceLoader;
|
||||
private final Map<String, IModLanguageProvider> languageProviderMap = new HashMap<>();
|
||||
private final Map<String, ModLanguageWrapper> languageProviderMap = new HashMap<>();
|
||||
|
||||
private static class ModLanguageWrapper {
|
||||
private final IModLanguageProvider modLanguageProvider;
|
||||
private final ArtifactVersion version;
|
||||
|
||||
public ModLanguageWrapper(IModLanguageProvider modLanguageProvider, ArtifactVersion version)
|
||||
{
|
||||
this.modLanguageProvider = modLanguageProvider;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public ArtifactVersion getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public IModLanguageProvider getModLanguageProvider()
|
||||
{
|
||||
return modLanguageProvider;
|
||||
}
|
||||
}
|
||||
LanguageLoadingProvider() {
|
||||
serviceLoader = ServiceLoader.load(IModLanguageProvider.class);
|
||||
serviceLoader.forEach(languageProviders::add);
|
||||
|
||||
languageProviders.forEach(lp -> {
|
||||
final Package pkg = lp.getClass().getPackage();
|
||||
fmlLog.debug(CORE, "Found system classpath language provider {}, version {}", lp.name(), pkg.getImplementationVersion());
|
||||
String implementationVersion = pkg.getImplementationVersion();
|
||||
if (implementationVersion == null) {
|
||||
implementationVersion = ForgeVersion.getVersion();
|
||||
}
|
||||
fmlLog.debug(CORE, "Found system classpath language provider {}, version {}", lp.name(), implementationVersion);
|
||||
languageProviderMap.put(lp.name(), new ModLanguageWrapper(lp, new DefaultArtifactVersion(implementationVersion)));
|
||||
});
|
||||
|
||||
languageProviders.forEach(lp->languageProviderMap.put(lp.name(), lp));
|
||||
}
|
||||
|
||||
public void addAdditionalLanguages(List<ModFile> modFiles)
|
||||
@@ -57,8 +84,15 @@ public class LanguageLoadingProvider
|
||||
serviceLoader.reload();
|
||||
}
|
||||
|
||||
public IModLanguageProvider getLanguage(String name)
|
||||
{
|
||||
return languageProviderMap.get(name);
|
||||
public IModLanguageProvider findLanguage(String modLoader, VersionRange modLoaderVersion) {
|
||||
final ModLanguageWrapper mlw = languageProviderMap.get(modLoader);
|
||||
if (mlw == null) {
|
||||
throw new MissingLanguageException("Missing language "+modLoader);
|
||||
}
|
||||
if (!modLoaderVersion.containsVersion(mlw.getVersion())) {
|
||||
throw new MissingLanguageException("Missing language "+ modLoader + " matching range "+modLoaderVersion + " found "+mlw.getVersion());
|
||||
}
|
||||
|
||||
return mlw.getModLanguageProvider();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class MissingLanguageException extends RuntimeException
|
||||
{
|
||||
public MissingLanguageException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 com.google.common.collect.Multimap;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.BackgroundScanHandler;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Master list of all mods
|
||||
*/
|
||||
public class ModList
|
||||
{
|
||||
private final List<ModFile> modFiles;
|
||||
private final List<ModInfo> sortedList;
|
||||
private BackgroundScanHandler scanner;
|
||||
|
||||
public ModList(final List<ModFile> modFiles, final List<ModInfo> sortedList)
|
||||
{
|
||||
this.modFiles = modFiles;
|
||||
this.sortedList = sortedList;
|
||||
}
|
||||
|
||||
public void addCoreMods()
|
||||
{
|
||||
modFiles.stream().map(ModFile::getCoreMods).flatMap(List::stream).forEach(FMLLoader.getCoreModProvider()::addCoreMod);
|
||||
}
|
||||
|
||||
public void addAccessTransformers()
|
||||
{
|
||||
modFiles.forEach(mod -> mod.getAccessTransformer().ifPresent(path -> FMLLoader.addAccessTransformer(path, mod)));
|
||||
}
|
||||
|
||||
public void addForScanning(BackgroundScanHandler backgroundScanHandler)
|
||||
{
|
||||
this.scanner = backgroundScanHandler;
|
||||
backgroundScanHandler.setModList(this);
|
||||
modFiles.forEach(backgroundScanHandler::submitForScanning);
|
||||
}
|
||||
|
||||
public List<ModFile> getModFiles()
|
||||
{
|
||||
return modFiles;
|
||||
}
|
||||
|
||||
public Path findResource(final String className)
|
||||
{
|
||||
for (final ModFile mf : modFiles) {
|
||||
final Path resource = mf.findResource(className);
|
||||
if (resource != null) return resource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModLoader
|
||||
{
|
||||
private final ClassLoader launchClassLoader;
|
||||
private final ModList modList;
|
||||
private final ModLoadingClassLoader modClassLoader;
|
||||
|
||||
public ModLoader(final ClassLoader launchClassLoader, final ModList modList)
|
||||
{
|
||||
this.launchClassLoader = launchClassLoader;
|
||||
this.modList = modList;
|
||||
this.modClassLoader = new ModLoadingClassLoader(this, this.launchClassLoader);
|
||||
}
|
||||
|
||||
public void classloadModFiles()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ModList getModList()
|
||||
{
|
||||
return modList;
|
||||
}
|
||||
|
||||
public void loadMods() {
|
||||
final List<ModContainer> collect = modList.getModFiles().stream().map(mf -> mf.buildMods(this.modClassLoader)).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureClassLoader;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
|
||||
public class ModLoadingClassLoader extends SecureClassLoader
|
||||
{
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
// We use a custom URL format : modjar:modid!/path/in/jarfile
|
||||
URL.setURLStreamHandlerFactory(protocol -> "modjar".equals(protocol) ? new URLStreamHandler() {
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
return new URLConnection(url) {
|
||||
@Override
|
||||
public void connect()
|
||||
{
|
||||
url.get
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseURL(URL u, String spec, int start, int limit)
|
||||
{
|
||||
|
||||
}
|
||||
} : null);
|
||||
}
|
||||
|
||||
private ModLoader modLoader;
|
||||
|
||||
protected ModLoadingClassLoader(ModLoader modLoader, ClassLoader parent) {
|
||||
super(parent);
|
||||
this.modLoader = modLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String name)
|
||||
{
|
||||
return super.getResource(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException
|
||||
{
|
||||
LogManager.getLogger("FML").debug(LOADING, "Loading class {}", name);
|
||||
final String className = name.replace('.','/').concat(".class");
|
||||
final Path classResource = modLoader.getModList().findResource(className);
|
||||
if (classResource != null) {
|
||||
try {
|
||||
final byte[] bytes = Files.readAllBytes(classResource);
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new ClassNotFoundException("Failed to load class file " + classResource + " for "+ className, e);
|
||||
}
|
||||
}
|
||||
throw new ClassNotFoundException("Failed to find class file "+ className);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URL findResource(String name)
|
||||
{
|
||||
return super.findResource(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.common.ForgeVersion;
|
||||
import net.minecraftforge.fml.Java9BackportUtils;
|
||||
import net.minecraftforge.fml.Logging;
|
||||
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.ModFile;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
|
||||
public class ModSorter
|
||||
{
|
||||
private final List<ModFile> modFiles;
|
||||
private List<ModInfo> sortedList;
|
||||
private Map<String, ModInfo> modIdNameLookup;
|
||||
|
||||
public ModSorter(final List<ModFile> modFiles)
|
||||
{
|
||||
this.modFiles = modFiles;
|
||||
}
|
||||
|
||||
public static ModList sort(List<ModFile> mods)
|
||||
{
|
||||
final ModSorter ms = new ModSorter(mods);
|
||||
ms.buildUniqueList();
|
||||
ms.verifyDependencyVersions();
|
||||
ms.sort();
|
||||
return new ModList(ms.modFiles, ms.sortedList);
|
||||
}
|
||||
|
||||
private void sort() {
|
||||
final TopologicalSort.DirectedGraph<ModInfo> topoGraph = new TopologicalSort.DirectedGraph<>();
|
||||
modFiles.stream().map(ModFile::getModInfos).
|
||||
flatMap(Collection::stream).forEach(topoGraph::addNode);
|
||||
modFiles.stream().map(ModFile::getModInfos).
|
||||
flatMap(Collection::stream).map(ModInfo::getDependencies).flatMap(Collection::stream).forEach(dep->addDependency(topoGraph, dep));
|
||||
}
|
||||
|
||||
private void addDependency(TopologicalSort.DirectedGraph<ModInfo> topoGraph, ModInfo.ModVersion dep)
|
||||
{
|
||||
}
|
||||
|
||||
private void buildUniqueList()
|
||||
{
|
||||
final Stream<ModInfo> modInfos = modFiles.stream().map(ModFile::getModInfos).flatMap(Collection::stream);
|
||||
final Map<String, List<ModInfo>> modIds = modInfos.collect(Collectors.groupingBy(ModInfo::getModId));
|
||||
|
||||
// TODO: make this figure out dupe handling better
|
||||
final List<Map.Entry<String, List<ModInfo>>> dupedMods = modIds.entrySet().stream().filter(e -> e.getValue().size() > 1).collect(Collectors.toList());
|
||||
|
||||
if (!dupedMods.isEmpty()) {
|
||||
throw new DuplicateModsFoundException(null);
|
||||
}
|
||||
|
||||
modIdNameLookup = modIds.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().get(0)));
|
||||
}
|
||||
|
||||
private void verifyDependencyVersions()
|
||||
{
|
||||
final Map<String, ArtifactVersion> modVersions = Stream.concat(modFiles.stream().map(ModFile::getModInfos).
|
||||
flatMap(Collection::stream), ForgeVersion.getModInfos().stream()).collect(Collectors.toMap(ModInfo::getModId, ModInfo::getVersion));
|
||||
final Map<ModInfo, List<ModInfo.ModVersion>> modVersionDependencies = modFiles.stream().
|
||||
map(ModFile::getModInfos).flatMap(Collection::stream).
|
||||
collect(Collectors.groupingBy(Function.identity(), Java9BackportUtils.flatMapping(e -> e.getDependencies().stream(), Collectors.toList())));
|
||||
final Set<ModInfo.ModVersion> mandatoryModVersions = modVersionDependencies.values().stream().flatMap(Collection::stream).
|
||||
filter(mv -> mv.isMandatory() && mv.getSide().isCorrectSide()).collect(Collectors.toSet());
|
||||
LogManager.getLogger("FML").debug(LOADING, "Found {} mandatory requirements", mandatoryModVersions.size());
|
||||
final Set<ModInfo.ModVersion> missingVersions = mandatoryModVersions.stream().filter(mv->this.modVersionMatches(mv, modVersions)).collect(Collectors.toSet());
|
||||
LogManager.getLogger("FML").debug(LOADING, "Found {} mandatory mod requirements missing", missingVersions.size());
|
||||
|
||||
if (!missingVersions.isEmpty()) {
|
||||
throw new MissingModsException(null,null,null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean modVersionMatches(final ModInfo.ModVersion mv, final Map<String, ArtifactVersion> modVersions)
|
||||
{
|
||||
return !modVersions.containsKey(mv.getModId()) || !mv.getVersionRange().containsVersion(modVersions.get(mv.getModId()));
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import net.minecraftforge.fml.loading.ModList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -38,6 +39,7 @@ public class BackgroundScanHandler
|
||||
private final List<ModFile> pendingFiles;
|
||||
private final List<ModFile> scannedFiles;
|
||||
private final List<ModFile> allFiles;
|
||||
private ModList modList;
|
||||
|
||||
public BackgroundScanHandler() {
|
||||
modContentScanner = Executors.newSingleThreadExecutor(r -> {
|
||||
@@ -84,4 +86,14 @@ public class BackgroundScanHandler
|
||||
public List<ModFile> getAllFiles() {
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
public void setModList(ModList modList)
|
||||
{
|
||||
this.modList = modList;
|
||||
}
|
||||
|
||||
public ModList getModList()
|
||||
{
|
||||
return modList;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class InvalidModFileException extends RuntimeException
|
||||
{
|
||||
private final ModFile.ModFileInfo modFileInfo;
|
||||
|
||||
public InvalidModFileException(String message, ModFile.ModFileInfo modFileInfo)
|
||||
{
|
||||
super(message);
|
||||
this.modFileInfo = modFileInfo;
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,13 @@ package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import cpw.mods.modlauncher.ServiceLoaderStreamUtils;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.LanguageLoadingProvider;
|
||||
import net.minecraftforge.fml.loading.ModList;
|
||||
import net.minecraftforge.fml.loading.ModSorter;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -61,11 +61,19 @@ public class ModDiscoverer {
|
||||
FMLLoader.getLanguageLoadingProvider().addAdditionalLanguages(modFiles.get(ModFile.Type.LANGPROVIDER));
|
||||
BackgroundScanHandler backgroundScanHandler = new BackgroundScanHandler();
|
||||
final List<ModFile> mods = modFiles.get(ModFile.Type.MOD);
|
||||
mods.forEach(ModFile::identifyMods);
|
||||
for (Iterator<ModFile> iterator = mods.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
ModFile mod = iterator.next();
|
||||
if (!mod.identifyMods()) {
|
||||
fmlLog.debug(SCAN, "Removing file {} from further analysis - it is invalid", mod);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
fmlLog.debug(SCAN,"Found {} mod files with {} mods", mods::size, ()->mods.stream().mapToInt(mf -> mf.getModInfos().size()).sum());
|
||||
mods.stream().map(ModFile::getCoreMods).flatMap(List::stream).forEach(FMLLoader.getCoreModProvider()::addCoreMod);
|
||||
mods.forEach(mod -> mod.getAccessTransformer().ifPresent(path -> FMLLoader.addAccessTransformer(path, mod)));
|
||||
mods.forEach(backgroundScanHandler::submitForScanning);
|
||||
final ModList sortedMods = ModSorter.sort(mods);
|
||||
sortedMods.addCoreMods();
|
||||
sortedMods.addAccessTransformers();
|
||||
sortedMods.addForScanning(backgroundScanHandler);
|
||||
return backgroundScanHandler;
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,24 @@
|
||||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import com.electronwill.nightconfig.core.file.FileConfig;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraftforge.common.config.ConfigCategory;
|
||||
import net.minecraftforge.fml.StringUtils;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.VersionRange;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.fml.loading.IModLanguageProvider;
|
||||
import net.minecraftforge.fml.loading.ModLoadingClassLoader;
|
||||
|
||||
import javax.swing.text.html.Option;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -32,6 +45,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -48,10 +62,29 @@ public class ModFile
|
||||
DEFAULTMANIFEST.getMainAttributes().putValue("FMLModType", "MOD");
|
||||
}
|
||||
|
||||
private final String jarVersion;
|
||||
private Map<String, Object> fileProperties;
|
||||
private IModLanguageProvider loader;
|
||||
|
||||
public void claimLanguage(String modId, IModLanguageProvider.IModLanguageLoader loader)
|
||||
public void setFileProperties(Map<String, Object> fileProperties)
|
||||
{
|
||||
this.modInfoMap.get(modId).setLoader(loader);
|
||||
this.fileProperties = fileProperties;
|
||||
}
|
||||
|
||||
public IModLanguageProvider getLoader()
|
||||
{
|
||||
return loader;
|
||||
}
|
||||
|
||||
public Path findResource(String className)
|
||||
{
|
||||
return locator.findPath(this, className);
|
||||
}
|
||||
|
||||
public List<ModContainer> buildMods(ModLoadingClassLoader modClassLoader)
|
||||
{
|
||||
return getScanResult().getTargets().entrySet().stream().
|
||||
map(e->e.getValue().loadMod(this.modInfoMap.get(e.getKey()), modClassLoader)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
@@ -60,9 +93,9 @@ public class ModFile
|
||||
private final Path filePath;
|
||||
private final Type modFileType;
|
||||
private final Manifest manifest;
|
||||
private List<ModInfo> modInfos;
|
||||
private Map<String, ModInfo> modInfoMap;
|
||||
private final IModLocator locator;
|
||||
private ModFileInfo modFileInfo;
|
||||
private Map<String, ModInfo> modInfoMap;
|
||||
private ScanResult fileScanResult;
|
||||
private CompletableFuture<ScanResult> futureScanResult;
|
||||
private List<CoreModFile> coreMods;
|
||||
@@ -78,8 +111,12 @@ public class ModFile
|
||||
else fmlLog.debug(SCAN,"Mod file {} is missing a manifest", file);
|
||||
final Optional<String> value = Optional.ofNullable(manifest.getMainAttributes().getValue(TYPE));
|
||||
modFileType = Type.valueOf(value.orElse("MOD"));
|
||||
jarVersion = Optional.ofNullable(manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION)).orElse("NONE");
|
||||
}
|
||||
|
||||
public Supplier<Map<String,Object>> getSubstitutionMap() {
|
||||
return () -> ImmutableMap.<String,Object>builder().put("jarVersion", jarVersion).putAll(fileProperties).build();
|
||||
}
|
||||
public Type getType() {
|
||||
return modFileType;
|
||||
}
|
||||
@@ -89,19 +126,22 @@ public class ModFile
|
||||
}
|
||||
|
||||
public List<ModInfo> getModInfos() {
|
||||
return modInfos;
|
||||
return modFileInfo.getMods();
|
||||
}
|
||||
|
||||
public Optional<Path> getAccessTransformer() {
|
||||
return Optional.ofNullable(Files.exists(accessTransformer) ? accessTransformer : null);
|
||||
}
|
||||
public void identifyMods() {
|
||||
this.modInfos = ModFileParser.readModList(this);
|
||||
this.modInfos.forEach(mi-> fmlLog.debug(LOADING,"Found mod {} for language {}", mi.getModId(), mi.getModLoader()));
|
||||
this.modInfoMap = this.modInfos.stream().collect(Collectors.toMap(ModInfo::getModId, Function.identity()));
|
||||
public boolean identifyMods() {
|
||||
this.modFileInfo = ModFileParser.readModList(this);
|
||||
if (this.modFileInfo == null) return false;
|
||||
fmlLog.debug(LOADING,"Loading mod file {} with language {}", this.getFilePath(), this.modFileInfo.modLoader);
|
||||
this.modInfoMap = this.getModInfos().stream().collect(Collectors.toMap(ModInfo::getModId, Function.identity()));
|
||||
this.coreMods = ModFileParser.getCoreMods(this);
|
||||
this.coreMods.forEach(mi-> fmlLog.debug(LOADING,"Found coremod {}", mi.getPath()));
|
||||
this.accessTransformer = locator.findPath(this, "META-INF", "accesstransformer.cfg");
|
||||
this.loader = FMLLoader.getLanguageLoadingProvider().findLanguage(this.modFileInfo.modLoader, this.modFileInfo.modLoaderVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,4 +192,54 @@ public class ModFile
|
||||
public IModLocator getLocator() {
|
||||
return locator;
|
||||
}
|
||||
|
||||
public ModFileInfo getModFileInfo() {
|
||||
return modFileInfo;
|
||||
}
|
||||
public static class ModFileInfo {
|
||||
private final UnmodifiableConfig config;
|
||||
private final ModFile modFile;
|
||||
private final URL updateJSONURL;
|
||||
private final URL issueURL;
|
||||
private final String modLoader;
|
||||
private final VersionRange modLoaderVersion;
|
||||
private final List<ModInfo> mods;
|
||||
private final Map<String,Object> properties;
|
||||
|
||||
public ModFileInfo(final ModFile modFile, final UnmodifiableConfig config)
|
||||
{
|
||||
this.modFile = modFile;
|
||||
this.config = config;
|
||||
this.modLoader = config.<String>getOptional("modLoader").
|
||||
orElseThrow(()->new InvalidModFileException("Missing ModLoader in file", this));
|
||||
this.modLoaderVersion = config.<String>getOptional("loaderVersion").
|
||||
map(VersionRange::createFromVersionSpec).
|
||||
orElseThrow(()->new InvalidModFileException("Missing ModLoader version in file", this));
|
||||
this.properties = config.<UnmodifiableConfig>getOptional("properties").
|
||||
map(UnmodifiableConfig::valueMap).orElse(Collections.emptyMap());
|
||||
this.modFile.setFileProperties(this.properties);
|
||||
final ArrayList<UnmodifiableConfig> modConfigs = config.getOrElse("mods", ArrayList::new);
|
||||
if (modConfigs.isEmpty()) {
|
||||
throw new InvalidModFileException("Missing mods list", this);
|
||||
}
|
||||
this.mods = modConfigs.stream().map(mi-> new ModInfo(this, mi)).collect(Collectors.toList());
|
||||
this.updateJSONURL = config.<String>getOptional("updateJSONURL").map(StringUtils::toURL).orElse(null);
|
||||
this.issueURL = config.<String>getOptional("issueTrackerURL").map(StringUtils::toURL).orElse(null);
|
||||
}
|
||||
|
||||
public List<ModInfo> getMods()
|
||||
{
|
||||
return mods;
|
||||
}
|
||||
|
||||
public ModFile getFile()
|
||||
{
|
||||
return this.modFile;
|
||||
}
|
||||
|
||||
public UnmodifiableConfig getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,10 @@
|
||||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import com.electronwill.nightconfig.core.path.PathConfig;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.InstanceCreator;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -35,26 +32,27 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class ModFileParser {
|
||||
protected static List<ModInfo> readModList(final ModFile modFile) {
|
||||
public static ModFile.ModFileInfo readModList(final ModFile modFile) {
|
||||
fmlLog.debug(LOADING,"Parsing mod file candidate {}", modFile.getFilePath());
|
||||
try {
|
||||
final Path modsjson = modFile.getLocator().findPath(modFile, "META-INF", "mods.json");
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(ModInfo.class, (InstanceCreator<ModInfo>)ic -> new ModInfo(modFile, null, null, null, null, null, null, null));
|
||||
gsonBuilder.registerTypeAdapter(ArtifactVersion.class, (JsonDeserializer<ArtifactVersion>) (element, type, context) -> new DefaultArtifactVersion(element.getAsString()));
|
||||
Gson gson = gsonBuilder.create();
|
||||
final ModInfo[] modInfos = gson.fromJson(Files.newBufferedReader(modsjson), ModInfo[].class);
|
||||
return Stream.of(modInfos).collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
fmlLog.debug(LOADING,"Ignoring invalid JAR file {}", modFile.getFilePath());
|
||||
return Collections.emptyList();
|
||||
final Path modsjson = modFile.getLocator().findPath(modFile, "META-INF", "mods.toml");
|
||||
if (!Files.exists(modsjson)) {
|
||||
fmlLog.warn(LOADING, "Mod file {} is missing mods.toml file", modFile);
|
||||
return null;
|
||||
}
|
||||
return loadModFile(modFile, modsjson);
|
||||
}
|
||||
|
||||
public static ModFile.ModFileInfo loadModFile(final ModFile file, final Path modsjson)
|
||||
{
|
||||
final PathConfig pathConfig = PathConfig.builder(modsjson).build();
|
||||
pathConfig.load();
|
||||
pathConfig.close();
|
||||
return new ModFile.ModFileInfo(file, pathConfig);
|
||||
}
|
||||
|
||||
protected static List<CoreModFile> getCoreMods(final ModFile modFile) {
|
||||
|
||||
@@ -19,40 +19,60 @@
|
||||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||
import net.minecraftforge.fml.FMLEnvironment;
|
||||
import net.minecraftforge.fml.StringSubstitutor;
|
||||
import net.minecraftforge.fml.StringUtils;
|
||||
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.loading.IModLanguageProvider;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModInfo {
|
||||
private final ModFile owningFile;
|
||||
private static final DefaultArtifactVersion DEFAULT_VERSION = new DefaultArtifactVersion("1");
|
||||
public static final VersionRange UNBOUNDED = VersionRange.createFromVersionSpec("");
|
||||
private final ModFile.ModFileInfo owningFile;
|
||||
private final String modId;
|
||||
private final ArtifactVersion version;
|
||||
private final String displayName;
|
||||
private final String description;
|
||||
private final URL updateJSONURL;
|
||||
private final String modLoader;
|
||||
private final List<ModInfo.ModVersion> dependencies;
|
||||
private IModLanguageProvider.IModLanguageLoader loader;
|
||||
private final Map<String,Object> properties;
|
||||
private final UnmodifiableConfig modConfig;
|
||||
|
||||
public ModInfo(final ModFile owningFile, final String modLoader, final String modId, final String displayName, final ArtifactVersion version, final String description, final URL updateJSONURL, final List<ModInfo.ModVersion> dependencies) {
|
||||
public ModInfo(final ModFile.ModFileInfo owningFile, final UnmodifiableConfig modConfig)
|
||||
{
|
||||
this.owningFile = owningFile;
|
||||
this.modLoader = modLoader;
|
||||
this.modId = modId;
|
||||
this.displayName = displayName;
|
||||
this.version = version;
|
||||
this.description = description;
|
||||
this.updateJSONURL = updateJSONURL;
|
||||
this.dependencies = dependencies;
|
||||
this.modConfig = modConfig;
|
||||
this.modId = modConfig.<String>getOptional("modId").orElseThrow(() -> new InvalidModFileException("Missing modId entry", owningFile));
|
||||
this.version = modConfig.<String>getOptional("version").
|
||||
map(s->StringSubstitutor.replace(s, owningFile != null ? owningFile.getFile() : null )).
|
||||
map(DefaultArtifactVersion::new).orElse(DEFAULT_VERSION);
|
||||
this.displayName = modConfig.<String>getOptional("displayName").orElse(null);
|
||||
this.description = modConfig.get("description");
|
||||
if (owningFile != null) {
|
||||
this.dependencies = owningFile.getConfig().<List<UnmodifiableConfig>>getOptional(Arrays.asList("dependencies", this.modId)).
|
||||
orElse(Collections.emptyList()).stream().map(dep -> new ModVersion(this, dep)).collect(Collectors.toList());
|
||||
this.properties = owningFile.getConfig().<UnmodifiableConfig>getOptional(Arrays.asList("modproperties", this.modId)).
|
||||
map(UnmodifiableConfig::valueMap).orElse(Collections.emptyMap());
|
||||
} else {
|
||||
this.dependencies = Collections.emptyList();
|
||||
this.properties = Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ModFile getOwningFile() {
|
||||
return owningFile;
|
||||
}
|
||||
|
||||
public String getModLoader() {
|
||||
return modLoader;
|
||||
return owningFile.getFile();
|
||||
}
|
||||
|
||||
public String getModId() {
|
||||
@@ -63,32 +83,72 @@ public class ModInfo {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setLoader(IModLanguageProvider.IModLanguageLoader loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
public List<ModInfo.ModVersion> getDependencies() {
|
||||
return this.dependencies;
|
||||
}
|
||||
|
||||
public enum Ordering {
|
||||
BEFORE, AFTER, NONE;
|
||||
BEFORE, AFTER, NONE
|
||||
}
|
||||
|
||||
public enum DependencySide {
|
||||
CLIENT, SERVER, BOTH;
|
||||
|
||||
public boolean isCorrectSide()
|
||||
{
|
||||
return this == BOTH || FMLEnvironment.side.name().equals(this.name());
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModVersion {
|
||||
private ModInfo owner;
|
||||
private final String modId;
|
||||
private final ArtifactVersion version;
|
||||
private final VersionRange versionRange;
|
||||
private final boolean mandatory;
|
||||
private final Ordering ordering;
|
||||
private final DependencySide side;
|
||||
|
||||
public ModVersion(final String modId, final ArtifactVersion version, final boolean mandatory, final Ordering ordering, final DependencySide side) {
|
||||
this.modId = modId;
|
||||
this.version = version;
|
||||
this.mandatory = mandatory;
|
||||
this.ordering = ordering;
|
||||
this.side = side;
|
||||
ModVersion(final ModInfo 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 ModInfo owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraftforge.fml.loading.FMLJavaModLanguageProvider;
|
||||
import net.minecraftforge.fml.loading.IModLanguageProvider;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +34,7 @@ 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;
|
||||
@@ -52,6 +56,17 @@ public class ScanResult {
|
||||
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;
|
||||
|
||||
@@ -45,9 +45,9 @@ public class Scanner {
|
||||
public ScanResult scan() {
|
||||
ScanResult result = new ScanResult(fileToScan);
|
||||
fileToScan.scanFile(p -> fileVisitor(p, result));
|
||||
final Set<IModLanguageProvider> modLoaders = fileToScan.getModInfos().stream().map(ModInfo::getModLoader).map(FMLLoader.getLanguageLoadingProvider()::getLanguage).collect(Collectors.toSet());
|
||||
modLoaders.stream().peek(ml-> fmlLog.debug(SCAN, "Scanning {} with language loader {}", fileToScan.getFilePath(), ml.name()))
|
||||
.map(IModLanguageProvider::getFileVisitor).forEach(c->c.accept(result));
|
||||
final IModLanguageProvider loader = fileToScan.getLoader();
|
||||
fmlLog.debug(SCAN, "Scanning {} with language loader {}", fileToScan.getFilePath(), loader.name());
|
||||
loader.getFileVisitor().accept(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user