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

Overhauled serialization system #3535

Merged
merged 141 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
2df869d
Revert "Revert "Merge PRs #3449 and #3446 by @eviltak - serialization…
Cervator Sep 22, 2018
61db3e1
Rename MappedContainerTypeHandler to ObjectFieldMapTypeHandler
eviltak Jul 25, 2018
3c84a10
Remove field name normalization in ObjectFieldMapTypeHandler
eviltak Jul 25, 2018
27d3efd
Remove MappedContainer check in ObjectFieldMapTypeHandlerFactory
eviltak Jul 25, 2018
6a064a9
Make getTypeHandlerForSuper methods consider target type itself
eviltak Jul 25, 2018
18b0591
Add incomplete ReflectionUtil.resolveFieldType
eviltak Jul 25, 2018
ea34be3
Handle GenericArrayType in resolveFieldType
eviltak Jul 25, 2018
37b69f0
Rename resolveFieldType to resolveType
eviltak Jul 25, 2018
0111d27
Handle ParameterizedType in resolveType, Add more resolveType tests
eviltak Jul 25, 2018
9003558
Handle WildcardType in resolveType
eviltak Jul 25, 2018
cba3745
Complete ObjectFieldMapTypeHandler + Factory definition
eviltak Jul 25, 2018
9561007
Resolve raw type TypeVariables as Object in resolveType
eviltak Jul 25, 2018
a27cffa
Ignore ObjectFieldMapTypeHandler in GsonTypeSerializationLibraryAdapt…
eviltak Jul 25, 2018
ba1b810
Add AssetTypeHandlerFactory
eviltak Jul 25, 2018
6d8fe6f
Add RuntimeDelegatingTypeHandler
eviltak Jul 26, 2018
f54143d
Resolve types in getTypeParameterForSuper
eviltak Jul 26, 2018
9b7eb99
Use getTypeParameterForSuper in Collection and StringMap handlers
eviltak Jul 26, 2018
125d19c
Document additions of #3453
eviltak Jul 26, 2018
b5f1022
Skip primitive types and static or transient fields during serialization
eviltak Jul 26, 2018
980522b
Make Rect2fTypeHandler use a TypeHandler for serializing vectors
eviltak Jul 26, 2018
252d036
Make Rect2iTypeHandler use a TypeHandler for serializing vectors
eviltak Jul 26, 2018
57e087b
Make Region3iTypeHandler use a TypeHandler for serializing vectors
eviltak Jul 26, 2018
e24a74e
Remove DeserializationContext.deserializeAs
eviltak Jul 26, 2018
3cd0e2a
Remove DeserializationContext usages
eviltak Jul 26, 2018
8369839
Remove DeserializationContext and implementations
eviltak Jul 26, 2018
b690c21
Remove SerializationContext.create(T, Class<? extends T>)
eviltak Jul 26, 2018
838c493
Remove GsonSerializationContext.context
eviltak Jul 26, 2018
326bd89
Remove ProtobufSerializationContext.library
eviltak Jul 26, 2018
7421deb
Rename SerializationContext to PersistedDataSerializer
eviltak Jul 26, 2018
1a54b9e
Rename PersistedDataSerializer.createXYZ to serializeXYZ
eviltak Jul 26, 2018
46333c2
Use first available constructor as last resort in ConstructorLibrary.get
eviltak Jul 26, 2018
99fa4dc
Use runtime type only if it is more specific in RuntimeDelegating han…
eviltak Jul 26, 2018
b716cd0
Add type handling integration test
eviltak Jul 26, 2018
6c37310
Introduce different TypeHander class in runtime handler test
eviltak Jul 27, 2018
5896080
Use Defaults.defaultValue while generating constructor params
eviltak Jul 27, 2018
027cd95
Serialize field only if field value is not default
eviltak Jul 27, 2018
819260b
Make TypeHandler abstract class
eviltak Jul 30, 2018
c3e8056
TypeHandler.serialize -> serializeNonNull, null serialized by default
eviltak Jul 30, 2018
aa5abeb
Update TypeHandler documentation
eviltak Jul 30, 2018
710cbbc
Use UnsafeAllocator in ConstructorLibrary as last resort
eviltak Jul 31, 2018
786ac1c
Remove null serialization in TypeHandler.serializeNotNull impls
eviltak Jul 31, 2018
ed4b491
Use LinkedHashMaps in ObjectFieldMapTypeHandlerFactory
eviltak Jul 31, 2018
40fe5ca
Remove BorderTypeHandler (already handled by ObjectMapTypeHandler)
eviltak Jul 31, 2018
00b3a8f
Remove Region3iTypeHandler (already handled by ObjectMapTypeHandler)
eviltak Jul 31, 2018
583ea07
Make TypeHandler.deserialize return Optional<T>
eviltak Jul 31, 2018
70970c4
Add TypeHandler.deserializeOrNull, deserializeOrGet, deserializeOrThrow
eviltak Jul 31, 2018
ac5411c
Add TypeHandler.deserializeOrNull usages
eviltak Jul 31, 2018
161f900
Add TypeHandler.deserializeOrThrow overload with error message
eviltak Jul 31, 2018
3783ecb
Add TypeHandler.deserializeOrThrow usages
eviltak Jul 31, 2018
bee9416
Return Optional.empty if data incorrect in TypeHandler.deserialize impls
eviltak Jul 31, 2018
0f4f81a
Add ArrayTypeHandler + Factory
eviltak Jul 31, 2018
fa0de16
Refer arrays as Object in ArrayTypeHandler to avoid cast exceptions
eviltak Aug 1, 2018
c65188c
Set bytes only if byteList non-empty in EntityData.ValueAdapter
eviltak Aug 3, 2018
8ebb064
Complete RuntimeDelegatingTypeHandlerAdapter.testSerialize
eviltak Oct 29, 2018
2db667e
Add PersistedMap.isValueMap and getAsValueMap implementations
eviltak Oct 29, 2018
d8e7a4c
Add RuntimeDelegatingTypeHandlerAdapter.testDeserialize
eviltak Oct 29, 2018
98ab203
Return Optional in TypeSerializationLibrary.getTypeHandler
eviltak Oct 29, 2018
e47023b
Add CharacterTypeHandler (credit @llvieira)
eviltak Oct 29, 2018
d168559
Add CharacterTypeHandlerTest
eviltak Oct 29, 2018
30e5b3c
Add fail case to CharacterTypeHandler.testDeserialize
eviltak Oct 29, 2018
e25defb
Add TypeHandlerFactoryContext
eviltak Oct 29, 2018
1552df9
Add context param in TypeHandlerFactory.create, ClassLoader in getTyp…
eviltak Oct 30, 2018
23dc409
Store multiple ClassLoaders in TypeHandlerFactoryContext
eviltak Oct 30, 2018
a1aaeb8
Add ReflectionUtil.getComprehensiveEngineClassLoaders
eviltak Oct 30, 2018
11b2678
Add RuntimeDelegatingTypeHandlerSandboxTest + test module
eviltak Oct 30, 2018
1dd161e
Add test-modules to engine-tests build config
eviltak Oct 30, 2018
93fc43c
Adapted (and refactored) RR serializer to use CollectionTypeHandler
llvieira Oct 30, 2018
6575e49
Write and read JsonElement instead of PersistentData itself
llvieira Oct 30, 2018
9764023
Pass in classLoaders to recorded event list TypeHandler
llvieira Oct 30, 2018
a585967
Mock ModuleEnvironmnet to prevent tests from failing
llvieira Oct 30, 2018
fedf155
Added error log when occur problems with recorded events deserialization
llvieira Nov 1, 2018
ef25400
Add TypeHandler overloads that take classes instead of class loaders
eviltak Nov 5, 2018
ad4d511
Test RuntimeDelegatingTypeHandler access of module class from module
eviltak Nov 5, 2018
77ba36b
Add getTypeHandler(TypeInfo, Class...) overload
eviltak Nov 5, 2018
ba5c4ba
Simplify serialization interface via Gson and ProtobufSerializer
eviltak Nov 5, 2018
eae5d58
Add string path overloads for writeJson and writeBytes
eviltak Nov 6, 2018
54c89f3
Use GsonSerializer in RecordedEventSerializer
eviltak Nov 6, 2018
749c12a
Add cyclic object graph support via FutureTypeHandler
eviltak Nov 12, 2018
4a51f44
Close writer to prevent file from not being fully written
llvieira Nov 15, 2018
65bc6e0
Add try-with-resource to close readers automatically
llvieira Nov 15, 2018
28ba172
Closing writers in the right place
llvieira Nov 15, 2018
7f4c69c
Further changes to ProtobufSerialization Documentation
nschnitzer Nov 30, 2018
2c71e69
Added Class Documentation to ProtobufSerializer
nschnitzer Dec 1, 2018
edd8e31
Minor Changes to Class Documentation of ProtobufSerializer
nschnitzer Dec 1, 2018
90fe7b5
Added Documentation to GsonSerializer.java
nschnitzer Dec 2, 2018
684a20c
Enhanced Gson Serializer
nschnitzer Dec 3, 2018
9c3c70c
Forgot one thing
nschnitzer Dec 3, 2018
f55a934
Fixed Grammatical Errors
nschnitzer Dec 4, 2018
c02804b
Minor Grammatical Fixes
nschnitzer Dec 11, 2018
5d4d484
Add TypeHandlerFactoryContext.getTypeHandler
eviltak Mar 16, 2019
d03a171
Check for runtime type assignability during deserialization in Runtim…
eviltak Mar 16, 2019
1043f9b
Change RuntimeDelegatingTypeHandler.TYPE_FIELD to "class" and VALUE_F…
eviltak Mar 16, 2019
aaaa19c
Rename TypeHandlerFactoryContext to TypeHandlerContext
eviltak Apr 1, 2019
98283de
Handle null chosenHandler in RuntimeDelegatingTypeHandler
eviltak May 4, 2019
cad700d
Remove TypeSerializationLibrary.reflectFactory and copyStrategies
eviltak Jun 1, 2019
635dd6a
Rename TypeSerializationLibrary to TypeHandlerLibrary
eviltak Jun 7, 2019
6e3b8af
Add TypeHandlerLibrary documentation
eviltak Jun 26, 2019
feb2110
Add concrete Type implementations in ReflectionUtil
eviltak Jun 26, 2019
97506c3
Add FutureTypeHandlerTest
eviltak Jun 26, 2019
17da5d7
Remove redundant TypeHandlerLibrary initialization
eviltak Jun 27, 2019
1b4e9f8
Add Reflections field to TypeHandlerLibrary
eviltak Jun 28, 2019
a525594
Use Reflections instead of ClassLoaders in serialization
eviltak Jun 28, 2019
004eb93
Use runtime type if declared type handler is missing during serializa…
eviltak Jun 29, 2019
908d67c
Revert "Add RuntimeDelegatingTypeHandlerSandboxTest + test module"
eviltak Jun 29, 2019
0cad6f6
Revert "Add test-modules to engine-tests build config"
eviltak Jun 29, 2019
2aa587a
Add AbstractSerializer and extend GsonSerializer
eviltak Jun 29, 2019
6623336
Remove ReflectionUtil.getComprehensiveEngineClassloaders
eviltak Jun 29, 2019
47128fa
Add GsonSerializer.fromJson implementations
eviltak Jun 29, 2019
5030652
Make ProtobufSerializer extend AbstractSerializer
eviltak Jun 29, 2019
b9d9dfb
Document Serializers
eviltak Jun 29, 2019
3a4f2f7
Add @SerializedName annotation
eviltak Jun 29, 2019
54c0d97
Add inherited type parameter resolution in ReflectionUtil
eviltak Jun 30, 2019
76213ed
Fix RuntimeDelegatingTypeHandler test
eviltak Jun 30, 2019
0dcfb64
Flatten RuntimeDelegatingTypeHandler serialized format
eviltak Jul 10, 2019
2dd8894
Change TypeInfo.rawType to Class<T>
eviltak Jul 10, 2019
4c2ac42
Add SerializationSandbox and implementations
eviltak Jul 20, 2019
af0ddb8
Sandbox TypeHandler addition
eviltak Jul 22, 2019
3197ec6
Update TypeHandlerLibrary static factory methods for sandbox
eviltak Jul 22, 2019
cad41d8
Add TypeHandlerLibrary.getBaseTypeHandler
eviltak Jul 22, 2019
a889596
Handle builtin types in ModuleEnvironmentSandbox.isValidHandlerDeclar…
eviltak Jul 23, 2019
f217204
Fix ModuleEnvSandbox.isValidHandler method
eviltak Jul 23, 2019
58e0548
Document sandbox, Check factory generated handlers for validity
eviltak Jul 24, 2019
0352f8e
Allow non-module handlers by default in serialization sandbox
eviltak Jul 24, 2019
d1e4537
Better error handling in RuntimeDelegatingTypeHandler
eviltak Jul 30, 2019
ff59080
Use ModuleContext in ModuleEnvironmentSandbox
eviltak Jul 30, 2019
d0a033a
Fix RuntimeDelegatingTypeHandler non-sub deserialization test
eviltak Jul 30, 2019
644fcff
Add RegisterTypeHandlerFactory annotation
eviltak Jul 30, 2019
b4acfaa
Use ModuleManager instead of environment in ModEnvSandbox
eviltak Jul 30, 2019
b08d52a
Fix ModuleEnvironmentSandbox.doesSubclassMatch
eviltak Jul 30, 2019
b362b2e
Fix NPE in ModuleEnvironmentSandbox
eviltak Jul 30, 2019
ac9e33f
Fix EventSystemReplay tests, Fix some static analysis warnings
eviltak Jul 31, 2019
7822f5e
Make TypeInfo @API
eviltak Aug 7, 2019
3391b62
Add TypeRegistry
eviltak Aug 7, 2019
6e1de25
Make TypeInfo abstract for more IDE/compiler enforcement
eviltak Aug 9, 2019
4e8e173
Use ClassLoaders to populate TypeRegistryImpl Reflections
eviltak Aug 9, 2019
1679be2
Reverse ClassLoader list in TypeRegistryImpl.reload
eviltak Aug 9, 2019
ef8c8b4
Add empty TypeRegistryImpl constructor
eviltak Aug 9, 2019
66a9dcd
Use TypeRegistry in ModuleEnvironmentSandbox
eviltak Aug 10, 2019
e16914f
Separate tests in TypeRegistryImplTest
eviltak Aug 10, 2019
715c929
Test for unittest module instead of Core in TypeRegistryImplTest
eviltak Aug 10, 2019
419b85a
Add PersistedDataMap.of
eviltak Aug 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions engine-tests/src/main/java/org/terasology/HeadlessEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.terasology.network.internal.NetworkSystemImpl;
import org.terasology.persistence.StorageManager;
import org.terasology.persistence.internal.ReadWriteStorageManager;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.persistence.typeHandling.extensionTypes.BlockFamilyTypeHandler;
import org.terasology.persistence.typeHandling.extensionTypes.BlockTypeHandler;
import org.terasology.persistence.typeHandling.extensionTypes.CollisionGroupTypeHandler;
Expand All @@ -64,6 +64,8 @@
import org.terasology.recording.RecordAndReplayCurrentStatus;
import org.terasology.recording.RecordAndReplaySerializer;
import org.terasology.recording.RecordAndReplayUtils;
import org.terasology.reflection.TypeRegistry;
import org.terasology.reflection.internal.TypeRegistryImpl;
import org.terasology.rendering.assets.animation.MeshAnimation;
import org.terasology.rendering.assets.animation.MeshAnimationImpl;
import org.terasology.rendering.assets.atlas.Atlas;
Expand Down Expand Up @@ -164,17 +166,17 @@ protected void setupEntitySystem() {
protected void setupCollisionManager() {
CollisionGroupManager collisionGroupManager = new CollisionGroupManager();
context.put(CollisionGroupManager.class, collisionGroupManager);
context.get(TypeSerializationLibrary.class).add(CollisionGroup.class, new CollisionGroupTypeHandler(collisionGroupManager));
context.get(TypeHandlerLibrary.class).addTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler(collisionGroupManager));
}

