Relocate dependency packages to prevent conflicts with other plugins
This commit is contained in:
parent
22006617d0
commit
19e6d4e4c8
@ -45,10 +45,65 @@
|
|||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<relocations>
|
<relocations>
|
||||||
|
<!-- shaded dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>net.kyori.text</pattern>
|
<pattern>net.kyori.text</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>me.lucko.jarreloator</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jarreloator</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
|
||||||
|
<!-- relocated dependencies -->
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.github.benmanes.caffeine</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.caffeine</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.mariadb.jdbc</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mariadb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mysql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mysql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.postgresql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.postgresql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.h2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.sqlite</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.sqlite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.zaxxer.hikari</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mongodb</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bson</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>redis.clients.jedis.shaded</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>ninja.leaping.configurate</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.typesafe.config</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.hocon</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -57,6 +57,8 @@ import me.lucko.luckperms.common.contexts.ContextManager;
|
|||||||
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader;
|
||||||
import me.lucko.luckperms.common.event.EventFactory;
|
import me.lucko.luckperms.common.event.EventFactory;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
||||||
@ -124,6 +126,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
private DefaultsProvider defaultsProvider;
|
private DefaultsProvider defaultsProvider;
|
||||||
private ChildPermissionProvider childPermissionProvider;
|
private ChildPermissionProvider childPermissionProvider;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private PluginClassLoader pluginClassLoader;
|
||||||
private DependencyManager dependencyManager;
|
private DependencyManager dependencyManager;
|
||||||
private CachedStateManager cachedStateManager;
|
private CachedStateManager cachedStateManager;
|
||||||
private ContextManager<Player> contextManager;
|
private ContextManager<Player> contextManager;
|
||||||
@ -151,6 +154,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
this.senderFactory = new BukkitSenderFactory(this);
|
this.senderFactory = new BukkitSenderFactory(this);
|
||||||
this.log = new SenderLogger(this, getConsoleSender());
|
this.log = new SenderLogger(this, getConsoleSender());
|
||||||
|
|
||||||
|
this.pluginClassLoader = new ReflectionClassLoader(this);
|
||||||
this.dependencyManager = new DependencyManager(this);
|
this.dependencyManager = new DependencyManager(this);
|
||||||
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||||
}
|
}
|
||||||
@ -633,6 +637,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
return this.localeManager;
|
return this.localeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluginClassLoader getPluginClassLoader() {
|
||||||
|
return this.pluginClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DependencyManager getDependencyManager() {
|
public DependencyManager getDependencyManager() {
|
||||||
return this.dependencyManager;
|
return this.dependencyManager;
|
||||||
|
@ -45,10 +45,65 @@
|
|||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<relocations>
|
<relocations>
|
||||||
|
<!-- shaded dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>net.kyori.text</pattern>
|
<pattern>net.kyori.text</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>me.lucko.jarreloator</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jarreloator</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
|
||||||
|
<!-- relocated dependencies -->
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.github.benmanes.caffeine</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.caffeine</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.mariadb.jdbc</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mariadb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mysql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mysql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.postgresql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.postgresql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.h2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.sqlite</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.sqlite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.zaxxer.hikari</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mongodb</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bson</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>redis.clients.jedis.shaded</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>ninja.leaping.configurate</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.typesafe.config</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.hocon</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -51,6 +51,8 @@ import me.lucko.luckperms.common.contexts.ContextManager;
|
|||||||
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader;
|
||||||
import me.lucko.luckperms.common.event.EventFactory;
|
import me.lucko.luckperms.common.event.EventFactory;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
||||||
@ -109,6 +111,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
private EventFactory eventFactory;
|
private EventFactory eventFactory;
|
||||||
private Logger log;
|
private Logger log;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private PluginClassLoader pluginClassLoader;
|
||||||
private DependencyManager dependencyManager;
|
private DependencyManager dependencyManager;
|
||||||
private CachedStateManager cachedStateManager;
|
private CachedStateManager cachedStateManager;
|
||||||
private ContextManager<ProxiedPlayer> contextManager;
|
private ContextManager<ProxiedPlayer> contextManager;
|
||||||
@ -128,6 +131,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
this.senderFactory = new BungeeSenderFactory(this);
|
this.senderFactory = new BungeeSenderFactory(this);
|
||||||
this.log = new SenderLogger(this, getConsoleSender());
|
this.log = new SenderLogger(this, getConsoleSender());
|
||||||
|
|
||||||
|
this.pluginClassLoader = new ReflectionClassLoader(this);
|
||||||
this.dependencyManager = new DependencyManager(this);
|
this.dependencyManager = new DependencyManager(this);
|
||||||
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
this.dependencyManager.loadDependencies(Collections.singleton(Dependency.CAFFEINE));
|
||||||
}
|
}
|
||||||
@ -435,6 +439,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
return this.localeManager;
|
return this.localeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluginClassLoader getPluginClassLoader() {
|
||||||
|
return this.pluginClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DependencyManager getDependencyManager() {
|
public DependencyManager getDependencyManager() {
|
||||||
return this.dependencyManager;
|
return this.dependencyManager;
|
||||||
|
@ -44,6 +44,24 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- jar-relocator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.lucko</groupId>
|
||||||
|
<artifactId>jar-relocator</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- text -->
|
<!-- text -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
|
@ -25,57 +25,83 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.dependencies;
|
package me.lucko.luckperms.common.dependencies;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
|
import me.lucko.jarreloator.Relocation;
|
||||||
|
import me.lucko.luckperms.common.dependencies.relocation.Relocations;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public enum Dependency {
|
public enum Dependency {
|
||||||
|
|
||||||
|
ASM(
|
||||||
|
"org.ow2.asm",
|
||||||
|
"asm",
|
||||||
|
"5.2",
|
||||||
|
"Pl6g19osUVXvT0cNkJLULeNOP1PbZYnHwH1nIa30uj4="
|
||||||
|
),
|
||||||
|
ASM_COMMONS(
|
||||||
|
"org.ow2.asm",
|
||||||
|
"asm-commons",
|
||||||
|
"5.2",
|
||||||
|
"zBMYiX4sdxy3l6aNX06mQcI6UfBDfKUXq+z5ZN2yZAs="
|
||||||
|
),
|
||||||
|
|
||||||
CAFFEINE(
|
CAFFEINE(
|
||||||
"com.github.ben-manes.caffeine",
|
"com{}github{}ben-manes{}caffeine",
|
||||||
"caffeine",
|
"caffeine",
|
||||||
"2.6.0",
|
"2.6.0",
|
||||||
"JmT16VQnCnVBAjRJCQkkkjmSVx2jajpzeBuKwpbzDA8="
|
"JmT16VQnCnVBAjRJCQkkkjmSVx2jajpzeBuKwpbzDA8=",
|
||||||
|
Relocations.of("caffeine", "com{}github{}benmanes{}caffeine")
|
||||||
),
|
),
|
||||||
MARIADB_DRIVER(
|
MARIADB_DRIVER(
|
||||||
"org.mariadb.jdbc",
|
"org{}mariadb{}jdbc",
|
||||||
"mariadb-java-client",
|
"mariadb-java-client",
|
||||||
"2.2.0",
|
"2.2.0",
|
||||||
"/q0LPGHrp3L9rvKr7TuA6urbtXBqvXis92mP4KhxzUw="
|
"/q0LPGHrp3L9rvKr7TuA6urbtXBqvXis92mP4KhxzUw=",
|
||||||
|
Relocations.of("mariadb", "org{}mariadb{}jdbc")
|
||||||
),
|
),
|
||||||
MYSQL_DRIVER(
|
MYSQL_DRIVER(
|
||||||
"mysql",
|
"mysql",
|
||||||
"mysql-connector-java",
|
"mysql-connector-java",
|
||||||
"5.1.44",
|
"5.1.44",
|
||||||
"d4RZVzTeWpoHBPB/tQP3mSafNy7L9MDUSOt4Ku9LGCc="
|
"d4RZVzTeWpoHBPB/tQP3mSafNy7L9MDUSOt4Ku9LGCc=",
|
||||||
|
Relocations.of("mysql", "com{}mysql")
|
||||||
),
|
),
|
||||||
POSTGRESQL_DRIVER(
|
POSTGRESQL_DRIVER(
|
||||||
"org.postgresql",
|
"org{}postgresql",
|
||||||
"postgresql",
|
"postgresql",
|
||||||
"9.4.1212",
|
"9.4.1212",
|
||||||
"DLKhWL4xrPIY4KThjI89usaKO8NIBkaHc/xECUsMNl0="
|
"DLKhWL4xrPIY4KThjI89usaKO8NIBkaHc/xECUsMNl0=",
|
||||||
|
Relocations.of("postgresql", "org{}postgresql")
|
||||||
),
|
),
|
||||||
H2_DRIVER(
|
H2_DRIVER(
|
||||||
"com.h2database",
|
"com.h2database",
|
||||||
"h2",
|
"h2",
|
||||||
"1.4.196",
|
"1.4.196",
|
||||||
"CgX0oNW4WEAUiq3OY6QjtdPDbvRHVjibT6rQjScz+vU="
|
"CgX0oNW4WEAUiq3OY6QjtdPDbvRHVjibT6rQjScz+vU=",
|
||||||
|
Relocations.of("h2", "org{}h2")
|
||||||
),
|
),
|
||||||
SQLITE_DRIVER(
|
SQLITE_DRIVER(
|
||||||
"org.xerial",
|
"org.xerial",
|
||||||
"sqlite-jdbc",
|
"sqlite-jdbc",
|
||||||
"3.21.0",
|
"3.21.0",
|
||||||
"bglRaH4Y+vQFZV7TfOdsVLO3rJpauJ+IwjuRULAb45Y="
|
"bglRaH4Y+vQFZV7TfOdsVLO3rJpauJ+IwjuRULAb45Y=",
|
||||||
|
Relocations.of("sqlite", "org{}sqlite")
|
||||||
),
|
),
|
||||||
HIKARI(
|
HIKARI(
|
||||||
"com.zaxxer",
|
"com{}zaxxer",
|
||||||
"HikariCP",
|
"HikariCP",
|
||||||
"2.7.4",
|
"2.7.4",
|
||||||
"y9JE6/VmbydCqlV1z468+oqdkBswBk6aw+ECT178AT4="
|
"y9JE6/VmbydCqlV1z468+oqdkBswBk6aw+ECT178AT4=",
|
||||||
|
Relocations.of("hikari", "com{}zaxxer{}hikari")
|
||||||
),
|
),
|
||||||
SLF4J_SIMPLE(
|
SLF4J_SIMPLE(
|
||||||
"org.slf4j",
|
"org.slf4j",
|
||||||
@ -93,58 +119,90 @@ public enum Dependency {
|
|||||||
"org.mongodb",
|
"org.mongodb",
|
||||||
"mongo-java-driver",
|
"mongo-java-driver",
|
||||||
"3.5.0",
|
"3.5.0",
|
||||||
"gxrbKVSI/xM6r+6uL7g7I0DzNV+hlNTtfw4UL13XdK8="
|
"gxrbKVSI/xM6r+6uL7g7I0DzNV+hlNTtfw4UL13XdK8=",
|
||||||
|
ImmutableList.<Relocation>builder()
|
||||||
|
.addAll(Relocations.of("mongodb", "com{}mongodb"))
|
||||||
|
.addAll(Relocations.of("bson", "org{}bson"))
|
||||||
|
.build()
|
||||||
),
|
),
|
||||||
JEDIS(
|
JEDIS(
|
||||||
"https://github.com/lucko/jedis/releases/download/jedis-2.9.1-shaded/jedis-2.9.1-shaded.jar",
|
"https://github.com/lucko/jedis/releases/download/jedis-2.9.1-shaded/jedis-2.9.1-shaded.jar",
|
||||||
"2.9.1-shaded",
|
"2.9.1-shaded",
|
||||||
"mM19X6LyD97KP4RSbcCR5BTRAwQ0x9y02voX7ePOSjE="
|
"mM19X6LyD97KP4RSbcCR5BTRAwQ0x9y02voX7ePOSjE=",
|
||||||
|
Relocations.of("jedis", "redis{}clients{}jedis{}shaded")
|
||||||
),
|
),
|
||||||
CONFIGURATE_CORE(
|
CONFIGURATE_CORE(
|
||||||
"ninja.leaping.configurate",
|
"ninja{}leaping{}configurate",
|
||||||
"configurate-core",
|
"configurate-core",
|
||||||
"3.3",
|
"3.3",
|
||||||
"4leBJEqj1kVszaifZeKNl4hgHxG5M+Nk5TJKkPW2s4Y="
|
"4leBJEqj1kVszaifZeKNl4hgHxG5M+Nk5TJKkPW2s4Y=",
|
||||||
|
Relocations.of("configurate", "ninja{}leaping{}configurate")
|
||||||
),
|
),
|
||||||
CONFIGURATE_GSON(
|
CONFIGURATE_GSON(
|
||||||
"ninja.leaping.configurate",
|
"ninja{}leaping{}configurate",
|
||||||
"configurate-gson",
|
"configurate-gson",
|
||||||
"3.3",
|
"3.3",
|
||||||
"4HxrW3/ZKdn095x/W4gylQMNskdmteXYVxVv0UKGJA4="
|
"4HxrW3/ZKdn095x/W4gylQMNskdmteXYVxVv0UKGJA4=",
|
||||||
|
Relocations.of("configurate", "ninja{}leaping{}configurate")
|
||||||
),
|
),
|
||||||
CONFIGURATE_YAML(
|
CONFIGURATE_YAML(
|
||||||
"ninja.leaping.configurate",
|
"ninja{}leaping{}configurate",
|
||||||
"configurate-yaml",
|
"configurate-yaml",
|
||||||
"3.3",
|
"3.3",
|
||||||
"hgADp3g+xHHPD34bAuxMWtB+OQ718Tlw69jVp2KPJNk="
|
"hgADp3g+xHHPD34bAuxMWtB+OQ718Tlw69jVp2KPJNk=",
|
||||||
|
Relocations.of("configurate", "ninja{}leaping{}configurate")
|
||||||
),
|
),
|
||||||
CONFIGURATE_HOCON(
|
CONFIGURATE_HOCON(
|
||||||
"ninja.leaping.configurate",
|
"ninja{}leaping{}configurate",
|
||||||
"configurate-hocon",
|
"configurate-hocon",
|
||||||
"3.3",
|
"3.3",
|
||||||
"UIy5FVmsBUG6+Z1mpIEE2EXgtOI1ZL0p/eEW+BbtGLU="
|
"UIy5FVmsBUG6+Z1mpIEE2EXgtOI1ZL0p/eEW+BbtGLU=",
|
||||||
|
ImmutableList.<Relocation>builder()
|
||||||
|
.addAll(Relocations.of("configurate", "ninja{}leaping{}configurate"))
|
||||||
|
.addAll(Relocations.of("hocon", "com{}typesafe{}config"))
|
||||||
|
.build()
|
||||||
),
|
),
|
||||||
HOCON_CONFIG(
|
HOCON_CONFIG(
|
||||||
"com.typesafe",
|
"com{}typesafe",
|
||||||
"config",
|
"config",
|
||||||
"1.3.1",
|
"1.3.1",
|
||||||
"5vrfxhCCINOmuGqn5OFsnnu4V7pYlViGMIuxOXImSvA="
|
"5vrfxhCCINOmuGqn5OFsnnu4V7pYlViGMIuxOXImSvA=",
|
||||||
|
Relocations.of("hocon", "com{}typesafe{}config")
|
||||||
);
|
);
|
||||||
|
|
||||||
private final String url;
|
private final String url;
|
||||||
private final String version;
|
private final String version;
|
||||||
private final byte[] checksum;
|
private final byte[] checksum;
|
||||||
|
private final List<Relocation> relocations;
|
||||||
|
|
||||||
private static final String MAVEN_CENTRAL_FORMAT = "https://repo1.maven.org/maven2/%s/%s/%s/%s-%s.jar";
|
private static final String MAVEN_CENTRAL_FORMAT = "https://repo1.maven.org/maven2/%s/%s/%s/%s-%s.jar";
|
||||||
|
|
||||||
Dependency(String groupId, String artifactId, String version, String checksum) {
|
Dependency(String groupId, String artifactId, String version, String checksum) {
|
||||||
this(String.format(MAVEN_CENTRAL_FORMAT, groupId.replace(".", "/"), artifactId, version, artifactId, version), version, checksum);
|
this(groupId, artifactId, version, checksum, Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Dependency(String url, String version, String checksum) {
|
Dependency(String groupId, String artifactId, String version, String checksum, List<Relocation> relocations) {
|
||||||
|
this(
|
||||||
|
String.format(MAVEN_CENTRAL_FORMAT,
|
||||||
|
rewriteEscaping(groupId).replace(".", "/"),
|
||||||
|
rewriteEscaping(artifactId),
|
||||||
|
version,
|
||||||
|
rewriteEscaping(artifactId),
|
||||||
|
version
|
||||||
|
),
|
||||||
|
version, checksum, relocations
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dependency(String url, String version, String checksum, List<Relocation> relocations) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.checksum = Base64.getDecoder().decode(checksum);
|
this.checksum = Base64.getDecoder().decode(checksum);
|
||||||
|
this.relocations = relocations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String rewriteEscaping(String s) {
|
||||||
|
return s.replace("{}", ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@ -180,4 +238,8 @@ public enum Dependency {
|
|||||||
public byte[] getChecksum() {
|
public byte[] getChecksum() {
|
||||||
return this.checksum;
|
return this.checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Relocation> getRelocations() {
|
||||||
|
return this.relocations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,64 +25,34 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.dependencies;
|
package me.lucko.luckperms.common.dependencies;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.platform.PlatformType;
|
import me.lucko.jarreloator.JarRelocator;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.jarreloator.Relocation;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.storage.StorageType;
|
import me.lucko.luckperms.common.storage.StorageType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for loading runtime dependencies.
|
* Responsible for loading runtime dependencies.
|
||||||
*/
|
*/
|
||||||
public class DependencyManager {
|
public class DependencyManager {
|
||||||
private static final Method ADD_URL_METHOD;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Method addUrlMethod;
|
|
||||||
try {
|
|
||||||
addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
|
||||||
addUrlMethod.setAccessible(true);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
throw new ExceptionInInitializerError(e);
|
|
||||||
}
|
|
||||||
ADD_URL_METHOD = addUrlMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Map<StorageType, List<Dependency>> STORAGE_DEPENDENCIES = ImmutableMap.<StorageType, List<Dependency>>builder()
|
|
||||||
.put(StorageType.JSON, ImmutableList.of(Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_GSON))
|
|
||||||
.put(StorageType.YAML, ImmutableList.of(Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_YAML))
|
|
||||||
.put(StorageType.HOCON, ImmutableList.of(Dependency.HOCON_CONFIG, Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_HOCON))
|
|
||||||
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
|
||||||
.put(StorageType.MARIADB, ImmutableList.of(Dependency.MARIADB_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
|
||||||
.put(StorageType.MYSQL, ImmutableList.of(Dependency.MYSQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
|
||||||
.put(StorageType.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
|
||||||
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
|
|
||||||
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final MessageDigest digest;
|
private final MessageDigest digest;
|
||||||
|
private final DependencyRegistry registry;
|
||||||
|
private final EnumSet<Dependency> alreadyLoaded = EnumSet.noneOf(Dependency.class);
|
||||||
|
|
||||||
public DependencyManager(LuckPermsPlugin plugin) {
|
public DependencyManager(LuckPermsPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -91,94 +61,142 @@ public class DependencyManager {
|
|||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
this.registry = new DependencyRegistry(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadStorageDependencies(Set<StorageType> storageTypes) {
|
public void loadStorageDependencies(Set<StorageType> storageTypes) {
|
||||||
Set<Dependency> dependencies = new LinkedHashSet<>();
|
loadDependencies(this.registry.resolveStorageDependencies(storageTypes));
|
||||||
for (StorageType storageType : storageTypes) {
|
|
||||||
dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
|
||||||
dependencies.add(Dependency.JEDIS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't load slf4j if it's already present
|
|
||||||
if (classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory")) {
|
|
||||||
dependencies.remove(Dependency.SLF4J_API);
|
|
||||||
dependencies.remove(Dependency.SLF4J_SIMPLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't load configurate dependencies on sponge
|
|
||||||
if (this.plugin.getServerType() == PlatformType.SPONGE) {
|
|
||||||
dependencies.remove(Dependency.CONFIGURATE_CORE);
|
|
||||||
dependencies.remove(Dependency.CONFIGURATE_GSON);
|
|
||||||
dependencies.remove(Dependency.CONFIGURATE_YAML);
|
|
||||||
dependencies.remove(Dependency.CONFIGURATE_HOCON);
|
|
||||||
dependencies.remove(Dependency.HOCON_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadDependencies(dependencies);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadDependencies(Set<Dependency> dependencies) {
|
public void loadDependencies(Set<Dependency> dependencies) {
|
||||||
this.plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
loadDependencies(dependencies, true);
|
||||||
|
|
||||||
File libDir = new File(this.plugin.getDataDirectory(), "lib");
|
|
||||||
if (!(libDir.exists() || libDir.mkdirs())) {
|
|
||||||
throw new RuntimeException("Unable to create lib dir - " + libDir.getPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download files.
|
public void loadDependencies(Set<Dependency> dependencies, boolean applyRemapping) {
|
||||||
List<File> filesToLoad = new ArrayList<>();
|
if (applyRemapping) {
|
||||||
|
this.plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
File saveDirectory = new File(this.plugin.getDataDirectory(), "lib");
|
||||||
|
if (!(saveDirectory.exists() || saveDirectory.mkdirs())) {
|
||||||
|
throw new RuntimeException("Unable to create lib dir - " + saveDirectory.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a list of file sources
|
||||||
|
List<Source> sources = new ArrayList<>();
|
||||||
|
|
||||||
|
// obtain a file for each of the dependencies
|
||||||
for (Dependency dependency : dependencies) {
|
for (Dependency dependency : dependencies) {
|
||||||
|
if (!this.alreadyLoaded.add(dependency)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
filesToLoad.add(downloadDependency(libDir, dependency));
|
File file = downloadDependency(saveDirectory, dependency);
|
||||||
|
sources.add(new Source(dependency, file));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
this.plugin.getLog().severe("Exception whilst downloading dependency " + dependency.name());
|
this.plugin.getLog().severe("Exception whilst downloading dependency " + dependency.name());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load classes.
|
// apply any remapping rules to the files
|
||||||
for (File file : filesToLoad) {
|
List<File> remappedJars = new ArrayList<>(sources.size());
|
||||||
|
if (applyRemapping) {
|
||||||
|
for (Source source : sources) {
|
||||||
try {
|
try {
|
||||||
loadJar(file);
|
// apply remap rules
|
||||||
} catch (Throwable t) {
|
List<Relocation> relocations = source.dependency.getRelocations();
|
||||||
this.plugin.getLog().severe("Failed to load dependency jar " + file.getName());
|
|
||||||
t.printStackTrace();
|
if (relocations.isEmpty()) {
|
||||||
|
remappedJars.add(source.file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
File input = source.file;
|
||||||
|
File output = new File(input.getParentFile(), "remap-" + input.getName());
|
||||||
|
|
||||||
|
// if the remapped file exists already, just use that.
|
||||||
|
if (output.exists()) {
|
||||||
|
remappedJars.add(output);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure ASM is loaded
|
||||||
|
Set<Dependency> asmDepends = EnumSet.noneOf(Dependency.class);
|
||||||
|
if (!DependencyRegistry.asmPresent()) {
|
||||||
|
asmDepends.add(Dependency.ASM);
|
||||||
|
}
|
||||||
|
if (!DependencyRegistry.asmCommonsPresent()) {
|
||||||
|
asmDepends.add(Dependency.ASM_COMMONS);
|
||||||
|
}
|
||||||
|
if (!asmDepends.isEmpty()) {
|
||||||
|
// load asm before calling the jar relocator
|
||||||
|
loadDependencies(asmDepends, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// attempt to remap the jar.
|
||||||
|
this.plugin.getLog().info("Attempting to remap " + input.getName() + "...");
|
||||||
|
JarRelocator relocator = new JarRelocator(input, output, relocations);
|
||||||
|
relocator.run();
|
||||||
|
|
||||||
|
remappedJars.add(output);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
this.plugin.getLog().severe("Unable to remap the source file '" + source.dependency.name() + "'.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Source source : sources) {
|
||||||
|
remappedJars.add(source.file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// load each of the jars
|
||||||
|
for (File file : remappedJars) {
|
||||||
|
try {
|
||||||
|
this.plugin.getPluginClassLoader().loadJar(file);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
this.plugin.getLog().severe("Failed to load dependency jar '" + file.getName() + "'.");
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File downloadDependency(File libDir, Dependency dependency) throws Exception {
|
private File downloadDependency(File saveDirectory, Dependency dependency) throws Exception {
|
||||||
String fileName = dependency.name().toLowerCase() + "-" + dependency.getVersion() + ".jar";
|
String fileName = dependency.name().toLowerCase() + "-" + dependency.getVersion() + ".jar";
|
||||||
|
File file = new File(saveDirectory, fileName);
|
||||||
|
|
||||||
File file = new File(libDir, fileName);
|
// if the file already exists, don't attempt to re-download it.
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = new URL(dependency.getUrl());
|
URL url = new URL(dependency.getUrl());
|
||||||
|
|
||||||
this.plugin.getLog().info("Dependency '" + fileName + "' could not be found. Attempting to download.");
|
|
||||||
try (InputStream in = url.openStream()) {
|
try (InputStream in = url.openStream()) {
|
||||||
|
|
||||||
|
// download the jar content
|
||||||
byte[] bytes = ByteStreams.toByteArray(in);
|
byte[] bytes = ByteStreams.toByteArray(in);
|
||||||
if (bytes.length == 0) {
|
if (bytes.length == 0) {
|
||||||
throw new RuntimeException("Empty stream");
|
throw new RuntimeException("Empty stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// compute a hash for the downloaded file
|
||||||
byte[] hash = this.digest.digest(bytes);
|
byte[] hash = this.digest.digest(bytes);
|
||||||
|
|
||||||
this.plugin.getLog().info("Successfully downloaded '" + fileName + "' with checksum: " + Base64.getEncoder().encodeToString(hash));
|
this.plugin.getLog().info("Successfully downloaded '" + fileName + "' with checksum: " + Base64.getEncoder().encodeToString(hash));
|
||||||
|
|
||||||
|
// ensure the hash matches the expected checksum
|
||||||
if (!Arrays.equals(hash, dependency.getChecksum())) {
|
if (!Arrays.equals(hash, dependency.getChecksum())) {
|
||||||
throw new RuntimeException("Downloaded file had an invalid hash. Expected: " + Base64.getEncoder().encodeToString(dependency.getChecksum()));
|
throw new RuntimeException("Downloaded file had an invalid hash. Expected: " + Base64.getEncoder().encodeToString(dependency.getChecksum()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the checksum matches, save the content to disk
|
||||||
Files.write(file.toPath(), bytes);
|
Files.write(file.toPath(), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure the file saved correctly
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
throw new IllegalStateException("File not present. - " + file.toString());
|
throw new IllegalStateException("File not present. - " + file.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -186,27 +204,13 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJar(File file) {
|
private static final class Source {
|
||||||
// get the classloader to load into
|
private final Dependency dependency;
|
||||||
ClassLoader classLoader = this.plugin.getClass().getClassLoader();
|
private final File file;
|
||||||
|
|
||||||
if (classLoader instanceof URLClassLoader) {
|
private Source(Dependency dependency, File file) {
|
||||||
try {
|
this.dependency = dependency;
|
||||||
ADD_URL_METHOD.invoke(classLoader, file.toURI().toURL());
|
this.file = file;
|
||||||
} catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) {
|
|
||||||
throw new RuntimeException("Unable to invoke URLClassLoader#addURL", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Unknown classloader type: " + classLoader.getClass());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean classExists(String className) {
|
|
||||||
try {
|
|
||||||
Class.forName(className);
|
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.dependencies;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.platform.PlatformType;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.common.storage.StorageType;
|
||||||
|
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class DependencyRegistry {
|
||||||
|
|
||||||
|
private static final Map<StorageType, List<Dependency>> STORAGE_DEPENDENCIES = ImmutableMap.<StorageType, List<Dependency>>builder()
|
||||||
|
.put(StorageType.JSON, ImmutableList.of(Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_GSON))
|
||||||
|
.put(StorageType.YAML, ImmutableList.of(Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_YAML))
|
||||||
|
.put(StorageType.HOCON, ImmutableList.of(Dependency.HOCON_CONFIG, Dependency.CONFIGURATE_CORE, Dependency.CONFIGURATE_HOCON))
|
||||||
|
.put(StorageType.MONGODB, ImmutableList.of(Dependency.MONGODB_DRIVER))
|
||||||
|
.put(StorageType.MARIADB, ImmutableList.of(Dependency.MARIADB_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
|
.put(StorageType.MYSQL, ImmutableList.of(Dependency.MYSQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
|
.put(StorageType.POSTGRESQL, ImmutableList.of(Dependency.POSTGRESQL_DRIVER, Dependency.SLF4J_API, Dependency.SLF4J_SIMPLE, Dependency.HIKARI))
|
||||||
|
.put(StorageType.SQLITE, ImmutableList.of(Dependency.SQLITE_DRIVER))
|
||||||
|
.put(StorageType.H2, ImmutableList.of(Dependency.H2_DRIVER))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
public DependencyRegistry(LuckPermsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Dependency> resolveStorageDependencies(Set<StorageType> storageTypes) {
|
||||||
|
Set<Dependency> dependencies = new LinkedHashSet<>();
|
||||||
|
for (StorageType storageType : storageTypes) {
|
||||||
|
dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||||
|
dependencies.add(Dependency.JEDIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't load slf4j if it's already present
|
||||||
|
if (slf4jPresent()) {
|
||||||
|
dependencies.remove(Dependency.SLF4J_API);
|
||||||
|
dependencies.remove(Dependency.SLF4J_SIMPLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't load configurate dependencies on sponge
|
||||||
|
if (this.plugin.getServerType() == PlatformType.SPONGE) {
|
||||||
|
dependencies.remove(Dependency.CONFIGURATE_CORE);
|
||||||
|
dependencies.remove(Dependency.CONFIGURATE_GSON);
|
||||||
|
dependencies.remove(Dependency.CONFIGURATE_YAML);
|
||||||
|
dependencies.remove(Dependency.CONFIGURATE_HOCON);
|
||||||
|
dependencies.remove(Dependency.HOCON_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean classExists(String className) {
|
||||||
|
try {
|
||||||
|
Class.forName(className);
|
||||||
|
return true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean slf4jPresent() {
|
||||||
|
return classExists("org.slf4j.Logger") && classExists("org.slf4j.LoggerFactory");
|
||||||
|
}
|
||||||
|
|
||||||
|
// used to remap dependencies - we check to see if they're present to avoid loading unnecessarily.
|
||||||
|
|
||||||
|
public static boolean asmPresent() {
|
||||||
|
return classExists("org.objectweb.asm.ClassReader") &&
|
||||||
|
classExists("org.objectweb.asm.ClassVisitor") &&
|
||||||
|
classExists("org.objectweb.asm.ClassWriter");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean asmCommonsPresent() {
|
||||||
|
return classExists("org.objectweb.asm.commons.ClassRemapper") &&
|
||||||
|
classExists("org.objectweb.asm.commons.Remapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.dependencies.classloader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the plugins classloader
|
||||||
|
*/
|
||||||
|
public interface PluginClassLoader {
|
||||||
|
|
||||||
|
void loadJar(URL url);
|
||||||
|
|
||||||
|
void loadJar(File file);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.dependencies.classloader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
|
public class ReflectionClassLoader implements PluginClassLoader {
|
||||||
|
private static final Method ADD_URL_METHOD;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Method addUrlMethod;
|
||||||
|
try {
|
||||||
|
addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||||
|
addUrlMethod.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new ExceptionInInitializerError(e);
|
||||||
|
}
|
||||||
|
ADD_URL_METHOD = addUrlMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final URLClassLoader classLoader;
|
||||||
|
|
||||||
|
public ReflectionClassLoader(Object plugin) throws IllegalStateException {
|
||||||
|
ClassLoader classLoader = plugin.getClass().getClassLoader();
|
||||||
|
if (classLoader instanceof URLClassLoader) {
|
||||||
|
this.classLoader = (URLClassLoader) classLoader;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("ClassLoader is not instance of URLClassLoader");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadJar(URL url) {
|
||||||
|
try {
|
||||||
|
ADD_URL_METHOD.invoke(this.classLoader, url);
|
||||||
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadJar(File file) {
|
||||||
|
try {
|
||||||
|
loadJar(file.toURI().toURL());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.dependencies.relocation;
|
||||||
|
|
||||||
|
import me.lucko.jarreloator.Relocation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class Relocations {
|
||||||
|
|
||||||
|
public static List<Relocation> of(String name, String... packages) {
|
||||||
|
List<Relocation> relocations = new ArrayList<>();
|
||||||
|
for (String p : packages) {
|
||||||
|
relocations.add(new Relocation(p.replace("{}", "."), "me.lucko.luckperms.lib." + name));
|
||||||
|
}
|
||||||
|
return relocations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Relocations() {}
|
||||||
|
}
|
@ -39,6 +39,7 @@ import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|||||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
|
||||||
import me.lucko.luckperms.common.event.EventFactory;
|
import me.lucko.luckperms.common.event.EventFactory;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.logging.Logger;
|
import me.lucko.luckperms.common.logging.Logger;
|
||||||
@ -154,6 +155,13 @@ public interface LuckPermsPlugin {
|
|||||||
*/
|
*/
|
||||||
LocaleManager getLocaleManager();
|
LocaleManager getLocaleManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the classloader wrapper for adding dependencies to the classpath
|
||||||
|
*
|
||||||
|
* @return the plugin classloader
|
||||||
|
*/
|
||||||
|
PluginClassLoader getPluginClassLoader();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the dependency manager for the plugin
|
* Gets the dependency manager for the plugin
|
||||||
*
|
*
|
||||||
|
@ -45,10 +45,53 @@
|
|||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<relocations>
|
<relocations>
|
||||||
|
<!-- shaded dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>net.kyori.text</pattern>
|
<pattern>net.kyori.text</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.text</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>me.lucko.jarreloator</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jarreloator</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
|
||||||
|
<!-- relocated dependencies -->
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.mariadb.jdbc</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mariadb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mysql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mysql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.postgresql</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.postgresql</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.h2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.h2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.sqlite</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.sqlite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.zaxxer.hikari</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.hikari</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.mongodb</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.mongodb</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bson</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>redis.clients.jedis.shaded</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
@ -47,6 +47,8 @@ import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
|||||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||||
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
import me.lucko.luckperms.common.contexts.LuckPermsCalculator;
|
||||||
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
|
||||||
|
import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader;
|
||||||
import me.lucko.luckperms.common.event.EventFactory;
|
import me.lucko.luckperms.common.event.EventFactory;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
import me.lucko.luckperms.common.locale.NoopLocaleManager;
|
||||||
@ -177,6 +179,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
private me.lucko.luckperms.common.logging.Logger log;
|
private me.lucko.luckperms.common.logging.Logger log;
|
||||||
private LuckPermsService service;
|
private LuckPermsService service;
|
||||||
private LocaleManager localeManager;
|
private LocaleManager localeManager;
|
||||||
|
private PluginClassLoader pluginClassLoader;
|
||||||
private DependencyManager dependencyManager;
|
private DependencyManager dependencyManager;
|
||||||
private CachedStateManager cachedStateManager;
|
private CachedStateManager cachedStateManager;
|
||||||
private ContextManager<Subject> contextManager;
|
private ContextManager<Subject> contextManager;
|
||||||
@ -195,6 +198,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
this.localeManager = new NoopLocaleManager();
|
this.localeManager = new NoopLocaleManager();
|
||||||
this.senderFactory = new SpongeSenderFactory(this);
|
this.senderFactory = new SpongeSenderFactory(this);
|
||||||
this.log = new SenderLogger(this, getConsoleSender());
|
this.log = new SenderLogger(this, getConsoleSender());
|
||||||
|
this.pluginClassLoader = new ReflectionClassLoader(this);
|
||||||
this.dependencyManager = new DependencyManager(this);
|
this.dependencyManager = new DependencyManager(this);
|
||||||
|
|
||||||
sendStartupBanner(getConsoleSender());
|
sendStartupBanner(getConsoleSender());
|
||||||
@ -598,6 +602,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
return this.localeManager;
|
return this.localeManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PluginClassLoader getPluginClassLoader() {
|
||||||
|
return this.pluginClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DependencyManager getDependencyManager() {
|
public DependencyManager getDependencyManager() {
|
||||||
return this.dependencyManager;
|
return this.dependencyManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user