mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 05:05:20 -05:00
Misc performance improvements.
This commit is contained in:
@@ -25,16 +25,20 @@
|
||||
package net.fabricmc.loom.configuration.providers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.AttributeHelper;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
|
||||
public record BundleMetadata(List<Entry> libraries, List<Entry> versions, String mainClass) {
|
||||
@@ -83,10 +87,38 @@ public record BundleMetadata(List<Entry> libraries, List<Entry> versions, String
|
||||
}
|
||||
|
||||
public record Entry(String sha1, String name, String path) {
|
||||
public void unpackEntry(Path jar, Path dest) throws IOException {
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar);
|
||||
InputStream is = Files.newInputStream(fs.get().getPath(path()))) {
|
||||
Files.copy(is, dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
public void unpackEntry(Path jar, Path dest, Project project) throws IOException {
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
|
||||
if (!extension.refreshDeps() && Files.exists(dest)) {
|
||||
final String hash = readHash(dest).orElse("");
|
||||
|
||||
if (hash.equals(sha1)) {
|
||||
// File exists with expected hash
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(jar)) {
|
||||
Files.copy(fs.get().getPath(path()), dest, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
writeHash(dest, sha1);
|
||||
}
|
||||
|
||||
private Optional<String> readHash(Path output) {
|
||||
try {
|
||||
return AttributeHelper.readAttribute(output, "LoomHash");
|
||||
} catch (IOException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeHash(Path output, String eTag) {
|
||||
try {
|
||||
AttributeHelper.writeAttribute(output, "LoomHash", eTag);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to write hash to (%s)".formatted(output), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class MinecraftLibraryProvider {
|
||||
|
||||
private void provideClientLibraries(boolean overrideLWJGL, boolean hasNativesToExtract) {
|
||||
final boolean isArm = Architecture.CURRENT.isArm();
|
||||
final boolean classpathArmNatives = !hasNativesToExtract && isArm;
|
||||
final boolean classpathArmNatives = !hasNativesToExtract && isArm && !IS_MACOS;
|
||||
|
||||
if (classpathArmNatives) {
|
||||
LoomRepositoryPlugin.forceLWJGLFromMavenCentral(project);
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class MinecraftProvider {
|
||||
throw new UnsupportedOperationException("Expected only 1 version in META-INF/versions.list, but got %d".formatted(getServerBundleMetadata().versions().size()));
|
||||
}
|
||||
|
||||
getServerBundleMetadata().versions().get(0).unpackEntry(minecraftServerJar.toPath(), getMinecraftExtractedServerJar().toPath());
|
||||
getServerBundleMetadata().versions().get(0).unpackEntry(minecraftServerJar.toPath(), getMinecraftExtractedServerJar().toPath(), project);
|
||||
}
|
||||
|
||||
public File workingDir() {
|
||||
|
||||
@@ -250,6 +250,7 @@ public class Download {
|
||||
|
||||
if (isHashValid(output)) {
|
||||
// Valid hash, no need to re-download
|
||||
writeHash(output, expectedHash);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -322,9 +323,9 @@ public class Download {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeHash(Path output, String eTag) throws DownloadException {
|
||||
private void writeHash(Path output, String value) throws DownloadException {
|
||||
try {
|
||||
AttributeHelper.writeAttribute(output, "LoomHash", eTag);
|
||||
AttributeHelper.writeAttribute(output, "LoomHash", value);
|
||||
} catch (IOException e) {
|
||||
throw error(e, "Failed to write hash to (%s)", output);
|
||||
}
|
||||
@@ -354,7 +355,7 @@ public class Download {
|
||||
|
||||
private boolean getAndResetLock(Path output) throws DownloadException {
|
||||
final Path lock = getLockFile(output);
|
||||
final boolean exists = Files.exists(lock);
|
||||
final boolean exists = exists(lock);
|
||||
|
||||
if (exists) {
|
||||
try {
|
||||
|
||||
@@ -33,16 +33,26 @@ import org.gradle.internal.logging.progress.ProgressLogger;
|
||||
import org.gradle.internal.logging.progress.ProgressLoggerFactory;
|
||||
|
||||
public class ProgressGroup implements Closeable {
|
||||
private final String name;
|
||||
private final ProgressLoggerFactory progressLoggerFactory;
|
||||
private final ProgressLogger progressGroup;
|
||||
|
||||
private ProgressLogger progressGroup;
|
||||
|
||||
public ProgressGroup(Project project, String name) {
|
||||
this.name = name;
|
||||
this.progressLoggerFactory = ((ProjectInternal) project).getServices().get(ProgressLoggerFactory.class);
|
||||
}
|
||||
|
||||
private void start() {
|
||||
this.progressGroup = this.progressLoggerFactory.newOperation(name).setDescription(name);
|
||||
this.progressGroup.started();
|
||||
}
|
||||
|
||||
public ProgressLogger createProgressLogger(String name) {
|
||||
if (progressGroup == null) {
|
||||
start();
|
||||
}
|
||||
|
||||
ProgressLogger progressLogger = this.progressLoggerFactory.newOperation(getClass(), progressGroup);
|
||||
progressLogger.setDescription(name);
|
||||
progressLogger.start(name, null);
|
||||
@@ -51,6 +61,9 @@ public class ProgressGroup implements Closeable {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.progressGroup.completed();
|
||||
if (this.progressGroup != null) {
|
||||
this.progressGroup.completed();
|
||||
this.progressGroup = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user