Skip to content

Commit

Permalink
make the log information meaningful and simple.
Browse files Browse the repository at this point in the history
  • Loading branch information
xsun committed Mar 9, 2017
1 parent 57db55e commit da7e58a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
11 changes: 4 additions & 7 deletions src/main/java/appeng/transformer/AppEngCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
package appeng.transformer;


import java.util.Map;

import javax.annotation.Nullable;

import appeng.core.AEConfig;
import com.google.common.eventbus.EventBus;

import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.Mod.EventHandler;
Expand All @@ -34,7 +30,8 @@
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;

import appeng.core.AEConfig;
import javax.annotation.Nullable;
import java.util.Map;


@MCVersion( "1.7.10" )
Expand Down Expand Up @@ -64,7 +61,7 @@ public void load( final FMLInitializationEvent event )
@Override
public String[] getASMTransformerClass()
{
return new String[] { "appeng.transformer.asm.ASMIntegration", "appeng.transformer.asm.ASMApiFixer" };
return new String[] { "appeng.transformer.asm.ASMIntegration", "appeng.transformer.asm.ApiRepairer" };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@
import appeng.helpers.Reflected;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import net.minecraft.launchwrapper.IClassTransformer;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.Level;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

Expand All @@ -41,43 +34,40 @@
* See also : https://github.com/xsun2001/Applied-Energistics-2-Unofficial/issues/1
*/
@Reflected
public class ASMApiFixer implements IClassTransformer
public class ApiRepairer implements IClassTransformer
{

public ASMApiFixer()
public ApiRepairer()
{
FMLRelaunchLog.log( "AE2-ApiFixer", Level.INFO, "ApiFixer Installed" );
FMLRelaunchLog.log( "AE2-ApiFixer", Level.INFO, "%s", getClass().getResource( "" ).toString() );
FMLRelaunchLog.log( "AE2-ApiRepairer", Level.INFO, "AE2 ApiFixer Installed" );
}

@Override public byte[] transform( String name, String transformedName, byte[] basicClass )
{
if( transformedName.startsWith( "appeng.api" ) )
{
FMLRelaunchLog.log( "AE2-ApiFixer", Level.INFO, "Fixing api class file:%s", transformedName );
try
{
String clazzurl = getClass().getResource( "" ).toString();
clazzurl = clazzurl.substring( 0, clazzurl.length() - 23 ) + transformedName.replace( '.', '/' ) + ".class";
//23 is "appeng/transformer/asm"'s length + 1
FMLRelaunchLog.log( "AE2-ApiFixer", Level.INFO, "Fixing...:%s", clazzurl );
URL url = new URL( clazzurl );
URLConnection connection = url.openConnection();
byte[] bytes = new byte[connection.getContentLength()];
if( connection.getInputStream().read( bytes ) == -1 )
{
FMLRelaunchLog.log( "AE2-ApiFixer", Level.ERROR, "Cannot fix:%s", transformedName );
FMLRelaunchLog.log( "AE2-ApiRepairer", Level.ERROR, "Failed to fix api class [%s] because the new class couldn't be read", transformedName );
return basicClass;
}
else
{
FMLRelaunchLog.log( "AE2-ApiFixer", Level.INFO, "Fix success:%s", transformedName );
FMLRelaunchLog.log( "AE2-ApiRepairer", Level.INFO, "Successfully fix api class [%s]", transformedName );
return bytes;
}
}
catch( Exception e )
{
FMLRelaunchLog.log( "AE2-ApiFixer", Level.ERROR, "Fix failed:%s|%s", transformedName, e.getClass().getName() );
FMLRelaunchLog.log( "AE2-ApiRepairer", Level.ERROR, "Failed to fix api class [%s] because of [%s]", transformedName, e.getClass().getName() );
return basicClass;
}
}
Expand Down

0 comments on commit da7e58a

Please sign in to comment.