Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev/1.7' into dev/1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 9, 2024
2 parents 5c2760d + fa8bf5e commit 351c5f7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/fabricmc/loom/task/DownloadAssetsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Objects;

import javax.inject.Inject;

Expand Down Expand Up @@ -93,8 +92,9 @@ public DownloadAssetsTask() {
getLegacyResourcesDirectory().set(new File(assetsDir, "/legacy/" + versionInfo.id()));
} else {
// pre-1.6 resources
RunConfigSettings client = Objects.requireNonNull(getExtension().getRunConfigs().findByName("client"), "Could not find client run config");
getLegacyResourcesDirectory().set(new File(getProject().getProjectDir(), client.getRunDir() + "/resources"));
RunConfigSettings client = getExtension().getRunConfigs().findByName("client");
String runDir = client != null ? client.getRunDir() : "run";
getLegacyResourcesDirectory().set(new File(getProject().getProjectDir(), runDir + "/resources"));
}

getResourcesBaseUrl().set(MirrorUtil.getResourcesBase(getProject()));
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/net/fabricmc/loom/util/ZipReprocessorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Calendar;
import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.zip.CRC32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -122,7 +123,12 @@ public static void reprocessZip(Path file, boolean reproducibleFileOrder, boolea
}

newEntry.setMethod(zipEntryCompressionMethod(zipEntryCompression));
copyZipEntry(zipOutputStream, newEntry, zipFile.getInputStream(entry));

if (zipEntryCompression == ZipEntryCompression.STORED) {
copyUncompressedZipEntry(zipOutputStream, newEntry, zipFile.getInputStream(entry));
} else {
copyZipEntry(zipOutputStream, newEntry, zipFile.getInputStream(entry));
}
}
}
}
Expand Down Expand Up @@ -176,6 +182,21 @@ private static void copyZipEntry(ZipOutputStream zipOutputStream, ZipEntry entry
zipOutputStream.closeEntry();
}

private static void copyUncompressedZipEntry(ZipOutputStream zipOutputStream, ZipEntry entry, InputStream inputStream) throws IOException {
// We need to read the entire input stream to calculate the CRC32 checksum and the size of the entry.
final byte[] data = inputStream.readAllBytes();

var crc = new CRC32();
crc.update(data);
entry.setCrc(crc.getValue());
entry.setSize(data.length);
entry.setCompressedSize(data.length);

zipOutputStream.putNextEntry(entry);
zipOutputStream.write(data, 0, data.length);
zipOutputStream.closeEntry();
}

private static void setConstantFileTime(ZipEntry entry) {
// See https://github.com/openjdk/jdk/blob/master/test/jdk/java/util/zip/ZipFile/ZipEntryTimeBounds.java
entry.setTime(new GregorianCalendar(1980, Calendar.JANUARY, 1, 0, 0, 0).getTimeInMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,32 @@ class RunConfigTest extends Specification implements GradleProjectTestTrait {
where:
version << STANDARD_TEST_VERSIONS
}
// Test that the download assets task doesnt depend on a client run existing.
@Unroll
def "cleared runs (gradle #version)"() {
setup:
def gradle = gradleProject(project: "minimalBase", version: version)
gradle.buildGradle << '''
dependencies {
minecraft "com.mojang:minecraft:1.18.1"
mappings "net.fabricmc:yarn:1.18.1+build.18:v2"
modImplementation "net.fabricmc:fabric-loader:0.12.12"
}
loom {
runs.clear()
}
'''
when:
def result = gradle.run(tasks: ["downloadAssets"])
then:
result.task(":downloadAssets").outcome == SUCCESS
where:
version << STANDARD_TEST_VERSIONS
}
}
18 changes: 18 additions & 0 deletions src/test/groovy/net/fabricmc/loom/test/unit/ZipUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.nio.file.Files
import java.time.ZoneId

import com.google.gson.JsonObject
import org.gradle.api.tasks.bundling.ZipEntryCompression
import spock.lang.Specification

import net.fabricmc.loom.util.Checksum
Expand Down Expand Up @@ -240,4 +241,21 @@ class ZipUtilsTest extends Specification {
then:
thrown FileSystemUtil.UnrecoverableZipException
}

def "reprocess uncompressed"() {
given:
// Create a reproducible input zip
def dir = Files.createTempDirectory("loom-zip-test")
def zip = Files.createTempFile("loom-zip-test", ".zip")
def fileInside = dir.resolve("text.txt")
Files.writeString(fileInside, "hello world")
ZipUtils.pack(dir, zip)

when:
ZipReprocessorUtil.reprocessZip(zip, true, false, ZipEntryCompression.STORED)

then:
ZipUtils.unpack(zip, "text.txt") == "hello world".bytes
Checksum.sha1Hex(zip) == "e699fa52a520553241aac798f72255ac0a912b05"
}
}

0 comments on commit 351c5f7

Please sign in to comment.