Search in sources :

Example 1 with ModCandidate

use of net.minecraftforge.fml.common.discovery.ModCandidate in project MinecraftForge by MinecraftForge.

the class ModAPIManager method registerDataTableAndParseAPI.

public void registerDataTableAndParseAPI(ASMDataTable dataTable) {
    this.dataTable = dataTable;
    Set<ASMData> apiList = dataTable.getAll("net.minecraftforge.fml.common.API");
    apiContainers = Maps.newHashMap();
    for (ASMData data : apiList) {
        Map<String, Object> annotationInfo = data.getAnnotationInfo();
        String apiPackage = data.getClassName().substring(0, data.getClassName().indexOf(".package-info"));
        String providedAPI = (String) annotationInfo.get("provides");
        String apiOwner = (String) annotationInfo.get("owner");
        String apiVersion = (String) annotationInfo.get("apiVersion");
        APIContainer container = apiContainers.get(providedAPI);
        if (container == null) {
            container = new APIContainer(providedAPI, apiVersion, data.getCandidate().getModContainer(), VersionParser.parseVersionReference(apiOwner));
            apiContainers.put(providedAPI, container);
        } else {
            container.validate(providedAPI, apiOwner, apiVersion);
        }
        container.addOwnedPackage(apiPackage);
        for (ModContainer mc : data.getCandidate().getContainedMods()) {
            String embeddedIn = mc.getModId();
            if (container.currentReferents.contains(embeddedIn)) {
                continue;
            }
            FMLLog.fine("Found API %s (owned by %s providing %s) embedded in %s", apiPackage, apiOwner, providedAPI, embeddedIn);
            if (!embeddedIn.equals(apiOwner)) {
                container.addAPIReference(embeddedIn);
            }
        }
    }
    for (APIContainer container : apiContainers.values()) {
        for (String pkg : container.packages) {
            Set<ModCandidate> candidates = dataTable.getCandidatesFor(pkg);
            for (ModCandidate candidate : candidates) {
                List<String> candidateIds = Lists.transform(candidate.getContainedMods(), new ModIdFunction());
                if (!candidateIds.contains(container.ownerMod.getLabel()) && !container.currentReferents.containsAll(candidateIds)) {
                    FMLLog.info("Found mod(s) %s containing declared API package %s (owned by %s) without associated API reference", candidateIds, pkg, container.ownerMod);
                    container.addAPIReferences(candidateIds);
                }
            }
        }
        if (apiContainers.containsKey(container.ownerMod.getLabel())) {
            ArtifactVersion owner = container.ownerMod;
            do {
                APIContainer parent = apiContainers.get(owner.getLabel());
                if (parent == container) {
                    FMLLog.finer("APIContainer %s is it's own parent. skipping", owner);
                    container.markSelfReferenced();
                    break;
                }
                FMLLog.finer("Removing upstream parent %s from %s", parent.ownerMod.getLabel(), container);
                container.currentReferents.remove(parent.ownerMod.getLabel());
                container.referredMods.remove(parent.ownerMod);
                owner = parent.ownerMod;
            } while (apiContainers.containsKey(owner.getLabel()));
        }
        FMLLog.fine("Creating API container dummy for API %s: owner: %s, dependents: %s", container.providedAPI, container.ownerMod, container.referredMods);
    }
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) DefaultArtifactVersion(net.minecraftforge.fml.common.versioning.DefaultArtifactVersion) ArtifactVersion(net.minecraftforge.fml.common.versioning.ArtifactVersion) ModCandidate(net.minecraftforge.fml.common.discovery.ModCandidate) ModIdFunction(net.minecraftforge.fml.common.functions.ModIdFunction)

Aggregations

ASMData (net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData)1 ModCandidate (net.minecraftforge.fml.common.discovery.ModCandidate)1 ModIdFunction (net.minecraftforge.fml.common.functions.ModIdFunction)1 ArtifactVersion (net.minecraftforge.fml.common.versioning.ArtifactVersion)1 DefaultArtifactVersion (net.minecraftforge.fml.common.versioning.DefaultArtifactVersion)1