Initial test of Gradle (not working yet)

This commit is contained in:
Sunstrike committed 2013-11-21 16:13:51 +00:00
1 parent e8b7378831
commit cb87c836c8
519 files changed
+351

No files matched your search

@@ -0,0 +1,173 @@
package tconstruct.preloader;
/*
* ASMInterfaceRepair is derived from code graciously provided by AlgorithmX2 of Applied Energistics.
* The code was adapted for this loader by Sunstrike. Any queries should be directed to him, not AlgorithmX2.
*/
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.signature.SignatureReader;
import org.objectweb.asm.signature.SignatureVisitor;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import tconstruct.preloader.helpers.PropertyManager;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ASMInterfaceRepair implements IClassTransformer
{
public static Map<String, Boolean> APIInterfaces = new HashMap<String, Boolean>();
@Override
public byte[] transform (String name, String transformedName, byte[] bytes)
{
if (name.startsWith("tconstruct.") && !isBlacklisted(name))
{
ClassReader cr = new ClassReader(bytes);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
boolean changed = false;
if (this.verifyAPI(cn))
changed = true;
if (changed)
{
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
bytes = cw.toByteArray();
log("Altering definition of " + transformedName);
}
}
return bytes;
}
private boolean isInternal (String path)
{
return path.startsWith("java/") || path.startsWith("cpw/mods/fml/") || path.startsWith("tconstruct/") || path.startsWith("com/google/") || path.startsWith("net/minecraftforge/")
|| path.startsWith("net/minecraft/");
}
// Used in transform() above.
private boolean isBlacklisted (String path)
{
return path.startsWith("tconstruct.plugins.") || path.startsWith("tconstruct.preloader.");
}
private boolean isClassAvailable (String inf)
{
if (APIInterfaces.containsKey(inf))
return APIInterfaces.get(inf);
boolean isAvailable = false;
Class obj = null;
try
{
obj = Class.forName(inf.replace("/", "."));
//obj = ReflectionHelper.getClass( getClass().getClassLoader(), inf.replace( "/", "." ) );
}
catch (Throwable _)
{
}
// java.io.InputStream is = this.getClass().getResourceAsStream( "/" + inf + ".class" );
APIInterfaces.put(inf, isAvailable = (obj != null));
return isAvailable;
}
class SigChecker extends SignatureVisitor
{
private ASMInterfaceRepair asmTransformer;
public boolean isAvailable = true;
public SigChecker(int api, ASMInterfaceRepair t)
{
super(api);
asmTransformer = t;
}
@Override
public void visitInnerClassType (String name)
{
visitTypeVariable(name);
}
@Override
public void visitClassType (String name)
{
visitTypeVariable(name);
}
@Override
public void visitTypeVariable (String className)
{
if (isInternal(className))
return;
isAvailable = isAvailable && asmTransformer.isClassAvailable(className);
log(className + " is " + (isAvailable ? "available" : "not available"));
}
}
private boolean verifyAPI (ClassNode cn)
{
boolean changed = false;
log("Examining " + cn.name);
Iterator<MethodNode> mn = cn.methods.iterator();
while (mn.hasNext())
{
MethodNode meth = mn.next();
SigChecker sc = new SigChecker(1, this);
(new SignatureReader(meth.desc)).accept(sc);
boolean isAvailable = sc.isAvailable;
if (!isAvailable)
{
mn.remove();
changed = true;
}
}
Iterator<String> i = cn.interfaces.iterator();
while (i.hasNext())
{
String inf = i.next();
if (isInternal(inf))
continue;
boolean isAvailable = isClassAvailable(inf);
log(inf + " is " + (isAvailable ? "available" : "not available"));
if (!isAvailable)
{
i.remove();
changed = true;
}
}
return changed;
}
private void log (String string)
{
if (PropertyManager.asmInterfaceRepair_verboseLog)
{
TConstructLoaderContainer.logger.info(string);
}
}
}
@@ -0,0 +1,146 @@
package tconstruct.preloader;
/*
* TConstructLoaderContainer is derived from code graciously provided by AlgorithmX2 of Applied Energistics.
* The code was adapted for this loader by Sunstrike. Any queries should be directed to him, not AlgorithmX2.
*/
import com.google.common.eventbus.EventBus;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import net.minecraftforge.event.ForgeSubscribe;
import tconstruct.preloader.helpers.PropertyManager;
import tconstruct.preloader.helpers.PropertyManager.PropAccessException;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Logger;
public class TConstructLoaderContainer extends DummyModContainer implements IFMLLoadingPlugin
{
private final String[] asmTransformers = new String[] { "tconstruct.preloader.ASMInterfaceRepair" };
private final ModMetadata md = new ModMetadata();
public static Logger logger = Logger.getLogger("TCon-Preloader");
public TConstructLoaderContainer()
{
logger.setParent(FMLLog.getLogger());
logger.info("Scalpel. Suction. Lumber axe. CLEAR! *zap*");
logger.info("Constructing preloader (Modules: " + Arrays.toString(asmTransformers) + ")");
try
{
PropertyManager.getOrCreateProps();
}
catch (PropAccessException ex)
{
logger.severe("Could not get or create properties file! Assuming defaults.");
logger.severe(Arrays.toString(ex.getStackTrace()));
}
if (PropertyManager.asmInterfaceRepair_verboseLog)
{
logger.warning("ASM Interface Repair is set to be verbose, this is NOT GOOD FOR SERVERS, as it will spam the logs!");
logger.warning("The debug mode is for debug use only. Turn it off unless instructed otherwise by a TCon developer!");
logger.warning("To reset advanced settings to default, delete the '" + PropertyManager.propFileName + "' file from the config folder.");
}
md.autogenerated = true;
md.credits = "AlgorithmX2 (original) and Sunstrike (porting)";
md.modId = getModId();
md.version = getVersion();
md.name = getName();
md.authorList = Arrays.asList("AlgorithmX2", "Sunstrike");
}
@ForgeSubscribe
public void preInit (FMLPreInitializationEvent evt)
{
}
@ForgeSubscribe
public void init (FMLInitializationEvent evt)
{
}
@ForgeSubscribe
public void postInit (FMLPostInitializationEvent evt)
{
}
@Override
public String getModId ()
{
return "TConstruct-Preloader";
}
@Override
public String getName ()
{
return "Tinkers Corestruct";
}
@Override
public String getVersion ()
{
return "0.0.1";
}
@Override
public String getDisplayVersion ()
{
return getVersion();
}
@Override
public ModMetadata getMetadata ()
{
return md;
}
@Override
public boolean registerBus (EventBus bus, LoadController controller)
{
bus.register(this);
return true;
}
@Override
public String[] getLibraryRequestClass ()
{
return null;
}
@Override
public String[] getASMTransformerClass ()
{
return asmTransformers;
}
@Override
public String getModContainerClass ()
{
return "tconstruct.preloader.TConstructLoaderContainer";
}
@Override
public String getSetupClass ()
{
return null;
}
@Override
public void injectData (Map<String, Object> data)
{
}
}
@@ -0,0 +1,89 @@
package tconstruct.preloader.helpers;
import tconstruct.preloader.TConstructLoaderContainer;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/**
* TCon Preloader properties file helper.
*
* We need this as at an early stage as we don't have access to Forge's Configuration object.
*
* @author Sunstrike
*/
public class PropertyManager
{
private PropertyManager()
{
} // Singleton
public static final String propFileName = "TConPreloader.cfg";
public static boolean asmInterfaceRepair_verboseLog = false;
/**
* Gets or creates the TCorestruct properties file.
*
* @throws PropAccessException Thrown if a properties file wasn't found and could not be created. Should be treated as a SEVERE log message.
* @return True if loaded from disk, false if file created instead.
*/
public static boolean getOrCreateProps () throws PropAccessException
{
File fp = new File("config/" + propFileName);
Properties props = new Properties();
if (fp.exists())
{
// Attempt read
try
{
TConstructLoaderContainer.logger.info("Found a properties file. Attempting load...");
props.load(new FileInputStream(fp));
asmInterfaceRepair_verboseLog = props.getProperty("asmInterfaceRepair_verboseLog", "false").equalsIgnoreCase("true");
TConstructLoaderContainer.logger.info("Loaded properties successfully. Using specified settings.");
}
catch (IOException ex)
{
throw new PropAccessException();
}
}
else
{
// Attempt creation
try
{
if (fp.createNewFile())
{
TConstructLoaderContainer.logger.info("Creating new properties file, as none found...");
props.setProperty("asmInterfaceRepair_verboseLog", "false");
props.store(new FileOutputStream(fp), null);
TConstructLoaderContainer.logger.info("Created properties file; using defaults this run.");
}
else
{
throw new PropAccessException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
throw new PropAccessException();
}
}
return false;
}
public static class PropAccessException extends Exception
{
}
}