Skip to content

Commit

Permalink
Merge pull request #318 from PolyhedralDev/dev/1.19
Browse files Browse the repository at this point in the history
Update to 1.19
  • Loading branch information
dfsek authored Jun 7, 2022
2 parents cec83ae + d0069ff commit 0feae25
Show file tree
Hide file tree
Showing 38 changed files with 556 additions and 720 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
preRelease(true)

versionProjects(":common:api", version("6.0.1"))
versionProjects(":common:implementation", version("6.0.1"))
versionProjects(":platforms", version("6.0.1"))
versionProjects(":common:api", version("6.1.0"))
versionProjects(":common:implementation", version("6.1.0"))
versionProjects(":platforms", version("6.1.0"))


allprojects {
Expand Down
13 changes: 11 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ plugins {
kotlin("jvm") version embeddedKotlinVersion
}

buildscript {
configurations.all {
resolutionStrategy {
force("org.ow2.asm:asm:9.3") // TODO: remove when ShadowJar updates ASM version
force("org.ow2.asm:asm-commons:9.3")
}
}
}

repositories {
mavenCentral()
gradlePluginPortal()
Expand All @@ -11,8 +20,8 @@ repositories {

dependencies {
implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:+")
implementation("org.ow2.asm:asm:9.2")
implementation("org.ow2.asm:asm-tree:9.2")
implementation("org.ow2.asm:asm:9.3")
implementation("org.ow2.asm:asm-tree:9.3")
implementation("com.dfsek.tectonic:common:4.2.0")
implementation("org.yaml:snakeyaml:1.27")
}
46 changes: 25 additions & 21 deletions buildSrc/src/main/kotlin/AddonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import java.io.File
import java.util.function.Predicate
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.extra
import kotlin.streams.asStream

Expand All @@ -12,28 +11,33 @@ import kotlin.streams.asStream
* Configures a directory where addons will be put.
*/
fun Project.addonDir(dir: File, task: Task) {
task.dependsOn("compileAddons")
task.doFirst {
dir.parentFile.mkdirs()
matchingAddons(dir) {
it.name.startsWith("Terra-") // Assume everything that starts with Terra- is a core addon.
}.forEach {
println("Deleting old addon: " + it.absolutePath)
it.delete()
}
forSubProjects(":common:addons") {
val jar = tasks.named("shadowJar").get() as ShadowJar

val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else ""
val target = File(dir, boot + jar.archiveFileName.get())

val base = "${jar.archiveBaseName.get()}-${version}"

println("Copying addon ${jar.archiveFileName.get()} to ${target.absolutePath}. Base name: $base")
val moveAddons = tasks.register("moveAddons" + task.name) {
dependsOn("compileAddons")
doLast {
dir.parentFile.mkdirs()
matchingAddons(dir) {
it.name.startsWith("Terra-") // Assume everything that starts with Terra- is a core addon.
}.forEach {
println("Deleting old addon: " + it.absolutePath)
it.delete()
}
forSubProjects(":common:addons") {
val jar = tasks.named("shadowJar").get() as ShadowJar

val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else ""
val target = File(dir, boot + jar.archiveFileName.get())

val base = "${jar.archiveBaseName.get()}-${version}"

println("Copying addon ${jar.archiveFileName.get()} to ${target.absolutePath}. Base name: $base")

jar.archiveFile.orNull?.asFile?.copyTo(target)
}
}

jar.archiveFile.orNull?.asFile?.copyTo(target)
}
}

task.dependsOn(moveAddons)
}

fun matchingAddons(dir: File, matcher: Predicate<File>): Set<File> {
Expand Down
8 changes: 5 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ object Versions {

object Fabric {
const val fabricLoader = "0.14.2"
const val fabricAPI = "0.53.4+1.18.2"
const val minecraft = "1.18.2"
const val yarn = "$minecraft+build.3"
const val fabricAPI = "0.55.1+1.19"
const val minecraft = "1.19"
const val yarn = "$minecraft+build.1"
const val permissionsAPI = "0.1-SNAPSHOT"
const val mixin = "0.11.2+mixin.0.8.5"
const val loom = "0.11-SNAPSHOT"
}

object Bukkit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,6 @@

import com.dfsek.tectonic.api.TypeRegistry;

import com.dfsek.terra.api.util.generic.pair.Pair;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileOutputStream;
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.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.dfsek.terra.addon.BootstrapAddonLoader;
import com.dfsek.terra.addon.DependencySorter;
import com.dfsek.terra.addon.EphemeralAddon;
Expand All @@ -64,6 +37,7 @@
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.Registry;
import com.dfsek.terra.api.registry.key.StringIdentifiable;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.api.util.mutable.MutableBoolean;
import com.dfsek.terra.api.util.reflection.TypeKey;
import com.dfsek.terra.config.GenericLoaders;
Expand All @@ -75,6 +49,21 @@
import com.dfsek.terra.registry.OpenRegistryImpl;
import com.dfsek.terra.registry.master.ConfigRegistry;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;


/**
* Skeleton implementation of {@link Platform}
Expand Down Expand Up @@ -119,8 +108,10 @@ protected void load() {
logger.info("Initializing Terra...");

try(InputStream stream = getClass().getResourceAsStream("/config.yml")) {
logger.info("Loading config.yml");
File configFile = new File(getDataFolder(), "config.yml");
if(!configFile.exists()) {
logger.info("Writing new config.yml...");
FileUtils.copyInputStreamToFile(stream, configFile);
}
} catch(IOException e) {
Expand Down Expand Up @@ -222,6 +213,7 @@ protected void dumpResources() {
Path data = getDataFolder().toPath();

Path addonsPath = data.resolve("addons");
Files.createDirectories(addonsPath);
Set<Pair<Path, String>> paths = Files
.walk(addonsPath)
.map(path -> Pair.of(path, data.relativize(path).toString()))
Expand Down Expand Up @@ -249,7 +241,6 @@ protected void dumpResources() {
.collect(Collectors.toSet());


// Terra-aaa-aaa-1.2.3-BETA+1e6af8923d.jar
String resourceYaml = IOUtils.toString(resourcesConfig, StandardCharsets.UTF_8);
Map<String, List<String>> resources = new Yaml().load(resourceYaml);
resources.forEach((dir, entries) -> entries.forEach(entry -> {
Expand All @@ -258,42 +249,44 @@ protected void dumpResources() {
if(resource.exists())
return; // dont overwrite

paths
.stream()
.filter(Pair.testRight(resourcePath::startsWith))
.forEach(Pair.consumeLeft(path -> {
logger.info("Removing outdated resource {}, replacing with {}", path, resourcePath);
try {
Files.delete(path);
} catch(IOException e) {
throw new UncheckedIOException(e);
}
}));

if(pathsNoMajor
.stream()
.anyMatch(resourcePath::startsWith) && // if any share name
paths
.stream()
.map(Pair.unwrapRight())
.noneMatch(resourcePath::startsWith)) { // but dont share major version
logger.warn(
"Addon {} has a new major version available. It will not be automatically updated; you will need to ensure " +
"compatibility and update manually.",
resourcePath);
}

logger.info("Dumping resource {}...", resource.getAbsolutePath());
try {
try(InputStream is = getClass().getResourceAsStream("/" + resourcePath)) {
if(is == null) {
logger.error("Resource {} doesn't exist on the classpath!", resourcePath);
return;
}

paths
.stream()
.filter(Pair.testRight(resourcePath::startsWith))
.forEach(Pair.consumeLeft(path -> {
logger.info("Removing outdated resource {}, replacing with {}", path, resourcePath);
try {
Files.delete(path);
} catch(IOException e) {
throw new UncheckedIOException(e);
}
}));

if(pathsNoMajor
.stream()
.anyMatch(resourcePath::startsWith) && // if any share name
paths
.stream()
.map(Pair.unwrapRight())
.noneMatch(resourcePath::startsWith)) { // but dont share major version
logger.warn(
"Addon {} has a new major version available. It will not be automatically updated; you will need to " +
"ensure " +
"compatibility and update manually.",
resourcePath);
}

logger.info("Dumping resource {}...", resource.getAbsolutePath());
resource.getParentFile().mkdirs();
resource.createNewFile();
} catch(IOException e) {
throw new UncheckedIOException(e);
}
logger.debug("Copying resource {}", resourcePath);
try(InputStream is = getClass().getResourceAsStream("/" + resourcePath);
OutputStream os = new FileOutputStream(resource)) {
IOUtils.copy(is, os);
try(OutputStream os = new FileOutputStream(resource)) {
IOUtils.copy(is, os);
}
} catch(IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,24 @@ private BootstrapBaseAddon<?> loadAddon(Path addonPath, BootstrapAddonClassLoade
}

} catch(IOException e) {
throw new UncheckedIOException(e);
throw new AddonLoadException("Failed to load addon from path " + addonPath, e);
}
}

@Override
public Iterable<BootstrapBaseAddon<?>> loadAddons(Path addonsFolder, BootstrapAddonClassLoader parent) {
Path bootstrapFolder = addonsFolder.resolve("bootstrap");
logger.debug("Loading bootstrap addons from {}", bootstrapFolder);

try(Stream<Path> bootstrapAddons = Files.walk(bootstrapFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
return bootstrapAddons.filter(path -> path.toFile().isFile())
.filter(path -> path.toFile().canRead())
.filter(path -> path.toString().endsWith(".jar"))
.map(path -> loadAddon(path, parent))
.collect(Collectors.toList());
try {
Path bootstrapFolder = addonsFolder.resolve("bootstrap");
Files.createDirectories(bootstrapFolder);
logger.debug("Loading bootstrap addons from {}", bootstrapFolder);

try(Stream<Path> bootstrapAddons = Files.walk(bootstrapFolder, 1, FileVisitOption.FOLLOW_LINKS)) {
return bootstrapAddons.filter(path -> path.toFile().isFile())
.filter(path -> path.toFile().canRead())
.filter(path -> path.toString().endsWith(".jar"))
.map(path -> loadAddon(path, parent))
.collect(Collectors.toList());
}
} catch(IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
12 changes: 8 additions & 4 deletions platforms/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import com.modrinth.minotaur.TaskModrinthUpload
import net.fabricmc.loom.task.RemapJarTask

plugins {
id("fabric-loom").version("0.11-SNAPSHOT")
id("fabric-loom").version(Versions.Fabric.loom)
id("com.modrinth.minotaur").version("1.1.0")
}

Expand All @@ -15,7 +15,7 @@ dependencies {

modImplementation("net.fabricmc:fabric-loader:${Versions.Fabric.fabricLoader}")

setOf("fabric-command-api-v1", "fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base").forEach { apiModule ->
setOf("fabric-lifecycle-events-v1", "fabric-resource-loader-v0", "fabric-api-base").forEach { apiModule ->
val module = fabricApi.module(apiModule, Versions.Fabric.fabricAPI)
modImplementation(module)
include(module)
Expand All @@ -24,8 +24,12 @@ dependencies {
include(modImplementation("me.lucko", "fabric-permissions-api", Versions.Fabric.permissionsAPI))
include("me.lucko", "fabric-permissions-api", Versions.Fabric.permissionsAPI)

include(modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud))
include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud)
"compileOnly"("net.fabricmc:sponge-mixin:${Versions.Fabric.mixin}")
"annotationProcessor"("net.fabricmc:sponge-mixin:${Versions.Fabric.mixin}")
"annotationProcessor"("net.fabricmc:fabric-loom:${Versions.Fabric.loom}")

//include(modImplementation("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud))
//include("cloud.commandframework", "cloud-fabric", Versions.Libraries.cloud)
}

loom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@

package com.dfsek.terra.fabric;

import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.WorldPresets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
import com.dfsek.terra.fabric.data.Codecs;


Expand All @@ -49,7 +45,7 @@ public static void register() { // register the things
@Override
public void onInitialize() {
logger.info("Initializing Terra Fabric mod...");

/*
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
CommandExecutionCoordinator.simpleCoordinator(),
serverCommandSource -> (CommandSender) serverCommandSource,
Expand All @@ -60,5 +56,7 @@ public void onInitialize() {
manager.brigadierManager().setNativeNumberSuggestions(false);
TERRA_PLUGIN.getEventManager().callEvent(new CommandRegistrationEvent(manager));
TODO: re-enable when Cloud updates
*/
}
}
Loading

0 comments on commit 0feae25

Please sign in to comment.