@Override
protected void setupBlockManager(AssetManager assetManager) {
WorldAtlas worldAtlas = new NullWorldAtlas();
BlockManagerImpl blockManager = new BlockManagerImpl(worldAtlas, assetManager);
context.put(BlockManager.class, blockManager);
TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
typeSerializationLibrary.add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
typeSerializationLibrary.add(Block.class, new BlockTypeHandler(blockManager));
TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
typeHandlerLibrary.addTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
typeHandlerLibrary.addTypeHandler(Block.class, new BlockTypeHandler(blockManager));
}

@Override
Expand Down Expand Up @@ -267,7 +269,10 @@ protected void setupConfig() {

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
ModuleManager moduleManager = ModuleManagerFactory.create();
TypeRegistryImpl typeRegistry = new TypeRegistryImpl();
context.put(TypeRegistry.class, typeRegistry);

ModuleManager moduleManager = ModuleManagerFactory.create(typeRegistry);
ModuleRegistry registry = moduleManager.getRegistry();

DependencyResolver resolver = new DependencyResolver(registry);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2019 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.Before;
import org.mockito.Mockito;
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.paths.PathManager;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ResolutionResult;
import org.terasology.reflection.TypeRegistry;
import org.terasology.reflection.internal.TypeRegistryImpl;
import org.terasology.testUtil.ModuleManagerFactory;

import java.nio.file.FileSystem;

import static org.junit.Assume.assumeTrue;

public abstract class ModuleEnvironmentTest {
protected ModuleManager moduleManager;
protected TypeRegistry typeRegistry;

@Before
public void before() throws Exception {
final JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
final FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(vfs.getPath(""));

typeRegistry = new TypeRegistryImpl();
moduleManager = ModuleManagerFactory.create((TypeRegistryImpl) typeRegistry);

DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleManager.getRegistry().getModuleIds());

assumeTrue(result.isSuccess());

moduleManager.loadEnvironment(result.getModules(), true);

setup();
}

protected void setup() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.terasology.recording.RecordAndReplaySerializer;
import org.terasology.recording.RecordAndReplayUtils;
import org.terasology.recording.RecordedEventStore;
import org.terasology.reflection.TypeRegistry;
import org.terasology.world.block.BlockManager;
import org.terasology.world.chunks.blockdata.ExtraBlockDataManager;

Expand Down Expand Up @@ -104,7 +105,7 @@ public void setup() throws Exception {
context.put(CharacterStateEventPositionMap.class, characterStateEventPositionMap);
DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
context.put(DirectionAndOriginPosRecorderList.class, directionAndOriginPosRecorderList);
RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(engineEntityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager.getEnvironment());
RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(engineEntityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, context.get(TypeRegistry.class));
context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);

Path savePath = PathManager.getInstance().getSavePath("world1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,43 @@
package org.terasology.testUtil;

import com.google.common.collect.Sets;
import org.mockito.Mockito;
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.reflection.internal.TypeRegistryImpl;

import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Set;

/**
*/
public final class ModuleManagerFactory {
private ModuleManagerFactory() {
}

// Named "create" for legacy reasons, but does more than create
public static ModuleManager create() throws Exception {
ModuleManager moduleManager = new ModuleManagerImpl("");
ModuleManager manager = create(Mockito.mock(TypeRegistryImpl.class));
manager.loadEnvironment(Sets.newHashSet(manager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
return manager;
}

/**
* Creates a new {@link ModuleManager} instance, but does not
* {@link ModuleManager#loadEnvironment(Set, boolean) load it's environment}.
*/
public static ModuleManager create(TypeRegistryImpl typeRegistry) throws Exception {
ModuleManager moduleManager = new ModuleManagerImpl("", typeRegistry);
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));
}
moduleManager.loadEnvironment(Sets.newHashSet(moduleManager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
return moduleManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.reflections.Reflections;
import org.terasology.context.internal.ContextImpl;
import org.terasology.engine.SimpleUri;
import org.terasology.entitySystem.entity.EntityRef;
Expand All @@ -36,12 +37,9 @@
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.network.NetworkMode;
import org.terasology.network.NetworkSystem;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.recording.EventCatcher;
import org.terasology.recording.RecordAndReplayCurrentStatus;
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.reflection.reflect.ReflectionReflectFactory;
import org.terasology.registry.CoreRegistry;

import java.util.List;
Expand All @@ -64,9 +62,9 @@ public class PojoEventSystemTests {
public void setup() {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ReflectFactory reflectFactory = new ReflectionReflectFactory();
CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);
TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies);

Reflections reflections = new Reflections(getClass().getClassLoader());
TypeHandlerLibrary serializationLibrary = new TypeHandlerLibrary(reflections);

EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
compLibrary = entitySystemLibrary.getComponentLibrary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.Before;
import org.junit.Test;
import org.reflections.Reflections;
import org.terasology.assets.AssetFactory;
import org.terasology.assets.ResourceUrn;
import org.terasology.assets.management.AssetManager;
Expand All @@ -32,12 +33,9 @@
import org.terasology.entitySystem.stubs.StringComponent;
import org.terasology.math.geom.Quat4f;
import org.terasology.math.geom.Vector3f;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler;
import org.terasology.persistence.typeHandling.mathTypes.Vector3fTypeHandler;
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.reflection.reflect.ReflectionReflectFactory;
import org.terasology.registry.CoreRegistry;
import org.terasology.testUtil.ModuleManagerFactory;
import org.terasology.utilities.Assets;
Expand All @@ -60,11 +58,13 @@ public void setup() throws Exception {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ModuleManager moduleManager = ModuleManagerFactory.create();
ReflectFactory reflectFactory = new ReflectionReflectFactory();
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
TypeSerializationLibrary lib = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
lib.add(Vector3f.class, new Vector3fTypeHandler());
lib.add(Quat4f.class, new Quat4fTypeHandler());

Reflections reflections = new Reflections(getClass().getClassLoader());
TypeHandlerLibrary lib = new TypeHandlerLibrary(reflections);

lib.addTypeHandler(Vector3f.class, new Vector3fTypeHandler());
lib.addTypeHandler(Quat4f.class, new Quat4fTypeHandler());

entitySystemLibrary = new EntitySystemLibrary(context, lib);
componentLibrary = entitySystemLibrary.getComponentLibrary();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.terasology.math.Side;
import org.terasology.network.NetworkMode;
import org.terasology.network.NetworkSystem;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.recording.RecordAndReplayCurrentStatus;
import org.terasology.registry.CoreRegistry;
import org.terasology.testUtil.ModuleManagerFactory;
Expand Down Expand Up @@ -78,8 +78,8 @@ public void setup() throws Exception {
assetTypeManager.registerCoreAssetType(Prefab.class,
(AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary);
TypeHandlerLibrary typeHandlerLibrary = context.get(TypeHandlerLibrary.class);
PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
assetTypeManager.registerCoreFormat(Prefab.class, prefabFormat);
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import org.junit.Before;
import org.junit.Test;
import org.reflections.Reflections;
import org.terasology.context.Context;
import org.terasology.context.internal.ContextImpl;
import org.terasology.engine.SimpleUri;
import org.terasology.entitySystem.stubs.OwnerComponent;
import org.terasology.entitySystem.stubs.StringComponent;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.reflection.reflect.ReflectionReflectFactory;
Expand All @@ -48,7 +49,8 @@ public void prepare() {

@Test
public void testStaticFieldsIgnored() {
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, new TypeSerializationLibrary(reflectFactory, copyStrategies));
Reflections reflections = new Reflections(getClass().getClassLoader());
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, new TypeHandlerLibrary(reflections));
ComponentLibrary lib = entitySystemLibrary.getComponentLibrary();
lib.register(new SimpleUri("unittest:string"), StringComponent.class);
ComponentMetadata<StringComponent> metadata = lib.getMetadata(StringComponent.class);
Expand All @@ -57,7 +59,8 @@ public void testStaticFieldsIgnored() {

@Test
public void testOwnsReferencesPopulated() {
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, new TypeSerializationLibrary(reflectFactory, copyStrategies));
Reflections reflections = new Reflections(getClass().getClassLoader());
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, new TypeHandlerLibrary(reflections));
ComponentLibrary lib = entitySystemLibrary.getComponentLibrary();
lib.register(new SimpleUri("unittest:owner"), OwnerComponent.class);
ComponentMetadata<OwnerComponent> metadata = lib.getMetadata(OwnerComponent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.reflections.Reflections;
import org.terasology.context.Context;
import org.terasology.context.internal.ContextImpl;
import org.terasology.engine.SimpleUri;
Expand All @@ -34,29 +35,22 @@
import org.terasology.math.geom.Vector3f;
import org.terasology.network.NetworkSystem;
import org.terasology.persistence.serializers.ComponentSerializer;
import org.terasology.persistence.typeHandling.TypeSerializationLibrary;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
import org.terasology.persistence.typeHandling.mathTypes.Quat4fTypeHandler;
import org.terasology.persistence.typeHandling.mathTypes.Vector3fTypeHandler;
import org.terasology.protobuf.EntityData;
import org.terasology.recording.RecordAndReplayCurrentStatus;
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.reflection.reflect.ReflectionReflectFactory;
import org.terasology.registry.CoreRegistry;
import org.terasology.testUtil.ModuleManagerFactory;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

/**
*/
public class ComponentSerializerTest {
private static ModuleManager moduleManager;
private ComponentSerializer componentSerializer;
private ReflectFactory reflectFactory = new ReflectionReflectFactory();
private CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
private Context context;

@BeforeClass
Expand All @@ -71,9 +65,11 @@ public void setup() {
context.put(ModuleManager.class, moduleManager);
CoreRegistry.setContext(context);

TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
serializationLibrary.add(Vector3f.class, new Vector3fTypeHandler());
serializationLibrary.add(Quat4f.class, new Quat4fTypeHandler());
Reflections reflections = new Reflections(getClass().getClassLoader());
TypeHandlerLibrary serializationLibrary = new TypeHandlerLibrary(reflections);

serializationLibrary.addTypeHandler(Vector3f.class, new Vector3fTypeHandler());
serializationLibrary.addTypeHandler(Quat4f.class, new Quat4fTypeHandler());

NetworkSystem networkSystem = mock(NetworkSystem.class);
context.put(NetworkSystem.class, networkSystem);
Expand Down
Loading