Skip to content

Commit cf38057

Browse files
committed
Fix tests
1 parent 4e722c6 commit cf38057

10 files changed

Lines changed: 57 additions & 52 deletions

File tree

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/MappingsUtilsImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515

1616
@ApiStatus.Internal
1717
public class MappingsUtilsImpl {
18-
private static String sourceNamespace = "official";
19-
20-
@ApiStatus.Internal
21-
public static String getSourceNamespace() {
22-
return sourceNamespace;
23-
}
24-
2518
public static String getTargetNamespace() {
2619
return FabricLoader.getInstance().getMappingResolver().getCurrentRuntimeNamespace();
2720
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/context/MappingsRegistryInstance.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
public class MappingsRegistryInstance extends MappingsRegistry {
2323
public List<String> vanillaClassNames = new ArrayList<>();
24-
private final MemoryMappingTree formatted = new MemoryMappingTree();
25-
private final MemoryMappingTree mods, additional;
24+
private MemoryMappingTree formatted = new MemoryMappingTree();
25+
private MemoryMappingTree mods, additional;
2626
private final MemoryMappingTree full = new MemoryMappingTree();
2727

2828
private String defaultPackage = "";
@@ -33,8 +33,8 @@ public MappingsRegistryInstance() {
3333

3434
try {
3535
this.formatVanillaMappings();
36-
mods = MappingTreeHelper.createMappingTree();
37-
additional = MappingTreeHelper.createMappingTree();
36+
mods = MappingTreeHelper.createMappingTree(this.sourceNamespace, getTargetNamespace());
37+
additional = MappingTreeHelper.createMappingTree(this.sourceNamespace, getTargetNamespace());
3838
} catch (IOException e) {
3939
throw new RuntimeException(e);
4040
}
@@ -83,15 +83,15 @@ public MemoryMappingTree getFormattedMappings() {
8383
public void addToFormattedMappings(InputStream stream) throws IOException {
8484
MappingTree extra = MappingTreeHelper.readMappings(stream);
8585

86-
MappingTreeHelper.merge(formatted, extra);
86+
formatted = MappingTreeHelper.mergeIntoNew(formatted, extra);
8787
}
8888

8989
@Override
9090
public void completeFormattedMappings() throws IOException {
9191
formatted.accept(full);
9292

9393
for (MappingTree.ClassMapping classView : formatted.getClasses()) {
94-
String className = classView.getName(MappingsUtilsImpl.getSourceNamespace());
94+
String className = classView.getName(this.getSourceNamespace());
9595

9696
if (className != null) {
9797
vanillaClassNames.add("/" + className + ".class");
@@ -172,6 +172,13 @@ public String getSourceNamespace() {
172172

173173
public void setSourceNamespace(String sourceNamespace) {
174174
this.sourceNamespace = sourceNamespace;
175+
176+
try {
177+
mods = MappingTreeHelper.createMappingTree(this.sourceNamespace, getTargetNamespace());
178+
additional = MappingTreeHelper.createMappingTree(this.sourceNamespace, getTargetNamespace());
179+
} catch (IOException e) {
180+
throw new RuntimeException(e);
181+
}
175182
}
176183

177184
@Override

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/context/ModRemapperContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.impl.context;
22

33
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry;
4+
import net.fabricmc.tinyremapper.TinyRemapper;
45

56
import java.nio.file.Path;
67
import java.util.List;
@@ -14,4 +15,5 @@ public interface ModRemapperContext {
1415
void gatherRemappers();
1516
Map<String, List<String>> getMixin2TargetMap();
1617
MappingsRegistry getMappingsRegistry();
18+
void addToRemapperBuilder(TinyRemapper.Builder builder);
1719
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/context/v1/ModRemapperV1Context.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import fr.catcore.modremapperapi.utils.Constants;
44
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.MappingBuilder;
55
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.ModRemapper;
6-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.LibraryHandler;
7-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingBuilderImpl;
8-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
9-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModDiscoverer;
6+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.*;
107
import io.github.fabriccompatibiltylayers.modremappingapi.impl.compatibility.V0ModRemapper;
118
import io.github.fabriccompatibiltylayers.modremappingapi.impl.context.BaseModRemapperContext;
129
import io.github.fabriccompatibiltylayers.modremappingapi.impl.context.MappingsRegistryInstance;
1310
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry;
1411
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.ModTrRemapper;
1512
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.SoftLockFixer;
13+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.visitor.MRAApplyVisitor;
1614
import io.github.fabriccompatibiltylayers.modremappingapi.impl.utils.CacheUtils;
1715
import net.fabricmc.loader.api.FabricLoader;
1816
import net.fabricmc.tinyremapper.TinyRemapper;
@@ -82,9 +80,9 @@ public void init() {
8280
public void remapMods(Map<Path, Path> pathMap) {
8381
Constants.MAIN_LOGGER.debug("Starting jar remapping!");
8482
SoftLockFixer.preloadClasses();
85-
TinyRemapper remapper = ModTrRemapper.makeRemapper(remappers);
83+
TinyRemapper remapper = ModTrRemapper.makeRemapper(this);
8684
Constants.MAIN_LOGGER.debug("Remapper created!");
87-
ModTrRemapper.remapMods(remapper, pathMap);
85+
ModTrRemapper.remapMods(remapper, pathMap, this.mappingsRegistry);
8886
Constants.MAIN_LOGGER.debug("Jar remapping done!");
8987

9088
this.mappingsRegistry.writeFullMappings();
@@ -131,4 +129,18 @@ private void registerAdditionalMappings() {
131129
remapper.registerMappings(builder);
132130
}
133131
}
132+
133+
@Override
134+
public void addToRemapperBuilder(TinyRemapper.Builder builder) {
135+
VisitorInfosImpl preInfos = new VisitorInfosImpl();
136+
VisitorInfosImpl postInfos = new VisitorInfosImpl();
137+
138+
for (ModRemapper modRemapper : remappers) {
139+
modRemapper.registerPreVisitors(preInfos);
140+
modRemapper.registerPostVisitors(postInfos);
141+
}
142+
143+
builder.extraPreApplyVisitor(new MRAApplyVisitor(preInfos));
144+
builder.extraPostApplyVisitor(new MRAApplyVisitor(postInfos));
145+
}
134146
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/mappings/MappingTreeHelper.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings;
22

3-
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
3+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModRemappingAPIImpl;
44
import net.fabricmc.loader.api.FabricLoader;
55
import net.fabricmc.loader.impl.util.log.Log;
66
import net.fabricmc.loader.impl.util.log.LogCategory;
@@ -33,7 +33,9 @@
3333
public class MappingTreeHelper {
3434

3535
@ApiStatus.Internal
36-
public static void mergeIntoNew(VisitableMappingTree result, MappingTree left, MappingTree right) throws IOException {
36+
public static MemoryMappingTree mergeIntoNew(MappingTree left, MappingTree right) throws IOException {
37+
MemoryMappingTree result = new MemoryMappingTree();
38+
3739
if (!Objects.equals(left.getSrcNamespace(), right.getSrcNamespace())) {
3840
throw new RuntimeException("Source namespace mismatch!");
3941
}
@@ -58,6 +60,8 @@ public static void mergeIntoNew(VisitableMappingTree result, MappingTree left, M
5860

5961
reorderedLeft.accept(result, VisitOrder.createByName());
6062
reorderedRight.accept(result, VisitOrder.createByName());
63+
64+
return result;
6165
}
6266

6367
@ApiStatus.Internal
@@ -71,7 +75,7 @@ public static void merge(VisitableMappingTree main, MappingTree additional) thro
7175
List<String> dstNamespaces = new ArrayList<>(additional.getDstNamespaces());
7276
dstNamespaces.add(main.getSrcNamespace());
7377

74-
visitor = new MappingDstNsReorder(reorder, dstNamespaces);
78+
visitor = new MappingDstNsReorder(visitor, dstNamespaces);
7579
}
7680

7781
additional.accept(visitor);
@@ -122,7 +126,9 @@ public static IMappingProvider createMappingProvider(MappingTree mappings, Strin
122126

123127
@ApiStatus.Internal
124128
public static MemoryMappingTree createMappingTree() throws IOException {
125-
return createMappingTree(MappingsUtilsImpl.getSourceNamespace(), MappingsUtilsImpl.getTargetNamespace());
129+
MappingsRegistry registry = ModRemappingAPIImpl.getCurrentContext().getMappingsRegistry();
130+
131+
return createMappingTree(registry.getSourceNamespace(), registry.getTargetNamespace());
126132
}
127133

128134
@ApiStatus.Internal

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/remapper/ModTrRemapper.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.fabriccompatibiltylayers.modremappingapi.impl.MappingsUtilsImpl;
66
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModRemappingAPIImpl;
77
import io.github.fabriccompatibiltylayers.modremappingapi.impl.VisitorInfosImpl;
8+
import io.github.fabriccompatibiltylayers.modremappingapi.impl.context.ModRemapperContext;
89
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingTreeHelper;
910
import io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry;
1011
import io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.minecraft.MinecraftRemapper;
@@ -25,7 +26,7 @@
2526

2627
@ApiStatus.Internal
2728
public class ModTrRemapper {
28-
public static TinyRemapper makeRemapper(List<ModRemapper> remappers) {
29+
public static TinyRemapper makeRemapper(ModRemapperContext context) {
2930
MappingsRegistry mappingsRegistry = ModRemappingAPIImpl.getCurrentContext().getMappingsRegistry();
3031

3132
List<MappingTree> trees = Arrays.asList(
@@ -44,28 +45,13 @@ public static TinyRemapper makeRemapper(List<ModRemapper> remappers) {
4445
}
4546

4647
for (MappingTree tree : trees) {
47-
builder.withMappings(MappingTreeHelper.createMappingProvider(tree, MappingsUtilsImpl.getSourceNamespace(), MappingsUtilsImpl.getTargetNamespace()));
48+
builder.withMappings(MappingTreeHelper.createMappingProvider(tree, context.getMappingsRegistry().getSourceNamespace(), context.getMappingsRegistry().getTargetNamespace()));
4849
}
4950

50-
MRAApplyVisitor preApplyVisitor = new MRAApplyVisitor();
51-
MRAApplyVisitor postApplyVisitor = new MRAApplyVisitor();
52-
MixinPostApplyVisitor mixinPostApplyVisitor = new MixinPostApplyVisitor();
53-
54-
VisitorInfosImpl preInfos = new VisitorInfosImpl();
55-
VisitorInfosImpl postInfos = new VisitorInfosImpl();
56-
57-
for (ModRemapper modRemapper : remappers) {
58-
modRemapper.registerPreVisitors(preInfos);
59-
modRemapper.registerPostVisitors(postInfos);
60-
}
51+
context.addToRemapperBuilder(builder);
6152

62-
preApplyVisitor.setInfos(preInfos);
63-
postApplyVisitor.setInfos(postInfos);
64-
65-
builder.extraPreApplyVisitor(preApplyVisitor);
66-
builder.extraPostApplyVisitor(postApplyVisitor);
53+
MixinPostApplyVisitor mixinPostApplyVisitor = new MixinPostApplyVisitor();
6754
builder.extraPostApplyVisitor(mixinPostApplyVisitor);
68-
6955
builder.extension(new MixinExtension(EnumSet.of(MixinExtension.AnnotationTarget.HARD)));
7056

7157
TinyRemapper remapper = builder.build();
@@ -81,12 +67,12 @@ public static TinyRemapper makeRemapper(List<ModRemapper> remappers) {
8167
return remapper;
8268
}
8369

84-
public static void remapMods(TinyRemapper remapper, Map<Path, Path> paths) {
70+
public static void remapMods(TinyRemapper remapper, Map<Path, Path> paths, MappingsRegistry mappingsRegistry) {
8571
List<OutputConsumerPath> outputConsumerPaths = new ArrayList<>();
8672

8773
List<OutputConsumerPath.ResourceRemapper> resourceRemappers = new ArrayList<>(NonClassCopyMode.FIX_META_INF.remappers);
8874
resourceRemappers.add(new RefmapRemapper());
8975

90-
TrRemapperHelper.applyRemapper(remapper, paths, outputConsumerPaths, resourceRemappers, true, MappingsUtilsImpl.getSourceNamespace(), MappingsUtilsImpl.getTargetNamespace());
76+
TrRemapperHelper.applyRemapper(remapper, paths, outputConsumerPaths, resourceRemappers, true, mappingsRegistry.getSourceNamespace(), mappingsRegistry.getTargetNamespace());
9177
}
9278
}

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/remapper/SoftLockFixer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public static void preloadClasses() {
8181
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.resource.RefmapRemapper",
8282
"io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingsRegistry",
8383
"io.github.fabriccompatibiltylayers.modremappingapi.impl.mappings.MappingTreeHelper",
84-
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.MixinRemappingHelper",
8584
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.ModTrRemapper",
8685
"io.github.fabriccompatibiltylayers.modremappingapi.impl.remapper.TrRemapperHelper",
8786

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/remapper/minecraft/MinecraftRemapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private static Collection<Path> getMinecraftJar(Collection<Path> sourcePaths, St
3030
Files.createDirectories(targetFolder);
3131
}
3232

33-
Map<Path, Path> paths = CacheUtils.computeLibraryPaths(sourcePaths, target);
33+
Map<Path, Path> paths = CacheUtils.computeLibraryPaths(new HashSet<>(sourcePaths), target);
3434

3535
if (FileUtils.exist(paths.values())) return paths.values();
3636

src/main/java/io/github/fabriccompatibiltylayers/modremappingapi/impl/remapper/visitor/MRAApplyVisitor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import org.objectweb.asm.ClassVisitor;
88

99
public class MRAApplyVisitor implements TinyRemapper.ApplyVisitorProvider {
10-
private VisitorInfosImpl infos;
10+
private final VisitorInfosImpl infos;
11+
12+
public MRAApplyVisitor(VisitorInfosImpl infos) {
13+
this.infos = infos;
14+
}
1115

1216
@Override
1317
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
1418
final String className = cls.getName();
1519
return new MRAClassVisitor(next, infos, className);
1620
}
17-
18-
public void setInfos(VisitorInfosImpl infos) {
19-
this.infos = infos;
20-
}
2121
}

src/test/java/io/github/fabriccompatibiltylayers/modremappingapi/test/ModRemapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.fabriccompatibiltylayers.modremappingapi.test;
22

3-
import io.github.fabriccompatibiltylayers.modremappingapi.api.MappingUtils;
3+
import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.MappingUtils;
44
import net.fabricmc.loader.api.FabricLoader;
55
import org.junit.jupiter.api.Assertions;
66
import org.junit.jupiter.api.BeforeAll;

0 commit comments

Comments
 (0)