9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-06 15:52:03 +00:00

改进依赖管理

This commit is contained in:
XiaoMoMi
2025-05-22 16:02:58 +08:00
parent 454e778378
commit 29c32054f0
8 changed files with 62 additions and 86 deletions

View File

@@ -46,7 +46,6 @@ dependencies {
compileOnly("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
// Adventure
compileOnly("net.kyori:adventure-api:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("net.kyori:adventure-platform-bukkit:${rootProject.properties["adventure_platform_version"]}")
compileOnly("net.kyori:adventure-text-minimessage:${rootProject.properties["adventure_bundle_version"]}")
compileOnly("net.kyori:adventure-text-serializer-gson:${rootProject.properties["adventure_bundle_version"]}") {
exclude("com.google.code.gson", "gson")

View File

@@ -11,7 +11,6 @@ public class Dependencies {
"asm",
"org.ow2.asm",
"asm",
"asm",
Collections.emptyList()
);
@@ -19,7 +18,6 @@ public class Dependencies {
"asm-commons",
"org.ow2.asm",
"asm-commons",
"asm-commons",
Collections.emptyList()
);
@@ -27,7 +25,6 @@ public class Dependencies {
"jar-relocator",
"me.lucko",
"jar-relocator",
"jar-relocator",
Collections.emptyList()
);
@@ -35,7 +32,6 @@ public class Dependencies {
"geantyref",
"io{}leangen{}geantyref",
"geantyref",
"geantyref",
List.of(Relocation.of("geantyref", "io{}leangen{}geantyref"))
);
@@ -43,7 +39,6 @@ public class Dependencies {
"cloud-core",
"org{}incendo",
"cloud-core",
"cloud-core",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"))
);
@@ -52,7 +47,6 @@ public class Dependencies {
"cloud-brigadier",
"org{}incendo",
"cloud-brigadier",
"cloud-brigadier",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"))
);
@@ -61,7 +55,6 @@ public class Dependencies {
"cloud-services",
"org{}incendo",
"cloud-services",
"cloud-services",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"))
);
@@ -70,7 +63,6 @@ public class Dependencies {
"cloud-bukkit",
"org{}incendo",
"cloud-bukkit",
"cloud-bukkit",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"),
Relocation.of("adventure", "net{}kyori{}adventure"),
@@ -82,7 +74,6 @@ public class Dependencies {
"cloud-paper",
"org{}incendo",
"cloud-paper",
"cloud-paper",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"),
Relocation.of("adventure", "net{}kyori{}adventure"),
@@ -94,7 +85,6 @@ public class Dependencies {
"cloud-minecraft-extras",
"org{}incendo",
"cloud-minecraft-extras",
"cloud-minecraft-extras",
List.of(Relocation.of("cloud", "org{}incendo{}cloud"),
Relocation.of("geantyref", "io{}leangen{}geantyref"),
Relocation.of("adventure", "net{}kyori{}adventure"),
@@ -106,7 +96,6 @@ public class Dependencies {
"boosted-yaml",
"dev{}dejvokep",
"boosted-yaml",
"boosted-yaml",
List.of(Relocation.of("boostedyaml", "dev{}dejvokep{}boostedyaml"))
);
@@ -114,7 +103,6 @@ public class Dependencies {
"bstats-base",
"org{}bstats",
"bstats-base",
"bstats-base",
List.of(Relocation.of("bstats", "org{}bstats"))
);
@@ -122,7 +110,6 @@ public class Dependencies {
"bstats-bukkit",
"org{}bstats",
"bstats-bukkit",
"bstats-bukkit",
List.of(Relocation.of("bstats", "org{}bstats"))
) {
@Override
@@ -135,7 +122,6 @@ public class Dependencies {
"gson",
"com.google.code.gson",
"gson",
"gson",
Collections.emptyList()
);
@@ -143,7 +129,6 @@ public class Dependencies {
"caffeine",
"com{}github{}ben-manes{}caffeine",
"caffeine",
"caffeine",
List.of(Relocation.of("caffeine", "com{}github{}benmanes{}caffeine"))
);
@@ -151,7 +136,6 @@ public class Dependencies {
"zstd-jni",
"com.github.luben",
"zstd-jni",
"zstd-jni",
Collections.emptyList()
);
@@ -159,7 +143,6 @@ public class Dependencies {
"slf4j-api",
"org.slf4j",
"slf4j-api",
"slf4j-api",
Collections.emptyList()
);
@@ -167,7 +150,6 @@ public class Dependencies {
"slf4j-simple",
"org.slf4j",
"slf4j-simple",
"slf4j-simple",
Collections.emptyList()
) {
@Override
@@ -180,7 +162,6 @@ public class Dependencies {
"commons-io",
"commons-io",
"commons-io",
"commons-io",
List.of(Relocation.of("commons", "org{}apache{}commons"))
);
@@ -188,7 +169,6 @@ public class Dependencies {
"byte-buddy",
"net{}bytebuddy",
"byte-buddy",
"byte-buddy",
List.of(Relocation.of("bytebuddy", "net{}bytebuddy"))
);
@@ -196,7 +176,6 @@ public class Dependencies {
"snake-yaml",
"org{}yaml",
"snakeyaml",
"snakeyaml",
List.of(Relocation.of("snakeyaml", "org{}yaml{}snakeyaml"))
);
@@ -204,7 +183,6 @@ public class Dependencies {
"option",
"net{}kyori",
"option",
"option",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -214,7 +192,6 @@ public class Dependencies {
"adventure-api",
"net{}kyori",
"adventure-api",
"adventure-api",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -224,7 +201,6 @@ public class Dependencies {
"adventure-key",
"net{}kyori",
"adventure-key",
"adventure-key",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -239,7 +215,6 @@ public class Dependencies {
"examination-api",
"net{}kyori",
"examination-api",
"examination-api",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -249,7 +224,6 @@ public class Dependencies {
"examination-string",
"net{}kyori",
"examination-string",
"examination-string",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -264,7 +238,6 @@ public class Dependencies {
"adventure-text-minimessage",
"net{}kyori",
"adventure-text-minimessage",
"adventure-text-minimessage",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -279,7 +252,6 @@ public class Dependencies {
"adventure-text-serializer-commons",
"net{}kyori",
"adventure-text-serializer-commons",
"adventure-text-serializer-commons",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -294,7 +266,6 @@ public class Dependencies {
"adventure-text-serializer-gson",
"net{}kyori",
"adventure-text-serializer-gson",
"adventure-text-serializer-gson",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -309,7 +280,6 @@ public class Dependencies {
"adventure-text-serializer-json-legacy-impl",
"net{}kyori",
"adventure-text-serializer-json-legacy-impl",
"adventure-text-serializer-json-legacy-impl",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -324,7 +294,6 @@ public class Dependencies {
"adventure-text-serializer-legacy",
"net{}kyori",
"adventure-text-serializer-legacy",
"adventure-text-serializer-legacy",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -339,7 +308,6 @@ public class Dependencies {
"adventure-text-serializer-json",
"net{}kyori",
"adventure-text-serializer-json",
"adventure-text-serializer-json",
List.of(Relocation.of("option", "net{}kyori{}option"),
Relocation.of("examination", "net{}kyori{}examination"),
Relocation.of("adventure", "net{}kyori{}adventure"))
@@ -354,7 +322,6 @@ public class Dependencies {
"ahocorasick",
"org{}ahocorasick",
"ahocorasick",
"aho-corasick",
List.of(Relocation.of("ahocorasick", "org{}ahocorasick"))
);
@@ -362,7 +329,6 @@ public class Dependencies {
"lz4",
"org{}lz4",
"lz4-java",
"lz4-java",
List.of(Relocation.of("jpountz", "net{}jpountz"))
);
@@ -370,7 +336,6 @@ public class Dependencies {
"evalex",
"com{}ezylang",
"EvalEx",
"evalex",
List.of(Relocation.of("evalex", "com{}ezylang{}evalex"))
);
@@ -378,7 +343,6 @@ public class Dependencies {
"netty-codec-http",
"io{}netty",
"netty-codec-http",
"netty-codec-http",
Collections.emptyList()
);
@@ -386,7 +350,6 @@ public class Dependencies {
"netty-codec-http2",
"io{}netty",
"netty-codec-http2",
"netty-codec-http2",
Collections.emptyList()
);
@@ -394,7 +357,6 @@ public class Dependencies {
"reactive-streams",
"org{}reactivestreams",
"reactive-streams",
"reactive-streams",
List.of(Relocation.of("reactivestreams", "org{}reactivestreams"))
);
@@ -402,7 +364,6 @@ public class Dependencies {
"jimfs",
"com{}google{}jimfs",
"jimfs",
"jimfs",
List.of(Relocation.of("jimfs", "com{}google{}common{}jimfs"))
);
@@ -410,7 +371,6 @@ public class Dependencies {
"commons-imaging",
"org{}apache{}commons",
"commons-imaging",
"commons-imaging",
List.of(Relocation.of("imaging", "org{}apache{}commons{}imaging"))
);
@@ -418,7 +378,6 @@ public class Dependencies {
"amazon-sdk-s3",
"software{}amazon{}awssdk",
"s3",
"amazon-s3",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -429,7 +388,6 @@ public class Dependencies {
"amazon-sdk-netty-nio-client",
"software{}amazon{}awssdk",
"netty-nio-client",
"amazon-netty-nio-client",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -445,7 +403,6 @@ public class Dependencies {
"amazon-sdk-core",
"software{}amazon{}awssdk",
"sdk-core",
"amazon-sdk-core",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -461,7 +418,6 @@ public class Dependencies {
"amazon-sdk-auth",
"software{}amazon{}awssdk",
"auth",
"amazon-auth",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -477,7 +433,6 @@ public class Dependencies {
"amazon-sdk-regions",
"software{}amazon{}awssdk",
"regions",
"amazon-regions",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -493,7 +448,6 @@ public class Dependencies {
"amazon-sdk-identity-spi",
"software{}amazon{}awssdk",
"identity-spi",
"amazon-identity-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -509,7 +463,6 @@ public class Dependencies {
"amazon-sdk-http-client-spi",
"software{}amazon{}awssdk",
"http-client-spi",
"amazon-http-client-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -525,7 +478,6 @@ public class Dependencies {
"amazon-sdk-protocol-core",
"software{}amazon{}awssdk",
"protocol-core",
"amazon-protocol-core",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -541,7 +493,6 @@ public class Dependencies {
"amazon-sdk-aws-xml-protocol",
"software{}amazon{}awssdk",
"aws-xml-protocol",
"amazon-aws-xml-protocol",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -557,7 +508,6 @@ public class Dependencies {
"amazon-sdk-json-utils",
"software{}amazon{}awssdk",
"json-utils",
"amazon-json-utils",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -573,7 +523,6 @@ public class Dependencies {
"amazon-sdk-aws-core",
"software{}amazon{}awssdk",
"aws-core",
"amazon-aws-core",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -589,7 +538,6 @@ public class Dependencies {
"amazon-sdk-utils",
"software{}amazon{}awssdk",
"utils",
"amazon-utils",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -605,7 +553,6 @@ public class Dependencies {
"amazon-sdk-annotations",
"software{}amazon{}awssdk",
"annotations",
"amazon-annotations",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -621,7 +568,6 @@ public class Dependencies {
"amazon-sdk-crt-core",
"software{}amazon{}awssdk",
"crt-core",
"amazon-crt-core",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -637,7 +583,6 @@ public class Dependencies {
"amazon-sdk-checksums",
"software{}amazon{}awssdk",
"checksums",
"amazon-checksums",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -653,7 +598,6 @@ public class Dependencies {
"amazon-sdk-eventstream",
"software{}amazon{}eventstream",
"eventstream",
"amazon-eventstream",
List.of(
Relocation.of("eventstream", "software{}amazon{}eventstream"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -664,7 +608,6 @@ public class Dependencies {
"amazon-sdk-profiles",
"software{}amazon{}awssdk",
"profiles",
"amazon-profiles",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -680,7 +623,6 @@ public class Dependencies {
"amazon-sdk-retries",
"software{}amazon{}awssdk",
"retries",
"amazon-retries",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -696,7 +638,6 @@ public class Dependencies {
"amazon-sdk-endpoints-spi",
"software{}amazon{}awssdk",
"endpoints-spi",
"amazon-endpoints-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -712,7 +653,6 @@ public class Dependencies {
"amazon-sdk-arns",
"software{}amazon{}awssdk",
"arns",
"amazon-arns",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -728,7 +668,6 @@ public class Dependencies {
"amazon-sdk-aws-query-protocol",
"software{}amazon{}awssdk",
"aws-query-protocol",
"amazon-aws-query-protocol",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -744,7 +683,6 @@ public class Dependencies {
"amazon-sdk-http-auth-aws",
"software{}amazon{}awssdk",
"http-auth-aws",
"amazon-http-auth-aws",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -760,7 +698,6 @@ public class Dependencies {
"amazon-sdk-http-auth-spi",
"software{}amazon{}awssdk",
"http-auth-spi",
"amazon-http-auth-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -776,7 +713,6 @@ public class Dependencies {
"amazon-sdk-http-auth",
"software{}amazon{}awssdk",
"http-auth",
"amazon-http-auth",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -792,7 +728,6 @@ public class Dependencies {
"amazon-sdk-http-auth-aws-eventstream",
"software{}amazon{}awssdk",
"http-auth-aws-eventstream",
"amazon-http-auth-aws-eventstream",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -808,7 +743,6 @@ public class Dependencies {
"amazon-sdk-checksums-spi",
"software{}amazon{}awssdk",
"checksums-spi",
"amazon-checksums-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -824,7 +758,6 @@ public class Dependencies {
"amazon-sdk-retries-spi",
"software{}amazon{}awssdk",
"retries-spi",
"amazon-retries-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -840,7 +773,6 @@ public class Dependencies {
"amazon-sdk-metrics-spi",
"software{}amazon{}awssdk",
"metrics-spi",
"amazon-metrics-spi",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")
@@ -856,7 +788,6 @@ public class Dependencies {
"amazon-sdk-third-party-jackson-core",
"software{}amazon{}awssdk",
"third-party-jackson-core",
"amazon-third-party-jackson-core",
List.of(
Relocation.of("awssdk", "software{}amazon{}awssdk"),
Relocation.of("reactivestreams", "org{}reactivestreams")

View File

@@ -11,14 +11,12 @@ public class Dependency {
private final String id;
private final String groupId;
private final String rawArtifactId;
private final String customArtifactID;
private final List<Relocation> relocations;
public Dependency(String id, String groupId, String rawArtifactId, String customArtifactID, List<Relocation> relocations) {
public Dependency(String id, String groupId, String artifactId, List<Relocation> relocations) {
this.id = id;
this.groupId = groupId;
this.rawArtifactId = rawArtifactId;
this.customArtifactID = customArtifactID;
this.rawArtifactId = artifactId;
this.relocations = relocations;
}
@@ -34,14 +32,14 @@ public class Dependency {
return rawArtifactId;
}
public String customArtifactID() {
return customArtifactID;
}
public List<Relocation> relocations() {
return relocations;
}
public String toLocalPath() {
return rewriteEscaping(groupId).replace(".", "/") + "/" + this.rawArtifactId + "/" + getVersion();
}
private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar";
public String mavenPath() {
@@ -55,7 +53,7 @@ public class Dependency {
}
public String fileName(String classifier) {
String name = customArtifactID.toLowerCase(Locale.ENGLISH).replace('_', '-');
String name = this.rawArtifactId.toLowerCase(Locale.ENGLISH).replace('_', '-');
String extra = classifier == null || classifier.isEmpty()
? ""
: "-" + classifier;
@@ -66,7 +64,7 @@ public class Dependency {
return PluginProperties.getValue(id);
}
private static String rewriteEscaping(String s) {
public static String rewriteEscaping(String s) {
return s.replace("{}", ".");
}

View File

@@ -5,16 +5,19 @@ import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
import net.momirealms.craftengine.core.plugin.dependency.classloader.IsolatedClassLoader;
import net.momirealms.craftengine.core.plugin.dependency.relocation.Relocation;
import net.momirealms.craftengine.core.plugin.dependency.relocation.RelocationHandler;
import net.momirealms.craftengine.core.util.FileUtils;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.stream.Stream;
public class DependencyManagerImpl implements DependencyManager {
private final DependencyRegistry registry;
@@ -112,18 +115,38 @@ public class DependencyManagerImpl implements DependencyManager {
private Path downloadDependency(Dependency dependency) throws DependencyDownloadException {
String fileName = dependency.fileName(null);
Path file = this.cacheDirectory.resolve(fileName);
Path file = this.cacheDirectory.resolve(dependency.toLocalPath()).resolve(fileName);
// if the file already exists, don't attempt to re-download it.
if (Files.exists(file)) {
return file;
}
// before downloading a newer version, delete those outdated files
Path versionFolder = file.getParent().getParent();
if (Files.exists(versionFolder) && Files.isDirectory(versionFolder)) {
String version = dependency.getVersion();
try (Stream<Path> dirStream = Files.list(versionFolder)) {
dirStream.filter(Files::isDirectory)
.filter(it -> !it.getFileName().toString().equals(version))
.forEach(dir -> {
try {
FileUtils.deleteDirectory(dir);
plugin.logger().info("Cleaned up outdated dependency " + dir);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
throw new RuntimeException("Failed to clean " + versionFolder, e);
}
}
DependencyDownloadException lastError = null;
List<DependencyRepository> repository = DependencyRepository.getByID("maven");
if (!repository.isEmpty()) {
int i = 0;
while (i < repository.size()) {
try {
plugin.logger().info("Downloading dependency(" + fileName + ")[" + repository.get(i).getUrl() + dependency.mavenPath() + "]");
plugin.logger().info("Downloading dependency " + repository.get(i).getUrl() + dependency.mavenPath());
repository.get(i).download(dependency, file);
plugin.logger().info("Successfully downloaded " + fileName);
return file;
@@ -142,7 +165,7 @@ public class DependencyManagerImpl implements DependencyManager {
return normalFile;
}
Path remappedFile = this.cacheDirectory.resolve(dependency.fileName(DependencyRegistry.isGsonRelocated() ? "remapped-legacy" : "remapped"));
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)) {
@@ -159,6 +182,7 @@ public class DependencyManagerImpl implements DependencyManager {
Path cacheDirectory = plugin.dataFolderPath().resolve("libs");
try {
if (Files.exists(cacheDirectory) && (Files.isDirectory(cacheDirectory) || Files.isSymbolicLink(cacheDirectory))) {
cleanDirectoryJars(cacheDirectory);
return cacheDirectory;
}
@@ -174,6 +198,16 @@ public class DependencyManagerImpl implements DependencyManager {
return cacheDirectory;
}
private static void cleanDirectoryJars(Path directory) throws IOException {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) {
for (Path file : stream) {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".jar")) {
Files.delete(file);
}
}
}
}
@Override
public void close() {
IOException firstEx = null;

View File

@@ -82,6 +82,7 @@ public enum DependencyRepository {
public void download(Dependency dependency, Path file) throws DependencyDownloadException {
try {
Files.createDirectories(file.getParent());
Files.write(file, download(dependency));
} catch (IOException e) {
throw new DependencyDownloadException(e);

View File

@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.util;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
@@ -19,6 +20,20 @@ public class FileUtils {
Files.createDirectories(Files.exists(path) ? path.toRealPath() : path);
}
public static void deleteDirectory(Path folder) throws IOException {
if (!Files.exists(folder)) return;
try (Stream<Path> walk = Files.walk(folder)) {
walk.sorted(Comparator.reverseOrder())
.forEach(path -> {
try {
Files.delete(path);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
});
}
}
public static List<Path> getYmlConfigsDeeply(Path configFolder) {
if (!Files.exists(configFolder)) {
return List.of();

View File

@@ -1,6 +1,5 @@
package net.momirealms.craftengine.core.world;
import net.kyori.adventure.sound.Sound;
import net.momirealms.craftengine.core.block.BlockStateWrapper;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.sound.SoundData;

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.54.3
project_version=0.0.54.5
config_version=33
lang_version=13
project_group=net.momirealms
@@ -21,7 +21,6 @@ asm_version=9.8
asm_commons_version=9.8
jar_relocator_version=1.7
adventure_bundle_version=4.21.0
adventure_platform_version=4.4.0
cloud_core_version=2.0.0
cloud_services_version=2.0.0
cloud_brigadier_version=2.0.0-beta.10