Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plan/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ subprojects {
slf4jVersion = "2.0.17"
geoIpVersion = "4.3.1"
gsonVersion = "2.13.1"
dependencyDownloadVersion = "1.3.1"
dependencyDownloadVersion = "2.0.0"
ipAddressMatcherVersion = "5.5.1"
jasyptVersion = "1.9.3"

Expand Down
2 changes: 1 addition & 1 deletion Plan/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
implementation "net.playeranalytics:platform-abstraction-layer-api:$palVersion"

compileOnly "net.kyori:adventure-api:$adventureVersion"
implementation("dev.vankka:dependencydownload-runtime:$dependencyDownloadVersion") {
api("dev.vankka:dependencydownload-runtime:$dependencyDownloadVersion") {
// Effectively disables relocating
exclude module: "jar-relocator"
}
Expand Down
11 changes: 11 additions & 0 deletions Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import com.djrapitops.plan.utilities.logging.ErrorContext;
import com.djrapitops.plan.utilities.logging.ErrorLogger;
import com.djrapitops.plan.version.VersionChecker;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import net.playeranalytics.plugin.server.PluginLogger;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.IOException;

/**
* PlanSystem contains everything Plan needs to run.
Expand Down Expand Up @@ -74,6 +76,7 @@ public class PlanSystem implements SubSystem {
private final ApiServices apiServices;
private final PluginLogger logger;
private final ErrorLogger errorLogger;
private final ApplicationDependencyManager applicationDependencyManager;

@Inject
public PlanSystem(
Expand All @@ -93,6 +96,7 @@ public PlanSystem(
DeliveryUtilities deliveryUtilities,
PluginLogger logger,
ErrorLogger errorLogger,
ApplicationDependencyManager applicationDependencyManager,
ApiServices apiServices, // API v5
@SuppressWarnings("deprecation") PlanAPI.PlanAPIHolder apiHolder, GatheringUtilities gatheringUtilities // Deprecated PlanAPI, backwards compatibility
) {
Expand All @@ -113,6 +117,7 @@ public PlanSystem(
this.gatheringUtilities = gatheringUtilities;
this.logger = logger;
this.errorLogger = errorLogger;
this.applicationDependencyManager = applicationDependencyManager;
this.apiServices = apiServices;

logger.info("§2");
Expand Down Expand Up @@ -192,6 +197,12 @@ public void disable() {

apiServices.disableExtensionDataUpdates();

try {
applicationDependencyManager.cleanupCacheDirectory();
} catch (IOException e) {
logger.warn("Failed to cleanup dependency cache directory", e);
}

Comment on lines +200 to +205

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I placed this in disable, as to avoid accidentally cleaning any dependencies that are loaded "late". As ApplicationDependencyManager will only know to keep files for dependencies that are included in it

disableSystems(
taskSystem,
cacheSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.djrapitops.plan.exceptions.LibraryLoadingException;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.utilities.dev.Untrusted;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import dev.vankka.dependencydownload.DependencyManager;
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
import dev.vankka.dependencydownload.repository.StandardRepository;
import dev.vankka.dependencydownload.repository.MavenRepository;
import dev.vankka.dependencydownload.resource.DependencyDownloadResource;
import net.playeranalytics.plugin.server.PluginLogger;

import javax.inject.Inject;
Expand All @@ -45,14 +47,21 @@ public class IpAllowListMatcher {
private final PluginLogger logger;
private final PlanFiles files;
private final AddressAllowList addressAllowList;
protected final ApplicationDependencyManager applicationDependencyManager;
private final AtomicBoolean failedDownload = new AtomicBoolean(false);
private ClassLoader libraryClassLoader;

@Inject
public IpAllowListMatcher(PluginLogger logger, PlanFiles files, AddressAllowList addressAllowList) {
public IpAllowListMatcher(
PluginLogger logger,
PlanFiles files,
AddressAllowList addressAllowList,
ApplicationDependencyManager applicationDependencyManager
) {
this.logger = logger;
this.files = files;
this.addressAllowList = addressAllowList;
this.applicationDependencyManager = applicationDependencyManager;
}

public synchronized void prepare() {
Expand All @@ -69,18 +78,26 @@ public synchronized void prepare() {
private void downloadLibrary() throws ExecutionException {
if (DOWNLOAD_LIBRARY) {
logger.info("Downloading IP Address parsing library for Allowlist checking, this may take a while...");
DependencyManager dependencyManager = new DependencyManager(files.getDataDirectory().resolve("libraries"));
dependencyManager.loadFromResource(getDependencyResource());
DependencyManager dependencyManager = new DependencyManager(
applicationDependencyManager.getDependencyPathProvider(),
applicationDependencyManager.getLogger()
);
dependencyManager.loadResource(DependencyDownloadResource.parse(getDependencyResource()));

try {
dependencyManager.downloadAll(null, List.of(
new StandardRepository("https://repo1.maven.org/maven2")
new MavenRepository("https://repo1.maven.org/maven2")
)).get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}

IsolatedClassLoader classLoader = new IsolatedClassLoader();
dependencyManager.load(null, classLoader);

// Include this dependency manager in the application dependency manager for library cleaning purposes
applicationDependencyManager.include(dependencyManager);

this.libraryClassLoader = classLoader;
} else {
libraryClassLoader = getClass().getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import dev.vankka.dependencydownload.path.DependencyPathProvider;
import net.playeranalytics.plugin.PluginInformation;

import javax.inject.Named;
import javax.inject.Singleton;
import java.io.File;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
Expand Down Expand Up @@ -123,4 +126,11 @@ JSONStorage provideJSONStorage(
return new JSONMemoryStorageShim(config, jsonFileStorage);
}

@Provides
@Singleton
ApplicationDependencyManager applicationDependencyManager(@Named("dataFolder") File dataFolder) {
Path librariesDirectory = dataFolder.toPath().resolve("libraries");
return new ApplicationDependencyManager(DependencyPathProvider.directory(librariesDirectory));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.HikariPool;
import dagger.Lazy;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.server.PluginLogger;

Expand Down Expand Up @@ -65,9 +66,19 @@ public MySQLDB(
Lazy<ServerInfo> serverInfo,
RunnableFactory runnableFactory,
PluginLogger pluginLogger,
ErrorLogger errorLogger
ErrorLogger errorLogger,
ApplicationDependencyManager applicationDependencyManager
) {
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, pluginLogger, errorLogger);
super(
() -> serverInfo.get().getServerUUID(),
locale,
config,
files,
runnableFactory,
pluginLogger,
errorLogger,
applicationDependencyManager
);
}

private static synchronized void increment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import com.djrapitops.plan.utilities.java.ThrowableUtils;
import com.djrapitops.plan.utilities.logging.ErrorContext;
import com.djrapitops.plan.utilities.logging.ErrorLogger;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import dev.vankka.dependencydownload.DependencyManager;
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
import dev.vankka.dependencydownload.repository.MavenRepository;
import dev.vankka.dependencydownload.repository.Repository;
import dev.vankka.dependencydownload.repository.StandardRepository;
import dev.vankka.dependencydownload.resource.DependencyDownloadResource;
import net.playeranalytics.plugin.scheduling.PluginRunnable;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.scheduling.TimeAmount;
Expand All @@ -67,8 +69,8 @@ public abstract class SQLDB extends AbstractDatabase {
private static boolean downloadDriver = true;

private static final List<Repository> DRIVER_REPOSITORIES = Arrays.asList(
new StandardRepository("https://repo.papermc.io/repository/maven-public"),
new StandardRepository("https://repo1.maven.org/maven2")
new MavenRepository("https://repo.papermc.io/repository/maven-public"),
new MavenRepository("https://repo1.maven.org/maven2")
);

private final Supplier<ServerUUID> serverUUIDSupplier;
Expand All @@ -79,6 +81,7 @@ public abstract class SQLDB extends AbstractDatabase {
protected final RunnableFactory runnableFactory;
protected final PluginLogger logger;
protected final ErrorLogger errorLogger;
protected final ApplicationDependencyManager applicationDependencyManager;

protected ClassLoader driverClassLoader;

Expand All @@ -97,7 +100,8 @@ protected SQLDB(
PlanFiles files,
RunnableFactory runnableFactory,
PluginLogger logger,
ErrorLogger errorLogger
ErrorLogger errorLogger,
ApplicationDependencyManager applicationDependencyManager
) {
this.serverUUIDSupplier = serverUUIDSupplier;
this.locale = locale;
Expand All @@ -106,6 +110,7 @@ protected SQLDB(
this.runnableFactory = runnableFactory;
this.logger = logger;
this.errorLogger = errorLogger;
this.applicationDependencyManager = applicationDependencyManager;

this.transactionExecutorServiceProvider = () -> {
String nameFormat = "Plan " + getClass().getSimpleName() + "-transaction-thread-%d";
Expand All @@ -129,8 +134,12 @@ public static void setDownloadDriver(boolean downloadDriver) {

public void downloadDriver() {
if (downloadDriver) {
DependencyManager dependencyManager = new DependencyManager(files.getDataDirectory().resolve("libraries"));
dependencyManager.loadFromResource(getDependencyResource());
DependencyManager dependencyManager = new DependencyManager(
applicationDependencyManager.getDependencyPathProvider(),
applicationDependencyManager.getLogger()
);
dependencyManager.loadResource(DependencyDownloadResource.parse(getDependencyResource()));

try {
dependencyManager.downloadAll(null, DRIVER_REPOSITORIES).get();
} catch (InterruptedException e) {
Expand All @@ -141,6 +150,10 @@ public void downloadDriver() {

IsolatedClassLoader classLoader = new IsolatedClassLoader();
dependencyManager.load(null, classLoader);

// Include this dependency manager in the application dependency manager for library cleaning purposes
applicationDependencyManager.include(dependencyManager);

this.driverClassLoader = classLoader;
} else {
this.driverClassLoader = getClass().getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.djrapitops.plan.utilities.SemaphoreAccessCounter;
import com.djrapitops.plan.utilities.logging.ErrorLogger;
import dagger.Lazy;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.scheduling.Task;
import net.playeranalytics.plugin.server.PluginLogger;
Expand Down Expand Up @@ -70,9 +71,19 @@ private SQLiteDB(
Lazy<ServerInfo> serverInfo,
RunnableFactory runnableFactory,
PluginLogger logger,
ErrorLogger errorLogger
ErrorLogger errorLogger,
ApplicationDependencyManager applicationDependencyManager
) {
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, logger, errorLogger);
super(
() -> serverInfo.get().getServerUUID(),
locale,
config,
files,
runnableFactory,
logger,
errorLogger,
applicationDependencyManager
);
dbName = databaseFile.getName();
this.databaseFile = databaseFile;
connectionLock = new SemaphoreAccessCounter();
Expand Down Expand Up @@ -240,6 +251,7 @@ public static class Factory {
private final PluginLogger logger;
private final ErrorLogger errorLogger1;
private final PlanFiles files;
private final ApplicationDependencyManager applicationDependencyManager;

@Inject
public Factory(
Expand All @@ -249,7 +261,8 @@ public Factory(
Lazy<ServerInfo> serverInfo,
RunnableFactory runnableFactory,
PluginLogger logger,
ErrorLogger errorLogger1
ErrorLogger errorLogger1,
ApplicationDependencyManager applicationDependencyManager
) {
this.locale = locale;
this.config = config;
Expand All @@ -258,6 +271,7 @@ public Factory(
this.runnableFactory = runnableFactory;
this.logger = logger;
this.errorLogger1 = errorLogger1;
this.applicationDependencyManager = applicationDependencyManager;
}

public SQLiteDB usingDefaultFile() {
Expand All @@ -271,7 +285,8 @@ public SQLiteDB usingFileCalled(String fileName) {
public SQLiteDB usingFile(File databaseFile) {
return new SQLiteDB(databaseFile,
locale, config, files, serverInfo,
runnableFactory, logger, errorLogger1
runnableFactory, logger, errorLogger1,
applicationDependencyManager
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.google.gson.Gson;
import dagger.Module;
import dagger.Provides;
import dev.vankka.dependencydownload.ApplicationDependencyManager;
import dev.vankka.dependencydownload.path.DependencyPathProvider;
import utilities.TestErrorLogger;
import utilities.TestResources;

Expand Down Expand Up @@ -93,4 +95,10 @@ File provideDataFolder(@Named("tempDir") Path tempDir) {
ErrorLogger provideErrorLogger() {
return new TestErrorLogger();
}

@Provides
@Singleton
ApplicationDependencyManager applicationDependencyManager(@Named("dataFolder") File dataFolder) {
return new ApplicationDependencyManager(DependencyPathProvider.directory(dataFolder.toPath()));
}
}