Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWTS does not seem to work with liteloader #2

Closed
Pokechu22 opened this issue Jan 28, 2018 · 3 comments
Closed

LWTS does not seem to work with liteloader #2

Pokechu22 opened this issue Jan 28, 2018 · 3 comments
Assignees

Comments

@Pokechu22
Copy link

When I run unit tests with liteloader, things do not work; it seems like the mixins are not being properly applied.

Here is the test output:

com.examplemod.SomeTest STANDARD_OUT
    [13:19:23] [Test worker/INFO]: Loading tweak class name com.examplemod.TestTweaker
    [13:19:23] [Test worker/INFO]: Using primary tweak class name com.examplemod.TestTweaker
    [13:19:23] [Test worker/INFO]: Calling tweak class com.examplemod.TestTweaker
    [13:19:23] [Test worker/INFO]: SpongePowered MIXIN Subsystem Version=0.7.3 Source=file:/C:/Users/Pokechu22/.gradle/caches/modules-2/files-2.1/org.spongepowered/mixin/0.7.3-SNAPSHOT/484e9031a994cdcc68cf79653c9d5dc288faa350/mixin-0.7.3-SNAPSHOT.jar Service=LaunchWrapper Env=UNKNOWN

com.examplemod.SomeTest STANDARD_ERROR
    /*************************************************************************************************************************************************************************************************************/
    /*                                                                              SpongePowered MIXIN (Verbose debugging enabled)                                                                              */
    /*************************************************************************************************************************************************************************************************************/
    /*                        Code source : file:/C:/Users/Pokechu22/.gradle/caches/modules-2/files-2.1/org.spongepowered/mixin/0.7.3-SNAPSHOT/484e9031a994cdcc68cf79653c9d5dc288faa350/mixin-0.7.3-SNAPSHOT.jar */
    /*                   Internal Version : 0.7.3                                                                                                                                                                */
    /*                   Java 8 Supported : true                                                                                                                                                                 */
    /*************************************************************************************************************************************************************************************************************/
    /*                       Service Name : LaunchWrapper                                                                                                                                                        */
    /*                      Service Class : org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper                                                                                                       */
    /*************************************************************************************************************************************************************************************************************/
    /*                        mixin.debug : <true>                                                                                                                                                               */
    /*                 mixin.debug.export : - <true>                                                                                                                                                             */
    /*          mixin.debug.export.filter : - - <null>                                                                                                                                                           */
    /*       mixin.debug.export.decompile : - - <true>                                                                                                                                                           */
    /* mixin.debug.export.decompile.async : - - - <true>                                                                                                                                                         */
    /*                 mixin.debug.verify : - <true>                                                                                                                                                             */
    /*                mixin.debug.verbose : - <true>                                                                                                                                                             */
    /*        mixin.debug.countInjections : - <true>                                                                                                                                                             */
    /*                 mixin.debug.strict : - <false>                                                                                                                                                            */
    /*          mixin.debug.strict.unique : - - <false>                                                                                                                                                          */
    /*         mixin.debug.strict.targets : - - <false>                                                                                                                                                          */
    /*               mixin.debug.profiler : - <true>                                                                                                                                                             */
    /*          mixin.dumpTargetOnFailure : <false>                                                                                                                                                              */
    /*                       mixin.checks : <false>                                                                                                                                                              */
    /*            mixin.checks.interfaces : - <false>                                                                                                                                                            */
    /*     mixin.checks.interfaces.strict : - - <false>                                                                                                                                                          */
    /*            mixin.ignoreConstraints : <false>                                                                                                                                                              */
    /*                      mixin.hotSwap : <false>                                                                                                                                                              */
    /*                          mixin.env : <false>                                                                                                                                                              */
    /*                      mixin.env.obf : - <false>                                                                                                                                                            */
    /*            mixin.env.disableRefMap : - <false>                                                                                                                                                            */
    /*              mixin.env.remapRefMap : - <false>                                                                                                                                                            */
    /*      mixin.env.refMapRemappingFile : - <>                                                                                                                                                                 */
    /*       mixin.env.refMapRemappingEnv : - <searge>                                                                                                                                                           */
    /*           mixin.env.ignoreRequired : - <false>                                                                                                                                                            */
    /*              mixin.env.compatLevel : - <false>                                                                                                                                                            */
    /*         mixin.env.shiftByViolation : - <warn>                                                                                                                                                             */
    /*     mixin.initialiserInjectionMode : <default>                                                                                                                                                            */
    /*************************************************************************************************************************************************************************************************************/
    /*                      Detected Side : UNKNOWN                                                                                                                                                              */
    /*************************************************************************************************************************************************************************************************************/

