Skip to content

Commit

Permalink
feat: upgrade to Gestalt 8 (#5267)
Browse files Browse the repository at this point in the history
* feat: upgrade to Gestalt 8
* fix: fix failing serialisation tests due to gestalt 8 changes
  • Loading branch information
BenjaminAmos authored Jul 29, 2024
1 parent 07a4555 commit 7f47891
Show file tree
Hide file tree
Showing 305 changed files with 442 additions and 312 deletions.
2 changes: 1 addition & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
implementation("org.jgrapht:jgrapht-core:1.5.0")

// for inspecting modules
implementation("org.terasology.gestalt:gestalt-module:7.2.0")
implementation("org.terasology.gestalt:gestalt-module:8.0.0-SNAPSHOT")

// plugins we configure
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.2.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ModuleMetadataForGradle(private val moduleConfig: ModuleMetadata) {
}

private fun versionStringFromGestaltDependency(gestaltDependency: DependencyInfo): String {
val version = if (gestaltDependency.versionPredicate() is VersionRange) {
gestaltDependency.versionPredicate().toString()
val version = if (gestaltDependency.versionRange() is VersionRange) {
gestaltDependency.versionRange().toString()
} else {
// TODO: gradle-compatible version expressions for gestalt dependencies
// https://github.com/MovingBlocks/gestalt/issues/114
Expand Down
13 changes: 12 additions & 1 deletion build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ dependencies {
implementation(group = "org.terasology.engine", name = "engine", version = moduleMetadata.engineVersion())
testImplementation(group = "org.terasology.engine", name = "engine-tests", version = moduleMetadata.engineVersion())

annotationProcessor("org.terasology.gestalt:gestalt-inject-java:8.0.0-SNAPSHOT")

for ((gradleDep, optional) in moduleMetadata.moduleDependencies()) {
if (optional) {
// `optional` module dependencies are ones it does not require for runtime
Expand Down Expand Up @@ -144,8 +146,17 @@ tasks.named("processResources") {
dependsOn("syncAssets", "syncOverrides", "syncDeltas", "syncModuleInfo")
}

tasks.named("compileJava") {
tasks.named<JavaCompile>("compileJava") {
dependsOn("processResources")
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.main.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.main.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}
tasks.named<JavaCompile>("compileTestJava") {
dependsOn("processResources")
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.test.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.test.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}

tasks.named<Test>("test") {
Expand Down
16 changes: 15 additions & 1 deletion engine-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ dependencies {
implementation("com.google.protobuf:protobuf-java:3.16.1")
implementation("org.terasology:reflections:0.9.12-MB")

implementation("com.github.zafarkhaja:java-semver:0.10.2")

annotationProcessor("org.terasology.gestalt:gestalt-inject-java:8.0.0-SNAPSHOT")
testAnnotationProcessor("org.terasology.gestalt:gestalt-inject-java:8.0.0-SNAPSHOT")

implementation("org.terasology.joml-ext:joml-test:0.1.0")

testImplementation("ch.qos.logback:logback-classic:1.4.14") {
Expand Down Expand Up @@ -91,8 +96,17 @@ tasks.register<Copy>("copyResourcesToClasses") {
into(sourceSets["main"].output.classesDirs.first())
}

tasks.named("compileJava") {
tasks.named<JavaCompile>("compileJava") {
dependsOn("copyResourcesToClasses")
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.main.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.main.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}
tasks.named<JavaCompile>("compileTestJava") {
dependsOn("copyResourcesToClasses")
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.test.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.test.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}

tasks.withType<Jar> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package org.terasology.unittest;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;

@API
public class ExampleClass implements ExampleInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package org.terasology.unittest;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
import org.terasology.context.annotation.IndexInherited;

@API
@IndexInherited
public interface ExampleInterface {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
@API
package org.terasology.unittest.stubs;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
@API
package org.terasology.unittest.worlds;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.testUtil.ModuleManagerFactory;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;

import java.net.URL;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.testUtil.ModuleManagerFactory;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.junit.jupiter.api.Test;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleMetadata;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
import org.terasology.gestalt.naming.Name;
import org.terasology.gestalt.naming.Version;
import org.terasology.unittest.ExampleClass;
Expand Down Expand Up @@ -56,9 +56,13 @@ public void directoryModuleContainsClass() {
public void archiveModuleContainsClass() throws IOException {
Module module = factory.createArchiveModule(new File("FIXME.jar"));

Class<?> someClassInTheModule = module.getModuleManifest().getTypesAnnotatedWith(API.class).iterator().next();
String someClassInTheModule = module.getClassIndex().getTypesAnnotatedWith(API.class.getName()).iterator().next();

assertTrue(module.getClassPredicate().test(someClassInTheModule));
try {
assertTrue(module.getClassPredicate().test(Class.forName(someClassInTheModule)));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
assertFalse(module.getClassPredicate().test(SOME_CLASS_OUTSIDE_THE_MODULE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.reflections.Reflections;
import org.terasology.engine.core.TerasologyConstants;
import org.terasology.gestalt.di.index.CompoundClassIndex;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleMetadata;
import org.terasology.gestalt.module.ModuleRegistry;
Expand Down Expand Up @@ -86,7 +86,7 @@ private Module buildSimpleModule(String id, String version) {
if (version != null) {
metadata.setVersion(new Version(version));
}
return new Module(metadata, new EmptyFileSource(), Collections.emptyList(), new Reflections(), (c) -> false);
return new Module(metadata, new EmptyFileSource(), Collections.emptyList(), new CompoundClassIndex(), (c) -> false);
}
private Module buildEngineModule(String version) {
return buildSimpleModule(TerasologyConstants.ENGINE_MODULE.toString(), version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.junit.jupiter.MockitoExtension;
import org.reflections.Reflections;
import org.terasology.engine.config.flexible.AutoConfig;
import org.terasology.engine.core.PathManager;
import org.terasology.engine.core.PathManagerProvider;
import org.terasology.engine.core.subsystem.EngineSubsystem;
import org.terasology.engine.logic.permission.PermissionSetComponent;
import org.terasology.engine.world.block.structure.AttachSupportRequiredComponent;
import org.terasology.gestalt.di.index.CompoundClassIndex;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.ModuleMetadata;
Expand Down Expand Up @@ -59,7 +59,7 @@ private Module getEmptyTestModule() {
new ModuleMetadata(new Name("EmptyTestModule"), new Version("0.0.1")),
new EmptyFileSource(),
Collections.emptyList(),
new Reflections(),
new CompoundClassIndex(),
(clazz) -> false
);
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public void engineModuleContainsSubsystems() {
environment = manager.getEnvironment();
engineModule = environment.get(ENGINE_MODULE);

assertThat(engineModule.getModuleManifest().getSubTypesOf(EngineSubsystem.class)).contains(subsystem);
assertThat(engineModule.getClassIndex().getSubtypesOf(EngineSubsystem.class.getName())).contains(subsystem.getName());

assertThat(environment.getSubtypesOf(EngineSubsystem.class)).contains(subsystem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gson.Gson;
import org.joml.Vector3f;
import org.junit.jupiter.api.Test;
import org.terasology.context.annotation.IndexInherited;
import org.terasology.engine.ModuleEnvironmentTest;
import org.terasology.engine.core.TerasologyConstants;
import org.terasology.engine.core.module.ModuleContext;
Expand All @@ -31,7 +32,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.terasology.engine.testUtil.Assertions.assertNotEmpty;

class TypeSerializerTest extends ModuleEnvironmentTest {
public class TypeSerializerTest extends ModuleEnvironmentTest {
private static final SomeClass<Integer> INSTANCE = new SomeClass<>(0xdeadbeef);
private static final String INSTANCE_JSON = "{\"generic-t\":-559038737,\"list\":[50,51,-52,-53]," +
"\"animals\":[{\"class\":\"org.terasology.engine.persistence.serializers.TypeSerializerTest$Dog\"," +
Expand Down Expand Up @@ -155,6 +156,7 @@ public String toString() {
}

@SuppressWarnings("checkstyle:FinalClass")
@IndexInherited
public static class Animal<T> {
public T data;

Expand All @@ -178,6 +180,11 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(data);
}

@Override
public String toString() {
return "Animal(data = " + data.toString() + ")";
}
}

public static final class Dog<T> extends Animal<T> {
Expand Down
34 changes: 26 additions & 8 deletions engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,25 @@ dependencies {
}
implementation("net.logstash.logback:logstash-logback-encoder:7.4")

// JSemVer (Semantic Versioning) - A dependency of Gestalt
implementation("com.github.zafarkhaja:java-semver:0.10.2")

// Our developed libs
api("org.terasology.gestalt:gestalt-asset-core:7.2.1-SNAPSHOT")
api("org.terasology.gestalt:gestalt-module:7.2.1-SNAPSHOT")
api("org.terasology.gestalt:gestalt-entity-system:7.2.1-SNAPSHOT")
api("org.terasology.gestalt:gestalt-util:7.2.1-SNAPSHOT")
api("org.terasology.gestalt:gestalt-asset-core:8.0.0-SNAPSHOT")
api("org.terasology.gestalt:gestalt-module:8.0.0-SNAPSHOT")
api("org.terasology.gestalt:gestalt-entity-system:8.0.0-SNAPSHOT")
api("org.terasology.gestalt:gestalt-util:8.0.0-SNAPSHOT")
api("org.terasology.gestalt:gestalt-inject:8.0.0-SNAPSHOT")

annotationProcessor("org.terasology.gestalt:gestalt-inject-java:8.0.0-SNAPSHOT")

api("org.terasology:TeraMath:1.5.0")
api("org.terasology:splash-screen:1.1.1")
api("org.terasology.jnlua:JNLua:0.1.0-SNAPSHOT")
api("org.terasology.jnbullet:JNBullet:1.0.4")
api("org.terasology.nui:nui:3.0.0")
api("org.terasology.nui:nui-reflect:3.0.0")
api("org.terasology.nui:nui-gestalt7:3.0.0")
api("org.terasology.nui:nui:4.0.0-SNAPSHOT")
api("org.terasology.nui:nui-reflect:4.0.0-SNAPSHOT")
api("org.terasology.nui:nui-gestalt:4.0.0-SNAPSHOT")


// Wildcard dependency to catch any libs provided with the project (remote repo preferred instead)
Expand Down Expand Up @@ -206,11 +212,23 @@ tasks.register<Copy>("copyResourcesToClasses") {
into(sourceSets["main"].output.classesDirs.first())
}

tasks.named("compileJava") {
tasks.named<JavaCompile>("compileJava") {
dependsOn(
tasks.named("copyResourcesToClasses"),
tasks.named("createVersionInfoFile")
)
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.main.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.main.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}
tasks.named<JavaCompile>("compileTestJava") {
dependsOn(
tasks.named("copyResourcesToClasses"),
tasks.named("createVersionInfoFile")
)
// Create an asset list during compilation (needed for Gestalt 8)
inputs.files(sourceSets.test.get().resources.srcDirs)
options.compilerArgs = arrayListOf("-Aresource=${sourceSets.test.get().resources.srcDirs.joinToString(File.pathSeparator)}")
}

// Instructions for packaging a jar file for the engine
Expand Down
3 changes: 2 additions & 1 deletion engine/src/main/java/org/terasology/engine/audio/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public abstract class Sound<T extends AssetData> extends Asset<T> implements org
* @param assetType The asset type this asset belongs to.
*/
protected Sound(ResourceUrn urn, AssetType<?, T> assetType, DisposableResource resource) {
super(urn, assetType, resource);
super(urn, assetType);
setDisposableResource(resource);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
*/
@API package org.terasology.engine.audio.events;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

@API package org.terasology.engine.audio;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.terasology.engine.utilities.gson.SetMultimapTypeAdapter;
import org.terasology.engine.utilities.gson.UriTypeAdapterFactory;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
import org.terasology.gestalt.naming.Name;
import org.terasology.gestalt.naming.Version;
import org.terasology.gestalt.naming.gson.NameTypeAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package org.terasology.engine.config;

import org.terasology.engine.core.subsystem.Resolution;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
import org.terasology.engine.rendering.cameras.PerspectiveCameraSettings;
import org.terasology.engine.rendering.nui.layers.mainMenu.videoSettings.DisplayModeSetting;
import org.terasology.engine.rendering.nui.layers.mainMenu.videoSettings.ScreenshotSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.utilities.subscribables.AbstractSubscribable;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.config.facade;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;

/**
* TelemetryConfiguration is a wrapper for {@link org.terasology.engine.config.TelemetryConfig}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.collect.ImmutableList;
import org.reflections.ReflectionUtils;
import org.terasology.context.annotation.IndexInherited;
import org.terasology.engine.config.flexible.internal.SettingBuilder;
import org.terasology.engine.config.flexible.internal.SettingImplBuilder;
import org.terasology.engine.core.SimpleUri;
Expand All @@ -18,6 +19,7 @@
* Represents a config class that will be automatically initialized and rendered by the engine.
* All settings must be contained in {@code public static} fields of type {@link Setting}.
*/
@IndexInherited
public abstract class AutoConfig {
private SimpleUri id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package org.terasology.engine.config.flexible;

import org.terasology.engine.config.flexible.constraints.SettingConstraint;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
import org.terasology.reflection.TypeInfo;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// SPDX-License-Identifier: Apache-2.0
@API package org.terasology.engine.config.flexible.constraints;

import org.terasology.gestalt.module.sandbox.API;
import org.terasology.context.annotation.API;
Loading

0 comments on commit 7f47891

Please sign in to comment.