Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking all] Gestalt v7 re-integration.... #4144

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a945a02
feature(reintegrate-gestaltv7): bump up gestalt dependencies version.…
DarkWeird Sep 7, 2020
d1cce0c
feature(reintegrate-gestaltv7): Fix all source code problems
DarkWeird Sep 7, 2020
3e7612d
feature(reintegrate-gestaltv7): Update gson.
DarkWeird Sep 7, 2020
89ff068
feature(reintegrate-gestaltv7): fix engine-tests
DarkWeird Sep 7, 2020
3ad747e
feature(gestaltv7): Restore Colorc in CanvasRenderers
DarkWeird Sep 7, 2020
eef934f
feature(reintegrate-gestaltv7): replace ShrinkWrapSystem with defalut…
DarkWeird Sep 8, 2020
0b0aaac
feature(reintegrate-gestaltv7): move engine to package `org.terasolo…
DarkWeird Sep 9, 2020
3602e53
feature(reintegrate-gestaltv7): fix packageNames for runConfigs. (ma…
DarkWeird Sep 9, 2020
9176592
feature(reintegrate-gestaltv7): move reflection in engine package
DarkWeird Sep 10, 2020
45b643d
feature(reintegrate-gestaltv7): move reflection package to engine pa…
DarkWeird Sep 10, 2020
3e3faaf
feature(reintegrate-gestaltv7): add reload handling on EnvironmentSw…
DarkWeird Sep 10, 2020
b95028b
feature(reintegrate-gestaltv7): migrate ui types from engine to nui(…
DarkWeird Sep 10, 2020
fec847a
feature(reintegrate-gestaltv7): update guava lib version
DarkWeird Sep 10, 2020
5646321
feature(reintegrate-gestaltv7): add gestalt's classes to whitelist a…
DarkWeird Sep 10, 2020
46b97c6
feature(reintegrate-gestaltv7): Fix emptymodules on return to main menu
DarkWeird Sep 11, 2020
15501d9
feature(reintegrate-gestaltv7): Fix tests
DarkWeird Sep 11, 2020
938d29e
feature(reintegrate-gestaltv7): Fix MTE tests
DarkWeird Sep 15, 2020
cc5236d
feature(reintegrate-gestaltv7): cleanup build.gradle
DarkWeird Sep 15, 2020
685c96c
feature(reintegrate-gestaltv7): cleanup and check gestalt related TODOs
DarkWeird Sep 15, 2020
66deb05
feature(reintegrate-gestaltv7): fix module downloading.
DarkWeird Sep 15, 2020
f987e3b
Merge remote-tracking branch 'origin/develop' into feature/gestalt-v7
DarkWeird Sep 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ if (project.name == "ModuleTestingEnvironment") {
implementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
implementation("org.mockito:mockito-junit-jupiter:3.2.0")
implementation("junit:junit:4.12")
//TODO: Remove shrinkwrap from code, you have FileSystem in java 8
implementation("org.jboss.shrinkwrap:shrinkwrap-depchain-java7:1.2.1")
}
}

Expand Down
4 changes: 4 additions & 0 deletions config/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ repositories {
url "http://maven.snplow.com/releases"
allowInsecureProtocol true // 😱
}
google()
maven {
url 'https://heisluft.tk/maven'
}
}

dependencies {
Expand Down
3 changes: 0 additions & 3 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")

implementation group: 'junit', name: 'junit', version: '4.12'

//TODO: Remove shrinkwrap from code, you have FileSystem in java 8
implementation group: 'org.jboss.shrinkwrap', name: 'shrinkwrap-depchain-java7', version: '1.2.1'
}

task copyResourcesToClasses(type:Copy) {
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/main/java/org/terasology/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.assets.management.AssetManager;
import org.terasology.context.Context;
import org.terasology.context.internal.ContextImpl;
import org.terasology.naming.Name;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.gestalt.naming.Name;
import org.terasology.recording.RecordAndReplayCurrentStatus;
import org.terasology.registry.CoreRegistry;

Expand Down
115 changes: 62 additions & 53 deletions engine-tests/src/main/java/org/terasology/HeadlessEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
*/
package org.terasology;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.assets.management.AssetManager;
import org.terasology.assets.module.ModuleAwareAssetTypeManager;
import org.terasology.audio.AudioManager;
import org.terasology.audio.StaticSound;
import org.terasology.audio.StreamingSound;
Expand All @@ -46,12 +41,16 @@
import org.terasology.entitySystem.entity.internal.EngineEntityManager;
import org.terasology.entitySystem.prefab.Prefab;
import org.terasology.entitySystem.prefab.internal.PojoPrefab;
import org.terasology.gestalt.assets.AssetType;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager;
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.ModuleRegistry;
import org.terasology.gestalt.module.dependencyresolution.DependencyResolver;
import org.terasology.gestalt.module.dependencyresolution.ResolutionResult;
import org.terasology.gestalt.naming.Name;
import org.terasology.logic.behavior.asset.BehaviorTree;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ModuleEnvironment;
import org.terasology.module.ModuleRegistry;
import org.terasology.module.ResolutionResult;
import org.terasology.naming.Name;
import org.terasology.network.NetworkSystem;
import org.terasology.network.internal.NetworkSystemImpl;
import org.terasology.nui.asset.UIElement;
Expand Down Expand Up @@ -79,6 +78,7 @@
import org.terasology.rendering.assets.skeletalmesh.SkeletalMesh;
import org.terasology.rendering.assets.texture.PNGTextureFormat;
import org.terasology.rendering.assets.texture.Texture;
import org.terasology.rendering.assets.texture.TextureData;
import org.terasology.rendering.assets.texture.subtexture.Subtexture;
import org.terasology.testUtil.ModuleManagerFactory;
import org.terasology.world.WorldProvider;
Expand All @@ -88,6 +88,7 @@
import org.terasology.world.block.family.BlockFamilyLibrary;
import org.terasology.world.block.internal.BlockManagerImpl;
import org.terasology.world.block.loader.BlockFamilyDefinition;
import org.terasology.world.block.loader.BlockFamilyDefinitionData;
import org.terasology.world.block.loader.BlockFamilyDefinitionFormat;
import org.terasology.world.block.shapes.BlockShape;
import org.terasology.world.block.shapes.BlockShapeImpl;
Expand All @@ -106,16 +107,16 @@
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* Setup a headless ( = no graphics ) environment.
* Based on TerasologyTestingEnvironment code.
*
* Setup a headless ( = no graphics ) environment. Based on TerasologyTestingEnvironment code.
*/
public class HeadlessEnvironment extends Environment {

Expand All @@ -142,12 +143,13 @@ protected void setupStorageManager() throws IOException {
RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);

ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment,context));
context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment, context));

ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);

context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(),
engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils,
recordAndReplayCurrentStatus));
}

@Override
Expand All @@ -167,7 +169,8 @@ protected void setupEntitySystem() {
protected void setupCollisionManager() {
CollisionGroupManager collisionGroupManager = new CollisionGroupManager();
context.put(CollisionGroupManager.class, collisionGroupManager);
context.get(TypeHandlerLibrary.class).addTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler(collisionGroupManager));
context.get(TypeHandlerLibrary.class).addTypeHandler(CollisionGroup.class,
new CollisionGroupTypeHandler(collisionGroupManager));
}

@Override
Expand All @@ -179,15 +182,15 @@ protected void setupBlockManager(AssetManager assetManager) {
typeHandlerLibrary.addTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
typeHandlerLibrary.addTypeHandler(Block.class, new BlockTypeHandler(blockManager));
}

@Override
protected void setupExtraDataManager(Context context) {
context.put(ExtraBlockDataManager.class, new ExtraBlockDataManager(context));
}

@Override
protected AssetManager setupEmptyAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());

context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
Expand All @@ -197,55 +200,59 @@ protected AssetManager setupEmptyAssetManager() {

@Override
protected AssetManager setupAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();

// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.registerCoreAssetType(Prefab.class,
PojoPrefab::new, false, "prefabs");
assetTypeManager.registerCoreAssetType(BlockShape.class,
assetTypeManager.createAssetType(Prefab.class,
PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class,
BlockShapeImpl::new, "shapes");
assetTypeManager.registerCoreAssetType(BlockSounds.class,
assetTypeManager.createAssetType(BlockSounds.class,
BlockSounds::new, "blockSounds");
assetTypeManager.registerCoreAssetType(BlockTile.class,
assetTypeManager.createAssetType(BlockTile.class,
BlockTile::new, "blockTiles");
assetTypeManager.registerCoreAssetType(BlockFamilyDefinition.class,
BlockFamilyDefinition::new, "blocks");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType =
assetTypeManager.createAssetType(BlockFamilyDefinition.class,
BlockFamilyDefinition::new, "blocks");

assetTypeManager.registerCoreAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.registerCoreAssetType(StreamingSound.class, NullStreamingSound::new, "music");

assetTypeManager.registerCoreFormat(BlockFamilyDefinition.class,
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(
new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));

assetTypeManager.registerCoreAssetType(UISkin.class,

assetTypeManager.createAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.createAssetType(StreamingSound.class, NullStreamingSound::new, "music");

assetTypeManager.createAssetType(UISkin.class,
UISkin::new, "skins");
assetTypeManager.registerCoreAssetType(BehaviorTree.class,
BehaviorTree::new, false, "behaviors");
assetTypeManager.registerCoreAssetType(UIElement.class,
assetTypeManager.createAssetType(BehaviorTree.class,
BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class,
UIElement::new, "ui");
assetTypeManager.registerCoreAssetType(Font.class,
assetTypeManager.createAssetType(Font.class,
FontImpl::new, "fonts");
assetTypeManager.registerCoreAssetType(Texture.class,
HeadlessTexture::new, "textures", "fonts");
assetTypeManager.registerCoreFormat(Texture.class,
new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getName(2).toString().equals("textures")));
assetTypeManager.registerCoreFormat(Texture.class,
new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getName(2).toString().equals("fonts")));

assetTypeManager.registerCoreAssetType(Shader.class,
AssetType<Texture, TextureData> textureDataAssetType = assetTypeManager.createAssetType(Texture.class,
HeadlessTexture::create, "textures", "fonts");
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(
new PNGTextureFormat(Texture.FilterMode.NEAREST,
path -> path.getPath().get(1).equals("textures")));
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(
new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getPath().get(1).equals("fonts")));

assetTypeManager.createAssetType(Shader.class,
HeadlessShader::new, "shaders");
assetTypeManager.registerCoreAssetType(Material.class,
assetTypeManager.createAssetType(Material.class,
HeadlessMaterial::new, "materials");
assetTypeManager.registerCoreAssetType(Mesh.class,
assetTypeManager.createAssetType(Mesh.class,
HeadlessMesh::new, "mesh");
assetTypeManager.registerCoreAssetType(SkeletalMesh.class,
assetTypeManager.createAssetType(SkeletalMesh.class,
HeadlessSkeletalMesh::new, "skeletalMesh");
assetTypeManager.registerCoreAssetType(MeshAnimation.class,
assetTypeManager.createAssetType(MeshAnimation.class,
MeshAnimationImpl::new, "animations");

assetTypeManager.registerCoreAssetType(Atlas.class,
assetTypeManager.createAssetType(Atlas.class,
Atlas::new, "atlas");
assetTypeManager.registerCoreAssetType(Subtexture.class,
assetTypeManager.createAssetType(Subtexture.class,
Subtexture::new);

assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
Expand All @@ -271,7 +278,8 @@ protected void setupConfig() {
@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
TypeRegistry typeRegistry = new TypeRegistry();
TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
TypeRegistry.WHITELISTED_CLASSES =
ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
context.put(TypeRegistry.class, typeRegistry);

ModuleManager moduleManager = ModuleManagerFactory.create();
Expand All @@ -298,9 +306,10 @@ protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
*/
@Override
protected void setupPathManager() throws IOException {
final JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
final FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(vfs.getPath(""));
PathManager.getInstance().useOverrideHomePath(
Paths.get(System.getProperty("java.io.tmpdir"),
"terasology",
UUID.randomUUID().toString()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/
package org.terasology;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.BeforeEach;
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.paths.PathManager;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ModuleEnvironment;
import org.terasology.module.ResolutionResult;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.dependencyresolution.DependencyResolver;
import org.terasology.gestalt.module.dependencyresolution.ResolutionResult;
import org.terasology.reflection.TypeRegistry;
import org.terasology.testUtil.ModuleManagerFactory;

import java.nio.file.FileSystem;
import java.nio.file.Paths;
import java.util.UUID;

import static org.junit.jupiter.api.Assumptions.assumeTrue;

Expand All @@ -37,9 +36,10 @@ public abstract class ModuleEnvironmentTest {

@BeforeEach
public void before() throws Exception {
final JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
final FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(vfs.getPath(""));
PathManager.getInstance().useOverrideHomePath(
Paths.get(System.getProperty("java.io.tmpdir"),
"terasology",
UUID.randomUUID().toString()));

moduleManager = ModuleManagerFactory.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.terasology;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.nio.file.ShrinkWrapFileSystems;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -32,9 +29,9 @@
import org.terasology.engine.paths.PathManager;
import org.terasology.entitySystem.entity.internal.EngineEntityManager;
import org.terasology.game.Game;
import org.terasology.gestalt.naming.Name;
import org.terasology.logic.console.Console;
import org.terasology.logic.console.ConsoleImpl;
import org.terasology.naming.Name;
import org.terasology.network.NetworkSystem;
import org.terasology.network.internal.NetworkSystemImpl;
import org.terasology.persistence.StorageManager;
Expand All @@ -49,8 +46,9 @@
import org.terasology.world.block.BlockManager;
import org.terasology.world.chunks.blockdata.ExtraBlockDataManager;

import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.mockito.Mockito.mock;

Expand All @@ -70,9 +68,9 @@ public abstract class TerasologyTestingEnvironment {

@BeforeAll
public static void setupEnvironment() throws Exception {
final JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
final FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(vfs.getPath(""));
Path systemTempDir= Paths.get(System.getProperty("java.io.tmpdir"));
Path tempDirectory = Files.createTempDirectory(systemTempDir, "terasologyTTE");
PathManager.getInstance().useOverrideHomePath(tempDirectory);
/*
* Create at least for each class a new headless environemnt as it is fast and prevents side effects
* (Reusing a headless environment after other tests have modified the core registry isn't really clean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.terasology;

import org.terasology.naming.Name;
import org.terasology.gestalt.naming.Name;
import org.terasology.registry.CoreRegistry;
import org.terasology.world.BlockEntityRegistry;
import org.terasology.world.WorldProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import org.terasology.engine.TerasologyConstants;
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.module.ModuleManagerImpl;
import org.terasology.module.ClasspathModule;
import org.terasology.module.ModuleMetadata;
import org.terasology.module.ModuleMetadataReader;
import org.terasology.naming.Name;
import org.terasology.gestalt.module.ModuleMetadata;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleMetadataJsonAdapter;
import org.terasology.gestalt.naming.Name;

import java.io.File;
import java.io.InputStreamReader;
import java.io.Reader;

Expand All @@ -36,8 +37,10 @@ private ModuleManagerFactory() {
public static ModuleManager create() throws Exception {
ModuleManager moduleManager = new ModuleManagerImpl("");
try (Reader reader = new InputStreamReader(ModuleManagerFactory.class.getResourceAsStream("/module.txt"), TerasologyConstants.CHARSET)) {
ModuleMetadata metadata = new ModuleMetadataReader().read(reader);
moduleManager.getRegistry().add(ClasspathModule.create(metadata, ModuleManagerFactory.class));
ModuleMetadata metadata = new ModuleMetadataJsonAdapter().read(reader);
Module unittestModule = moduleManager.getModuleFactory().createModule(metadata,
new File(ModuleManagerFactory.class.getResource("/").getFile())); // some hack to load current directory. TODO: moving to package module
moduleManager.getRegistry().add(unittestModule);
}
moduleManager.loadEnvironment(Sets.newHashSet(moduleManager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
return moduleManager;
Expand Down