com.examplemod.SomeTest STANDARD_OUT
    [13:19:24] [Test worker/INFO]: Attempting to load Fernflower decompiler (Threaded mode)
    [13:19:24] [Test worker/INFO]: Fernflower could not be loaded, exported classes will not be decompiled. NoClassDefFoundError: org/jetbrains/java/decompiler/main/extern/IResultSaver
    [13:19:24] [Test worker/INFO]: FML platform manager could not load class cpw.mods.fml.relauncher.CoreModManager. Proceeding without FML support.
    [13:19:24] [Test worker/WARN]: MixinBootstrap.doInit() called during a tweak constructor. Expect CoModificationException in 5.. 4..
    [13:19:24] [Test worker/INFO]: Compatibility level set to JAVA_8
    sun.misc.Launcher$AppClassLoader@73d16e93
    [13:19:24] [Test worker/INFO]: Loading tweak class name org.spongepowered.asm.mixin.EnvironmentStateTweaker
    [13:19:24] [Test worker/INFO]: Calling tweak class org.spongepowered.asm.mixin.EnvironmentStateTweaker
    [13:19:24] [Test worker/INFO]: Preparing mixins for MixinEnvironment[DEFAULT]
    [13:19:24] [Test worker/INFO]: Selecting config mixins.example.json
    [13:19:24] [Test worker/WARN]: Reference map 'mixins.example.refmap.json' for mixins.example.json could not be read. If this is a development environment you can ignore this message
    [13:19:24] [Test worker/INFO]: Preparing mixins.example.json (2)
    [13:19:24] [Test worker/INFO]: Prepared 2 mixins in 0.381 sec (190.5ms avg) (14ms load, 0ms transform, 0ms plugin)
    [13:19:24] [Test worker/INFO]: Launching wrapped minecraft {org.spongepowered.lwts.TestMain}

com.examplemod.SomeTest > testFoo STANDARD_OUT
    sun.misc.Launcher$AppClassLoader@73d16e93
Gradle Test Executor 7 finished executing tests.

com.examplemod.SomeTest > testFoo FAILED
    java.lang.ClassCastException: net.minecraft.util.ResourceLocation cannot be cast to com.examplemod.Foo
        at com.examplemod.SomeTest.testFoo(SomeTest.java:14)

Here's a zip of my test project (which is just the liteloader examplemod plus some other code that works with tests; the mixin I'm testing is only for this and doesn't actually have any value when launched with MC). lwts-test.zip

LWTS does work on sponge on my machine. I added System.out.println(this.getClass().getClassLoader()) to TestTweaker and CatalogTypeClassesTest (the second was just randomly chosen as one of the tests that uses LWTS), and for TestTweaker it was sun.misc.Launcher$AppClassLoader@73d16e93 but for CatalogTypeClassesTest it was net.minecraft.launchwrapper.LaunchClassLoader@30f10695. This differs from my liteloader result, where both were AppClassLoader (see log above). I'm guessing that that is the reason why I'm getting non-mixed-in classes... but I have no clue why this is happening otherwise.

I'm running with gradle wrapper 4.4.1.

@Pokechu22
Copy link
Author

So, this got more confusing. It is not related to liteloader. I stripped out basically all of the liteloader code, and tried with vanillagradle (both client and server). I also tried with forge, same issue. Here's the same project, set up with vanillagradle (server): lwts-test-2.zip.

Some debugging has gotten me down to this line of launchwrapper.

final Class<?> clazz = Class.forName(launchTarget, false, classLoader);

For some reason, that is inexplicable to me, on sponge this actually does use the classLoader instance passed in while for me it is using the default class loader (verified using the debugger). I have no clue why. And it's not that the class has already been loaded or something; I tried with -verbose:class and the class is only loaded when that line is hit.

It seems to be that that line is behaving differently on sponge for no discernable reason...

@stephan-gh
Copy link
Contributor

This is the problem: https://github.com/Mojang/LegacyLauncher/blob/master/src/main/java/net/minecraft/launchwrapper/Launch.java#L97

Launchwrapper automatically adds a classloader exclusion for the package your tweaker is in. You need to put it into a separate package so SomeTest and TestMain are not excluded from Launchwrapper.

This is also what's different for Sponge: We have the tweaker in a separate launch package: https://github.com/SpongePowered/SpongeCommon/tree/bleeding/src/test/java/org/spongepowered/common/launch :)

@Pokechu22
Copy link
Author

Pokechu22 commented Feb 12, 2018

Ah, makes sense. Confirmed that that fixes my test program, and it should also fix my actual larger program. Thanks!

Pokechu22 added a commit to Pokechu22/WorldDownloader that referenced this issue Feb 23, 2018
As per SpongePowered/LaunchWrapperTestSuite#2, the tweaker must be in a different package.  I also needed to add the java6 mixin code to my classpath for things to work, and have added the generated .mixin.out folders to my .gitignore.
mikroskeem added a commit to OrionMinecraft/LegacyLauncher that referenced this issue Mar 15, 2018
"Launchwrapper automatically adds a classloader exclusion for the
package your tweaker is in."

See SpongePowered/LaunchWrapperTestSuite#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants