001    package cpw.mods.fml.common;
002    
003    import java.io.File;
004    import java.util.regex.Pattern;
005    
006    import org.objectweb.asm.Type;
007    
008    import cpw.mods.fml.common.discovery.ModCandidate;
009    import cpw.mods.fml.common.discovery.asm.ASMModParser;
010    import cpw.mods.fml.common.discovery.asm.ModAnnotation;
011    import cpw.mods.fml.common.modloader.ModLoaderModContainer;
012    
013    public 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 (modParser.isBaseMod(container.getRememberedBaseMods()))
029            {
030                FMLLog.fine("Found a basemod %s of non-standard naming format", className);
031                container.rememberBaseModType(className);
032            }
033    
034            // We warn if it's not a basemod instance -- compatibility requires it to be in net.minecraft.src *sigh*
035            if (className.startsWith("net.minecraft.src.") && container.isClasspath())
036            {
037                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. "
038                        + " 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 "
039                        + "a new package. Go on. DO IT NOW!",className);
040            }
041    
042            for (ModAnnotation ann : modParser.getAnnotations())
043            {
044                if (ann.getASMType().equals(Type.getType(Mod.class)))
045                {
046                    FMLLog.fine("Identified a FMLMod type mod %s", className);
047                    return new FMLModContainer(className, modSource, ann.getValues());
048                }
049            }
050    
051            return null;
052        }
053    }