Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 9, 2023
1 parent 7dcec87 commit 78b01fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;

public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequirements, @Nullable InstallerData installerData, RefmapRemapType refmapRemapType) {
public record ArtifactMetadata(boolean isFabricMod, RemapRequirements remapRequirements, @Nullable InstallerData installerData, MixinRemapType mixinRemapType) {
private static final String INSTALLER_PATH = "fabric-installer.json";
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
private static final String MANIFEST_REMAP_KEY = "Fabric-Loom-Remap";
Expand All @@ -52,7 +52,7 @@ public static ArtifactMetadata create(ArtifactRef artifact) throws IOException {
boolean isFabricMod;
RemapRequirements remapRequirements = RemapRequirements.DEFAULT;
InstallerData installerData = null;
RefmapRemapType refmapRemapType = RefmapRemapType.MIXIN;
MixinRemapType refmapRemapType = MixinRemapType.MIXIN;

try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(artifact.path())) {
isFabricMod = FabricModJsonFactory.containsMod(fs);
Expand All @@ -61,17 +61,17 @@ public static ArtifactMetadata create(ArtifactRef artifact) throws IOException {
if (Files.exists(manifestPath)) {
final var manifest = new Manifest(new ByteArrayInputStream(Files.readAllBytes(manifestPath)));
final Attributes mainAttributes = manifest.getMainAttributes();
final String remapKey = mainAttributes.getValue(MANIFEST_REMAP_KEY);
final String remapValue = mainAttributes.getValue(MANIFEST_REMAP_KEY);
final String mixinRemapType = mainAttributes.getValue(MANIFEST_MIXIN_REMAP_TYPE);

if (remapKey != null) {
if (remapValue != null) {
// Support opting into and out of remapping with "Fabric-Loom-Remap" manifest entry
remapRequirements = Boolean.parseBoolean(remapKey) ? RemapRequirements.OPT_IN : RemapRequirements.OPT_OUT;
remapRequirements = Boolean.parseBoolean(remapValue) ? RemapRequirements.OPT_IN : RemapRequirements.OPT_OUT;
}

if (mixinRemapType != null) {
try {
refmapRemapType = RefmapRemapType.valueOf(mixinRemapType.toUpperCase(Locale.ROOT));
refmapRemapType = MixinRemapType.valueOf(mixinRemapType.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Unknown mixin remap type: " + mixinRemapType);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ private Predicate<ArtifactMetadata> getShouldRemap() {
}
}

public enum RefmapRemapType {
public enum MixinRemapType {
// Jar uses refmaps, so will be remapped by mixin
MIXIN,
// Jar does not use refmaps, so will be remapped by tiny-remapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void remapJars(List<ModDependency> remapList) throws IOException {

final Set<InputTag> remapMixins = new HashSet<>();
final boolean requiresStaticMixinRemap = remapList.stream()
.anyMatch(modDependency -> modDependency.getMetadata().refmapRemapType() == ArtifactMetadata.RefmapRemapType.STATIC);
.anyMatch(modDependency -> modDependency.getMetadata().mixinRemapType() == ArtifactMetadata.MixinRemapType.STATIC);

if (requiresStaticMixinRemap) {
// Configure the mixin extension to remap mixins from mod jars that were remapped with the mixin extension.
Expand Down Expand Up @@ -187,7 +187,7 @@ private void remapJars(List<ModDependency> remapList) throws IOException {

// Note: this is done at a jar level, not at the level of an individual mixin config.
// If a mod has multiple mixin configs, it's assumed that either all or none of them have refmaps.
if (info.getMetadata().refmapRemapType() == ArtifactMetadata.RefmapRemapType.STATIC) {
if (info.getMetadata().mixinRemapType() == ArtifactMetadata.MixinRemapType.STATIC) {
if (!requiresStaticMixinRemap) {
// Should be impossible but stranger things have happened.
throw new IllegalStateException("Was not configured for static remap, but a mod required it?!");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/fabricmc/loom/task/RemapJarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void run() {
// Add the mixin refmap remap type to the manifest
// This is used by the mod dependency remapper to determine if it should remap the refmap
// or if the refmap should be remapped by mixin at runtime.
final var refmapRemapType = mixinAp ? ArtifactMetadata.RefmapRemapType.MIXIN : ArtifactMetadata.RefmapRemapType.STATIC;
final var refmapRemapType = mixinAp ? ArtifactMetadata.MixinRemapType.MIXIN : ArtifactMetadata.MixinRemapType.STATIC;
params.getManifestAttributes().put(ArtifactMetadata.MANIFEST_MIXIN_REMAP_TYPE, refmapRemapType.manifestValue());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import spock.lang.Specification
import net.fabricmc.loom.configuration.mods.ArtifactMetadata
import net.fabricmc.loom.configuration.mods.ArtifactRef

import static net.fabricmc.loom.configuration.mods.ArtifactMetadata.RefmapRemapType.MIXIN
import static net.fabricmc.loom.configuration.mods.ArtifactMetadata.RefmapRemapType.STATIC
import static net.fabricmc.loom.configuration.mods.ArtifactMetadata.MixinRemapType.MIXIN
import static net.fabricmc.loom.configuration.mods.ArtifactMetadata.MixinRemapType.STATIC
import static net.fabricmc.loom.configuration.mods.ArtifactMetadata.RemapRequirements.*
import static net.fabricmc.loom.test.util.ZipTestUtils.*

Expand Down Expand Up @@ -108,7 +108,7 @@ class ArtifactMetadataTest extends Specification {
def zip = createZip(entries)
when:
def metadata = createMetadata(zip)
def result = metadata.refmapRemapType()
def result = metadata.mixinRemapType()
then:
result == type
where:
Expand Down

0 comments on commit 78b01fd

Please sign in to comment.