mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
验证remap文件的正确性
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
package net.momirealms.craftengine.core.plugin.dependency;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class Dependencies {
|
||||
|
||||
@@ -176,7 +186,16 @@ public class Dependencies {
|
||||
"commons-imaging",
|
||||
"org{}apache{}commons",
|
||||
"commons-imaging",
|
||||
List.of(Relocation.of("commons", "org{}apache{}commons"))
|
||||
List.of(Relocation.of("commons", "org{}apache{}commons")),
|
||||
(p) -> {
|
||||
try (JarFile jarFile = new JarFile(p.toFile())) {
|
||||
ZipEntry entry = jarFile.getEntry("net/momirealms/craftengine/libraries/commons/imaging/Imaging.class");
|
||||
return entry != null;
|
||||
} catch (IOException e) {
|
||||
CraftEngine.instance().logger().warn("Error reading jar file", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public static final Dependency BYTE_BUDDY = new Dependency(
|
||||
|
||||
@@ -3,21 +3,37 @@ package net.momirealms.craftengine.core.plugin.dependency;
|
||||
import net.momirealms.craftengine.core.plugin.PluginProperties;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Dependency {
|
||||
private final String id;
|
||||
private final String groupId;
|
||||
private final String rawArtifactId;
|
||||
private final List<Relocation> relocations;
|
||||
private final Predicate<Path> verifier;
|
||||
|
||||
public Dependency(String id, String groupId, String artifactId, List<Relocation> relocations) {
|
||||
this.id = id;
|
||||
this.groupId = groupId;
|
||||
this.rawArtifactId = artifactId;
|
||||
this.relocations = relocations;
|
||||
this.verifier = (p) -> true;
|
||||
}
|
||||
|
||||
public Dependency(String id, String groupId, String artifactId, List<Relocation> relocations, Predicate<Path> verifier) {
|
||||
this.id = id;
|
||||
this.groupId = groupId;
|
||||
this.rawArtifactId = artifactId;
|
||||
this.relocations = relocations;
|
||||
this.verifier = verifier;
|
||||
}
|
||||
|
||||
public boolean verify(Path remapped) {
|
||||
return this.verifier.test(remapped);
|
||||
}
|
||||
|
||||
public String id() {
|
||||
|
||||
@@ -168,7 +168,7 @@ public class DependencyManagerImpl implements DependencyManager {
|
||||
Path remappedFile = this.cacheDirectory.resolve(dependency.toLocalPath()).resolve(dependency.fileName(DependencyRegistry.isGsonRelocated() ? "remapped-legacy" : "remapped"));
|
||||
|
||||
// if the remapped source exists already, just use that.
|
||||
if (Files.exists(remappedFile)) {
|
||||
if (Files.exists(remappedFile) && dependency.verify(remappedFile)) {
|
||||
return remappedFile;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user