    001package cpw.mods.fml.common;
    002
    003import java.io.File;
    004import java.util.regex.Pattern;
    005
    006import org.objectweb.asm.Type;
    007
    008import cpw.mods.fml.common.discovery.ModCandidate;
    009import cpw.mods.fml.common.discovery.asm.ASMModParser;
    010import cpw.mods.fml.common.discovery.asm.ModAnnotation;
    011import cpw.mods.fml.common.modloader.ModLoaderModContainer;
    012
    013public class ModContainerFactory
    014{
    015    private static Pattern modClass = Pattern.compile(".*(\\.|)(mod\\_[^\\s$]+)$");
    016    private static ModContainerFactory INSTANCE = new ModContainerFactory();
    017    public static ModContainerFactory instance() {
    018        return INSTANCE;
    019    }
    020    public ModContainer build(ASMModParser modParser, File modSource, ModCandidate container)
    021    {
    022        String className = modParser.getASMType().getClassName();
    023        if (modParser.isBaseMod(container.getRememberedBaseMods()) && modClass.matcher(className).find())
    024        {
    025            FMLLog.fine("Identified a BaseMod type mod %s", className);
    026            return new ModLoaderModContainer(className, modSource, modParser.getBaseModProperties());
    027        }
    028        else if (modClass.matcher(className).find())
    029        {
    030            FMLLog.fine("Identified a class %s following modloader naming convention but not directly a BaseMod or currently seen subclass", className);
    031            container.rememberModCandidateType(modParser);
    032        }
    033        else if (modParser.isBaseMod(container.getRememberedBaseMods()))
    034        {
    035            FMLLog.fine("Found a basemod %s of non-standard naming format", className);
    036            container.rememberBaseModType(className);
    037        }
    038
    039        // We warn if it's not a basemod instance -- compatibility requires it to be in net.minecraft.src *sigh*
    040        if (className.startsWith("net.minecraft.src.") && container.isClasspath() && !container.isMinecraftJar())
    041        {
    042            FMLLog.severe("FML has detected a mod that is using a package name based on 'net.minecraft.src' : %s. This is generally a severe programming error. "
    043                    + " There should be no mod code in the minecraft namespace. MOVE YOUR MOD! If you're in eclipse, select your source code and 'refactor' it into "
    044                    + "a new package. Go on. DO IT NOW!",className);
    045        }
    046
    047        for (ModAnnotation ann : modParser.getAnnotations())
    048        {
    049            if (ann.getASMType().equals(Type.getType(Mod.class)))
    050            {
    051                FMLLog.fine("Identified an FMLMod type mod %s", className);
    052                return new FMLModContainer(className, modSource, ann.getValues());
    053            }
    054        }
    055
    056        return null;
    057    }
    058}