Compare commits

...

7 Commits

Author SHA1 Message Date
dfsek 90a48345c2 automatically update addons when minor & patch versions are changed 2022-06-07 00:39:05 -07:00
dfsek 7c00cad4c9 add Pair function API 2022-06-07 00:38:09 -07:00
dfsek 5d703327db bump versions 2022-06-04 15:11:59 -07:00
dfsek 136ceddff5 getOrDefault with empty list 2022-06-04 14:27:48 -07:00
dfsek c1dc637eb2 fix run task addon dependency 2022-06-02 22:05:24 -07:00
dfsek a5db29f2ad fix TerraScript EqualsStatement 2022-06-02 22:04:52 -07:00
dfsek 20e6b8bb63 promote terrascript log function to info level 2022-06-02 22:03:36 -07:00
9 changed files with 130 additions and 17 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
preRelease(true)
versionProjects(":common:api", version("6.0.0"))
versionProjects(":common:implementation", version("6.0.0"))
versionProjects(":platforms", version("6.0.0"))
versionProjects(":common:api", version("6.0.1"))
versionProjects(":common:implementation", version("6.0.1"))
versionProjects(":platforms", version("6.0.1"))
allprojects {
+1
View File
@@ -12,6 +12,7 @@ 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) {
+15 -8
View File
@@ -7,16 +7,19 @@ import java.nio.file.Files
import java.nio.file.StandardCopyOption
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
fun Project.configureDistribution() {
apply(plugin = "com.github.johnrengelman.shadow")
@@ -29,13 +32,17 @@ fun Project.configureDistribution() {
}
}
val installAddons = tasks.create("installAddons") {
group = "terra"
val compileAddons = tasks.create("compileAddons") {
forSubProjects(":common:addons") {
afterEvaluate {
dependsOn(getJarTask())
}
}
}
val installAddons = tasks.create("installAddons") {
group = "terra"
dependsOn(compileAddons)
doLast {
// https://github.com/johnrengelman/shadow/issues/111
@@ -44,18 +51,18 @@ fun Project.configureDistribution() {
FileSystems.newFileSystem(dest, mapOf("create" to "false"), null).use { fs ->
forSubProjects(":common:addons") {
val jar = getJarTask()
println("Packaging addon ${jar.archiveFileName.get()} to $dest. size: ${jar.archiveFile.get().asFile.length() / 1024}KB")
val boot = if (extra.has("bootstrap") && extra.get("bootstrap") as Boolean) "bootstrap/" else ""
val addonPath = fs.getPath("/addons/$boot${jar.archiveFileName.get()}");
if(!Files.exists(addonPath)) {
if (!Files.exists(addonPath)) {
Files.createDirectories(addonPath.parent)
Files.createFile(addonPath)
Files.copy(jar.archiveFile.get().asFile.toPath(), addonPath, StandardCopyOption.REPLACE_EXISTING)
}
}
}
}
@@ -120,7 +127,7 @@ fun Project.configureDistribution() {
relocate("com.dfsek.paralithic", "com.dfsek.terra.lib.paralithic")
relocate("org.json", "com.dfsek.terra.lib.json")
relocate("org.yaml", "com.dfsek.terra.lib.yaml")
finalizedBy(installAddons)
}
@@ -1,6 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
version = version("1.0.0")
version = version("1.0.1")
dependencies {
api("commons-io:commons-io:2.7")
@@ -32,7 +32,7 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
}
return left.equals(rightUnwrapped);
return leftUnwrapped.equals(rightUnwrapped);
}
@@ -99,7 +99,7 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
.registerFunction("rotationDegrees", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().getDegrees(),
Returnable.ReturnType.NUMBER))
.registerFunction("print",
new UnaryStringFunctionBuilder(string -> LOGGER.debug("[TerraScript:{}] {}", id, string)))
new UnaryStringFunctionBuilder(string -> LOGGER.info("[TerraScript:{}] {}", id, string)))
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> FastMath.pow2(number.doubleValue())))
.registerFunction("pow", new BinaryNumberFunctionBuilder(
@@ -11,6 +11,10 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
public final class Pair<L, R> {
@@ -18,6 +22,38 @@ public final class Pair<L, R> {
private final L left;
private final R right;
public static <L, R, T> Function<Pair<L, R>, Pair<T, R>> mapLeft(Function<L, T> function) {
return pair -> of(function.apply(pair.left), pair.right);
}
public static <L, R, T> Function<Pair<L, R>, Pair<L, T>> mapRight(Function<R, T> function) {
return pair -> of(pair.left, function.apply(pair.right));
}
public static <L> Predicate<Pair<L, ?>> testLeft(Predicate<L> predicate) {
return pair -> predicate.test(pair.left);
}
public static <R> Predicate<Pair<?, R>> testRight(Predicate<R> predicate) {
return pair -> predicate.test(pair.right);
}
public static <L> Consumer<Pair<L, ?>> consumeLeft(Consumer<L> consumer) {
return pair -> consumer.accept(pair.left);
}
public static <R> Consumer<Pair<?, R>> consumeRight(Consumer<R> consumer) {
return pair -> consumer.accept(pair.right);
}
public static <R> Function<Pair<?, R>, R> unwrapRight() {
return pair -> pair.right;
}
public static <L> Function<Pair<L, ?>, L> unwrapLeft() {
return pair -> pair.left;
}
private Pair(L left, R right) {
this.left = left;
this.right = right;
@@ -108,4 +144,9 @@ public final class Pair<L, R> {
return Objects.equals(this.left, that.left) && Objects.equals(this.right, that.right);
}
}
@Override
public String toString() {
return String.format("{%s,%s}", left, right);
}
}
@@ -18,6 +18,9 @@
package com.dfsek.terra;
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;
@@ -33,12 +36,15 @@ 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;
@@ -212,13 +218,71 @@ public abstract class AbstractPlatform implements Platform {
logger.info("No resources config found. Skipping resource dumping.");
return;
}
Path data = getDataFolder().toPath();
Path addonsPath = data.resolve("addons");
Set<Pair<Path, String>> paths = Files
.walk(addonsPath)
.map(path -> Pair.of(path, data.relativize(path).toString()))
.map(Pair.mapRight(s -> {
if(s.contains("+")) { // remove commit hash
return s.substring(0, s.lastIndexOf('+'));
}
return s;
}))
.filter(Pair.testRight(s -> s.contains("."))) // remove patch version
.map(Pair.mapRight(s -> s.substring(0, s.lastIndexOf('.'))))
.filter(Pair.testRight(s -> s.contains("."))) // remove minor version
.map(Pair.mapRight(s -> s.substring(0, s.lastIndexOf('.'))))
.collect(Collectors.toSet());
Set<String> pathsNoMajor = paths
.stream()
.filter(Pair.testRight(s -> s.contains(".")))
.map(Pair.mapRight(s -> s.substring(0, s.lastIndexOf('.')))) // remove major version
.map(Pair.unwrapRight())
.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 -> {
String resourcePath = String.format("%s/%s", dir, entry);
String resourcePath = dir + File.separatorChar + entry;
File resource = new File(getDataFolder(), resourcePath);
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 {
resource.getParentFile().mkdirs();
@@ -54,7 +54,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
private final long seed;
private final Map<ConcentricRingsStructurePlacement, Lazy<List<ChunkCoordIntPair>>> h = new Object2ObjectArrayMap<>();
private static final Lazy<List<ChunkCoordIntPair>> EMPTY = Lazy.lazy(List::of);
public NMSChunkGeneratorDelegate(ChunkGenerator vanilla, ConfigPack pack, NMSBiomeProvider biomeProvider, long seed) {
@@ -154,7 +154,7 @@ public class NMSChunkGeneratorDelegate extends ChunkGenerator {
@Override
public List<ChunkCoordIntPair> a(ConcentricRingsStructurePlacement concentricringsstructureplacement) {
this.i();
return this.h.get(concentricringsstructureplacement).value();
return this.h.getOrDefault(concentricringsstructureplacement, EMPTY).value();
}
private volatile boolean rings = false;