diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ba6f51fe..0954f3f8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ lorenz-tiny = "4.0.2" mercury = "0.4.3.18" mercury-mixin = "0.2.2" loom-native = "0.2.0" -unpick = "3.0.0-beta.9" +unpick = "3.0.0-beta.13" # Plugins spotless = "7.2.1" diff --git a/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java b/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java index 585cb63c..8120e377 100644 --- a/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/AbstractRemapJarTask.java @@ -158,7 +158,7 @@ public abstract class AbstractRemapJarTask extends Jar { final WorkQueue workQueue = getWorkerExecutor().noIsolation(); workQueue.submit(workAction, params -> { - params.getMainInputFile().set(getInputFile()); + params.getInputFile().set(getInputFile()); params.getArchiveFile().set(getArchiveFile()); params.getSourceNamespace().set(getSourceNamespace()); @@ -199,7 +199,7 @@ public abstract class AbstractRemapJarTask extends Jar { protected abstract Provider getClientOnlyEntriesOptionsProvider(SourceSet clientSourceSet); public interface AbstractRemapParams extends WorkParameters { - RegularFileProperty getMainInputFile(); + RegularFileProperty getInputFile(); RegularFileProperty getArchiveFile(); Property getSourceNamespace(); @@ -263,24 +263,26 @@ public abstract class AbstractRemapJarTask extends Jar { } } + // Note: the inputFile parameter is the remapping input file. + // The main input jar is available in the parameters, but should not be used + // for remapping as it might be missing some files added manually to this task. protected abstract void execute(Path inputFile) throws IOException; protected void modifyJarManifest() throws IOException { int count = ZipUtils.transform(outputFile, Map.of(Constants.Manifest.PATH, bytes -> { var manifest = new Manifest(new ByteArrayInputStream(bytes)); - - if (!getParameters().getPlatform().get().isForgeLike()) { - getParameters().getJarManifestService().get().apply(manifest, getParameters().getManifestAttributes().get()); - manifest.getMainAttributes().putValue(Constants.Manifest.MAPPING_NAMESPACE, getParameters().getTargetNamespace().get()); - } - - byte[] sourceManifestBytes = ZipUtils.unpackNullable(getParameters().getMainInputFile().get().getAsFile().toPath(), Constants.Manifest.PATH); + byte[] sourceManifestBytes = ZipUtils.unpackNullable(getParameters().getInputFile().get().getAsFile().toPath(), Constants.Manifest.PATH); if (sourceManifestBytes != null) { var sourceManifest = new Manifest(new ByteArrayInputStream(sourceManifestBytes)); mergeManifests(manifest, sourceManifest); } + if (!getParameters().getPlatform().get().isForgeLike()) { + getParameters().getJarManifestService().get().apply(manifest, getParameters().getManifestAttributes().get()); + manifest.getMainAttributes().putValue(Constants.Manifest.MAPPING_NAMESPACE, getParameters().getTargetNamespace().get()); + } + ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); return out.toByteArray(); diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/RemapJarContentsTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/RemapJarContentsTest.groovy index fdf556b5..85bb2e46 100644 --- a/src/test/groovy/net/fabricmc/loom/test/integration/RemapJarContentsTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/integration/RemapJarContentsTest.groovy @@ -51,6 +51,10 @@ class RemapJarContentsTest extends Specification implements GradleProjectTestTra ZipUtils.contains(gradle.getOutputFile('fabric-example-mod-1.0.0-sources.jar').toPath(), 'test_src_file.txt') def manifest = readManifest(gradle.getOutputFile('fabric-example-mod-1.0.0.jar')) manifest.mainAttributes.getValue('Hello-World') == 'test' + manifest.mainAttributes.getValue('Inherited-In-Remap-Jar') == '1234' + manifest.getAttributes('fabric.mod.json').getValue('Inherited-In-Remap-Jar') == '5678' + manifest.getAttributes('modid.mixins.json').getValue('Hello-World') == 'another test' + manifest.getAttributes('modid.mixins.json').getValue('Inherited-In-Remap-Jar') == '9' where: version << STANDARD_TEST_VERSIONS diff --git a/src/test/resources/projects/remapJarContents/build.gradle b/src/test/resources/projects/remapJarContents/build.gradle index b8b56edf..d7a60cc0 100644 --- a/src/test/resources/projects/remapJarContents/build.gradle +++ b/src/test/resources/projects/remapJarContents/build.gradle @@ -78,11 +78,21 @@ publishing { } } +jar { + manifest { + attributes 'Inherited-In-Remap-Jar': '1234' + attributes(['Inherited-In-Remap-Jar': '5678'], 'fabric.mod.json') // category not present in remapJar + attributes(['Inherited-In-Remap-Jar': '9'], 'modid.mixins.json') // category present in remapJar + attributes 'Hello-World': 'shadowed in remapJar' + } +} + remapJar { from 'test_file.txt' manifest { attributes 'Hello-World': 'test' + attributes(['Hello-World': 'another test'], 'modid.mixins.json') } }