Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
implementation "net.fabricmc:mapping-io:0.7.1"

testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
testCompileOnly ('net.fabricmc:sponge-mixin:0.16.2+mixin.0.8.7') {
testImplementation ('net.fabricmc:sponge-mixin:0.16.2+mixin.0.8.7') {
transitive = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;

import net.fabricmc.tinyremapper.api.TrMember;
import net.fabricmc.tinyremapper.api.TrRemapper;
import net.fabricmc.tinyremapper.extension.mixin.common.IMappable;
import net.fabricmc.tinyremapper.extension.mixin.common.ResolveUtility;
import net.fabricmc.tinyremapper.extension.mixin.common.data.CommonData;
Expand All @@ -44,16 +45,20 @@ public MemberInfo result() {
return info;
}

TrRemapper trRemapper = data.mapper.asTrRemapper();
Optional<TrMember> resolved = data.resolver.resolveMember(info.getOwner(), info.getName(), info.getDesc(), ResolveUtility.FLAG_UNIQUE | ResolveUtility.FLAG_RECURSIVE);

if (resolved.isPresent()) {
String newOwner = data.mapper.asTrRemapper().map(info.getOwner());
String newOwner = trRemapper.map(info.getOwner());
String newName = data.mapper.mapName(resolved.get());
String newDesc = data.mapper.mapDesc(resolved.get());

return new MemberInfo(newOwner, newName, info.getQuantifier(), newDesc);
} else {
return info;
}

// Workaround for https://github.com/FabricMC/tiny-remapper/issues/155
String newOwner = trRemapper.map(info.getOwner());
String newDesc = info.getType() == TrMember.MemberType.FIELD ? trRemapper.mapDesc(info.getDesc()) : trRemapper.mapMethodDesc(info.getDesc());
return new MemberInfo(newOwner, info.getName(), info.getQuantifier(), newDesc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,53 @@
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;

import net.fabricmc.tinyremapper.IMappingProvider;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;
import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.TargetMixin;
import net.fabricmc.tinyremapper.extension.mixin.integration.targets.Target;
import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.NonObfuscatedOverrideMixin;
import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.WildcardTargetMixin;
import net.fabricmc.tinyremapper.extension.mixin.integration.targets.NonObfuscatedOverrideTarget;
import net.fabricmc.tinyremapper.extension.mixin.integration.targets.WildcardTarget;

public class MixinIntegrationTest {
@TempDir
static Path folder;
Path folder;

@Test
public void remapWildcardName() throws IOException {
Path classpath = createJar(Target.class);
Path input = createJar(TargetMixin.class);
String remapped = remap(WildcardTarget.class, WildcardTargetMixin.class, out ->
out.acceptClass("java/lang/String", "com/example/NotString"));

// Check constructor inject did not gain a desc
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"<init>*\"}"));
// Check that wildcard desc is remapped without a name
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"*()Lcom/example/NotString;\"}"));
}

@Test
public void remapInvokeNonObfuscatedOverride() throws IOException {
String remapped = remap(NonObfuscatedOverrideTarget.class, NonObfuscatedOverrideMixin.class, out -> {
String fqn = "net/fabricmc/tinyremapper/extension/mixin/integration/targets/NonObfuscatedOverrideTarget";
out.acceptClass(fqn, "com/example/Obfuscated");
out.acceptMethod(new IMappingProvider.Member(fqn, "callAdd", "(Ljava/lang/Object;)V"), "obfuscatedCallAdd");
});

assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"obfuscatedCallAdd\""));
// Method is implemented in the target class
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/At;(value=\"INVOKE\", target=\"Lcom/example/Obfuscated;add(Ljava/lang/Object;)Z\""));
// Method is NOT implemented in the target class and instead comes from unobfuscated super class
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/At;(value=\"INVOKE\", target=\"Lcom/example/Obfuscated;addAll(Ljava/util/Collection;)Z\""));
}

private String remap(Class<?> target, Class<?> mixin, IMappingProvider mappings) throws IOException {
Path classpath = createJar(target);
Path input = createJar(mixin);
Path output = folder.resolve("output.jar");

TinyRemapper tinyRemapper = TinyRemapper.newRemapper()
.extension(new MixinExtension())
.withMappings(out -> out.acceptClass("java/lang/String", "com/example/NotString"))
.withMappings(mappings)
.build();

try (OutputConsumerPath outputConsumer = new OutputConsumerPath.Builder(output).build()) {
Expand All @@ -65,11 +93,7 @@ public void remapWildcardName() throws IOException {
tinyRemapper.apply(outputConsumer);
}

String remapped = textify(output, TargetMixin.class);
// Check constructor inject did not gain a desc
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"<init>*\"}"));
// Check that wildcard desc is remapped without a name
assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"*()Lcom/example/NotString;\"}"));
return textify(output, mixin);
}

// Create a zip file in the temp dir containing only the passed class file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2025, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.fabricmc.tinyremapper.extension.mixin.integration.mixins;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.fabricmc.tinyremapper.extension.mixin.integration.targets.NonObfuscatedOverrideTarget;

@Mixin(NonObfuscatedOverrideTarget.class)
public class NonObfuscatedOverrideMixin {
@Inject(method = "callAdd", at = @At(value = "INVOKE", target = "Lnet/fabricmc/tinyremapper/extension/mixin/integration/targets/NonObfuscatedOverrideTarget;add(Ljava/lang/Object;)Z"))
private void overridingTarget(Object add, CallbackInfo ci) {
}

@Inject(method = "callAdd", at = @At(value = "INVOKE", target = "Lnet/fabricmc/tinyremapper/extension/mixin/integration/targets/NonObfuscatedOverrideTarget;addAll(Ljava/util/Collection;)Z"))
private void superTarget(Object add, CallbackInfo ci) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.fabricmc.tinyremapper.extension.mixin.integration.targets.Target;
import net.fabricmc.tinyremapper.extension.mixin.integration.targets.WildcardTarget;

@Mixin(Target.class)
public abstract class TargetMixin {
@Mixin(WildcardTarget.class)
public abstract class WildcardTargetMixin {
@Inject(method = "<init>*", at = @At(value = "RETURN"))
private void constructorHook(final CallbackInfo ci) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2016, 2018, Player, asie
* Copyright (c) 2025, FabricMC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package net.fabricmc.tinyremapper.extension.mixin.integration.targets;

import java.util.ArrayList;

public class NonObfuscatedOverrideTarget<T> extends ArrayList<T> {
@Override
public boolean add(T t) {
return super.add(t);
}

public void callAdd(T t) {
this.add(t);
this.addAll(new ArrayList<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

package net.fabricmc.tinyremapper.extension.mixin.integration.targets;

public class Target {
public Target(String name) {
public class WildcardTarget {
public WildcardTarget(String name) {
}

public String getName() {
Expand Down