Dependency downloading (#1795)

Affects issues:
- Fix #1759
This commit is contained in:
Risto Lahtela 2021-03-15 15:28:36 +02:00 committed by GitHub
parent 42ecfa7298
commit bfcb7eea85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 22 deletions

View File

@ -66,7 +66,7 @@ subprojects {
ext.daggerVersion = "2.33"
ext.daggerCompilerVersion = "2.33"
ext.palVersion = "4.0.5"
ext.palVersion = "4.0.9"
ext.bukkitVersion = "1.13.2-R0.1-SNAPSHOT"
ext.spigotVersion = "1.13.2-R0.1-SNAPSHOT"

View File

@ -34,13 +34,13 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Main class for Bukkit that manages the plugin.
@ -55,12 +55,23 @@ public class Plan extends JavaPlugin implements PlanPlugin {
private PluginLogger logger;
private RunnableFactory runnableFactory;
private PlatformAbstractionLayer abstractionLayer;
@Override
public void onLoad() {
abstractionLayer = new BukkitPlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
try {
new DependencyStartup(logger, abstractionLayer.getDependencyLoader()).loadDependencies();
} catch (IOException e) {
getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName());
}
}
@Override
public void onEnable() {
PlatformAbstractionLayer abstractionLayer = new BukkitPlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
PlanBukkitComponent component = DaggerPlanBukkitComponent.builder()
.plan(this)
.abstractionLayer(abstractionLayer)
@ -86,7 +97,7 @@ public class Plan extends JavaPlugin implements PlanPlugin {
onDisable();
} catch (Exception e) {
String version = abstractionLayer.getPluginInformation().getVersion();
Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName() + "-v" + version);
logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
onDisable();

View File

@ -29,6 +29,7 @@ import net.playeranalytics.plugin.PlatformAbstractionLayer;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.server.PluginLogger;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -45,12 +46,23 @@ public class PlanBungee extends Plugin implements PlanPlugin {
private PluginLogger logger;
private RunnableFactory runnableFactory;
private PlatformAbstractionLayer abstractionLayer;
@Override
public void onLoad() {
abstractionLayer = new BungeePlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
try {
new DependencyStartup(logger, abstractionLayer.getDependencyLoader()).loadDependencies();
} catch (IOException e) {
getLogger().log(Level.SEVERE, e, () -> this.getClass().getSimpleName());
}
}
@Override
public void onEnable() {
PlatformAbstractionLayer abstractionLayer = new BungeePlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
PlanBungeeComponent component = DaggerPlanBungeeComponent.builder()
.plan(this)
.abstractionLayer(abstractionLayer)

View File

@ -6,9 +6,9 @@ dependencies {
compile "org.apache.commons:commons-text:$commonsTextVersion"
compile "org.apache.commons:commons-compress:$commonsCompressVersion"
compile "com.github.ben-manes.caffeine:caffeine:$caffeineVersion"
compile "com.h2database:h2:$h2Version"
compile "mysql:mysql-connector-java:$mysqlVersion"
compile "org.xerial:sqlite-jdbc:$sqliteVersion"
implementation "com.h2database:h2:$h2Version"
implementation "mysql:mysql-connector-java:$mysqlVersion"
implementation "org.xerial:sqlite-jdbc:$sqliteVersion"
compile "com.zaxxer:HikariCP:$hikariVersion"
compile "org.slf4j:slf4j-nop:$slf4jVersion"
compile "org.slf4j:slf4j-api:$slf4jVersion"
@ -43,14 +43,13 @@ shadowJar {
exclude "**/*.psd"
exclude "**/module-info.class"
exclude 'META-INF/versions/' // Causes Sponge to crash
exclude 'META-INF/versions/' // Causes Sponge to crash
exclude 'org/apache/http/**/*' // Unnecessary http client depended on by geolite2 implementation
exclude 'mozilla/**/*'
relocate 'com.maxmind', 'plan.com.maxmind'
relocate 'com.fasterxml', 'plan.com.fasterxml'
relocate 'com.zaxxer', 'plan.com.zaxxer'
relocate 'com.googlecode.htmlcompressor', 'plan.com.google.htmlcompressor'
relocate 'com.google.protobuf', 'plan.com.google.protobuf'
relocate 'com.google.gson', 'plan.com.google.gson'
relocate 'com.google.errorprone', 'plan.com.google.errorprone'

View File

@ -0,0 +1,78 @@
/*
* 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.djrapitops.plan.utilities.java.Lists;
import net.playeranalytics.plugin.dependencies.DependencyLoader;
import net.playeranalytics.plugin.me.lucko.jarrelocator.Relocation;
import net.playeranalytics.plugin.server.PluginLogger;
import java.io.IOException;
public class DependencyStartup {
private static final String REPOSITORY_MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
private final PluginLogger logger;
private final DependencyLoader dependencyLoader;
public DependencyStartup(PluginLogger logger, DependencyLoader dependencyLoader) {
this.logger = logger;
this.dependencyLoader = dependencyLoader;
}
public void loadDependencies() throws IOException {
logger.info("Resolving runtime dependencies..");
dependencyLoader.addDependency(REPOSITORY_MAVEN_CENTRAL,
"com.h2database", "h2", "1.4.199",
Lists.builder(Relocation.class)
.add(new Relocation(
new String(new char[]{'o', 'r', 'g', '.', 'h', '2'}),
"plan.org.h2"
)).build()
);
dependencyLoader.addDependency(REPOSITORY_MAVEN_CENTRAL,
"mysql", "mysql-connector-java", "8.0.23",
Lists.builder(Relocation.class)
.add(new Relocation(
new String(new char[]{'c', 'o', 'm', '.', 'm', 'y', 's', 'q', 'l'}),
"plan.com.mysql"
)).build()
);
dependencyLoader.addDependency(REPOSITORY_MAVEN_CENTRAL,
"org.xerial", "sqlite-jdbc", "3.34.0",
Lists.builder(Relocation.class)
.add(new Relocation(
new String(new char[]{'o', 'r', 'g', '.', 's', 'q', 'l', 'i', 't', 'e'}),
"plan.org.sqlite"
)).build()
);
logger.info("Loading runtime dependencies..");
dependencyLoader.load();
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
logger.error("Could not load SQLite driver");
}
try {
Class.forName("com.mysql.cj.jdbc.Driver");
} catch (ClassNotFoundException e) {
logger.error("Could not load MySQL driver");
}
}
}

View File

@ -34,6 +34,7 @@ import net.playeranalytics.plugin.PlatformAbstractionLayer;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.server.PluginLogger;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@ -59,12 +60,23 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
private final Map<String, Subcommand> commands = new HashMap<>();
private PluginLogger logger;
private RunnableFactory runnableFactory;
private PlatformAbstractionLayer abstractionLayer;
@Override
public void onLoad() {
abstractionLayer = new NukkitPlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
try {
new DependencyStartup(logger, abstractionLayer.getDependencyLoader()).loadDependencies();
} catch (IOException e) {
Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName());
}
}
@Override
public void onEnable() {
PlatformAbstractionLayer abstractionLayer = new NukkitPlatformLayer(this);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
PlanNukkitComponent component = DaggerPlanNukkitComponent.builder()
.plan(this)
.abstractionLayer(abstractionLayer)

View File

@ -20,9 +20,9 @@ shadowJar {
exclude 'org/apache/logging/**'
}
relocate 'dagger', 'plan.dagger'
relocate 'com.mysql.jdbc', 'plan.com.mysql.jdbc'
relocate 'com.mysql', 'plan.com.mysql'
relocate 'com.mysql', 'plan.com.mysql'
relocate 'org.sqlite', 'plan.org.sqlite'
relocate 'com.mysql.cj', 'plan.com.mysql.cj'
relocate 'javax.inject', 'plan.javax.inject'
relocate 'com.github.benmanes', 'plan.com.github.benmanes'

View File

@ -36,6 +36,7 @@ import org.spongepowered.api.command.CommandManager;
import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Dependency;
@ -43,6 +44,7 @@ import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Task;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
@ -78,6 +80,7 @@ public class PlanSponge implements PlanPlugin {
private ServerShutdownSave serverShutdownSave;
private PluginLogger logger;
private RunnableFactory runnableFactory;
private PlatformAbstractionLayer abstractionLayer;
@com.google.inject.Inject
public PlanSponge(
@ -94,6 +97,11 @@ public class PlanSponge implements PlanPlugin {
private final Map<String, CommandMapping> commands = new HashMap<>();
@Listener
public void onServerLoad(GamePreInitializationEvent event) {
onLoad();
}
@Listener
public void onServerStart(GameStartedServerEvent event) {
onEnable();
@ -104,10 +112,18 @@ public class PlanSponge implements PlanPlugin {
onDisable();
}
public void onEnable() {
PlatformAbstractionLayer abstractionLayer = new SpongePlatformLayer(this, dataFolder, slf4jLogger);
private void onLoad() {
abstractionLayer = new SpongePlatformLayer(this, dataFolder, slf4jLogger);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
try {
new DependencyStartup(logger, abstractionLayer.getDependencyLoader()).loadDependencies();
} catch (IOException e) {
java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName());
}
}
public void onEnable() {
PlanSpongeComponent component = DaggerPlanSpongeComponent.builder()
.plan(this)
.abstractionLayer(abstractionLayer)

View File

@ -37,6 +37,7 @@ import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.logging.Level;
@ -93,7 +94,17 @@ public class PlanVelocity implements PlanPlugin {
PlatformAbstractionLayer abstractionLayer = new VelocityPlatformLayer(this, proxy, slf4jLogger, dataFolderPath);
logger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
PlanVelocityComponent component = DaggerPlanVelocityComponent.builder().plan(this).build();
try {
new DependencyStartup(logger, abstractionLayer.getDependencyLoader()).loadDependencies();
} catch (IOException e) {
java.util.logging.Logger.getGlobal().log(Level.SEVERE, e, () -> this.getClass().getSimpleName());
}
PlanVelocityComponent component = DaggerPlanVelocityComponent.builder()
.plan(this)
.abstractionLayer(abstractionLayer)
.build();
try {
system = component.system();
locale = system.getLocaleSystem().getLocale();