Tidy up some output and also add libraries from the modfile detection into the transforming classloader.

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-12-05 22:47:34 -05:00
parent 3ba78225c3
commit cfc53c939e
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7
4 changed files with 26 additions and 2 deletions

View file

@ -23,6 +23,7 @@ import cpw.mods.modlauncher.api.IEnvironment;
import cpw.mods.modlauncher.api.ITransformingClassLoader;
import cpw.mods.modlauncher.api.ITransformingClassLoaderBuilder;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.loading.moddiscovery.ModFile;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -41,6 +42,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static net.minecraftforge.fml.loading.LogMarkers.CORE;
import static net.minecraftforge.fml.loading.LogMarkers.LOADING;
public abstract class FMLCommonLaunchHandler
{
@ -54,6 +56,8 @@ public abstract class FMLCommonLaunchHandler
"net.minecraftforge.eventbus.", "net.minecraftforge.api.", "com.mojang.util.QueueLogAppender"
);
private final List<Path> additionalLibraries = new ArrayList<>();
protected Predicate<String> getPackagePredicate() {
return cn -> SKIPPACKAGES.stream().noneMatch(cn::startsWith);
}
@ -69,6 +73,7 @@ public abstract class FMLCommonLaunchHandler
public void configureTransformationClassLoader(final ITransformingClassLoaderBuilder builder) {
builder.addTransformationPath(FMLLoader.getForgePath());
Arrays.stream(FMLLoader.getMCPaths()).forEach(builder::addTransformationPath);
additionalLibraries.forEach(builder::addTransformationPath);
FMLLoader.getLanguageLoadingProvider().getLibraries().forEach(builder::addTransformationPath);
builder.setClassBytesLocator(getClassLoaderLocatorFunction());
builder.setManifestLocator(getClassLoaderManifestLocatorFunction());
@ -137,4 +142,12 @@ public abstract class FMLCommonLaunchHandler
}
protected abstract String getNaming();
void addLibraries(final List<ModFile> libraries) {
libraries
.stream()
.map(ModFile::getFilePath)
.peek(p->LOGGER.debug(LOADING, "Adding {} as a library to the transforming classloader", p))
.forEach(additionalLibraries::add);
}
}

View file

@ -81,6 +81,7 @@ public class FMLLoader
private static String forgeGroup;
private static Predicate<String> classLoaderExclusions;
private static String launchHandlerName;
private static FMLCommonLaunchHandler commonLaunchHandler;
static void onInitialLoad(IEnvironment environment, Set<String> otherServices) throws IncompatibleEnvironmentException
{
@ -175,7 +176,7 @@ public class FMLLoader
launchHandlerName = launchHandler.get().name();
gamePath = environment.getProperty(IEnvironment.Keys.GAMEDIR.get()).orElse(Paths.get(".").toAbsolutePath());
FMLCommonLaunchHandler commonLaunchHandler = (FMLCommonLaunchHandler)launchHandler.get();
commonLaunchHandler = (FMLCommonLaunchHandler)launchHandler.get();
naming = commonLaunchHandler.getNaming();
dist = commonLaunchHandler.getDist();
EarlyProgressVisualization.INSTANCE.accept(dist);
@ -206,6 +207,7 @@ public class FMLLoader
modDiscoverer = new ModDiscoverer(arguments);
final BackgroundScanHandler backgroundScanHandler = modDiscoverer.discoverMods();
loadingModList = backgroundScanHandler.getLoadingModList();
commonLaunchHandler.addLibraries(backgroundScanHandler.getModFiles().getOrDefault(IModFile.Type.LIBRARY, Collections.emptyList()));
return backgroundScanHandler.getModFiles();
}

View file

@ -24,6 +24,8 @@ import net.minecraftforge.forgespi.language.MavenVersionAdapter;
import net.minecraftforge.forgespi.language.IModFileInfo;
import net.minecraftforge.forgespi.language.IModInfo;
import net.minecraftforge.fml.loading.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.maven.artifact.versioning.VersionRange;
import java.net.URL;
@ -31,8 +33,11 @@ import java.util.*;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import static net.minecraftforge.fml.loading.LogMarkers.LOADING;
public class ModFileInfo implements IModFileInfo
{
private static final Logger LOGGER = LogManager.getLogger();
private final UnmodifiableConfig config;
private final ModFile modFile;
private final URL issueURL;
@ -64,6 +69,10 @@ public class ModFileInfo implements IModFileInfo
}
this.mods = modConfigs.stream().map(mi-> new ModInfo(this, mi)).collect(Collectors.toList());
this.issueURL = config.<String>getOptional("issueTrackerURL").map(StringUtils::toURL).orElse(null);
LOGGER.debug(LOADING, "Found valid mod file {} with {} mods - versions {}",
this.modFile::getFileName,
() -> mods.stream().map(IModInfo::getModId).collect(Collectors.joining(",", "{", "}")),
() -> mods.stream().map(IModInfo::getVersion).map(Objects::toString).collect(Collectors.joining(",", "{", "}")));
}
@Override

View file

@ -42,7 +42,7 @@ public class ModFileParser {
private static final Logger LOGGER = LogManager.getLogger();
public static IModFileInfo readModList(final ModFile modFile) {
LOGGER.debug(LOADING,"Parsing mod file candidate {}", modFile.getFilePath());
LOGGER.debug(LOADING,"Considering mod file candidate {}", modFile.getFilePath());
final Path modsjson = modFile.getLocator().findPath(modFile, "META-INF", "mods.toml");
if (!Files.exists(modsjson)) {
LOGGER.warn(LOADING, "Mod file {} is missing mods.toml file", modFile);