mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Rewrite dependency extraction to use mod list system (#4841)
This commit is contained in:
1 parent
3f4dfbb367
commit
9d0771b3d7
17 files changed
+1497
-414
No files matched your search
@@ -32,8 +32,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.classloading.FMLForgePlugin;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.common.config.ConfigManager;
|
||||
@@ -42,6 +44,8 @@ import net.minecraftforge.fml.common.LoaderState.ModState;
|
||||
import net.minecraftforge.fml.common.ModContainer.Disableable;
|
||||
import net.minecraftforge.fml.common.ProgressManager.ProgressBar;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ContainerType;
|
||||
import net.minecraftforge.fml.common.discovery.ModCandidate;
|
||||
import net.minecraftforge.fml.common.discovery.ModDiscoverer;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLLoadEvent;
|
||||
@@ -54,8 +58,11 @@ import net.minecraftforge.fml.common.toposort.ModSortingException.SortingExcepti
|
||||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.DependencyParser;
|
||||
import net.minecraftforge.fml.common.versioning.VersionParser;
|
||||
import net.minecraftforge.fml.relauncher.ModListHelper;
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.libraries.Artifact;
|
||||
import net.minecraftforge.fml.relauncher.libraries.LibraryManager;
|
||||
import net.minecraftforge.fml.relauncher.libraries.Repository;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.ObjectHolderRegistry;
|
||||
|
||||
@@ -384,18 +391,42 @@ public class Loader
|
||||
mods.add(new InjectedModContainer(mc,mc.getSource()));
|
||||
}
|
||||
ModDiscoverer discoverer = new ModDiscoverer();
|
||||
FMLLog.log.debug("Attempting to load mods contained in the minecraft jar file and associated classes");
|
||||
discoverer.findClasspathMods(modClassLoader);
|
||||
FMLLog.log.debug("Minecraft jar mods loaded successfully");
|
||||
|
||||
FMLLog.log.info("Found {} mods from the command line. Injecting into mod discoverer", ModListHelper.additionalMods.size());
|
||||
FMLLog.log.info("Searching {} for mods", canonicalModsDir.getAbsolutePath());
|
||||
discoverer.findModDirMods(canonicalModsDir, ModListHelper.additionalMods.values().toArray(new File[0]));
|
||||
File versionSpecificModsDir = new File(canonicalModsDir,mccversion);
|
||||
if (versionSpecificModsDir.isDirectory())
|
||||
if (!FMLForgePlugin.RUNTIME_DEOBF) //Only descover mods in the classpath if we're in the dev env.
|
||||
{ //TODO: Move this to GradleStart?
|
||||
FMLLog.log.debug("Attempting to load mods contained in the minecraft jar file and associated classes");
|
||||
discoverer.findClasspathMods(modClassLoader);
|
||||
FMLLog.log.debug("Minecraft jar mods loaded successfully");
|
||||
}
|
||||
|
||||
List<Artifact> maven_canidates = LibraryManager.flattenLists(minecraftDir);
|
||||
List<File> file_canidates = LibraryManager.gatherLegacyCanidates(minecraftDir);
|
||||
|
||||
for (Artifact artifact : maven_canidates)
|
||||
{
|
||||
FMLLog.log.info("Also searching {} for mods", versionSpecificModsDir);
|
||||
discoverer.findModDirMods(versionSpecificModsDir);
|
||||
artifact = Repository.resolveAll(artifact);
|
||||
if (artifact != null)
|
||||
{
|
||||
File target = artifact.getFile();
|
||||
if (!file_canidates.contains(target))
|
||||
file_canidates.add(target);
|
||||
}
|
||||
}
|
||||
//Do we want to sort the full list after resolving artifacts?
|
||||
//TODO: Add dependency gathering?
|
||||
|
||||
for (File mod : file_canidates)
|
||||
{
|
||||
// skip loaded coremods
|
||||
if (CoreModManager.getIgnoredMods().contains(mod.getName()))
|
||||
{
|
||||
FMLLog.log.trace("Skipping already parsed coremod or tweaker {}", mod.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.log.debug("Found a candidate zip or jar file {}", mod.getName());
|
||||
discoverer.addCandidate(new ModCandidate(mod, mod, ContainerType.JAR));
|
||||
}
|
||||
}
|
||||
|
||||
mods.addAll(discoverer.identifyMods());
|
||||
|
||||
+6
-8
@@ -24,20 +24,21 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.google.common.io.CharSource;
|
||||
|
||||
public class ModAccessTransformer extends AccessTransformer {
|
||||
public class ModAccessTransformer extends AccessTransformer
|
||||
{
|
||||
public static final Attributes.Name FMLAT = new Attributes.Name("FMLAT");
|
||||
private static Map<String, String> embedded = Maps.newHashMap(); //Needs to be primitive so that both classloaders get the same class.
|
||||
@SuppressWarnings("unchecked")
|
||||
public ModAccessTransformer() throws Exception
|
||||
public ModAccessTransformer() throws Exception
|
||||
{
|
||||
super(ModAccessTransformer.class);
|
||||
//We are in the new ClassLoader here, so we need to get the static field from the other ClassLoader.
|
||||
@@ -59,11 +60,8 @@ public class ModAccessTransformer extends AccessTransformer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addJar(JarFile jar) throws IOException
|
||||
public static void addJar(JarFile jar, String atList) throws IOException
|
||||
{
|
||||
Manifest manifest = jar.getManifest();
|
||||
String atList = manifest.getMainAttributes().getValue("FMLAT");
|
||||
if (atList == null) return;
|
||||
for (String at : atList.split(" "))
|
||||
{
|
||||
JarEntry jarEntry = jar.getJarEntry("META-INF/"+at);
|
||||
|
||||
@@ -21,24 +21,17 @@ package net.minecraftforge.fml.common.discovery;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraftforge.fml.common.FMLLog;
|
||||
import net.minecraftforge.fml.common.LoaderException;
|
||||
import net.minecraftforge.fml.common.ModClassLoader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.fml.relauncher.CoreModManager;
|
||||
import net.minecraftforge.fml.relauncher.FileListHelper;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.ObjectArrays;
|
||||
|
||||
public class ModDiscoverer
|
||||
{
|
||||
private static Pattern zipJar = Pattern.compile("(.+).(zip|jar)$");
|
||||
|
||||
private List<ModCandidate> candidates = Lists.newArrayList();
|
||||
|
||||
private ASMDataTable dataTable = new ASMDataTable();
|
||||
@@ -89,45 +82,6 @@ public class ModDiscoverer
|
||||
|
||||
}
|
||||
|
||||
public void findModDirMods(File modsDir)
|
||||
{
|
||||
findModDirMods(modsDir, new File[0]);
|
||||
}
|
||||
|
||||
public void findModDirMods(File modsDir, File[] supplementalModFileCandidates)
|
||||
{
|
||||
File[] modList = FileListHelper.sortFileList(modsDir, null);
|
||||
modList = FileListHelper.sortFileList(ObjectArrays.concat(modList, supplementalModFileCandidates, File.class));
|
||||
for (File modFile : modList)
|
||||
{
|
||||
// skip loaded coremods
|
||||
if (CoreModManager.getIgnoredMods().contains(modFile.getName()))
|
||||
{
|
||||
FMLLog.log.trace("Skipping already parsed coremod or tweaker {}", modFile.getName());
|
||||
}
|
||||
else if (modFile.isDirectory())
|
||||
{
|
||||
//TODO Remove in 1.13+ Mods should never be directory based anymore.
|
||||
FMLLog.log.debug("Found a candidate mod directory {}", modFile.getName());
|
||||
addCandidate(new ModCandidate(modFile, modFile, ContainerType.DIR));
|
||||
}
|
||||
else
|
||||
{
|
||||
Matcher matcher = zipJar.matcher(modFile.getName());
|
||||
|
||||
if (matcher.matches())
|
||||
{
|
||||
FMLLog.log.debug("Found a candidate zip or jar file {}", matcher.group(0));
|
||||
addCandidate(new ModCandidate(modFile, modFile, ContainerType.JAR));
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.log.debug("Ignoring unknown file {} in mods directory", modFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModContainer> identifyMods()
|
||||
{
|
||||
List<ModContainer> modList = Lists.newArrayList();
|
||||
@@ -165,7 +119,7 @@ public class ModDiscoverer
|
||||
return nonModLibs;
|
||||
}
|
||||
|
||||
private void addCandidate(ModCandidate candidate)
|
||||
public void addCandidate(ModCandidate candidate)
|
||||
{
|
||||
for (ModCandidate c : candidates)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
|
||||
import net.minecraftforge.fml.relauncher.FMLSecurityManager;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
Reference in new issue
Block a user