mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 01:27:42 +01:00
parent
e4999ba072
commit
efd3b75a29
@ -8,7 +8,6 @@ buildscript {
|
||||
|
||||
plugins {
|
||||
id "com.github.johnrengelman.shadow" version "7.1.0" apply false
|
||||
// id "io.github.slimjar" version "1.3.0" apply false
|
||||
id "java"
|
||||
id "jacoco"
|
||||
id "checkstyle"
|
||||
@ -49,7 +48,6 @@ logger.lifecycle("Building artifact for version $fullVersion")
|
||||
subprojects {
|
||||
// Build plugins
|
||||
apply plugin: "com.github.johnrengelman.shadow"
|
||||
// apply plugin: "io.github.slimjar"
|
||||
apply plugin: "java"
|
||||
apply plugin: "maven-publish"
|
||||
|
||||
@ -104,7 +102,6 @@ subprojects {
|
||||
|
||||
dependencies {
|
||||
// Dependency Injection used across the project
|
||||
// implementation "io.github.slimjar:slimjar:1.2.6" // Runtime dependency injection
|
||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
||||
testAnnotationProcessor "com.google.dagger:dagger-compiler:$daggerCompilerVersion"
|
||||
|
@ -61,22 +61,6 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
||||
abstractionLayer = new BukkitPlatformLayer(this);
|
||||
pluginLogger = abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// getLogger().log(Level.INFO, "Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.appending("Plan")
|
||||
// .logger((message, args) -> getLogger().log(Level.INFO, message, args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
||||
// getLogger().log(Level.SEVERE, "Plan failed to load its dependencies correctly!");
|
||||
// getLogger().log(Level.SEVERE, "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -230,4 +214,4 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
||||
public PlanSystem getSystem() {
|
||||
return system;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,22 +52,6 @@ public class PlanBungee extends Plugin implements PlanPlugin {
|
||||
abstractionLayer = new BungeePlatformLayer(this);
|
||||
logger = abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// getLogger().log(Level.INFO, "Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.appending("Plan")
|
||||
// .logger((message, args) -> getLogger().log(Level.INFO, message, args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
||||
// getLogger().log(Level.SEVERE, "Plan failed to load its dependencies correctly!");
|
||||
// getLogger().log(Level.SEVERE, "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,3 +1,32 @@
|
||||
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
|
||||
|
||||
plugins {
|
||||
id "dev.vankka.dependencydownload.plugin" version "1.1.4"
|
||||
}
|
||||
|
||||
configurations {
|
||||
mysqlDriver
|
||||
sqliteDriver
|
||||
testImplementation.extendsFrom mysqlDriver, sqliteDriver
|
||||
compileOnly.extendsFrom mysqlDriver, sqliteDriver
|
||||
}
|
||||
|
||||
task generateResourceForMySQLDriver(type: GenerateDependencyDownloadResourceTask) {
|
||||
var conf = configurations.mysqlDriver
|
||||
configuration = conf
|
||||
file = "assets/plan/dependencies/" + conf.name + ".txt"
|
||||
// Not necessary to include in the resource
|
||||
includeShadowJarRelocations = false
|
||||
}
|
||||
|
||||
task generateResourceForSQLiteDriver(type: GenerateDependencyDownloadResourceTask) {
|
||||
var conf = configurations.sqliteDriver
|
||||
configuration = conf
|
||||
file = "assets/plan/dependencies/" + conf.name + ".txt"
|
||||
// Not necessary to include in the resource
|
||||
includeShadowJarRelocations = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "net.playeranalytics:platform-abstraction-layer-api:$palVersion"
|
||||
implementation project(":api")
|
||||
@ -6,14 +35,18 @@ dependencies {
|
||||
implementation "org.apache.commons:commons-text:$commonsTextVersion"
|
||||
implementation "org.apache.commons:commons-compress:$commonsCompressVersion"
|
||||
implementation "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
|
||||
implementation "mysql:mysql-connector-java:$mysqlVersion"
|
||||
implementation "org.xerial:sqlite-jdbc:$sqliteVersion"
|
||||
implementation "com.zaxxer:HikariCP:$hikariVersion"
|
||||
implementation "org.slf4j:slf4j-nop:$slf4jVersion"
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "com.maxmind.geoip2:geoip2:$geoIpVersion"
|
||||
implementation "com.google.code.gson:gson:$gsonVersion"
|
||||
// implementation slimjar("1.2.5")
|
||||
|
||||
implementation("dev.vankka.dependencydownload:runtime:1.1.4") {
|
||||
// Effectively disables relocating
|
||||
exclude module: "jar-relocator"
|
||||
}
|
||||
mysqlDriver "mysql:mysql-connector-java:$mysqlVersion"
|
||||
sqliteDriver "org.xerial:sqlite-jdbc:$sqliteVersion"
|
||||
|
||||
testImplementation project(":api")
|
||||
testImplementation "com.google.code.gson:gson:$gsonVersion"
|
||||
@ -55,7 +88,7 @@ task determineWebAssetModifications {
|
||||
}
|
||||
|
||||
processResources {
|
||||
dependsOn determineWebAssetModifications
|
||||
dependsOn determineWebAssetModifications, generateResourceForMySQLDriver, generateResourceForSQLiteDriver
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
dependsOn updateVersion
|
||||
from 'build/sources/resources'
|
||||
@ -96,4 +129,4 @@ shadowJar {
|
||||
exclude "org/jayway/**/*"
|
||||
exclude "google/protobuf/**/*"
|
||||
exclude "jargs/gnu/**/*"
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.DatabaseSettings;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
@ -34,11 +35,13 @@ import net.playeranalytics.plugin.server.PluginLogger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -56,12 +59,13 @@ public class MySQLDB extends SQLDB {
|
||||
public MySQLDB(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
PlanFiles files,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger pluginLogger,
|
||||
ErrorLogger errorLogger
|
||||
) {
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, pluginLogger, errorLogger);
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, pluginLogger, errorLogger);
|
||||
}
|
||||
|
||||
private static synchronized void increment() {
|
||||
@ -73,11 +77,12 @@ public class MySQLDB extends SQLDB {
|
||||
return DBType.MYSQL;
|
||||
}
|
||||
|
||||
private void loadMySQLDriver() {
|
||||
@Override
|
||||
protected List<String> getDependencyResource() {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
errorLogger.critical(e, ErrorContext.builder().whatToDo("Install MySQL Driver to the server").build());
|
||||
return files.getResourceFromJar("dependencies/mysqlDriver.txt").asLines();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to get MySQL dependency information", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,9 +91,18 @@ public class MySQLDB extends SQLDB {
|
||||
*/
|
||||
@Override
|
||||
public void setupDataSource() {
|
||||
try {
|
||||
loadMySQLDriver();
|
||||
if (driverClassLoader == null) {
|
||||
logger.info("Downloading MySQL Driver, this may take a while...");
|
||||
downloadDriver();
|
||||
}
|
||||
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
||||
|
||||
// Set the context class loader to the driver class loader for Hikari to use for finding the Driver
|
||||
currentThread.setContextClassLoader(driverClassLoader);
|
||||
|
||||
try {
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
|
||||
String host = config.get(DatabaseSettings.MYSQL_HOST);
|
||||
@ -129,6 +143,9 @@ public class MySQLDB extends SQLDB {
|
||||
} finally {
|
||||
unloadMySQLDriver();
|
||||
}
|
||||
|
||||
// Reset the context classloader back to what it was originally set to, now that the DataSource is created
|
||||
currentThread.setContextClassLoader(previousClassLoader);
|
||||
}
|
||||
|
||||
private void unloadMySQLDriver() {
|
||||
|
@ -32,9 +32,14 @@ import com.djrapitops.plan.storage.database.transactions.init.CreateTablesTransa
|
||||
import com.djrapitops.plan.storage.database.transactions.init.OperationCriticalTransaction;
|
||||
import com.djrapitops.plan.storage.database.transactions.init.RemoveIncorrectTebexPackageDataPatch;
|
||||
import com.djrapitops.plan.storage.database.transactions.patches.*;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
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.DependencyManager;
|
||||
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||
import dev.vankka.dependencydownload.repository.Repository;
|
||||
import dev.vankka.dependencydownload.repository.StandardRepository;
|
||||
import net.playeranalytics.plugin.scheduling.PluginRunnable;
|
||||
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
||||
import net.playeranalytics.plugin.scheduling.TimeAmount;
|
||||
@ -43,10 +48,7 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@ -58,14 +60,22 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class SQLDB extends AbstractDatabase {
|
||||
|
||||
private static final List<Repository> DRIVER_REPOSITORIES = Arrays.asList(
|
||||
new StandardRepository("https://papermc.io/repo/repository/maven-public/"),
|
||||
new StandardRepository("https://repo1.maven.org/maven2/")
|
||||
);
|
||||
|
||||
private final Supplier<ServerUUID> serverUUIDSupplier;
|
||||
|
||||
protected final Locale locale;
|
||||
protected final PlanConfig config;
|
||||
protected final PlanFiles files;
|
||||
protected final RunnableFactory runnableFactory;
|
||||
protected final PluginLogger logger;
|
||||
protected final ErrorLogger errorLogger;
|
||||
|
||||
protected IsolatedClassLoader driverClassLoader;
|
||||
|
||||
private Supplier<ExecutorService> transactionExecutorServiceProvider;
|
||||
private ExecutorService transactionExecutor;
|
||||
|
||||
@ -73,6 +83,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
Supplier<ServerUUID> serverUUIDSupplier,
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
PlanFiles files,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger logger,
|
||||
ErrorLogger errorLogger
|
||||
@ -80,6 +91,7 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
this.serverUUIDSupplier = serverUUIDSupplier;
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.files = files;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.logger = logger;
|
||||
this.errorLogger = errorLogger;
|
||||
@ -98,6 +110,18 @@ public abstract class SQLDB extends AbstractDatabase {
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract List<String> getDependencyResource();
|
||||
|
||||
public void downloadDriver() {
|
||||
DependencyManager dependencyManager = new DependencyManager(files.getDataDirectory().resolve("libraries"));
|
||||
dependencyManager.loadFromResource(getDependencyResource());
|
||||
dependencyManager.download(null, DRIVER_REPOSITORIES);
|
||||
|
||||
IsolatedClassLoader classLoader = new IsolatedClassLoader();
|
||||
dependencyManager.load(null, classLoader);
|
||||
this.driverClassLoader = classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
List<Runnable> unfinishedTransactions = closeTransactionExecutor(transactionExecutor);
|
||||
|
@ -25,7 +25,6 @@ import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plan.storage.upkeep.DBKeepAliveTask;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.SemaphoreAccessCounter;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
import dagger.Lazy;
|
||||
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
||||
@ -35,10 +34,14 @@ import net.playeranalytics.plugin.server.PluginLogger;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author AuroraLS3
|
||||
@ -57,20 +60,32 @@ public class SQLiteDB extends SQLDB {
|
||||
*/
|
||||
private final SemaphoreAccessCounter connectionLock = new SemaphoreAccessCounter();
|
||||
|
||||
private Constructor<?> connectionConstructor;
|
||||
|
||||
private SQLiteDB(
|
||||
File databaseFile,
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
PlanFiles files,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger logger,
|
||||
ErrorLogger errorLogger
|
||||
) {
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, logger, errorLogger);
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, files, runnableFactory, logger, errorLogger);
|
||||
dbName = databaseFile.getName();
|
||||
this.databaseFile = databaseFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getDependencyResource() {
|
||||
try {
|
||||
return files.getResourceFromJar("dependencies/sqliteDriver.txt").asLines();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to get SQLite dependency information", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupDataSource() {
|
||||
try {
|
||||
@ -84,13 +99,10 @@ public class SQLiteDB extends SQLDB {
|
||||
}
|
||||
|
||||
public Connection getNewConnection(File dbFile) throws SQLException {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
} catch (ClassNotFoundException e) {
|
||||
errorLogger.critical(e, ErrorContext.builder().whatToDo("Install SQLite Driver to the server").build());
|
||||
return null;
|
||||
if (driverClassLoader == null) {
|
||||
logger.info("Downloading SQLite Driver, this may take a while...");
|
||||
downloadDriver();
|
||||
}
|
||||
|
||||
String dbFilePath = dbFile.getAbsolutePath();
|
||||
|
||||
Connection newConnection = getConnectionFor(dbFilePath);
|
||||
@ -99,11 +111,42 @@ public class SQLiteDB extends SQLDB {
|
||||
}
|
||||
|
||||
private Connection getConnectionFor(String dbFilePath) throws SQLException {
|
||||
ensureConstructorIsAvailable();
|
||||
return tryToConnect(dbFilePath, true);
|
||||
}
|
||||
|
||||
private void ensureConstructorIsAvailable() {
|
||||
if (connectionConstructor != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath + "?journal_mode=WAL");
|
||||
} catch (SQLException ignored) {
|
||||
Class<?> connectionClass = driverClassLoader.loadClass("org.sqlite.jdbc4.JDBC4Connection");
|
||||
connectionConstructor = connectionClass.getConstructor(String.class, String.class, Properties.class);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
throw new DBInitException("Failed to initialize SQLite Driver", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection tryToConnect(String dbFilePath, boolean withWAL) throws SQLException {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
if (withWAL) properties.put("journal_mode", "WAL");
|
||||
|
||||
return (Connection) connectionConstructor.newInstance("jdbc:sqlite:" + dbFilePath, dbFilePath, properties);
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (!withWAL && cause instanceof SQLException) {
|
||||
throw (SQLException) cause;
|
||||
} else if (!(cause instanceof SQLException)) {
|
||||
throw new DBInitException("Failed to initialize SQLite Driver", cause);
|
||||
}
|
||||
|
||||
// Run the method again with withWAL set to false, if it fails again, an exception will be thrown above
|
||||
logger.info(locale.getString(PluginLang.DB_NOTIFY_SQLITE_WAL));
|
||||
return DriverManager.getConnection("jdbc:sqlite:" + dbFilePath);
|
||||
return tryToConnect(dbFilePath, false);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new DBInitException("Failed to initialize SQLite Driver", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +259,7 @@ public class SQLiteDB extends SQLDB {
|
||||
|
||||
public SQLiteDB usingFile(File databaseFile) {
|
||||
return new SQLiteDB(databaseFile,
|
||||
locale, config, serverInfo,
|
||||
locale, config, files, serverInfo,
|
||||
runnableFactory, logger, errorLogger1
|
||||
);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
||||
|
||||
private final File oldDependencyCache;
|
||||
private final File dependencyCache;
|
||||
private final File librariesCache;
|
||||
|
||||
private final ErrorLogger errorLogger;
|
||||
|
||||
@ -45,6 +46,7 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
||||
) {
|
||||
oldDependencyCache = files.getDataDirectory().resolve("dependency_cache").toFile();
|
||||
dependencyCache = files.getDataDirectory().resolve("dep_cache").toFile();
|
||||
librariesCache = files.getDataDirectory().resolve("libraries").toFile();
|
||||
this.errorLogger = errorLogger;
|
||||
}
|
||||
|
||||
@ -58,6 +60,17 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
|
||||
public void run() {
|
||||
tryToDeleteDirectory(oldDependencyCache);
|
||||
tryToDeleteDirectory(dependencyCache);
|
||||
|
||||
if (librariesCache.exists()) {
|
||||
// Only delete sub folders as jar files in the directory are still needed
|
||||
File[] files = librariesCache.listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
tryToDeleteDirectory(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tryToDeleteDirectory(File directory) {
|
||||
|
@ -69,8 +69,8 @@
|
||||
|
||||
<!-- Metrics -->
|
||||
<module name="ClassFanOutComplexity">
|
||||
<!-- This value is high. Notable: SQLDB: 61 -->
|
||||
<property name="max" value="65"/>
|
||||
<!-- This value is high. Notable: SQLDB: 66 -->
|
||||
<property name="max" value="70"/>
|
||||
</module>
|
||||
<module name="CyclomaticComplexity">
|
||||
<!-- This value is high. Notable: ThemeConfig: 16 -->
|
||||
|
@ -49,11 +49,6 @@ processResources {
|
||||
from 'build/sources/resources'
|
||||
}
|
||||
|
||||
//slimJar {
|
||||
// relocate 'com.mysql', 'plan.com.mysql'
|
||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
//}
|
||||
|
||||
shadowJar {
|
||||
configurations = [project.configurations.shadow]
|
||||
exclude('net.fabricmc:*')
|
||||
@ -63,13 +58,13 @@ shadowJar {
|
||||
exclude 'org/apache/logging/**'
|
||||
}
|
||||
relocate 'dagger', 'plan.dagger'
|
||||
// Don't relocate SQLite since the org.sqlite.NativeDB class calls are not relocated properly
|
||||
// Don't relocate MySQL or SQLite since they are loaded with a isolated class loader
|
||||
// relocate 'org.sqlite', 'plan.org.sqlite'
|
||||
// relocate 'com.mysql', 'plan.com.mysql'
|
||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
relocate 'javax.inject', 'plan.javax.inject'
|
||||
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
||||
|
||||
relocate 'com.mysql', 'plan.com.mysql'
|
||||
relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
relocate 'dev.vankka.dependencydownload', 'plan.dev.vankka.dependencydownload'
|
||||
}
|
||||
|
||||
remapJar {
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.playeranalytics.plan;
|
||||
|
||||
import net.fabricmc.loader.launch.common.FabricLauncher;
|
||||
import net.fabricmc.loader.launch.common.FabricLauncherBase;
|
||||
import net.playeranalytics.plugin.server.FabricPluginLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Custom Injectable implementation for Fabric.
|
||||
* Appends dependencies to the classpath via Fabric's own launcher.
|
||||
*/
|
||||
public class FabricInjectable /*implements Injectable*/ {
|
||||
|
||||
private final FabricLauncher launcher;
|
||||
private final FabricPluginLogger pluginLogger;
|
||||
|
||||
public FabricInjectable(FabricPluginLogger pluginLogger) {
|
||||
this.pluginLogger = pluginLogger;
|
||||
this.launcher = FabricLauncherBase.getLauncher();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void inject(final URL url) throws IOException, InvocationTargetException, IllegalAccessException, URISyntaxException {
|
||||
pluginLogger.info("Proposed " + Paths.get(url.toURI()).getFileName().toString() + " to classpath");
|
||||
launcher.propose(url);
|
||||
}
|
||||
}
|
@ -158,22 +158,6 @@ public class PlanFabric implements PlanPlugin, DedicatedServerModInitializer {
|
||||
pluginLogger = (FabricPluginLogger) abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// pluginLogger.info("Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.injecting("Plan", new FabricInjectable(pluginLogger))
|
||||
// .logger((message, args) -> pluginLogger.info(message, args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// pluginLogger.error(this.getClass().getSimpleName() + "-v" + version, e);
|
||||
// pluginLogger.error("Plan failed to load its dependencies correctly!");
|
||||
// pluginLogger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> {
|
||||
this.server = (MinecraftDedicatedServer) server;
|
||||
onEnable();
|
||||
|
@ -66,22 +66,6 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
|
||||
abstractionLayer = new NukkitPlatformLayer(this);
|
||||
logger = abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// getLogger().info( "Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.appending("Plan")
|
||||
// .logger((message, args) -> Logger.getGlobal().log(Level.INFO, message, args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
||||
// getLogger().error("Plan failed to load its dependencies correctly!");
|
||||
// getLogger().error( "This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -210,4 +194,4 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
|
||||
}).runTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,22 +13,18 @@ dependencies {
|
||||
testImplementation project(path: ":velocity", configuration: 'testArtifacts')
|
||||
}
|
||||
|
||||
//slimJar {
|
||||
// relocate 'com.mysql', 'plan.com.mysql'
|
||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
//}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.apache', 'plan.org.apache') {
|
||||
exclude 'org/apache/logging/**'
|
||||
}
|
||||
relocate 'dagger', 'plan.dagger'
|
||||
// Don't relocate SQLite since the org.sqlite.NativeDB class calls are not relocated properly
|
||||
// Don't relocate MySQL or SQLite since they are loaded with a isolated class loader
|
||||
// relocate 'org.sqlite', 'plan.org.sqlite'
|
||||
// relocate 'com.mysql', 'plan.com.mysql'
|
||||
// relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
relocate 'javax.inject', 'plan.javax.inject'
|
||||
relocate 'com.github.benmanes', 'plan.com.github.benmanes'
|
||||
relocate 'com.mysql', 'plan.com.mysql'
|
||||
relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
|
||||
relocate 'dev.vankka.dependencydownload', 'plan.dev.vankka.dependencydownload'
|
||||
|
||||
destinationDirectory.set(file("$rootDir/builds/"))
|
||||
archiveBaseName.set('Plan')
|
||||
@ -49,4 +45,4 @@ publishing {
|
||||
artifact shadowJar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,22 +115,6 @@ public class PlanSponge implements PlanPlugin {
|
||||
abstractionLayer = new SpongePlatformLayer(this, dataFolder, slf4jLogger);
|
||||
logger = abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// logger.info("Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.appending("Plan")
|
||||
// .logger((message, args) -> java.util.logging.Logger.getGlobal().log(Level.INFO, message, args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
||||
// logger.error("Plan failed to load its dependencies correctly!");
|
||||
// logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
@ -91,22 +91,6 @@ public class PlanVelocity implements PlanPlugin {
|
||||
logger = abstractionLayer.getPluginLogger();
|
||||
runnableFactory = abstractionLayer.getRunnableFactory();
|
||||
|
||||
// logger.info("Loading dependencies, this might take a while...");
|
||||
// try {
|
||||
// ApplicationBuilder.injecting("Plan", new VelocityInjectable(this, proxy, logger))
|
||||
// .logger((message, args) -> slf4jLogger.info(fixMsgParams(message), args))
|
||||
// // Use paper repository for downloading slimjar dependencies
|
||||
// .internalRepositories(Collections.singletonList(new Repository(new URL("https://papermc.io/repo/repository/maven-public/"))))
|
||||
// .downloadDirectoryPath(Paths.get(getDataFolder().getAbsolutePath()).resolve("libraries"))
|
||||
// .build();
|
||||
// } catch (IOException | ReflectiveOperationException | URISyntaxException | NoSuchAlgorithmException e) {
|
||||
// String version = abstractionLayer.getPluginInformation().getVersion();
|
||||
// java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
|
||||
// logger.error("Plan failed to load its dependencies correctly!");
|
||||
// logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
|
||||
// onDisable();
|
||||
// }
|
||||
|
||||
onEnable();
|
||||
}
|
||||
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.playeranalytics.plugin.server.PluginLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Custom Injectable implementation for Velocity.
|
||||
* Appends dependencies to the classpath via Velocity's internal methods.
|
||||
*/
|
||||
public class VelocityInjectable /*implements Injectable*/ {
|
||||
|
||||
private final PlanPlugin plugin;
|
||||
private final ProxyServer proxyServer;
|
||||
private final PluginLogger logger;
|
||||
|
||||
public VelocityInjectable(PlanPlugin plugin, ProxyServer proxyServer, PluginLogger logger) {
|
||||
this.plugin = plugin;
|
||||
this.proxyServer = proxyServer;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void inject(URL url) throws IOException, InvocationTargetException, IllegalAccessException, URISyntaxException {
|
||||
logger.info("Proposed " + Paths.get(url.toURI()).getFileName().toString() + " to classpath");
|
||||
proxyServer.getPluginManager().addToClasspath(plugin, Paths.get(url.toURI()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user