Remove JarProcessor#isInvalid and impl getId correctly.
This commit is contained in:
		
							parent
							
								
									4158062ce5
								
							
						
					
					
						commit
						19143fc5a8
					
				
					 6 changed files with 18 additions and 53 deletions
				
			
		|  | @ -30,7 +30,6 @@ import java.io.UncheckedIOException; | ||||||
| import java.nio.file.Files; | import java.nio.file.Files; | ||||||
| import java.nio.file.NoSuchFileException; | import java.nio.file.NoSuchFileException; | ||||||
| import java.nio.file.Path; | import java.nio.file.Path; | ||||||
| import java.util.Arrays; |  | ||||||
| 
 | 
 | ||||||
| import com.google.common.hash.Hashing; | import com.google.common.hash.Hashing; | ||||||
| import org.gradle.api.Project; | import org.gradle.api.Project; | ||||||
|  | @ -39,6 +38,7 @@ import net.fabricmc.accesswidener.AccessWidener; | ||||||
| import net.fabricmc.accesswidener.AccessWidenerReader; | import net.fabricmc.accesswidener.AccessWidenerReader; | ||||||
| import net.fabricmc.loom.LoomGradleExtension; | import net.fabricmc.loom.LoomGradleExtension; | ||||||
| import net.fabricmc.loom.configuration.processors.JarProcessor; | import net.fabricmc.loom.configuration.processors.JarProcessor; | ||||||
|  | import net.fabricmc.loom.util.Checksum; | ||||||
| import net.fabricmc.loom.util.ZipUtils; | import net.fabricmc.loom.util.ZipUtils; | ||||||
| 
 | 
 | ||||||
| public class AccessWidenerJarProcessor implements JarProcessor { | public class AccessWidenerJarProcessor implements JarProcessor { | ||||||
|  | @ -57,7 +57,7 @@ public class AccessWidenerJarProcessor implements JarProcessor { | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public String getId() { | 	public String getId() { | ||||||
| 		return "loom:access_widener"; | 		return "loom:access_widener:" + Checksum.toHex(inputHash); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
|  | @ -91,21 +91,4 @@ public class AccessWidenerJarProcessor implements JarProcessor { | ||||||
| 			throw new UncheckedIOException("Failed to write aw jar hash", e); | 			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? |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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 static class TransitiveDetectorVisitor implements AccessWidenerVisitor { | ||||||
| 		private boolean transitive = false; | 		private boolean transitive = false; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -29,7 +29,6 @@ import java.io.IOException; | ||||||
| import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||||
| import java.nio.file.Path; | import java.nio.file.Path; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Arrays; |  | ||||||
| import java.util.Collections; | import java.util.Collections; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.LinkedHashSet; | import java.util.LinkedHashSet; | ||||||
|  | @ -38,6 +37,7 @@ import java.util.Map; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
| 
 | 
 | ||||||
|  | import com.google.common.base.Preconditions; | ||||||
| import com.google.common.hash.Hasher; | import com.google.common.hash.Hasher; | ||||||
| import com.google.common.hash.Hashing; | import com.google.common.hash.Hashing; | ||||||
| import com.google.gson.Gson; | 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.api.mappings.layered.MappingsNamespace; | ||||||
| import net.fabricmc.loom.configuration.RemappedConfigurationEntry; | import net.fabricmc.loom.configuration.RemappedConfigurationEntry; | ||||||
| import net.fabricmc.loom.configuration.processors.JarProcessor; | import net.fabricmc.loom.configuration.processors.JarProcessor; | ||||||
|  | import net.fabricmc.loom.util.Checksum; | ||||||
| import net.fabricmc.loom.util.Constants; | import net.fabricmc.loom.util.Constants; | ||||||
| import net.fabricmc.loom.util.Pair; | import net.fabricmc.loom.util.Pair; | ||||||
| import net.fabricmc.loom.util.TinyRemapperHelper; | import net.fabricmc.loom.util.TinyRemapperHelper; | ||||||
|  | @ -83,6 +84,12 @@ public class InterfaceInjectionProcessor implements JarProcessor { | ||||||
| 		return injectedInterfaces.isEmpty(); | 		return injectedInterfaces.isEmpty(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	@Override | ||||||
|  | 	public String getId() { | ||||||
|  | 		Preconditions.checkArgument(!isEmpty()); | ||||||
|  | 		return "loom:interface_injection:" + Checksum.toHex(inputHash); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void setup() { | 	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<InjectedInterface> getInjectedInterfaces() { | 	private List<InjectedInterface> getInjectedInterfaces() { | ||||||
| 		List<InjectedInterface> result = new ArrayList<>(); | 		List<InjectedInterface> result = new ArrayList<>(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -33,11 +33,9 @@ public interface JarProcessor { | ||||||
| 	 * <p>If the jar processor implementation class supports creating multiple jar processors with different effects, | 	 * <p>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}. | 	 * 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() { | 	String getId(); | ||||||
| 		return getClass().getName(); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	void setup(); | 	void setup(); | ||||||
| 
 | 
 | ||||||
|  | @ -45,9 +43,4 @@ public interface JarProcessor { | ||||||
| 	 * Currently this is a destructive process that replaces the existing jar. | 	 * Currently this is a destructive process that replaces the existing jar. | ||||||
| 	 */ | 	 */ | ||||||
| 	void process(File file); | 	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); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -83,7 +83,7 @@ public class JarProcessorManager { | ||||||
| 			throw new UncheckedIOException("Could not check jar manifest of " + file, e); | 			throw new UncheckedIOException("Could not check jar manifest of " + file, e); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		return jarProcessors.stream().anyMatch(jarProcessor -> jarProcessor.isInvalid(file)); | 		return false; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private String getJarProcessorHash() { | 	private String getJarProcessorHash() { | ||||||
|  |  | ||||||
|  | @ -30,6 +30,7 @@ import java.io.UncheckedIOException; | ||||||
| 
 | 
 | ||||||
| import com.google.common.hash.HashCode; | import com.google.common.hash.HashCode; | ||||||
| import com.google.common.hash.Hashing; | import com.google.common.hash.Hashing; | ||||||
|  | import com.google.common.io.BaseEncoding; | ||||||
| import com.google.common.io.Files; | import com.google.common.io.Files; | ||||||
| import org.gradle.api.logging.Logger; | import org.gradle.api.logging.Logger; | ||||||
| import org.gradle.api.logging.Logging; | import org.gradle.api.logging.Logging; | ||||||
|  | @ -70,4 +71,8 @@ public class Checksum { | ||||||
| 			throw new UncheckedIOException("Failed to get file hash of " + file, e); | 			throw new UncheckedIOException("Failed to get file hash of " + file, e); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	public static String toHex(byte[] bytes) { | ||||||
|  | 		return BaseEncoding.base16().lowerCase().encode(bytes); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue