mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Apply dependency remapping using an isolated classloader
* Fixes the issue which prevented LP from loading on Java 9 * Should also fix #697
This commit is contained in:
parent
04ffd00c0e
commit
03a93b1186
@ -50,10 +50,6 @@
|
|||||||
<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.jarrelocator</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jarrelocator</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
|
|
||||||
<!-- relocated dependencies -->
|
<!-- relocated dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
@ -93,9 +89,13 @@
|
|||||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis.shaded</pattern>
|
<pattern>redis.clients.jedis</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.apache.commons.pool2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.commonspool2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>ninja.leaping.configurate</pattern>
|
<pattern>ninja.leaping.configurate</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
||||||
|
@ -50,10 +50,6 @@
|
|||||||
<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.jarrelocator</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jarrelocator</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
|
|
||||||
<!-- relocated dependencies -->
|
<!-- relocated dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
@ -93,9 +89,13 @@
|
|||||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis.shaded</pattern>
|
<pattern>redis.clients.jedis</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.apache.commons.pool2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.commonspool2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>ninja.leaping.configurate</pattern>
|
<pattern>ninja.leaping.configurate</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.configurate</shadedPattern>
|
||||||
|
@ -44,24 +44,6 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- jar-relocator -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.lucko</groupId>
|
|
||||||
<artifactId>jar-relocator</artifactId>
|
|
||||||
<version>1.2</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>
|
||||||
@ -101,7 +83,7 @@
|
|||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>19.0</version>
|
<version>19.0</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- caffeine -->
|
<!-- caffeine -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -169,7 +151,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>2.9.1-shaded</version>
|
<version>2.9.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- MongoDB -->
|
<!-- MongoDB -->
|
||||||
|
@ -28,8 +28,7 @@ package me.lucko.luckperms.common.dependencies;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import me.lucko.jarrelocator.Relocation;
|
import me.lucko.luckperms.common.dependencies.relocation.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;
|
||||||
@ -53,55 +52,61 @@ public enum Dependency {
|
|||||||
"5.2",
|
"5.2",
|
||||||
"zBMYiX4sdxy3l6aNX06mQcI6UfBDfKUXq+z5ZN2yZAs="
|
"zBMYiX4sdxy3l6aNX06mQcI6UfBDfKUXq+z5ZN2yZAs="
|
||||||
),
|
),
|
||||||
|
JAR_RELOCATOR(
|
||||||
|
"me.lucko",
|
||||||
|
"jar-relocator",
|
||||||
|
"1.2",
|
||||||
|
"ECR0wrAMwmM0dpmuY1ifCG+2rpObOIlSI127jBbSrbI="
|
||||||
|
),
|
||||||
|
|
||||||
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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.of("hikari", "com{}zaxxer{}hikari")
|
||||||
),
|
),
|
||||||
SLF4J_SIMPLE(
|
SLF4J_SIMPLE(
|
||||||
"org.slf4j",
|
"org.slf4j",
|
||||||
@ -121,36 +126,47 @@ public enum Dependency {
|
|||||||
"3.5.0",
|
"3.5.0",
|
||||||
"gxrbKVSI/xM6r+6uL7g7I0DzNV+hlNTtfw4UL13XdK8=",
|
"gxrbKVSI/xM6r+6uL7g7I0DzNV+hlNTtfw4UL13XdK8=",
|
||||||
ImmutableList.<Relocation>builder()
|
ImmutableList.<Relocation>builder()
|
||||||
.addAll(Relocations.of("mongodb", "com{}mongodb"))
|
.addAll(Relocation.of("mongodb", "com{}mongodb"))
|
||||||
.addAll(Relocations.of("bson", "org{}bson"))
|
.addAll(Relocation.of("bson", "org{}bson"))
|
||||||
.build()
|
.build()
|
||||||
),
|
),
|
||||||
JEDIS(
|
JEDIS(
|
||||||
"https://github.com/lucko/jedis/releases/download/jedis-2.9.1-shaded/jedis-2.9.1-shaded.jar",
|
"redis.clients",
|
||||||
"2.9.1-shaded",
|
"jedis",
|
||||||
"mM19X6LyD97KP4RSbcCR5BTRAwQ0x9y02voX7ePOSjE=",
|
"2.9.0",
|
||||||
Relocations.of("jedis", "redis{}clients{}jedis{}shaded")
|
"HqqWy45QVeTVF0Z/DzsrPLvGKn2dHotqI8YX7GDThvo=",
|
||||||
|
ImmutableList.<Relocation>builder()
|
||||||
|
.addAll(Relocation.of("jedis", "redis{}clients{}jedis"))
|
||||||
|
.addAll(Relocation.of("commonspool2", "org{}apache{}commons{}pool2"))
|
||||||
|
.build()
|
||||||
|
),
|
||||||
|
COMMONS_POOL_2(
|
||||||
|
"org.apache.commons",
|
||||||
|
"commons-pool2",
|
||||||
|
"2.4.2",
|
||||||
|
"IREqpnNzPfzQRTVN33WzHh1GS5nI5RWXQ0myUyJUzFM=",
|
||||||
|
Relocation.of("commonspool2", "org{}apache{}commons{}pool2")
|
||||||
),
|
),
|
||||||
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")
|
Relocation.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")
|
Relocation.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")
|
Relocation.of("configurate", "ninja{}leaping{}configurate")
|
||||||
),
|
),
|
||||||
CONFIGURATE_HOCON(
|
CONFIGURATE_HOCON(
|
||||||
"ninja{}leaping{}configurate",
|
"ninja{}leaping{}configurate",
|
||||||
@ -158,8 +174,8 @@ public enum Dependency {
|
|||||||
"3.3",
|
"3.3",
|
||||||
"UIy5FVmsBUG6+Z1mpIEE2EXgtOI1ZL0p/eEW+BbtGLU=",
|
"UIy5FVmsBUG6+Z1mpIEE2EXgtOI1ZL0p/eEW+BbtGLU=",
|
||||||
ImmutableList.<Relocation>builder()
|
ImmutableList.<Relocation>builder()
|
||||||
.addAll(Relocations.of("configurate", "ninja{}leaping{}configurate"))
|
.addAll(Relocation.of("configurate", "ninja{}leaping{}configurate"))
|
||||||
.addAll(Relocations.of("hocon", "com{}typesafe{}config"))
|
.addAll(Relocation.of("hocon", "com{}typesafe{}config"))
|
||||||
.build()
|
.build()
|
||||||
),
|
),
|
||||||
HOCON_CONFIG(
|
HOCON_CONFIG(
|
||||||
@ -167,7 +183,7 @@ public enum Dependency {
|
|||||||
"config",
|
"config",
|
||||||
"1.3.1",
|
"1.3.1",
|
||||||
"5vrfxhCCINOmuGqn5OFsnnu4V7pYlViGMIuxOXImSvA=",
|
"5vrfxhCCINOmuGqn5OFsnnu4V7pYlViGMIuxOXImSvA=",
|
||||||
Relocations.of("hocon", "com{}typesafe{}config")
|
Relocation.of("hocon", "com{}typesafe{}config")
|
||||||
);
|
);
|
||||||
|
|
||||||
private final String url;
|
private final String url;
|
||||||
|
@ -27,8 +27,8 @@ package me.lucko.luckperms.common.dependencies;
|
|||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import me.lucko.jarrelocator.JarRelocator;
|
import me.lucko.luckperms.common.dependencies.relocation.Relocation;
|
||||||
import me.lucko.jarrelocator.Relocation;
|
import me.lucko.luckperms.common.dependencies.relocation.RelocationHandler;
|
||||||
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;
|
||||||
|
|
||||||
@ -53,6 +53,7 @@ public class DependencyManager {
|
|||||||
private final MessageDigest digest;
|
private final MessageDigest digest;
|
||||||
private final DependencyRegistry registry;
|
private final DependencyRegistry registry;
|
||||||
private final EnumSet<Dependency> alreadyLoaded = EnumSet.noneOf(Dependency.class);
|
private final EnumSet<Dependency> alreadyLoaded = EnumSet.noneOf(Dependency.class);
|
||||||
|
private RelocationHandler relocationHandler = null;
|
||||||
|
|
||||||
public DependencyManager(LuckPermsPlugin plugin) {
|
public DependencyManager(LuckPermsPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -64,23 +65,29 @@ public class DependencyManager {
|
|||||||
this.registry = new DependencyRegistry(plugin);
|
this.registry = new DependencyRegistry(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized RelocationHandler getRelocationHandler() {
|
||||||
|
if (this.relocationHandler == null) {
|
||||||
|
this.relocationHandler = new RelocationHandler(this);
|
||||||
|
}
|
||||||
|
return this.relocationHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getSaveDirectory() {
|
||||||
|
File saveDirectory = new File(this.plugin.getDataDirectory(), "lib");
|
||||||
|
if (!(saveDirectory.exists() || saveDirectory.mkdirs())) {
|
||||||
|
throw new RuntimeException("Unable to create lib dir - " + saveDirectory.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
return saveDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
public void loadStorageDependencies(Set<StorageType> storageTypes) {
|
public void loadStorageDependencies(Set<StorageType> storageTypes) {
|
||||||
loadDependencies(this.registry.resolveStorageDependencies(storageTypes));
|
loadDependencies(this.registry.resolveStorageDependencies(storageTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadDependencies(Set<Dependency> dependencies) {
|
public void loadDependencies(Set<Dependency> dependencies) {
|
||||||
loadDependencies(dependencies, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadDependencies(Set<Dependency> dependencies, boolean applyRemapping) {
|
|
||||||
if (applyRemapping) {
|
|
||||||
this.plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
this.plugin.getLog().info("Identified the following dependencies: " + dependencies.toString());
|
||||||
}
|
File saveDirectory = getSaveDirectory();
|
||||||
|
|
||||||
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
|
// create a list of file sources
|
||||||
List<Source> sources = new ArrayList<>();
|
List<Source> sources = new ArrayList<>();
|
||||||
@ -102,7 +109,6 @@ public class DependencyManager {
|
|||||||
|
|
||||||
// apply any remapping rules to the files
|
// apply any remapping rules to the files
|
||||||
List<File> remappedJars = new ArrayList<>(sources.size());
|
List<File> remappedJars = new ArrayList<>(sources.size());
|
||||||
if (applyRemapping) {
|
|
||||||
for (Source source : sources) {
|
for (Source source : sources) {
|
||||||
try {
|
try {
|
||||||
// apply remap rules
|
// apply remap rules
|
||||||
@ -122,23 +128,12 @@ public class DependencyManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure ASM is loaded
|
// init the relocation handler
|
||||||
Set<Dependency> asmDepends = EnumSet.noneOf(Dependency.class);
|
RelocationHandler relocationHandler = getRelocationHandler();
|
||||||
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.
|
// attempt to remap the jar.
|
||||||
this.plugin.getLog().info("Attempting to remap " + input.getName() + "...");
|
this.plugin.getLog().info("Attempting to apply relocations to " + input.getName() + "...");
|
||||||
JarRelocator relocator = new JarRelocator(input, output, relocations);
|
relocationHandler.remap(input, output, relocations);
|
||||||
relocator.run();
|
|
||||||
|
|
||||||
remappedJars.add(output);
|
remappedJars.add(output);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -146,11 +141,6 @@ public class DependencyManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for (Source source : sources) {
|
|
||||||
remappedJars.add(source.file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// load each of the jars
|
// load each of the jars
|
||||||
for (File file : remappedJars) {
|
for (File file : remappedJars) {
|
||||||
@ -163,7 +153,7 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File downloadDependency(File saveDirectory, Dependency dependency) throws Exception {
|
public 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(saveDirectory, fileName);
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ public class DependencyRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||||
|
dependencies.add(Dependency.COMMONS_POOL_2);
|
||||||
dependencies.add(Dependency.JEDIS);
|
dependencies.add(Dependency.JEDIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,20 +25,33 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.dependencies.relocation;
|
package me.lucko.luckperms.common.dependencies.relocation;
|
||||||
|
|
||||||
import me.lucko.jarrelocator.Relocation;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class Relocations {
|
public final class Relocation {
|
||||||
|
|
||||||
public static List<Relocation> of(String name, String... packages) {
|
public static List<Relocation> of(String name, String... packages) {
|
||||||
List<Relocation> relocations = new ArrayList<>();
|
List<Relocation> ret = new ArrayList<>();
|
||||||
for (String p : packages) {
|
for (String p : packages) {
|
||||||
relocations.add(new Relocation(p.replace("{}", "."), "me.lucko.luckperms.lib." + name));
|
ret.add(new Relocation(p.replace("{}", "."), "me.lucko.luckperms.lib." + name));
|
||||||
}
|
}
|
||||||
return relocations;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String pattern;
|
||||||
|
private final String relocatedPattern;
|
||||||
|
|
||||||
|
public Relocation(String pattern, String relocatedPattern) {
|
||||||
|
this.pattern = pattern;
|
||||||
|
this.relocatedPattern = relocatedPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRelocatedPattern() {
|
||||||
|
return this.relocatedPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Relocations() {}
|
|
||||||
}
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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.luckperms.common.dependencies.Dependency;
|
||||||
|
import me.lucko.luckperms.common.dependencies.DependencyManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles class runtime relocation of packages in downloaded dependencies
|
||||||
|
*/
|
||||||
|
public class RelocationHandler implements AutoCloseable {
|
||||||
|
private final DependencyManager dependencyManager;
|
||||||
|
|
||||||
|
private URLClassLoader classLoader;
|
||||||
|
private Constructor<?> relocatorConstructor;
|
||||||
|
private Method relocatorRunMethod;
|
||||||
|
|
||||||
|
public RelocationHandler(DependencyManager dependencyManager) {
|
||||||
|
this.dependencyManager = dependencyManager;
|
||||||
|
try {
|
||||||
|
setup();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setup() throws Exception {
|
||||||
|
File saveDirectory = this.dependencyManager.getSaveDirectory();
|
||||||
|
|
||||||
|
// download the required dependencies for the remapping.
|
||||||
|
File asm = this.dependencyManager.downloadDependency(saveDirectory, Dependency.ASM);
|
||||||
|
File asmCommons = this.dependencyManager.downloadDependency(saveDirectory, Dependency.ASM_COMMONS);
|
||||||
|
File jarRelocator = this.dependencyManager.downloadDependency(saveDirectory, Dependency.JAR_RELOCATOR);
|
||||||
|
|
||||||
|
URL[] urls = new URL[]{
|
||||||
|
asm.toURI().toURL(),
|
||||||
|
asmCommons.toURI().toURL(),
|
||||||
|
jarRelocator.toURI().toURL()
|
||||||
|
};
|
||||||
|
|
||||||
|
// construct an isolated classloader instance containing the dependencies needed
|
||||||
|
this.classLoader = new URLClassLoader(urls, null);
|
||||||
|
|
||||||
|
// load the relocator class
|
||||||
|
Class<?> relocatorClass = this.classLoader.loadClass("me.lucko.jarrelocator.JarRelocator");
|
||||||
|
|
||||||
|
// prepare the the reflected constructor & method instances
|
||||||
|
this.relocatorConstructor = relocatorClass.getDeclaredConstructor(File.class, File.class, Map.class);
|
||||||
|
this.relocatorConstructor.setAccessible(true);
|
||||||
|
|
||||||
|
this.relocatorRunMethod = relocatorClass.getDeclaredMethod("run");
|
||||||
|
this.relocatorRunMethod.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remap(File input, File output, List<Relocation> relocations) throws Exception {
|
||||||
|
if (this.classLoader == null) {
|
||||||
|
throw new IllegalStateException("ClassLoader is closed");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> mappings = new HashMap<>();
|
||||||
|
for (Relocation relocation : relocations) {
|
||||||
|
mappings.put(relocation.getPattern(), relocation.getRelocatedPattern());
|
||||||
|
}
|
||||||
|
|
||||||
|
// create and invoke a new relocator
|
||||||
|
Object relocator = this.relocatorConstructor.newInstance(input, output, mappings);
|
||||||
|
this.relocatorRunMethod.invoke(relocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (this.classLoader == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.classLoader.close();
|
||||||
|
this.classLoader = null;
|
||||||
|
}
|
||||||
|
}
|
@ -27,10 +27,10 @@ package me.lucko.luckperms.common.messaging;
|
|||||||
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
import redis.clients.jedis.shaded.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.shaded.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.shaded.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
import redis.clients.jedis.shaded.JedisPubSub;
|
import redis.clients.jedis.JedisPubSub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using Redis.
|
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using Redis.
|
||||||
|
@ -50,10 +50,6 @@
|
|||||||
<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.jarrelocator</pattern>
|
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jarrelocator</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
|
|
||||||
<!-- relocated dependencies -->
|
<!-- relocated dependencies -->
|
||||||
<relocation>
|
<relocation>
|
||||||
@ -89,9 +85,13 @@
|
|||||||
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.bson</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis.shaded</pattern>
|
<pattern>redis.clients.jedis</pattern>
|
||||||
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
<shadedPattern>me.lucko.luckperms.lib.jedis</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.apache.commons.pool2</pattern>
|
||||||
|
<shadedPattern>me.lucko.luckperms.lib.commonspool2</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
Loading…
Reference in New Issue
Block a user