code cleanup

This commit is contained in:
FalsePattern committed 2022-07-31 20:41:56 +02:00
1 parent eaec528f5d
commit 316908baae
76 files changed
+691 -622

No files matched your search

@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -24,8 +24,8 @@ import com.falsepattern.lib.dependencies.DependencyLoader;
import com.falsepattern.lib.dependencies.Version;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.Internet;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.util.FileUtil;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@@ -66,11 +66,9 @@ public class DependencyLoaderImpl {
mavenRepositories.add(url);
}
public static void loadLibrary(@NonNull String loadingModId, @NonNull String groupId, @NonNull String artifactId,
@NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion,
String regularSuffix, String devSuffix) {
new DependencyLoadTask(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion, regularSuffix, devSuffix)
.load();
public static void loadLibrary(@NonNull String loadingModId, @NonNull String groupId, @NonNull String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String regularSuffix, String devSuffix) {
new DependencyLoadTask(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion,
regularSuffix, devSuffix).load();
}
private static String bytesToHex(byte[] hash) {
@@ -188,8 +186,8 @@ public class DependencyLoaderImpl {
private void setupLibraryNames() {
suffix = FalsePatternLib.isDeveloperEnvironment() ? devSuffix : regularSuffix;
artifactLogName =
String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion, suffix != null ? "-" + suffix : "");
artifactLogName = String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion,
suffix != null ? "-" + suffix : "");
log.info("Adding library {}, requested by mod {}", artifactLogName, loadingModId);
artifact = groupId + ":" + artifactId + ":" + suffix;
}
@@ -230,8 +228,8 @@ public class DependencyLoaderImpl {
}
}
val modsDir = Paths.get(homeDir, "mods").toFile();
mavenJarName = String.format("%s-%s%s.jar", artifactId, preferredVersion,
(suffix != null) ? ("-" + suffix) : "");
mavenJarName =
String.format("%s-%s%s.jar", artifactId, preferredVersion, (suffix != null) ? ("-" + suffix) : "");
jarName = groupId + "-" + mavenJarName;
libDir = new File(modsDir, "falsepattern");
if (!libDir.exists()) {
@@ -244,7 +242,9 @@ public class DependencyLoaderImpl {
}
private boolean tryLoadingExistingFile() {
if (!file.exists()) return false;
if (!file.exists()) {
return false;
}
try {
addToClasspath(file);
loadedLibraries.put(artifact, preferredVersion);
@@ -273,8 +273,8 @@ public class DependencyLoaderImpl {
if (!repo.endsWith("/")) {
repo = repo + "/";
}
val url = String.format("%s%s/%s/%s/%s", repo, groupId.replace('.', '/'), artifactId,
preferredVersion, mavenJarName);
val url = String.format("%s%s/%s/%s/%s", repo, groupId.replace('.', '/'), artifactId, preferredVersion,
mavenJarName);
String finalRepo = repo;
int retryCount = 0;
while (true) {
@@ -283,14 +283,14 @@ public class DependencyLoaderImpl {
break;
}
val success = new AtomicBoolean(false);
Internet.connect(new URL(url), (ex) -> log.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName, finalRepo, ex.getMessage()),
(input) -> {
log.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, file);
log.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
});
Internet.connect(new URL(url),
(ex) -> log.debug("Artifact {} could not be downloaded from repo {}: {}",
artifactLogName, finalRepo, ex.getMessage()), (input) -> {
log.debug("Downloading {} from {}", artifactLogName, finalRepo);
download(input, file);
log.debug("Downloaded {} from {}", artifactLogName, finalRepo);
success.set(true);
});
if (success.get()) {
log.debug("Validating checksum for {}", artifactLogName);
val hadChecksum = validateChecksum(url);
@@ -322,13 +322,13 @@ public class DependencyLoaderImpl {
log.debug("Attempting to get {} checksum...", checksumType);
val success = new AtomicBoolean(false);
Internet.connect(new URL(checksumURL),
(ex) -> log.debug("Could not get {} checksum for {}: {}", checksumType, artifactLogName, ex.getMessage()),
(input) -> {
log.debug("Downloading {} checksum for {}", checksumType, artifactLogName);
download(input, checksumFile);
log.debug("Downloaded {} checksum for {}", checksumType, artifactLogName);
success.set(true);
});
(ex) -> log.debug("Could not get {} checksum for {}: {}", checksumType,
artifactLogName, ex.getMessage()), (input) -> {
log.debug("Downloading {} checksum for {}", checksumType, artifactLogName);
download(input, checksumFile);
log.debug("Downloaded {} checksum for {}", checksumType, artifactLogName);
success.set(true);
});
if (success.get()) {
val fileHash = hash(checksumType, file);
val referenceHash = new String(Files.readAllBytes(checksumFile.toPath()));
@@ -347,7 +347,9 @@ public class DependencyLoaderImpl {
}
private enum ChecksumStatus {
OK, FAILED, MISSING
OK,
FAILED,
MISSING
}
}
}