From 19143fc5a8e1b63f73c3cdd4e289a9025cc2543e Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 4 Jan 2022 21:40:20 +0000 Subject: [PATCH] Remove JarProcessor#isInvalid and impl getId correctly. --- .../AccessWidenerJarProcessor.java | 21 ++------------- .../TransitiveAccessWidenerJarProcessor.java | 6 ----- .../InterfaceInjectionProcessor.java | 26 ++++++------------- .../processors/JarProcessor.java | 11 ++------ .../processors/JarProcessorManager.java | 2 +- .../java/net/fabricmc/loom/util/Checksum.java | 5 ++++ 6 files changed, 18 insertions(+), 53 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java index 8b4a2fc..e1b23ea 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java @@ -30,7 +30,6 @@ import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.Arrays; import com.google.common.hash.Hashing; import org.gradle.api.Project; @@ -39,6 +38,7 @@ import net.fabricmc.accesswidener.AccessWidener; import net.fabricmc.accesswidener.AccessWidenerReader; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.configuration.processors.JarProcessor; +import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.ZipUtils; public class AccessWidenerJarProcessor implements JarProcessor { @@ -57,7 +57,7 @@ public class AccessWidenerJarProcessor implements JarProcessor { @Override public String getId() { - return "loom:access_widener"; + return "loom:access_widener:" + Checksum.toHex(inputHash); } @Override @@ -91,21 +91,4 @@ public class AccessWidenerJarProcessor implements JarProcessor { throw new UncheckedIOException("Failed to write aw jar hash", e); } } - - @Override - public boolean isInvalid(File file) { - byte[] hash; - - try { - hash = ZipUtils.unpackNullable(file.toPath(), HASH_FILENAME); - } catch (IOException e) { - return true; - } - - if (hash == null) { - return true; - } - - return !Arrays.equals(inputHash, hash); // TODO how do we know if the current jar as the correct access applied? save the hash of the input? - } } diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/TransitiveAccessWidenerJarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/TransitiveAccessWidenerJarProcessor.java index 00a1d34..65a7c5e 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/TransitiveAccessWidenerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/TransitiveAccessWidenerJarProcessor.java @@ -185,12 +185,6 @@ public class TransitiveAccessWidenerJarProcessor implements JarProcessor { } } - @Override - public boolean isInvalid(File file) { - // The hash is handled by getId() - return false; - } - private static class TransitiveDetectorVisitor implements AccessWidenerVisitor { private boolean transitive = false; diff --git a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java index 956de6e..bdf1473 100644 --- a/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/ifaceinject/InterfaceInjectionProcessor.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; @@ -38,6 +37,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import com.google.common.base.Preconditions; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; import com.google.gson.Gson; @@ -54,6 +54,7 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.RemappedConfigurationEntry; import net.fabricmc.loom.configuration.processors.JarProcessor; +import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Pair; import net.fabricmc.loom.util.TinyRemapperHelper; @@ -83,6 +84,12 @@ public class InterfaceInjectionProcessor implements JarProcessor { return injectedInterfaces.isEmpty(); } + @Override + public String getId() { + Preconditions.checkArgument(!isEmpty()); + return "loom:interface_injection:" + Checksum.toHex(inputHash); + } + @Override public void setup() { } @@ -148,23 +155,6 @@ public class InterfaceInjectionProcessor implements JarProcessor { }; } - @Override - public boolean isInvalid(File file) { - byte[] hash; - - try { - hash = ZipUtils.unpackNullable(file.toPath(), HASH_FILENAME); - } catch (IOException e) { - return true; - } - - if (hash == null) { - return true; - } - - return !Arrays.equals(inputHash, hash); - } - private List getInjectedInterfaces() { List result = new ArrayList<>(); diff --git a/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessor.java index 71f9a6b..b1cf429 100644 --- a/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessor.java @@ -33,11 +33,9 @@ public interface JarProcessor { *

If the jar processor implementation class supports creating multiple jar processors with different effects, * the needed configuration should also be included in this ID. Example: {@code path.to.MyJarProcessor#someOption}. * - * @return the ID of this jar processor + * @return the unique ID of this jar processor */ - default String getId() { - return getClass().getName(); - } + String getId(); void setup(); @@ -45,9 +43,4 @@ public interface JarProcessor { * Currently this is a destructive process that replaces the existing jar. */ void process(File file); - - /** - * Return true to make all jar processors run again, return false to use the existing results of jar processing. - */ - boolean isInvalid(File file); } diff --git a/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessorManager.java b/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessorManager.java index 580dfef..1d602c3 100644 --- a/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessorManager.java +++ b/src/main/java/net/fabricmc/loom/configuration/processors/JarProcessorManager.java @@ -83,7 +83,7 @@ public class JarProcessorManager { throw new UncheckedIOException("Could not check jar manifest of " + file, e); } - return jarProcessors.stream().anyMatch(jarProcessor -> jarProcessor.isInvalid(file)); + return false; } private String getJarProcessorHash() { diff --git a/src/main/java/net/fabricmc/loom/util/Checksum.java b/src/main/java/net/fabricmc/loom/util/Checksum.java index e3607d4..da3256a 100644 --- a/src/main/java/net/fabricmc/loom/util/Checksum.java +++ b/src/main/java/net/fabricmc/loom/util/Checksum.java @@ -30,6 +30,7 @@ import java.io.UncheckedIOException; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; +import com.google.common.io.BaseEncoding; import com.google.common.io.Files; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; @@ -70,4 +71,8 @@ public class Checksum { throw new UncheckedIOException("Failed to get file hash of " + file, e); } } + + public static String toHex(byte[] bytes) { + return BaseEncoding.base16().lowerCase().encode(bytes); + } }