/* * Minecraft Forge * Copyright (c) 2016-2019. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation version 2.1 * of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package net.minecraftforge.fml.loading.moddiscovery; import com.electronwill.nightconfig.core.UnmodifiableConfig; import net.minecraftforge.forgespi.language.MavenVersionAdapter; import net.minecraftforge.forgespi.language.IModFileInfo; import net.minecraftforge.forgespi.language.IModInfo; import net.minecraftforge.fml.loading.StringUtils; import org.apache.maven.artifact.versioning.VersionRange; import java.net.URL; import java.util.*; import java.util.jar.Manifest; import java.util.stream.Collectors; public class ModFileInfo implements IModFileInfo { private final UnmodifiableConfig config; private final ModFile modFile; private final URL issueURL; private final String modLoader; private final VersionRange modLoaderVersion; private final List mods; private final Map properties; ModFileInfo(final ModFile modFile, final UnmodifiableConfig config) { this.modFile = modFile; this.config = config; this.modLoader = config.getOptional("modLoader"). orElseThrow(()->new InvalidModFileException("Missing ModLoader in file", this)); this.modLoaderVersion = config.getOptional("loaderVersion"). map(MavenVersionAdapter::createFromVersionSpec). orElseThrow(()->new InvalidModFileException("Missing ModLoader version in file", this)); this.properties = config.getOptional("properties"). map(UnmodifiableConfig::valueMap).orElse(Collections.emptyMap()); this.modFile.setFileProperties(this.properties); final ArrayList 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.issueURL = config.getOptional("issueTrackerURL").map(StringUtils::toURL).orElse(null); } @Override public List getMods() { return mods; } public ModFile getFile() { return this.modFile; } @Override public UnmodifiableConfig getConfig() { return this.config; } @Override public String getModLoader() { return modLoader; } @Override public VersionRange getModLoaderVersion() { return modLoaderVersion; } @Override public Map getFileProperties() { return this.properties; } public Optional getManifest() { return modFile.getLocator().findManifest(modFile.getFilePath()); } }