Skip to content

Commit

Permalink
Update to ModLauncher 7.0 - Fixes SpongePowered#439
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Sep 17, 2020
1 parent 9438945 commit 9f5191d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ dependencies {
modlauncherCompile "org.ow2.asm:asm-tree:$modlauncherAsmVersion"
modlauncherCompile "org.ow2.asm:asm-commons:$modlauncherAsmVersion"
modlauncherCompile "org.ow2.asm:asm-util:$modlauncherAsmVersion"
modlauncherCompile ('cpw.mods:modlauncher:4.2.0') {
modlauncherCompile ("cpw.mods:modlauncher:$modlauncherVersion") {
exclude module: 'log4j-core'
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ buildType=SNAPSHOT
asmVersion=6.2
legacyForgeAsmVersion=5.0.3
modlauncherAsmVersion=6.2
modlauncherVersion=7.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ synchronized boolean applyMixins(MixinEnvironment environment, String name, Clas
} catch (MixinTransformerError er) {
throw er;
} catch (Throwable th) {
th.printStackTrace();
this.dumpClassOnFailure(name, targetClassNode, environment);
throw new MixinTransformerError("An unexpected critical error was encountered", th);
} finally {
Expand All @@ -374,9 +373,9 @@ private String getInvalidClassError(String name, ClassNode targetClassNode, Mixi
return String.format("Illegal classload request for %s. Mixin is defined in %s and cannot be referenced directly", name, ownedByConfig);
}

// AnnotationNode shadow = Annotations.getInvisible(targetClassNode, Shadow.class);
// if (shadow != null) {
// return String.format("Illegal classload request for UNRESOLVED @Shadow %s. "
// AnnotationNode proxy = Annotations.getInvisible(targetClassNode, Proxy.class);
// if (proxy != null) {
// return String.format("Illegal classload request for UNRESOLVED @Proxy %s. "
// + "The proxy was referenced outside a mixin or the mixin processor encountered an internal error.", name);
// }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ public byte[] transformClassBytes(String name, String transformedName, byte[] ba
return this.transformClass(environment, transformedName, basicClass);
}

/**
* Called when the transformation reason is computing_frames. The only
* operation we care about here is adding interfaces to target classes but
* at the moment we don't have sufficient scaffolding to determine that
* without triggering re-entrance. Currently just a no-op in order to not
* cause a re-entrance crash under ModLauncher 7.0+.
*
* @param environment Current environment
* @param name Class transformed name
* @param classNode Class tree
* @return true if the class was transformed
*/
public boolean computeFramesForClass(MixinEnvironment environment, String name, ClassNode classNode) {
// TODO compute added interfaces
return false;
}

/**
* Apply mixins and postprocessors to the supplied class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ public EnumSet<Phase> handlesClass(Type classType, boolean isEmpty, final String
*/
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType, String reason) {
if (MixinLaunchPlugin.NAME.equals(reason)) {
return false;
}

boolean processed = false;

synchronized (this.processors) {
Expand Down Expand Up @@ -168,11 +164,17 @@ public void customAuditConsumer(String className, Consumer<String[]> auditDataAc
}
}

@Override
// @Override ModLauncher 4.0
@Deprecated
public void addResource(Path resource, String name) {
this.service.getPrimaryContainer().addResource(name, resource);
}

// ModLauncher 7.0+
@Override
public void offerResource(Path resource, String name) {
this.service.getPrimaryContainer().addResource(name, resource);
}

@Override
public void addResources(List<Entry<String, Path>> resources) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.launch.IClassProcessor;
import org.spongepowered.asm.launch.MixinLaunchPlugin;
import org.spongepowered.asm.launch.Phases;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.service.ISyntheticClassInfo;
import org.spongepowered.asm.service.ISyntheticClassRegistry;

import cpw.mods.modlauncher.api.ITransformerActivity;
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService.Phase;

/**
Expand Down Expand Up @@ -100,12 +102,22 @@ public synchronized boolean processClass(Phase phase, ClassNode classNode, Type
} else {
transformer = this.transformer;
}

// Don't transform when the reason is mixin (side-loading in progress)
if (MixinLaunchPlugin.NAME.equals(reason)) {
return false;
}

MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
ISyntheticClassInfo syntheticClass = this.registry.findSyntheticClass(classType.getClassName());
if (syntheticClass != null) {
return transformer.generateClass(environment, classType.getClassName(), classNode);
}

if (ITransformerActivity.COMPUTING_FRAMES_REASON.equals(reason)) {
return transformer.computeFramesForClass(environment, classType.getClassName(), classNode);
}

return transformer.transformClass(environment, classType.getClassName(), classNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.spongepowered.asm.launch.Phases;
import org.spongepowered.asm.service.IClassTracker;

import cpw.mods.modlauncher.api.ITransformerActivity;
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService.Phase;

/**
Expand Down Expand Up @@ -102,8 +103,11 @@ public EnumSet<Phase> handlesClass(Type classType, boolean isEmpty, String reaso
*/
@Override
public boolean processClass(Phase phase, ClassNode classNode, Type classType, String reason) {
synchronized (this.loadedClasses) {
this.loadedClasses.add(classType.getClassName());
// Only track the classload if the reason is actually classloading
if (ITransformerActivity.CLASSLOADING_REASON.equals(reason)) {
synchronized (this.loadedClasses) {
this.loadedClasses.add(classType.getClassName());
}
}

return false;
Expand Down

0 comments on commit 9f5191d

Please sign in to comment.