mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-08 16:56:07 +00:00
Merge remote-tracking branch 'origin/ver/6.0.0' into ver/6.0.0
# Conflicts: # build.gradle.kts # buildSrc/src/main/kotlin/DependencyConfig.kt # buildSrc/src/main/kotlin/DistributionConfig.kt # common/addons/biome-provider-image/build.gradle.kts # common/addons/biome-provider-pipeline/build.gradle.kts # common/addons/biome-provider-single/build.gradle.kts # common/addons/chunk-generator-noise-3d/build.gradle.kts # common/addons/command-addons/build.gradle.kts # common/addons/command-packs/build.gradle.kts # common/addons/command-profiler/build.gradle.kts # common/addons/command-structures/build.gradle.kts # common/addons/config-biome/build.gradle.kts # common/addons/config-distributors/build.gradle.kts # common/addons/config-feature/build.gradle.kts # common/addons/config-flora/build.gradle.kts # common/addons/config-locators/build.gradle.kts # common/addons/config-noise-function/build.gradle.kts # common/addons/config-ore/build.gradle.kts # common/addons/config-palette/build.gradle.kts # common/addons/config-structure/build.gradle.kts # common/addons/generation-stage-feature/build.gradle.kts # common/addons/generation-stage-structure/build.gradle.kts # common/addons/language-yaml/build.gradle.kts # common/addons/manifest-addon-loader/build.gradle.kts # common/addons/palette-block-shortcut/build.gradle.kts # common/addons/structure-block-shortcut/build.gradle.kts # common/addons/structure-mutator/build.gradle.kts # common/addons/structure-sponge-loader/build.gradle.kts # common/addons/structure-terrascript-loader/build.gradle.kts # common/addons/terrascript-function-check-noise-3d/build.gradle.kts # common/addons/terrascript-function-sampler/build.gradle.kts # common/api/build.gradle.kts # common/implementation/base/build.gradle.kts # common/implementation/bootstrap-addon-loader/build.gradle.kts # platforms/bukkit/build.gradle.kts # platforms/cli/build.gradle.kts # platforms/merged/build.gradle.kts
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.addon.loader;
|
||||
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
|
||||
|
||||
public class ApiAddon implements BaseAddon {
|
||||
private final Version version;
|
||||
private final String id;
|
||||
|
||||
public ApiAddon(Version version, String id) {
|
||||
this.version = version;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addon.loader;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
|
||||
public class ApiAddonClassLoader extends URLClassLoader {
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
public ApiAddonClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapBaseAddon;
|
||||
|
||||
|
||||
@@ -21,7 +22,8 @@ public class ApiAddonLoader implements BootstrapBaseAddon<BaseAddon> {
|
||||
private static final Version VERSION = Versions.getVersion(1, 0, 0);
|
||||
|
||||
@Override
|
||||
public Iterable<BaseAddon> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||
public Iterable<BaseAddon> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -2,16 +2,12 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
version = version("0.1.0")
|
||||
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
api("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
}
|
||||
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("com.dfsek.paralithic", "com.dfsek.terra.addons.noise.lib.paralithic")
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import com.dfsek.terra.addons.noise.config.templates.noise.fractal.RidgedFractal
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ClampNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.NormalNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.PosterizationNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ProbabilityNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ScaleNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.AdditionSampler;
|
||||
@@ -90,6 +91,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register(addon.key("CLAMP"), ClampNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("PROBABILITY"), ProbabilityNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("SCALE"), ScaleNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("POSTERIZATION"), PosterizationNormalizerTemplate::new);
|
||||
|
||||
noiseRegistry.register(addon.key("IMAGE"), ImageSamplerTemplate::new);
|
||||
|
||||
@@ -121,7 +123,6 @@ public class NoiseAddon implements AddonInitializer {
|
||||
|
||||
noiseRegistry.register(addon.key("LINEAR_HEIGHTMAP"), LinearHeightmapSamplerTemplate::new);
|
||||
|
||||
|
||||
noiseRegistry.register(addon.key("ADD"), () -> new BinaryArithmeticTemplate<>(AdditionSampler::new));
|
||||
noiseRegistry.register(addon.key("SUB"), () -> new BinaryArithmeticTemplate<>(SubtractionSampler::new));
|
||||
noiseRegistry.register(addon.key("MUL"), () -> new BinaryArithmeticTemplate<>(MultiplicationSampler::new));
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.noise.config.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.normalizer.PosterizationNormalizer;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class PosterizationNormalizerTemplate extends NormalizerTemplate<PosterizationNormalizer> {
|
||||
@Value("steps")
|
||||
private @Meta int steps;
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
return new PosterizationNormalizer(function, steps);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
public class PosterizationNormalizer extends Normalizer {
|
||||
private final double stepSize;
|
||||
|
||||
public PosterizationNormalizer(NoiseSampler sampler, int steps) {
|
||||
super(sampler);
|
||||
this.stepSize = 2.0 / (steps - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double normalize(double in) {
|
||||
return FastMath.roundToInt((in + 1) / stepSize) * stepSize - 1;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
api("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}")
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
api("commons-io:commons-io:2.6")
|
||||
api("commons-io:commons-io:2.7")
|
||||
implementation("com.dfsek.tectonic:yaml:${Versions.Libraries.tectonic}")
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ import ca.solostudios.strata.version.VersionRange;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -72,13 +75,9 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
throw new AddonException("Addon " + manifest.getID() + " has unknown schema version: " + manifest.getSchemaVersion());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed", "resource" })
|
||||
ManifestAddonClassLoader childLoader = new ManifestAddonClassLoader(new URL[]{ addonPath.toUri().toURL() },
|
||||
loader);
|
||||
|
||||
List<AddonInitializer> initializers = manifest.getEntryPoints().stream().map(entryPoint -> {
|
||||
try {
|
||||
Object in = childLoader.loadClass(entryPoint).getConstructor().newInstance();
|
||||
Object in = loader.loadClass(entryPoint).getConstructor().newInstance();
|
||||
if(!(in instanceof AddonInitializer)) {
|
||||
throw new AddonException(in.getClass() + " does not extend " + AddonInitializer.class);
|
||||
}
|
||||
@@ -103,7 +102,7 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||
public Iterable<ManifestAddon> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
|
||||
logger.debug("Loading addons...");
|
||||
|
||||
try(Stream<Path> files = Files.walk(addonsFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
|
||||
@@ -114,16 +113,16 @@ public class ManifestAddonLoader implements BootstrapBaseAddon<ManifestAddon> {
|
||||
.filter(path -> path.toString().endsWith(".jar"))
|
||||
.toList();
|
||||
|
||||
ManifestAddonClassLoader loader = new ManifestAddonClassLoader(addons.stream().map(path -> {
|
||||
addons.stream().map(path -> {
|
||||
try {
|
||||
return path.toUri().toURL();
|
||||
} catch(MalformedURLException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}).toArray(URL[]::new), getClass().getClassLoader());
|
||||
}).forEach(parent::addURL);
|
||||
|
||||
return addons.stream()
|
||||
.map(jar -> loadAddon(jar, loader))
|
||||
.map(jar -> loadAddon(jar, parent))
|
||||
.collect(Collectors.toList());
|
||||
} catch(IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
version = version("0.1.0")
|
||||
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url = uri("https://jitpack.io/") }
|
||||
}
|
||||
@@ -13,9 +9,9 @@ repositories {
|
||||
dependencies {
|
||||
api("commons-io:commons-io:2.7")
|
||||
api("com.github.Querz:NBT:6.1")
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("org.apache.commons", "com.dfsek.terra.addons.sponge.lib.commons")
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,9 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
|
||||
version = version("0.1.0")
|
||||
|
||||
|
||||
plugins {
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api("commons-io:commons-io:2.7")
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
api(project(":common:addons:chunk-generator-noise-3d"))
|
||||
api(project(":common:addons:structure-terrascript-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:chunk-generator-noise-3d"))
|
||||
compileOnlyApi(project(":common:addons:structure-terrascript-loader"))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
version = version("0.1.0")
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":common:addons:manifest-addon-loader"))
|
||||
api(project(":common:addons:config-noise-function"))
|
||||
api(project(":common:addons:structure-terrascript-loader"))
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
compileOnlyApi(project(":common:addons:config-noise-function"))
|
||||
compileOnlyApi(project(":common:addons:structure-terrascript-loader"))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
dependencies {
|
||||
compileOnlyApi("ca.solo-studios", "strata", Versions.Libraries.strata)
|
||||
compileOnlyApi("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
|
||||
compileOnlyApi("cloud.commandframework", "cloud-core", Versions.Libraries.cloud)
|
||||
api("ca.solo-studios", "strata", Versions.Libraries.strata)
|
||||
api("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
|
||||
api("cloud.commandframework", "cloud-core", Versions.Libraries.cloud)
|
||||
|
||||
compileOnlyApi("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
|
||||
api("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
|
||||
|
||||
compileOnlyApi("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dfsek.terra.api.addon.bootstrap;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
|
||||
|
||||
public class BootstrapAddonClassLoader extends URLClassLoader {
|
||||
public BootstrapAddonClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
}
|
||||
|
||||
public BootstrapAddonClassLoader(URL[] urls) {
|
||||
super(urls);
|
||||
}
|
||||
|
||||
public BootstrapAddonClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
|
||||
super(urls, parent, factory);
|
||||
}
|
||||
|
||||
public BootstrapAddonClassLoader(String name, URL[] urls, ClassLoader parent) {
|
||||
super(name, urls, parent);
|
||||
}
|
||||
|
||||
public BootstrapAddonClassLoader(String name, URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
|
||||
super(name, urls, parent, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(URL url) {
|
||||
super.addURL(url);
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,5 @@ public interface BootstrapBaseAddon<T extends BaseAddon> extends BaseAddon {
|
||||
*
|
||||
* @return Loaded addons
|
||||
*/
|
||||
Iterable<T> loadAddons(Path addonsFolder, ClassLoader parent);
|
||||
Iterable<T> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent);
|
||||
}
|
||||
|
||||
@@ -3,22 +3,11 @@ dependencies {
|
||||
api(project(":common:implementation:bootstrap-addon-loader"))
|
||||
|
||||
implementation("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO)
|
||||
|
||||
implementation("org.apache.commons", "commons-text", Versions.Libraries.Internal.apacheText)
|
||||
|
||||
implementation("com.dfsek.tectonic", "yaml", Versions.Libraries.tectonic)
|
||||
implementation("com.dfsek.tectonic", "common", Versions.Libraries.tectonic)
|
||||
|
||||
implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
|
||||
implementation("ca.solo-studios", "strata", Versions.Libraries.strata)
|
||||
|
||||
implementation("cloud.commandframework", "cloud-core", Versions.Libraries.cloud)
|
||||
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
|
||||
implementation("org.ow2.asm", "asm", Versions.Libraries.Internal.asm)
|
||||
|
||||
|
||||
|
||||
testImplementation("org.slf4j", "slf4j-api", Versions.Libraries.slf4j)
|
||||
implementation("com.dfsek", "paralithic", Versions.Libraries.paralithic)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,6 +34,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
@@ -162,12 +166,14 @@ public abstract class AbstractPlatform implements Platform {
|
||||
|
||||
Injector<Platform> platformInjector = new InjectorImpl<>(this);
|
||||
platformInjector.addExplicitTarget(Platform.class);
|
||||
|
||||
BootstrapAddonClassLoader bootstrapAddonClassLoader = new BootstrapAddonClassLoader(new URL[] {}, getClass().getClassLoader());
|
||||
|
||||
bootstrapAddonLoader.loadAddons(addonsFolder, getClass().getClassLoader())
|
||||
bootstrapAddonLoader.loadAddons(addonsFolder, bootstrapAddonClassLoader)
|
||||
.forEach(bootstrapAddon -> {
|
||||
platformInjector.inject(bootstrapAddon);
|
||||
|
||||
bootstrapAddon.loadAddons(addonsFolder, getClass().getClassLoader())
|
||||
bootstrapAddon.loadAddons(addonsFolder, bootstrapAddonClassLoader)
|
||||
.forEach(addonList::add);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
dependencies {
|
||||
"api"(project(":common:api"))
|
||||
compileOnlyApi(project(":common:api"))
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addon;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
|
||||
public class AddonClassLoader extends URLClassLoader {
|
||||
static {
|
||||
ClassLoader.registerAsParallelCapable();
|
||||
}
|
||||
|
||||
public AddonClassLoader(URL[] urls, ClassLoader parent) {
|
||||
super(urls, parent);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.dfsek.terra.addon;
|
||||
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
|
||||
public BootstrapAddonLoader() { }
|
||||
|
||||
private BootstrapBaseAddon<?> loadAddon(Path addonPath, ClassLoader parent) {
|
||||
private BootstrapBaseAddon<?> loadAddon(Path addonPath, BootstrapAddonClassLoader parent) {
|
||||
logger.debug("Loading bootstrap addon from JAR {}", addonPath);
|
||||
try(JarFile jar = new JarFile(addonPath.toFile())) {
|
||||
String entry = jar.getManifest().getMainAttributes().getValue("Terra-Bootstrap-Addon-Entry-Point");
|
||||
@@ -54,10 +55,8 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
|
||||
//noinspection NestedTryStatement
|
||||
try {
|
||||
@SuppressWarnings({ "resource", "IOResourceOpenedButNotSafelyClosed" })
|
||||
AddonClassLoader loader = new AddonClassLoader(new URL[]{ addonPath.toUri().toURL() }, parent);
|
||||
|
||||
Object addonObject = loader.loadClass(entry).getConstructor().newInstance();
|
||||
parent.addURL(addonPath.toUri().toURL());
|
||||
Object addonObject = parent.loadClass(entry).getConstructor().newInstance();
|
||||
|
||||
if(!(addonObject instanceof BootstrapBaseAddon<?> addon)) {
|
||||
throw new AddonLoadException(
|
||||
@@ -81,7 +80,7 @@ public class BootstrapAddonLoader implements BootstrapBaseAddon<BootstrapBaseAdd
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, ClassLoader parent) {
|
||||
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
|
||||
Path bootstrapFolder = addonsFolder.resolve("bootstrap");
|
||||
logger.debug("Loading bootstrap addons from {}", bootstrapFolder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user