mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-26 17:18:29 +01:00
Add logging for downloading dependencies
This commit is contained in:
parent
312159e9ec
commit
6344503f04
@ -181,8 +181,8 @@ public abstract class AbstractDiscordSRV<
|
||||
* Method that should be called at the end of implementors constructors.
|
||||
*/
|
||||
protected final void load() {
|
||||
this.dependencyManager = new DiscordSRVDependencyManager(this, bootstrap.lifecycleManager() != null ? bootstrap.lifecycleManager().getDependencyLoader() : null);
|
||||
this.logger = new DiscordSRVLogger(this);
|
||||
this.dependencyManager = new DiscordSRVDependencyManager(this, bootstrap.lifecycleManager() != null ? bootstrap.lifecycleManager().getDependencyLoader() : null);
|
||||
this.eventBus = new EventBusImpl(this);
|
||||
this.moduleManager = new ModuleManager(this);
|
||||
this.profileManager = new ProfileManager(this);
|
||||
@ -804,7 +804,7 @@ public abstract class AbstractDiscordSRV<
|
||||
try {
|
||||
try {
|
||||
StorageType storageType = getStorageType();
|
||||
logger().info("Using " + storageType.prettyName() + " as storage");
|
||||
logger().info("Using " + storageType.prettyName() + " as storage, loading drivers...");
|
||||
if (storageType == StorageType.MEMORY) {
|
||||
logger().warning("Using memory as storage backend.");
|
||||
logger().warning("Data will not persist across server restarts.");
|
||||
@ -848,6 +848,7 @@ public abstract class AbstractDiscordSRV<
|
||||
+ "but linked-accounts.provider is set to \"minecraftauth\". Linked accounts will be disabled");
|
||||
break;
|
||||
}
|
||||
logger().info("Loading MinecraftAuth library");
|
||||
dependencyManager.mcAuthLib().downloadRelocateAndLoad().get();
|
||||
linkProvider = new MinecraftAuthenticationLinker(this);
|
||||
logger().info("Using minecraftauth.me for linked accounts");
|
||||
|
@ -61,6 +61,7 @@ public class LifecycleManager {
|
||||
resourcePaths.addAll(Arrays.asList(dependencyResources));
|
||||
|
||||
this.dependencyLoader = new DependencyLoader(
|
||||
logger,
|
||||
dataDirectory,
|
||||
taskPool,
|
||||
classpathAppender,
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of DiscordSRV, licensed under the GPLv3 License
|
||||
* Copyright (c) 2016-2024 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.common.core.dependency;
|
||||
|
||||
import com.discordsrv.common.core.logging.Logger;
|
||||
import com.discordsrv.common.core.logging.NamedLogger;
|
||||
import dev.vankka.dependencydownload.dependency.Dependency;
|
||||
|
||||
public class DependencyDownloadLogger implements dev.vankka.dependencydownload.logger.Logger {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public DependencyDownloadLogger(Logger logger) {
|
||||
this.logger = new NamedLogger(logger, "DependencyDownload");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadStart() {
|
||||
logger.info("Downloading dependencies...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadDependency(Dependency dependency) {
|
||||
logger.info("Downloading " + dependency.getGAV());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadSuccess(Dependency dependency) {
|
||||
logger.info("Downloaded " + dependency.getGAV());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void relocateStart() {
|
||||
logger.info("Relocating dependencies...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadStart() {
|
||||
logger.info("Loading dependencies...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadEnd() {
|
||||
logger.info("Loaded dependencies");
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
package com.discordsrv.common.core.dependency;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.core.logging.Logger;
|
||||
import dev.vankka.dependencydownload.DependencyManager;
|
||||
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
@ -49,14 +50,23 @@ public class DependencyLoader {
|
||||
return dataDirectory.resolve("cache");
|
||||
}
|
||||
|
||||
public static DependencyManager fromPaths(Path dataDirectory, String[] resources) throws IOException {
|
||||
DependencyManager dependencyManager = new DependencyManager(DependencyPathProvider.directory(resolvePath(dataDirectory)));
|
||||
public static DependencyDownloadResource loadResource(String resourceName) throws IOException {
|
||||
URL resource = DependencyLoader.class.getClassLoader().getResource(resourceName);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("Could not find resource with: " + resourceName);
|
||||
}
|
||||
|
||||
return DependencyDownloadResource.parse(resource);
|
||||
}
|
||||
|
||||
private static DependencyManager makeManager(Logger logger, Path dataDirectory, String[] resources) throws IOException {
|
||||
DependencyManager dependencyManager = new DependencyManager(
|
||||
DependencyPathProvider.directory(resolvePath(dataDirectory)),
|
||||
new DependencyDownloadLogger(logger)
|
||||
);
|
||||
|
||||
for (String dependencyResource : resources) {
|
||||
URL resource = DependencyLoader.class.getClassLoader().getResource(dependencyResource);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("Could not find resource with: " + dependencyResource);
|
||||
}
|
||||
dependencyManager.loadResource(DependencyDownloadResource.parse(resource));
|
||||
dependencyManager.loadResource(loadResource(dependencyResource));
|
||||
}
|
||||
|
||||
return dependencyManager;
|
||||
@ -66,13 +76,8 @@ public class DependencyLoader {
|
||||
private final Executor executor;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
|
||||
|
||||
public DependencyLoader(DiscordSRV discordSRV, String[] paths) throws IOException {
|
||||
this(discordSRV, fromPaths(discordSRV.dataDirectory(), paths));
|
||||
}
|
||||
|
||||
public DependencyLoader(Path dataDirectory, Executor executor, ClasspathAppender classpathAppender, String[] paths) throws IOException {
|
||||
this(executor, classpathAppender, fromPaths(dataDirectory, paths));
|
||||
public DependencyLoader(Logger logger, Path dataDirectory, Executor executor, ClasspathAppender classpathAppender, String[] paths) throws IOException {
|
||||
this(executor, classpathAppender, makeManager(logger, dataDirectory, paths));
|
||||
}
|
||||
|
||||
public DependencyLoader(DiscordSRV discordSRV, DependencyManager dependencyManager) {
|
||||
@ -80,9 +85,9 @@ public class DependencyLoader {
|
||||
}
|
||||
|
||||
public DependencyLoader(Executor executor, ClasspathAppender classpathAppender, DependencyManager dependencyManager) {
|
||||
this.dependencyManager = dependencyManager;
|
||||
this.executor = executor;
|
||||
this.classpathAppender = classpathAppender;
|
||||
this.dependencyManager = dependencyManager;
|
||||
}
|
||||
|
||||
public DependencyManager getDependencyManager() {
|
||||
|
@ -34,7 +34,10 @@ public class DiscordSRVDependencyManager {
|
||||
public DiscordSRVDependencyManager(DiscordSRV discordSRV, DependencyLoader initialLoader) {
|
||||
this.discordSRV = discordSRV;
|
||||
Path cacheDirectory = DependencyLoader.resolvePath(discordSRV.dataDirectory());
|
||||
this.dependencyManager = new ApplicationDependencyManager(DependencyPathProvider.directory(cacheDirectory));
|
||||
this.dependencyManager = new ApplicationDependencyManager(
|
||||
DependencyPathProvider.directory(cacheDirectory),
|
||||
new DependencyDownloadLogger(discordSRV.logger())
|
||||
);
|
||||
|
||||
if (initialLoader != null) {
|
||||
dependencyManager.include(initialLoader.getDependencyManager());
|
||||
@ -42,31 +45,31 @@ public class DiscordSRVDependencyManager {
|
||||
}
|
||||
|
||||
private DependencyLoader loader(DependencyManager manager) {
|
||||
return new DependencyLoader(discordSRV, dependencyManager.include(manager));
|
||||
return new DependencyLoader(discordSRV, manager);
|
||||
}
|
||||
|
||||
private DependencyLoader loader(String[] paths) throws IOException {
|
||||
return loader(DependencyLoader.fromPaths(discordSRV.dataDirectory(), paths));
|
||||
private DependencyLoader loader(String resourceName) throws IOException {
|
||||
return loader(dependencyManager.includeResource(DependencyLoader.loadResource(resourceName)));
|
||||
}
|
||||
|
||||
public DependencyLoader hikari() throws IOException {
|
||||
return loader(new String[] {"dependencies/hikari.txt"});
|
||||
return loader("dependencies/hikari.txt");
|
||||
}
|
||||
|
||||
public DependencyLoader h2() throws IOException {
|
||||
return loader(new String[] {"dependencies/h2Driver.txt"});
|
||||
return loader("dependencies/h2Driver.txt");
|
||||
}
|
||||
|
||||
public DependencyLoader mysql() throws IOException {
|
||||
return loader(new String[] {"dependencies/mysqlDriver.txt"});
|
||||
return loader("dependencies/mysqlDriver.txt");
|
||||
}
|
||||
|
||||
public DependencyLoader mariadb() throws IOException {
|
||||
return loader(new String[] {"dependencies/mariadbDriver.txt"});
|
||||
return loader("dependencies/mariadbDriver.txt");
|
||||
}
|
||||
|
||||
public DependencyLoader mcAuthLib() throws IOException {
|
||||
return loader(new String[] {"dependencies/mcAuthLib.txt"});
|
||||
return loader("dependencies/mcAuthLib.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,16 +25,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NamedLogger implements Logger {
|
||||
|
||||
private final DiscordSRV discordSRV;
|
||||
private final Logger logger;
|
||||
private final String name;
|
||||
|
||||
public NamedLogger(DiscordSRV discordSRV, String name) {
|
||||
this.discordSRV = discordSRV;
|
||||
this(discordSRV.logger(), name);
|
||||
}
|
||||
|
||||
public NamedLogger(Logger logger, String name) {
|
||||
this.logger = logger;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(@Nullable String loggerName, @NotNull LogLevel logLevel, @Nullable String message, @Nullable Throwable throwable) {
|
||||
discordSRV.logger().log(name, logLevel, message, throwable);
|
||||
logger.log(name, logLevel, message, throwable);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user