mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-09 12:38:01 +02:00
Change layout of library storage
This commit is contained in:
parent
446fa48d9a
commit
4cfee76202
@ -343,6 +343,10 @@ public enum Dependency {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return name().toLowerCase().replace('_', '-') + "-" + this.version;
|
||||||
|
}
|
||||||
|
|
||||||
public List<URL> getUrls() {
|
public List<URL> getUrls() {
|
||||||
return this.urls;
|
return this.urls;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,8 @@ public class DependencyManager {
|
|||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
private final MessageDigest digest;
|
private final MessageDigest digest;
|
||||||
private final DependencyRegistry registry;
|
private final DependencyRegistry registry;
|
||||||
|
private final Path libsDirectory;
|
||||||
|
|
||||||
private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
|
private final EnumMap<Dependency, Path> loaded = new EnumMap<>(Dependency.class);
|
||||||
private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>();
|
private final Map<ImmutableSet<Dependency>, IsolatedClassLoader> loaders = new HashMap<>();
|
||||||
private RelocationHandler relocationHandler = null;
|
private RelocationHandler relocationHandler = null;
|
||||||
@ -73,6 +75,22 @@ public class DependencyManager {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
this.registry = new DependencyRegistry(plugin);
|
this.registry = new DependencyRegistry(plugin);
|
||||||
|
|
||||||
|
this.libsDirectory = this.plugin.getBootstrap().getDataDirectory().resolve("libs");
|
||||||
|
try {
|
||||||
|
MoreFiles.createDirectoriesIfNotExists(this.libsDirectory);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("Unable to create libs directory", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path oldLibsDirectory = this.plugin.getBootstrap().getDataDirectory().resolve("lib");
|
||||||
|
if (Files.exists(oldLibsDirectory)) {
|
||||||
|
try {
|
||||||
|
MoreFiles.deleteDirectory(oldLibsDirectory);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized RelocationHandler getRelocationHandler() {
|
private synchronized RelocationHandler getRelocationHandler() {
|
||||||
@ -82,16 +100,6 @@ public class DependencyManager {
|
|||||||
return this.relocationHandler;
|
return this.relocationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path getSaveDirectory() {
|
|
||||||
Path saveDirectory = this.plugin.getBootstrap().getDataDirectory().resolve("lib");
|
|
||||||
try {
|
|
||||||
MoreFiles.createDirectoriesIfNotExists(saveDirectory);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Unable to create lib directory", e);
|
|
||||||
}
|
|
||||||
return saveDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IsolatedClassLoader obtainClassLoaderWith(Set<Dependency> dependencies) {
|
public IsolatedClassLoader obtainClassLoaderWith(Set<Dependency> dependencies) {
|
||||||
ImmutableSet<Dependency> set = ImmutableSet.copyOf(dependencies);
|
ImmutableSet<Dependency> set = ImmutableSet.copyOf(dependencies);
|
||||||
|
|
||||||
@ -129,8 +137,6 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void loadDependencies(Set<Dependency> dependencies) {
|
public void loadDependencies(Set<Dependency> dependencies) {
|
||||||
Path saveDirectory = getSaveDirectory();
|
|
||||||
|
|
||||||
// create a list of file sources
|
// create a list of file sources
|
||||||
List<Source> sources = new ArrayList<>();
|
List<Source> sources = new ArrayList<>();
|
||||||
|
|
||||||
@ -141,7 +147,7 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path file = downloadDependency(saveDirectory, dependency);
|
Path file = downloadDependency(dependency);
|
||||||
sources.add(new Source(dependency, file));
|
sources.add(new Source(dependency, file));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
this.plugin.getLogger().severe("Exception whilst downloading dependency " + dependency.name());
|
this.plugin.getLogger().severe("Exception whilst downloading dependency " + dependency.name());
|
||||||
@ -163,7 +169,7 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Path input = source.file;
|
Path input = source.file;
|
||||||
Path output = input.getParent().resolve("remapped-" + input.getFileName().toString());
|
Path output = this.libsDirectory.resolve(source.dependency.getFileName() + "-remapped.jar");
|
||||||
|
|
||||||
// if the remapped file exists already, just use that.
|
// if the remapped file exists already, just use that.
|
||||||
if (Files.exists(output)) {
|
if (Files.exists(output)) {
|
||||||
@ -201,9 +207,8 @@ public class DependencyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path downloadDependency(Path saveDirectory, Dependency dependency) throws Exception {
|
private Path downloadDependency(Dependency dependency) throws Exception {
|
||||||
String fileName = dependency.name().toLowerCase() + "-" + dependency.getVersion() + ".jar";
|
Path file = this.libsDirectory.resolve(dependency.getFileName() + ".jar");
|
||||||
Path file = saveDirectory.resolve(fileName);
|
|
||||||
|
|
||||||
// if the file already exists, don't attempt to re-download it.
|
// if the file already exists, don't attempt to re-download it.
|
||||||
if (Files.exists(file)) {
|
if (Files.exists(file)) {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package me.lucko.luckperms.common.util;
|
package me.lucko.luckperms.common.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@ -57,4 +58,22 @@ public final class MoreFiles {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteDirectory(Path path) throws IOException {
|
||||||
|
if (!Files.exists(path) || !Files.isDirectory(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (DirectoryStream<Path> contents = Files.newDirectoryStream(path)) {
|
||||||
|
for (Path file : contents) {
|
||||||
|
if (Files.isDirectory(file)) {
|
||||||
|
deleteDirectory(file);
|
||||||
|
} else {
|
||||||
|
Files.delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Files.delete(path);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user