Coremod
This commit is contained in:
parent
9f8a9196d8
commit
66b6150027
|
@ -31,6 +31,7 @@ import java.nio.file.Path;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class FMLConfig
|
||||
|
@ -78,7 +79,7 @@ public class FMLConfig
|
|||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
fmlLog.error("Unable to read FML config at {}", configFile, ioe);
|
||||
fmlLog.error(CORE,"Unable to read FML config at {}", configFile, ioe);
|
||||
throw new RuntimeException("Unable to read FML config", ioe);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.nio.file.FileAlreadyExistsException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class FileUtils
|
||||
|
@ -31,20 +32,20 @@ public class FileUtils
|
|||
public static Path getOrCreateDirectory(Path dirPath, String dirLabel) {
|
||||
if (!Files.isDirectory(dirPath))
|
||||
{
|
||||
fmlLog.debug("Making {} directory : {}", dirLabel, dirPath);
|
||||
fmlLog.debug(CORE,"Making {} directory : {}", dirLabel, dirPath);
|
||||
try {
|
||||
Files.createDirectory(dirPath);
|
||||
} catch (IOException e) {
|
||||
if (e instanceof FileAlreadyExistsException) {
|
||||
fmlLog.error("Failed to create {} directory - there is a file in the way", dirLabel);
|
||||
fmlLog.error(CORE,"Failed to create {} directory - there is a file in the way", dirLabel);
|
||||
} else {
|
||||
fmlLog.error("Problem with creating {} directory (Permissions?)", dirLabel, e);
|
||||
fmlLog.error(CORE,"Problem with creating {} directory (Permissions?)", dirLabel, e);
|
||||
}
|
||||
throw new RuntimeException("Problem creating directory", e);
|
||||
}
|
||||
fmlLog.debug("Created {} directory : {}", dirLabel, dirPath);
|
||||
fmlLog.debug(CORE,"Created {} directory : {}", dirLabel, dirPath);
|
||||
} else {
|
||||
fmlLog.debug("Found existing {} directory : {}", dirLabel, dirPath);
|
||||
fmlLog.debug(CORE,"Found existing {} directory : {}", dirLabel, dirPath);
|
||||
}
|
||||
return dirPath;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,14 @@ package net.minecraftforge.fml;
|
|||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
|
||||
public class Logging
|
||||
{
|
||||
public static final Logger fmlLog = LogManager.getLogger("FML");
|
||||
public static final Marker CORE = MarkerManager.getMarker("CORE");
|
||||
public static final Marker LOADING = MarkerManager.getMarker("LOADING");
|
||||
public static final Marker SCAN = MarkerManager.getMarker("SCAN");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Created by cpw on 05/06/17.
|
||||
*/
|
||||
public class StringUtils
|
||||
{
|
||||
public static String toLowerCase(final String str) {
|
||||
return str.toLowerCase(java.util.Locale.ROOT);
|
||||
}
|
||||
|
||||
public static boolean endsWith(final String search, final String... endings) {
|
||||
String lowerSearch = toLowerCase(search);
|
||||
return java.util.stream.Stream.of(endings).anyMatch(lowerSearch::endsWith);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import java.nio.file.Paths;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public enum FMLPaths
|
||||
|
@ -70,7 +71,7 @@ public enum FMLPaths
|
|||
for (FMLPaths path : FMLPaths.values())
|
||||
{
|
||||
path.absolutePath = rootPath.resolve(path.relativePath).toAbsolutePath();
|
||||
fmlLog.debug("Path {} is {}", ()-> path, ()-> path.absolutePath);
|
||||
fmlLog.debug(CORE,"Path {} is {}", ()-> path, ()-> path.absolutePath);
|
||||
if (path.isDirectory)
|
||||
{
|
||||
FileUtils.getOrCreateDirectory(path.absolutePath, path.name());
|
||||
|
|
|
@ -25,9 +25,20 @@ import cpw.mods.modlauncher.api.IncompatibleEnvironmentException;
|
|||
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
|
||||
import net.minecraftforge.common.ForgeVersion;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModDiscoverer;
|
||||
import net.minecraftforge.forgespi.ICoreModProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class FMLLoader
|
||||
|
@ -35,28 +46,48 @@ public class FMLLoader
|
|||
|
||||
private static ILaunchPluginService accessTransformer;
|
||||
private static ModDiscoverer modDiscoverer;
|
||||
private static ICoreModProvider coreMod;
|
||||
|
||||
static void initialize(IEnvironment environment, Set<String> otherServices) throws IncompatibleEnvironmentException
|
||||
static void onInitialLoad(IEnvironment environment, Set<String> otherServices) throws IncompatibleEnvironmentException
|
||||
{
|
||||
final String version = ForgeVersion.getVersion();
|
||||
fmlLog.debug("FML {} loading", version);
|
||||
fmlLog.debug(CORE,"FML {} loading", version);
|
||||
final Package modLauncherPackage = ITransformationService.class.getPackage();
|
||||
fmlLog.debug("FML found ModLauncher version : {}", modLauncherPackage.getImplementationVersion());
|
||||
fmlLog.debug(CORE,"FML found ModLauncher version : {}", modLauncherPackage.getImplementationVersion());
|
||||
if (!modLauncherPackage.isCompatibleWith("1.0")) {
|
||||
fmlLog.error("Found incompatible ModLauncher specification : {}, version {} from {}", modLauncherPackage.getSpecificationVersion(), modLauncherPackage.getImplementationVersion(), modLauncherPackage.getImplementationVendor());
|
||||
fmlLog.error(CORE,"Found incompatible ModLauncher specification : {}, version {} from {}", modLauncherPackage.getSpecificationVersion(), modLauncherPackage.getImplementationVersion(), modLauncherPackage.getImplementationVendor());
|
||||
throw new IncompatibleEnvironmentException("Incompatible modlauncher found "+modLauncherPackage.getSpecificationVersion());
|
||||
}
|
||||
|
||||
accessTransformer = environment.findLaunchPlugin("accesstransformer").orElseThrow(()-> new IncompatibleEnvironmentException("Missing AccessTransformer, cannot run"));
|
||||
|
||||
final Package atPackage = accessTransformer.getClass().getPackage();
|
||||
fmlLog.debug("FML found AccessTransformer version : {}", atPackage.getImplementationVersion());
|
||||
fmlLog.debug(CORE,"FML found AccessTransformer version : {}", atPackage.getImplementationVersion());
|
||||
if (!atPackage.isCompatibleWith("1.0")) {
|
||||
fmlLog.error("Found incompatible AccessTransformer specification : {}, version {} from {}", atPackage.getSpecificationVersion(), atPackage.getImplementationVersion(), atPackage.getImplementationVendor());
|
||||
fmlLog.error(CORE,"Found incompatible AccessTransformer specification : {}, version {} from {}", atPackage.getSpecificationVersion(), atPackage.getImplementationVersion(), atPackage.getImplementationVendor());
|
||||
throw new IncompatibleEnvironmentException("Incompatible accesstransformer found "+atPackage.getSpecificationVersion());
|
||||
}
|
||||
// final ILaunchPluginService coreMod = environment.findLaunchPlugin("coremod").orElseThrow(()-> new IncompatibleEnvironmentException("Missing CoreMod, cannot run"));
|
||||
|
||||
fmlLog.debug("Scanning for Mod Locators");
|
||||
final ArrayList<ICoreModProvider> coreModProviders = new ArrayList<>();
|
||||
ServiceLoader.load(ICoreModProvider.class).forEach(coreModProviders::add);
|
||||
|
||||
if (coreModProviders.isEmpty()) {
|
||||
fmlLog.error(CORE, "Found no coremod provider. Cannot run");
|
||||
throw new IncompatibleEnvironmentException("No coremod library found");
|
||||
} else if (coreModProviders.size() > 1) {
|
||||
fmlLog.error(CORE, "Found multiple coremod providers : {}. Cannot run", coreModProviders.stream().map(p -> p.getClass().getName()).collect(Collectors.toList()));
|
||||
throw new IncompatibleEnvironmentException("Multiple coremod libraries found");
|
||||
}
|
||||
|
||||
coreMod = coreModProviders.get(0);
|
||||
final Package coremodPackage = coreMod.getClass().getPackage();
|
||||
fmlLog.debug(CORE,"FML found CoreMod version : {}", coremodPackage.getImplementationVersion());
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
fmlLog.debug(SCAN,"Scanning for Mod Locators");
|
||||
modDiscoverer = new ModDiscoverer();
|
||||
modDiscoverer.discoverMods();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ import net.minecraftforge.fml.FMLConfig;
|
|||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.CORE;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class FMLServiceProvider implements ITransformationService
|
||||
|
@ -54,16 +54,18 @@ public class FMLServiceProvider implements ITransformationService
|
|||
@Override
|
||||
public void initialize(IEnvironment environment)
|
||||
{
|
||||
fmlLog.debug("Setting up basic FML game directories");
|
||||
fmlLog.debug(CORE,"Setting up basic FML game directories");
|
||||
FMLPaths.setup(environment);
|
||||
fmlLog.debug("Loading configuration");
|
||||
fmlLog.debug(CORE,"Loading configuration");
|
||||
FMLConfig.load();
|
||||
fmlLog.debug(CORE,"Initiating mod scan");
|
||||
FMLLoader.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad(IEnvironment environment, Set<String> otherServices) throws IncompatibleEnvironmentException
|
||||
{
|
||||
FMLLoader.initialize(environment, otherServices);
|
||||
FMLLoader.onInitialLoad(environment, otherServices);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class BackgroundScanHandler
|
||||
|
@ -56,7 +57,7 @@ public class BackgroundScanHandler
|
|||
|
||||
private void addCompletedFile(final ModFile file, final ScanResult scanResult, final Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
fmlLog.error("An error occurred scanning file {}", file, throwable);
|
||||
fmlLog.error(SCAN,"An error occurred scanning file {}", file, throwable);
|
||||
}
|
||||
pendingFiles.remove(file);
|
||||
scannedFiles.add(file);
|
||||
|
|
|
@ -19,24 +19,31 @@
|
|||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
public class CoreModFile implements net.minecraftforge.forgespi.ICoreModFile {
|
||||
private final java.nio.file.Path internalPath;
|
||||
import net.minecraftforge.forgespi.ICoreModFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CoreModFile implements ICoreModFile {
|
||||
private final Path internalPath;
|
||||
private final ModFile file;
|
||||
private final String name;
|
||||
|
||||
CoreModFile(final String name, final java.nio.file.Path path, final ModFile file) {
|
||||
CoreModFile(final String name, final Path path, final ModFile file) {
|
||||
this.name = name;
|
||||
this.internalPath = path;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.io.Reader readCoreMod() throws java.io.IOException {
|
||||
return java.nio.file.Files.newBufferedReader(this.internalPath);
|
||||
public Reader readCoreMod() throws IOException {
|
||||
return Files.newBufferedReader(this.internalPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.nio.file.Path getPath() {
|
||||
public Path getPath() {
|
||||
return this.internalPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,17 +26,33 @@ import java.nio.file.Path;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class ExplodedDirectoryLocator implements IModLocator {
|
||||
private static final String DIR = System.getProperty("fml.explodedDir", "modclasses");
|
||||
private final Path rootDir;
|
||||
|
||||
ExplodedDirectoryLocator() {
|
||||
public ExplodedDirectoryLocator() {
|
||||
this.rootDir = FileSystems.getDefault().getPath(DIR);
|
||||
if (!Files.exists(this.rootDir)) {
|
||||
fmlLog.debug(LOADING,"Creating directory {}" + this.rootDir);
|
||||
try
|
||||
{
|
||||
Files.createDirectory(this.rootDir);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
fmlLog.error(LOADING,"Error creating {}", this.rootDir, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,12 +75,24 @@ public class ExplodedDirectoryLocator implements IModLocator {
|
|||
|
||||
@Override
|
||||
public void scanFile(final ModFile modFile, final Consumer<Path> pathConsumer) {
|
||||
fmlLog.debug("Scanning directory {}", rootDir);
|
||||
fmlLog.debug(SCAN,"Scanning directory {}", rootDir);
|
||||
try (Stream<Path> files = Files.find(rootDir, Integer.MAX_VALUE, (p, a) -> p.getNameCount() > 0 && p.getFileName().toString().endsWith(".class"))) {
|
||||
files.forEach(pathConsumer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
fmlLog.debug("Directory scan complete {}", rootDir);
|
||||
fmlLog.debug(SCAN,"Directory scan complete {}", rootDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{ExplodedDir locator at "+this.rootDir+"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Manifest> findManifest(Path file)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Map;
|
|||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class ModDiscoverer {
|
||||
|
@ -36,7 +37,7 @@ public class ModDiscoverer {
|
|||
public ModDiscoverer() {
|
||||
locators = ServiceLoader.load(IModLocator.class);
|
||||
locatorList = ServiceLoaderStreamUtils.toList(this.locators);
|
||||
fmlLog.debug("Found Mod Locators : {}", ()->locatorList.stream().map(IModLocator::name).collect(Collectors.joining(",")));
|
||||
fmlLog.debug(SCAN,"Found Mod Locators : {}", ()->locatorList.stream().map(iModLocator -> "("+iModLocator.name() + ":" + iModLocator.getClass().getPackage().getImplementationVersion()+")").collect(Collectors.joining(",")));
|
||||
}
|
||||
|
||||
ModDiscoverer(List<IModLocator> locatorList) {
|
||||
|
@ -45,22 +46,21 @@ public class ModDiscoverer {
|
|||
}
|
||||
|
||||
public BackgroundScanHandler discoverMods() {
|
||||
fmlLog.debug("Scanning for mods and other resources to load. We know {} ways to find mods", locatorList.size());
|
||||
fmlLog.debug(SCAN,"Scanning for mods and other resources to load. We know {} ways to find mods", locatorList.size());
|
||||
final Map<ModFile.Type, List<ModFile>> modFiles = locatorList.stream()
|
||||
.peek(loc -> fmlLog.debug("Trying locator {}", loc))
|
||||
.peek(loc -> fmlLog.debug(SCAN,"Trying locator {}", loc))
|
||||
.map(IModLocator::scanMods)
|
||||
.flatMap(Collection::stream)
|
||||
.peek(mf -> fmlLog.debug("Found mod file {} of type {} with locator {}", mf.getFileName(), mf.getType(), mf.getLocator()))
|
||||
.peek(mf -> fmlLog.debug(SCAN,"Found mod file {} of type {} with locator {}", mf.getFileName(), mf.getType(), mf.getLocator()))
|
||||
.collect(Collectors.groupingBy(ModFile::getType));
|
||||
|
||||
ModLanguageProvider.loadAdditionalLanguages(modFiles.get(ModFile.Type.LANGPROVIDER));
|
||||
//ModLanguageProvider.loadAdditionalLanguages(modFiles.get(ModFile.Type.LANGPROVIDER));
|
||||
BackgroundScanHandler backgroundScanHandler = new BackgroundScanHandler();
|
||||
final List<ModFile> mods = modFiles.get(ModFile.Type.MOD);
|
||||
mods.forEach(ModFile::identifyMods);
|
||||
fmlLog.debug("Found {} mod files with {} mods", mods::size, ()->mods.stream().mapToInt(mf -> mf.getModInfos().size()).sum());
|
||||
mods.stream().map(ModFile::getCoreMods).flatMap(List::stream).forEach(ServiceProviders.getCoreModProvider()::addCoreMod);
|
||||
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(ServiceProviders.getCoreModProvider()::addCoreMod);
|
||||
mods.forEach(backgroundScanHandler::submitForScanning);
|
||||
return backgroundScanHandler;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.util.function.Consumer;
|
|||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.LOADING;
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class ModFile
|
||||
|
@ -56,8 +58,8 @@ public class ModFile
|
|||
this.locator = locator;
|
||||
this.filePath = file;
|
||||
manifest = locator.findManifest(file).orElse(DEFAULTMANIFEST);
|
||||
if (manifest != DEFAULTMANIFEST) fmlLog.debug("Mod file {} has a manifest", file);
|
||||
else fmlLog.debug("Mod file {} is missing a manifest", file);
|
||||
if (manifest != DEFAULTMANIFEST) fmlLog.debug(SCAN,"Mod file {} has a manifest", file);
|
||||
else fmlLog.debug(SCAN,"Mod file {} is missing a manifest", file);
|
||||
modFileType = Type.valueOf(manifest.getMainAttributes().getValue(TYPE));
|
||||
}
|
||||
|
||||
|
@ -75,9 +77,9 @@ public class ModFile
|
|||
|
||||
public void identifyMods() {
|
||||
this.modInfos = ModFileParser.readModList(this);
|
||||
this.modInfos.forEach(mi-> fmlLog.debug("Found mod {} for language {}", mi.getModId(), mi.getModLoader()));
|
||||
this.modInfos.forEach(mi-> fmlLog.debug(LOADING,"Found mod {} for language {}", mi.getModId(), mi.getModLoader()));
|
||||
this.coreMods = ModFileParser.getCoreMods(this);
|
||||
this.coreMods.forEach(mi-> fmlLog.debug("Found coremod {}", mi.getPath()));
|
||||
this.coreMods.forEach(mi-> fmlLog.debug(LOADING,"Found coremod {}", mi.getPath()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,45 +27,54 @@ import com.google.gson.reflect.TypeToken;
|
|||
import net.minecraftforge.fml.common.versioning.ArtifactVersion;
|
||||
import net.minecraftforge.fml.common.versioning.DefaultArtifactVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
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 java.util.List<net.minecraftforge.fml.loading.moddiscovery.ModInfo> readModList(final ModFile modFile) {
|
||||
fmlLog.debug("Parsing mod file candidate {}", modFile.getFilePath());
|
||||
protected static List<ModInfo> readModList(final ModFile modFile) {
|
||||
fmlLog.debug(LOADING,"Parsing mod file candidate {}", modFile.getFilePath());
|
||||
try {
|
||||
final java.nio.file.Path modsjson = modFile.getLocator().findPath(modFile, "META-INF", "mods.json");
|
||||
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(java.nio.file.Files.newBufferedReader(modsjson), ModInfo[].class);
|
||||
return java.util.stream.Stream.of(modInfos).collect(java.util.stream.Collectors.toList());
|
||||
} catch (java.io.IOException e) {
|
||||
fmlLog.debug("Ignoring invalid JAR file {}", modFile.getFilePath());
|
||||
return java.util.Collections.emptyList();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
protected static java.util.List<CoreModFile> getCoreMods(final ModFile modFile) {
|
||||
java.util.Map<String,String> coreModPaths;
|
||||
protected static List<CoreModFile> getCoreMods(final ModFile modFile) {
|
||||
Map<String,String> coreModPaths;
|
||||
try {
|
||||
final java.nio.file.Path coremodsjson = modFile.getLocator().findPath(modFile, "META-INF", "coremods.json");
|
||||
if (!java.nio.file.Files.exists(coremodsjson)) {
|
||||
return java.util.Collections.emptyList();
|
||||
final Path coremodsjson = modFile.getLocator().findPath(modFile, "META-INF", "coremods.json");
|
||||
if (!Files.exists(coremodsjson)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final java.lang.reflect.Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
final Type type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
final Gson gson = new Gson();
|
||||
coreModPaths = gson.fromJson(java.nio.file.Files.newBufferedReader(coremodsjson), type);
|
||||
} catch (java.io.IOException e) {
|
||||
fmlLog.debug("Failed to read coremod list coremods.json", e);
|
||||
return java.util.Collections.emptyList();
|
||||
coreModPaths = gson.fromJson(Files.newBufferedReader(coremodsjson), type);
|
||||
} catch (IOException e) {
|
||||
fmlLog.debug(LOADING,"Failed to read coremod list coremods.json", e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return coreModPaths.entrySet().stream().
|
||||
peek(e-> fmlLog.debug("Found coremod {} with Javascript path {}", e.getKey(), e.getValue())).
|
||||
peek(e-> fmlLog.debug(LOADING,"Found coremod {} with Javascript path {}", e.getKey(), e.getValue())).
|
||||
map(e -> new CoreModFile(e.getKey(), modFile.getLocator().findPath(modFile, e.getValue()),modFile)).
|
||||
collect(java.util.stream.Collectors.toList());
|
||||
collect(Collectors.toList());
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package net.minecraftforge.fml.loading.moddiscovery;
|
||||
|
||||
import net.minecraftforge.fml.StringUtils;
|
||||
import net.minecraftforge.fml.common.FMLPaths;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -31,12 +32,16 @@ import java.util.Comparator;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipError;
|
||||
|
||||
import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck;
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
/**
|
||||
|
@ -57,6 +62,7 @@ public class ModsFolderLocator implements IModLocator {
|
|||
|
||||
@Override
|
||||
public List<ModFile> scanMods() {
|
||||
fmlLog.debug(SCAN,"Scanning mods dir {} for mods", this.modFolder);
|
||||
return uncheck(()-> Files.list(this.modFolder)).
|
||||
sorted(Comparator.comparing(path-> StringUtils.toLowerCase(path.getFileName().toString()))).
|
||||
filter(p->StringUtils.toLowerCase(p.getFileName().toString()).endsWith(SUFFIX)).
|
||||
|
@ -74,7 +80,7 @@ public class ModsFolderLocator implements IModLocator {
|
|||
try {
|
||||
return FileSystems.newFileSystem(modFile.getFilePath(), modFile.getClass().getClassLoader());
|
||||
} catch (ZipError | IOException e) {
|
||||
fmlLog.debug("Ignoring invalid JAR file {}", modFile.getFilePath());
|
||||
fmlLog.debug(SCAN,"Ignoring invalid JAR file {}", modFile.getFilePath());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +95,7 @@ public class ModsFolderLocator implements IModLocator {
|
|||
|
||||
@Override
|
||||
public void scanFile(final ModFile file, final Consumer<Path> pathConsumer) {
|
||||
fmlLog.debug("Scan started: {}", file);
|
||||
fmlLog.debug(SCAN,"Scan started: {}", file);
|
||||
FileSystem fs = modJars.get(file);
|
||||
fs.getRootDirectories().forEach(path -> {
|
||||
try (Stream<Path> files = Files.find(path, Integer.MAX_VALUE, (p, a) -> p.getNameCount() > 0 && p.getFileName().toString().endsWith(".class"))) {
|
||||
|
@ -98,11 +104,24 @@ public class ModsFolderLocator implements IModLocator {
|
|||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
fmlLog.debug("Scan finished: {}", file);
|
||||
fmlLog.debug(SCAN,"Scan finished: {}", file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{FolderJar locator at "+this.modFolder+"}";
|
||||
return "{ModJarsFolder locator at "+this.modFolder+"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Manifest> findManifest(final Path file)
|
||||
{
|
||||
try (JarFile jf = new JarFile(file.toFile()))
|
||||
{
|
||||
return Optional.ofNullable(jf.getManifest());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package net.minecraftforge.fml.loading.moddiscovery;
|
|||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.SCAN;
|
||||
import static net.minecraftforge.fml.Logging.fmlLog;
|
||||
|
||||
public class Scanner {
|
||||
|
@ -38,7 +39,7 @@ public class Scanner {
|
|||
|
||||
private void fileVisitor(final java.nio.file.Path path, final ScanResult result) {
|
||||
try {
|
||||
fmlLog.debug("Scanning {} path {}", fileToScan, path);
|
||||
fmlLog.debug(SCAN,"Scanning {} path {}", fileToScan, path);
|
||||
ModClassVisitor mcv = new ModClassVisitor();
|
||||
org.objectweb.asm.ClassReader cr = new ClassReader(java.nio.file.Files.newInputStream(path));
|
||||
cr.accept(mcv, 0);
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
net.minecraftforge.fml.loading.moddiscovery.ModsFolderLocator
|
||||
net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator
|
|
@ -2,7 +2,7 @@
|
|||
<Configuration status="WARN" packages="com.mojang.util">
|
||||
<Appenders>
|
||||
<Console name="FmlSysOut" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] [%logger]: %msg%n" />
|
||||
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level] [%logger/%marker]: %msg%n" />
|
||||
</Console>
|
||||
<Console name="SysOut" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n" />
|
||||
|
|
Loading…
Reference in New Issue