├── .gitattributes ├── .github └── labels.json ├── .gitignore ├── Jenkinsfile ├── LICENSE ├── README.md ├── build.gradle.kts ├── config ├── checkstyle │ ├── checkstyle.xml │ └── suppressions.xml ├── findbugs │ └── findbugs-exclude.xml └── pmd │ └── pmd.xml ├── gestalt-android-testbed ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── android │ │ └── testbed │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── logback.xml │ │ └── modules │ │ │ ├── archiveModule.zip │ │ │ ├── directoryModule │ │ │ └── module.json │ │ │ └── moduleAAndroid.jar │ ├── java │ │ └── org │ │ │ └── terasology │ │ │ └── gestalt │ │ │ └── android │ │ │ └── testbed │ │ │ ├── GestaltTestActivity.java │ │ │ ├── assettypes │ │ │ ├── Text.java │ │ │ ├── TextData.java │ │ │ ├── TextFactory.java │ │ │ └── TextFileFormat.java │ │ │ ├── packageModuleA │ │ │ ├── PackageModuleAText.java │ │ │ └── TextComponent.java │ │ │ └── packageModuleB │ │ │ └── PackageModuleBText.java │ ├── res │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ │ └── activity_gestalt_test.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ └── resources │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── android │ │ └── testbed │ │ ├── packageModuleA │ │ └── assets │ │ │ └── text │ │ │ └── moduleAText.txt │ │ └── packageModuleB │ │ └── assets │ │ └── text │ │ └── moduleBText.txt │ └── test │ └── java │ └── org │ └── terasology │ └── gestalt │ └── android │ └── testbed │ └── ExampleUnitTest.java ├── gestalt-android ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle ├── lintconfig.xml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── android │ │ ├── AndroidAssetsFileSource.java │ │ ├── AndroidModuleClassLoader.java │ │ └── AndroidModulePathScanner.java │ └── res │ └── values │ └── strings.xml ├── gestalt-asset-core ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── assets │ │ ├── AbstractFragmentDataProducer.java │ │ ├── Asset.java │ │ ├── AssetData.java │ │ ├── AssetDataProducer.java │ │ ├── AssetFactory.java │ │ ├── AssetType.java │ │ ├── DisposableResource.java │ │ ├── DisposalHook.java │ │ ├── ResolutionStrategy.java │ │ ├── ResourceUrn.java │ │ ├── exceptions │ │ ├── InvalidAssetDataException.java │ │ ├── InvalidAssetFilenameException.java │ │ ├── InvalidUrnException.java │ │ └── package-info.java │ │ ├── format │ │ ├── AbstractAssetAlterationFileFormat.java │ │ ├── AbstractAssetFileFormat.java │ │ ├── AssetAlterationFileFormat.java │ │ ├── AssetDataFile.java │ │ ├── AssetFileFormat.java │ │ ├── FileFormat.java │ │ ├── FileUtil.java │ │ ├── package-info.java │ │ └── producer │ │ │ ├── AssetFileDataProducer.java │ │ │ ├── FileChangeSubscriber.java │ │ │ ├── ModuleDependencyProvider.java │ │ │ ├── UnloadedAssetData.java │ │ │ └── package-info.java │ │ ├── management │ │ ├── AssetManager.java │ │ ├── AssetTypeManager.java │ │ ├── Context.java │ │ ├── ContextManager.java │ │ ├── MapAssetTypeManager.java │ │ └── package-info.java │ │ ├── module │ │ ├── ModuleAssetScanner.java │ │ ├── ModuleAwareAssetTypeManager.java │ │ ├── ModuleAwareAssetTypeManagerImpl.java │ │ ├── ModuleDependencyResolutionStrategy.java │ │ ├── ModuleEnvironmentDependencyProvider.java │ │ ├── annotations │ │ │ ├── RegisterAssetDataProducer.java │ │ │ ├── RegisterAssetDeltaFileFormat.java │ │ │ ├── RegisterAssetFileFormat.java │ │ │ ├── RegisterAssetSupplementalFileFormat.java │ │ │ ├── RegisterAssetType.java │ │ │ └── package-info.java │ │ ├── autoreload │ │ │ ├── AssetReloadOnChangeHandler.java │ │ │ ├── AutoReloadAssetTypeManager.java │ │ │ ├── ModuleEnvironmentWatcher.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── package-info.java │ └── test │ ├── java │ ├── org │ │ └── terasology │ │ │ └── gestalt │ │ │ └── assets │ │ │ ├── AbstractFragmentProducerTest.java │ │ │ ├── AssetManagerTest.java │ │ │ ├── AssetTypeTest.java │ │ │ ├── OptionalAnswer.java │ │ │ ├── ResourceUrnTest.java │ │ │ ├── Return.java │ │ │ └── module │ │ │ ├── AssetFileDataProducerTest.java │ │ │ ├── ModuleAwareAssetTypeManagerTest.java │ │ │ ├── ModuleDependencyResolutionStrategyTest.java │ │ │ ├── TestModulesUtil.java │ │ │ └── autoreload │ │ │ └── ModuleEnvironmentWatcherTest.java │ └── virtualModules │ │ └── test │ │ └── stubs │ │ ├── book │ │ ├── Book.java │ │ ├── BookData.java │ │ ├── BookFactory.java │ │ ├── BookFileFormat.java │ │ └── BookFragmentDataProducer.java │ │ ├── extensions │ │ ├── ExtensionAsset.java │ │ ├── ExtensionData.java │ │ ├── ExtensionDataProducer.java │ │ ├── ExtensionDeltaFileFormat.java │ │ ├── ExtensionFactory.java │ │ ├── ExtensionFileFormat.java │ │ └── ExtensionSupplementalFileFormat.java │ │ ├── inheritance │ │ ├── AlternateAsset.java │ │ ├── AlternateAssetData.java │ │ ├── AlternateAssetFactory.java │ │ ├── ChildAsset.java │ │ ├── ChildAssetData.java │ │ ├── ChildAssetFactory.java │ │ └── ParentAsset.java │ │ └── text │ │ ├── Text.java │ │ ├── TextData.java │ │ ├── TextDeltaFileFormat.java │ │ ├── TextFactory.java │ │ ├── TextFileFormat.java │ │ └── TextMetadataFileFormat.java │ └── resources │ ├── logback-test.xml │ ├── module.json │ └── virtualModules │ ├── deltaA │ ├── deltas │ │ └── test │ │ │ └── text │ │ │ └── example.delta │ └── module.json │ ├── moduleA │ ├── assets │ │ └── text │ │ │ └── example.txt │ └── module.json │ ├── moduleB │ └── module.json │ ├── overrideA │ ├── module.json │ └── overrides │ │ └── test │ │ └── text │ │ └── example.txt │ ├── overrideB │ ├── module.json │ └── overrides │ │ └── test │ │ └── text │ │ └── example.txt │ ├── overrideC │ ├── module.json │ └── overrides │ │ └── test │ │ └── text │ │ └── example.txt │ ├── overrideD │ ├── module.json │ └── overrides │ │ └── test │ │ └── text │ │ └── example.txt │ ├── overrideE │ ├── module.json │ └── overrides │ │ └── test │ │ └── nontext │ │ └── example.txt │ ├── overrideSupplement │ ├── module.json │ └── overrides │ │ └── supplementA │ │ └── text │ │ ├── example.info │ │ └── example.txt │ ├── overrideWithSupplementOnly │ ├── module.json │ └── overrides │ │ └── moduleA │ │ └── text │ │ └── example.info │ ├── redirectA │ ├── assets │ │ └── text │ │ │ ├── double.redirect │ │ │ ├── example.redirect │ │ │ └── real.txt │ └── module.json │ ├── supplementA │ ├── assets │ │ └── text │ │ │ ├── example.info │ │ │ └── example.txt │ └── module.json │ └── test │ ├── assets │ ├── books │ │ ├── test_body.txt │ │ └── test_header.txt │ └── text │ │ └── example.txt │ └── module.json ├── gestalt-di ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── di │ │ ├── BeanContext.java │ │ ├── BeanEnvironment.java │ │ ├── BeanIntercept.java │ │ ├── BeanKey.java │ │ ├── BeanScanner.java │ │ ├── DefaultBeanContext.java │ │ ├── DefaultBeanResolution.java │ │ ├── ServiceRegistry.java │ │ ├── exceptions │ │ ├── BeanResolutionException.java │ │ ├── DependencyResolutionException.java │ │ └── UnknownContextTypeException.java │ │ ├── index │ │ ├── ClassIndex.java │ │ ├── CompoundClassIndex.java │ │ ├── PackagePrefixedUrlClassLoader.java │ │ └── UrlClassIndex.java │ │ ├── instance │ │ ├── BeanProvider.java │ │ ├── ClassProvider.java │ │ └── SupplierProvider.java │ │ └── scanners │ │ └── StandardScanner.java │ └── test │ └── java │ └── org │ └── terasology │ └── gestalt │ └── di │ ├── AbstractBeanTest.java │ ├── AnnotationTest.java │ ├── AutoClosableTest.java │ ├── BeanContextResolutionTest.java │ ├── BeanEnvironmentTest.java │ ├── CollectionResolveTest.java │ ├── InheritanceBeanTest.java │ ├── IntrospectedClass.java │ ├── ProviderInjectTest.java │ ├── SupplierInjectionTest.java │ ├── TestRegistryTests.java │ ├── annotation │ ├── AnnotatedClass.java │ ├── AnnotationValue.java │ ├── NestedWithTestQualifier1.java │ ├── SubAnnotation.java │ ├── TestAnnotation.java │ ├── TestQualifier1.java │ ├── TestQualifier2.java │ ├── TestQualifier3.java │ ├── WithProperties.java │ └── WithTestQualifier1.java │ ├── beans │ ├── ContextDep.java │ ├── Dep1.java │ ├── Dep2.java │ ├── Dep3.java │ ├── Dep4.java │ ├── NestedClassDep.java │ ├── ParentDep.java │ └── TestRegistry.java │ ├── injection │ ├── DependencyInjectionTest.java │ ├── DependencyResolutionTest.java │ ├── OptionalDependencyTest.java │ └── beans │ │ ├── Counter1.java │ │ ├── Counter2.java │ │ ├── Counter3.java │ │ ├── CounterTester.java │ │ ├── ICounter.java │ │ ├── ICounter2.java │ │ └── SampleQualifier.java │ └── scanner │ └── standard │ ├── StandardScannerTest.java │ └── beans │ ├── SingletonBean.java │ └── TransientBean.java ├── gestalt-entity-system ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── entitysystem │ │ ├── component │ │ ├── Component.java │ │ ├── ComponentIterator.java │ │ ├── EmptyComponent.java │ │ ├── management │ │ │ ├── AbstractComponentTypeFactory.java │ │ │ ├── ComponentManager.java │ │ │ ├── ComponentPropertyInfo.java │ │ │ ├── ComponentType.java │ │ │ ├── ComponentTypeFactory.java │ │ │ ├── ComponentTypeGenerationException.java │ │ │ ├── ComponentTypeIndex.java │ │ │ ├── PropertyAccessor.java │ │ │ ├── ReflectionComponentTypeFactory.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ └── store │ │ │ ├── ArrayComponentStore.java │ │ │ ├── ComponentStore.java │ │ │ ├── ConcurrentComponentStore.java │ │ │ ├── SparseComponentStore.java │ │ │ └── package-info.java │ │ ├── entity │ │ ├── AbstractNOPEntityRef.java │ │ ├── EntityIterator.java │ │ ├── EntityManager.java │ │ ├── EntityRef.java │ │ ├── NullEntityRef.java │ │ ├── manager │ │ │ ├── CoreEntityManager.java │ │ │ ├── ManagedEntityRef.java │ │ │ └── package-info.java │ │ └── pacakge-info.java │ │ ├── event │ │ ├── After.java │ │ ├── Before.java │ │ ├── Event.java │ │ ├── EventHandler.java │ │ ├── EventHandlerFactory.java │ │ ├── EventResult.java │ │ ├── EventSystem.java │ │ ├── ReceiveEvent.java │ │ ├── Synchronous.java │ │ ├── exception │ │ │ ├── EventSystemException.java │ │ │ ├── InvalidEventReceiverObjectException.java │ │ │ └── package-info.java │ │ ├── impl │ │ │ ├── EventProcessor.java │ │ │ ├── EventReceiverMethodSupport.java │ │ │ ├── EventSystemImpl.java │ │ │ ├── ReflectionEventHandler.java │ │ │ └── package-info.java │ │ ├── lifecycle │ │ │ ├── LifecycleAwareComponentStore.java │ │ │ ├── LifecycleEvent.java │ │ │ ├── LifecycleEventManager.java │ │ │ ├── OnAdded.java │ │ │ ├── OnChanged.java │ │ │ ├── OnRemoved.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ └── prefab │ │ ├── EntityRecipe.java │ │ ├── EntityRecipeRef.java │ │ ├── GeneratedFromRecipeComponent.java │ │ ├── Prefab.java │ │ ├── PrefabData.java │ │ ├── PrefabJsonFormat.java │ │ ├── PrefabRef.java │ │ └── package-info.java │ └── test │ ├── java │ ├── modules │ │ └── test │ │ │ ├── TestChildEvent.java │ │ │ ├── TestEvent.java │ │ │ ├── TestEventReceiver.java │ │ │ ├── TestSynchEvent.java │ │ │ └── components │ │ │ ├── ArrayContainingComponent.java │ │ │ ├── BasicComponent.java │ │ │ ├── Empty.java │ │ │ ├── PublicAttributeComponent.java │ │ │ ├── Reference.java │ │ │ ├── Sample.java │ │ │ └── Second.java │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── entitysystem │ │ ├── component │ │ └── management │ │ │ ├── ComponentManagerTest.java │ │ │ ├── ComponentTypeFactoryTest.java │ │ │ ├── ComponentTypeIndexTest.java │ │ │ └── ReflectionComponentManagerTest.java │ │ ├── entity │ │ └── FullSetupExample.java │ │ ├── event │ │ ├── EventProcessorTest.java │ │ ├── EventReceiverMethodSupportTest.java │ │ └── EventSystemTest.java │ │ └── prefab │ │ ├── PrefabInstantiationTest.java │ │ └── PrefabJsonFormatTest.java │ └── resources │ └── modules │ └── test │ ├── assets │ └── prefabs │ │ ├── abridged-single.prefab │ │ ├── external-composition.prefab │ │ ├── inheritance.prefab │ │ ├── lenient-single.prefab │ │ ├── multi-explicit-root.prefab │ │ ├── multi-root-last.prefab │ │ ├── multi.prefab │ │ ├── reference-list.prefab │ │ └── single.prefab │ └── module.json ├── gestalt-es-perf ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── entitysystem │ │ ├── component │ │ └── management │ │ │ ├── LambdaComponentTypeFactory.java │ │ │ └── MethodHandleComponentTypeFactory.java │ │ └── event │ │ └── MethodHandleEventHandle.java │ └── test │ └── java │ ├── modules │ └── test │ │ ├── TestChildEvent.java │ │ ├── TestEvent.java │ │ ├── TestEventReceiver.java │ │ ├── TestSynchEvent.java │ │ └── components │ │ ├── ArrayContainingComponent.java │ │ ├── BasicComponent.java │ │ ├── Empty.java │ │ ├── PublicAttributeComponent.java │ │ ├── Sample.java │ │ └── Second.java │ └── org │ └── terasology │ └── gestalt │ └── entitysystem │ ├── component │ └── management │ │ ├── LambdaComponentTypeFactoryTest.java │ │ ├── MethodHandleComponentTypeFactoryTest.java │ │ └── perf │ │ └── ComponentManagerTest.java │ └── event │ ├── AbstractEventReceiverMethodSupportTest.java │ └── MethodHandleEventRecieverMethodSupportTest.java ├── gestalt-inject-java ├── build.gradle.kts └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── terasology │ │ │ └── gestalt │ │ │ └── annotation │ │ │ └── processing │ │ │ ├── AnnotationTypeWriter.java │ │ │ ├── BeanDefinitionProcessor.java │ │ │ ├── ClassIndexProcessor.java │ │ │ ├── ElementUtility.java │ │ │ ├── ResourceProcessor.java │ │ │ ├── ServiceTypeWriter.java │ │ │ └── SubtypesTypeWriter.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── javax.annotation.processing.Processor │ └── test │ └── java │ └── org │ └── terasology │ └── gestalt │ └── support │ └── Parser.java ├── gestalt-inject ├── build.gradle.kts └── src │ └── main │ └── java │ └── org │ └── terasology │ └── context │ ├── AbstractBeanDefinition.java │ ├── AnnotationMetadata.java │ ├── AnnotationValue.java │ ├── Argument.java │ ├── BeanDefinition.java │ ├── BeanResolution.java │ ├── DefaultAnnotationMetadata.java │ ├── DefaultAnnotationValue.java │ ├── DefaultArgument.java │ ├── EmptyAnnotationMetadata.java │ ├── FindResourcesClassLoader.java │ ├── Lifetime.java │ ├── SingleGenericArgument.java │ ├── SoftServiceLoader.java │ ├── annotation │ ├── API.java │ ├── Index.java │ ├── IndexInherited.java │ ├── RegisterSystem.java │ ├── Scoped.java │ ├── Service.java │ ├── Transient.java │ └── UsedByGeneratedCode.java │ ├── exception │ ├── BeanNotFoundException.java │ ├── CloseBeanException.java │ └── DependencyInjectionException.java │ ├── injection │ ├── NameQualifier.java │ ├── Qualifier.java │ ├── Qualifiers.java │ └── StereotypeQualifier.java │ ├── service │ ├── DefaultServiceDefinition.java │ ├── ServiceDefinition.java │ ├── SoftServiceLoader.java │ └── StreamSoftServiceLoader.java │ └── utils │ └── BeanUtilities.java ├── gestalt-module ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle.kts ├── src │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── terasology │ │ │ └── gestalt │ │ │ ├── i18n │ │ │ ├── I18nMap.java │ │ │ ├── gson │ │ │ │ ├── I18nMapTypeAdapter.java │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ │ ├── module │ │ │ ├── Module.java │ │ │ ├── ModuleEnvironment.java │ │ │ ├── ModuleFactory.java │ │ │ ├── ModuleMetadata.java │ │ │ ├── ModuleMetadataJsonAdapter.java │ │ │ ├── ModuleMetadataLoader.java │ │ │ ├── ModulePathScanner.java │ │ │ ├── ModuleRegistry.java │ │ │ ├── ModuleServiceRegistry.java │ │ │ ├── TableModuleRegistry.java │ │ │ ├── dependencyresolution │ │ │ │ ├── DependencyInfo.java │ │ │ │ ├── DependencyResolver.java │ │ │ │ ├── OptionalResolutionStrategy.java │ │ │ │ ├── ResolutionAttempt.java │ │ │ │ ├── ResolutionResult.java │ │ │ │ └── package-info.java │ │ │ ├── exceptions │ │ │ │ ├── InvalidModulePathException.java │ │ │ │ ├── MissingModuleMetadataException.java │ │ │ │ ├── ModuleException.java │ │ │ │ ├── UnresolvedDependencyException.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── predicates │ │ │ │ ├── FromModule.java │ │ │ │ └── package-info.java │ │ │ ├── resources │ │ │ │ ├── ArchiveFileSource.java │ │ │ │ ├── ClasspathFileSource.java │ │ │ │ ├── CompositeFileSource.java │ │ │ │ ├── DirectoryFileSource.java │ │ │ │ ├── EmptyFileSource.java │ │ │ │ ├── FileReference.java │ │ │ │ └── ModuleFileSource.java │ │ │ └── sandbox │ │ │ │ ├── APIScanner.java │ │ │ │ ├── BytecodeInjector.java │ │ │ │ ├── JavaModuleClassLoader.java │ │ │ │ ├── ModuleClassLoader.java │ │ │ │ ├── ModuleSecurityManager.java │ │ │ │ ├── ModuleSecurityPermission.java │ │ │ │ ├── ModuleSecurityPolicy.java │ │ │ │ ├── ObtainClassloader.java │ │ │ │ ├── PermissionProvider.java │ │ │ │ ├── PermissionProviderFactory.java │ │ │ │ ├── PermissionSet.java │ │ │ │ ├── PermitAllPermissionProviderFactory.java │ │ │ │ ├── PredicatePermissionProvider.java │ │ │ │ ├── SetUnionPermissionProvider.java │ │ │ │ ├── StandardPermissionProviderFactory.java │ │ │ │ ├── WarnOnlyProviderFactory.java │ │ │ │ └── package-info.java │ │ │ └── naming │ │ │ ├── Name.java │ │ │ ├── NameVersion.java │ │ │ ├── Version.java │ │ │ ├── VersionRange.java │ │ │ ├── exception │ │ │ ├── VersionParseException.java │ │ │ └── package-info.java │ │ │ ├── gson │ │ │ ├── NameTypeAdapter.java │ │ │ ├── VersionTypeAdapter.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── test │ │ ├── java │ │ └── org │ │ │ └── terasology │ │ │ └── gestalt │ │ │ ├── i18n │ │ │ └── I18nMapTest.java │ │ │ ├── module │ │ │ ├── DependencyResolverTestBase.java │ │ │ ├── EmbeddedLibraryTest.java │ │ │ ├── ForceIncludeOptionalDependencyResolverTest.java │ │ │ ├── ModuleMetadataJsonAdapterTest.java │ │ │ ├── NormalDependencyResolverTest.java │ │ │ ├── PermissiveSandboxTest.java │ │ │ ├── SandboxTest.java │ │ │ ├── TableModuleRegistryTest.java │ │ │ ├── UseOptionalIfAvailableDependencyResolverTest.java │ │ │ ├── di │ │ │ │ └── BeanContextInModuleTest.java │ │ │ ├── packageModule │ │ │ │ └── StandaloneClass.java │ │ │ ├── resources │ │ │ │ ├── ArchiveFileSourceTest.java │ │ │ │ ├── BaseFileSourceTest.java │ │ │ │ ├── ClasspathFileSourceTest.java │ │ │ │ ├── CompositeFileSourceTest.java │ │ │ │ └── DirectoryFileSourceTest.java │ │ │ └── sandbox │ │ │ │ ├── APIClass.java │ │ │ │ ├── APIScannerTest.java │ │ │ │ └── NonAPIClassInheritingAPIClass.java │ │ │ └── naming │ │ │ ├── NameTest.java │ │ │ ├── NameVersionTest.java │ │ │ ├── VersionRangeTest.java │ │ │ └── VersionTest.java │ │ └── resources │ │ ├── archive.zip │ │ ├── content │ │ ├── fake.class │ │ ├── folder │ │ │ └── some.resource │ │ ├── readme.txt │ │ └── subfolder │ │ │ ├── subpath │ │ │ └── another.resource │ │ │ └── test.resource │ │ ├── halfone │ │ └── content │ │ │ ├── folder │ │ │ └── some.resource │ │ │ ├── readme.txt │ │ │ └── subfolder │ │ │ └── subpath │ │ │ └── another.resource │ │ ├── halftwo.zip │ │ ├── hidden.txt │ │ └── logback-test.xml └── test-modules │ └── moduleE │ └── module.json ├── gestalt-util ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── util │ │ ├── Varargs.java │ │ ├── collection │ │ ├── CircularDependencyException.java │ │ ├── KahnSorter.java │ │ ├── TopologicalSorter.java │ │ ├── TypeKeyedMap.java │ │ ├── UniqueQueue.java │ │ └── package-info.java │ │ ├── io │ │ ├── FileExtensionPathMatcher.java │ │ ├── FileScanning.java │ │ ├── FileTypesFilter.java │ │ ├── FilesUtil.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── reflection │ │ ├── ClassFactory.java │ │ ├── GenericsUtil.java │ │ ├── ParameterProvider.java │ │ ├── SimpleClassFactory.java │ │ └── package-info.java │ └── test │ └── java │ └── org │ └── terasology │ └── gestalt │ └── util │ ├── collection │ └── KahnSorterTest.java │ ├── io │ └── FileExtensionPathMatcherTest.java │ └── reflection │ ├── ClassFactoryTest.java │ └── GenericsUtilTest.java ├── gradle.properties ├── gradle ├── common.gradle.kts └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── testpack ├── moduleA ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── terasology │ │ └── moduleA │ │ ├── ModuleAClass.java │ │ └── TextProducer.java │ └── resources │ └── module.json ├── moduleB ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ ├── module │ │ ├── a │ │ │ ├── DepA.java │ │ │ └── DepB.java │ │ └── b │ │ │ └── DepByInterface.java │ │ └── terasology │ │ └── moduleB │ │ ├── ModuleBClass.java │ │ └── ModuleBPermittedClass.java │ └── resources │ └── module.json ├── moduleC ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── terasology │ │ └── moduleC │ │ └── ModuleCClass.java │ └── resources │ └── module.json ├── moduleD ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ ├── module │ │ └── a │ │ │ └── DepC.java │ │ └── terasology │ │ └── moduleD │ │ └── ModuleDRestrictedClass.java │ └── resources │ └── module.json ├── moduleE └── module.json ├── moduleF ├── build.gradle └── src │ └── main │ ├── java │ └── org │ │ └── terasology │ │ └── gestalt │ │ └── example │ │ └── modulef │ │ └── MyComponent.java │ └── resources │ └── module.json └── testpack-api ├── build.gradle └── src └── main ├── java └── org │ ├── module │ ├── Test1Scoped.java │ └── TestImplementation1.java │ └── terasology │ └── test │ └── api │ ├── ApiInterface.java │ ├── IOInterface.java │ ├── IndexForTest.java │ └── RestrictedInterface.java └── resources └── module.info /.gitattributes: -------------------------------------------------------------------------------- 1 | # Force default for all text just in case - commit with LF, check out with OS-specific line endings 2 | * text=auto 3 | 4 | *.bat text eol=crlf 5 | *.block text 6 | *.command text eol=lf 7 | *.glsl text 8 | *.gradle text 9 | *.groovy text 10 | *.html text diff=html 11 | *.java text diff=java 12 | *.markdown text 13 | *.py text diff=python 14 | *.properties text 15 | *.sh text eol=lf 16 | *.shape text 17 | *.texinfo text 18 | *.txt text 19 | *.xml text diff=html 20 | 21 | *.blend binary 22 | *.exe binary 23 | *.jar binary 24 | *.keystore binary 25 | *.png binary 26 | 27 | gradlew text eol=lf 28 | LICENSE text 29 | NOTICE text 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gestalt specific files to be excluded 2 | /gestalt-di/test-modules/ 3 | # used to test if a module.jar is loaded correctly, so part of repo 4 | # despite it is recreated. 5 | /gestalt-es-perf/test-modules/moduleF.jar 6 | /gestalt-module/test-modules/* 7 | 8 | # Ignore general 9 | /.* 10 | !.gitignore 11 | *~ 12 | ._* 13 | *.bak 14 | 15 | # Mobile Tools for Java (J2ME) 16 | .mtj.tmp/ 17 | 18 | # Package Files # 19 | #*.jar 20 | *.war 21 | *.ear 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | # Ignore Gradle 27 | /.gradle/ 28 | build/ 29 | local.properties 30 | 31 | # Ignore IntelliJ 32 | out/ 33 | *.iml 34 | /*.ipr 35 | /*.iws 36 | 37 | # Ignore Eclipse 38 | .checkstyle 39 | .project 40 | .classpath 41 | .settings/ 42 | bin/ 43 | 44 | # Ignore Linux 45 | *.directory 46 | 47 | #Ignore OSX 48 | Icon 49 | 50 | #Ignore Windows 51 | ehthumbs.db 52 | Thumbs.db 53 | 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gestalt 2 | A family of libraries providing a variety of core capabilities for use by games and game engines. 3 | 4 | For documentations and usage examples, see https://github.com/MovingBlocks/gestalt/wiki 5 | 6 | ## Development 7 | To build locally, use `gradlew jar`. 8 | ### Android Set-Up (optional) 9 | To build `gestalt-android`, you will need to: 10 | * Download the Android SDK and use the `sdkmanager` tool to install the API 30 build tools. 11 | * Create a `local.properties` file in the repository root containing: 12 | `sdk.dir=`, 13 | where is the directory in which you installed the Android SDK. 14 | 15 | -------------------------------------------------------------------------------- /config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/findbugs/findbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /gestalt-android-testbed/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gestalt-android-testbed/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/assets/logback.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | %msg 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/assets/modules/archiveModule.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/assets/modules/archiveModule.zip -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/assets/modules/directoryModule/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "DirectoryModule", 3 | "version": "1.0.0", 4 | "displayName": "Directory Module", 5 | "description": "This is a directory module on android" 6 | } 7 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/assets/modules/moduleAAndroid.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/assets/modules/moduleAAndroid.jar -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/java/org/terasology/gestalt/android/testbed/assettypes/TextFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.android.testbed.assettypes; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class TextFactory implements AssetFactory { 27 | @Override 28 | public Text build(ResourceUrn urn, AssetType type, TextData data) { 29 | return new Text(urn, data, type); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/java/org/terasology/gestalt/android/testbed/packageModuleA/PackageModuleAText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.android.testbed.packageModuleA; 18 | 19 | import org.terasology.test.api.ApiInterface; 20 | 21 | public class PackageModuleAText implements ApiInterface { 22 | 23 | @Override 24 | public String apiMethod() { 25 | return "Hello from Package Module A!"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/java/org/terasology/gestalt/android/testbed/packageModuleA/TextComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.android.testbed.packageModuleA; 18 | 19 | import org.terasology.gestalt.entitysystem.component.Component; 20 | 21 | public class TextComponent implements Component { 22 | 23 | private boolean dirty; 24 | private String text; 25 | 26 | public String getText() { 27 | return text; 28 | } 29 | 30 | public void setText(String text) { 31 | this.text = text; 32 | } 33 | 34 | @Override 35 | public void copyFrom(TextComponent other) { 36 | this.text = other.text; 37 | this.dirty = true; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/java/org/terasology/gestalt/android/testbed/packageModuleB/PackageModuleBText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.android.testbed.packageModuleB; 18 | 19 | import org.terasology.test.api.ApiInterface; 20 | 21 | public class PackageModuleBText implements ApiInterface { 22 | 23 | @Override 24 | public String apiMethod() { 25 | return "Greetings from Package Module B"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-android-testbed/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | #008577 19 | #00574B 20 | #D81B60 21 | 22 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | gestalt-android-testbed 19 | 20 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/resources/org/terasology/gestalt/android/testbed/packageModuleA/assets/text/moduleAText.txt: -------------------------------------------------------------------------------- 1 | This text is from an asset in module PackageModuleA -------------------------------------------------------------------------------- /gestalt-android-testbed/src/main/resources/org/terasology/gestalt/android/testbed/packageModuleB/assets/text/moduleBText.txt: -------------------------------------------------------------------------------- 1 | Hey, bro. He're some text from your boi, PackageModuleB -------------------------------------------------------------------------------- /gestalt-android-testbed/src/test/java/org/terasology/gestalt/android/testbed/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.android.testbed; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | /** 24 | * Example local unit test, which will execute on the development machine (host). 25 | * 26 | * @see Testing documentation 27 | */ 28 | public class ExampleUnitTest { 29 | @Test 30 | public void addition_isCorrect() { 31 | assertEquals(4, 2 + 2); 32 | } 33 | } -------------------------------------------------------------------------------- /gestalt-android/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /gestalt-android/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Android 2 | Copyright 2019 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). -------------------------------------------------------------------------------- /gestalt-android/README.md: -------------------------------------------------------------------------------- 1 | gestalt-android 2 | ============== 3 | 4 | This project provides android-specific enhancements and glue code for gestalt. 5 | -------------------------------------------------------------------------------- /gestalt-android/lintconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gestalt-android/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /gestalt-android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /gestalt-android/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Gestalt Android 19 | 20 | -------------------------------------------------------------------------------- /gestalt-asset-core/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Asset-Core 2 | Copyright 2015 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). -------------------------------------------------------------------------------- /gestalt-asset-core/README.md: -------------------------------------------------------------------------------- 1 | gestalt-assets-core 2 | =================== 3 | 4 | A library providing an asset system, intended for usage in game engines. Extending on gestalt-module, this asset system allows modules to contain assets, which are referred to and loaded at runtime using uris or partial uris. 5 | -------------------------------------------------------------------------------- /gestalt-asset-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply(from = "$rootDir/gradle/common.gradle.kts") 4 | 5 | plugins { 6 | `java-library` 7 | } 8 | 9 | // Primary dependencies definition 10 | dependencies { 11 | implementation(project(":gestalt-util")) 12 | implementation(project(":gestalt-module")) 13 | implementation(project(":gestalt-inject")) 14 | annotationProcessor(project(":gestalt-inject-java")) 15 | 16 | implementation(libs.guava) 17 | implementation(libs.slf4j.api) 18 | implementation(libs.android.annotation) 19 | api(libs.jcip) 20 | 21 | testAnnotationProcessor(project(":gestalt-inject-java")) 22 | testImplementation(libs.junit) 23 | testImplementation(libs.logback) 24 | testImplementation(libs.mockito) 25 | } 26 | 27 | // include resource dirs from main or test, depending if is test compile or not 28 | tasks.withType().configureEach { 29 | val resourceDirs = sourceSets[if (name == "compileTestJava") "test" else "main"].resources.srcDirs 30 | inputs.files(resourceDirs) 31 | options.compilerArgs.addAll( 32 | listOf("-Aresource=${resourceDirs.joinToString(File.pathSeparator)}") 33 | ) 34 | } -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/DisposableResource.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.assets; 2 | 3 | /** 4 | * Interface for a resource that can be disposed. This is used by asset to register a resource 5 | * to be disposed of when an asset is disposed, or after it is garbage collected. 6 | */ 7 | public interface DisposableResource extends AutoCloseable { 8 | 9 | /** 10 | * Closes the asset. It is expected this should only happen once. 11 | */ 12 | void close(); 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/ResolutionStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.assets; 18 | 19 | import org.terasology.gestalt.naming.Name; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * ResolutionStrategy is a filter used when determining what modules providing a resource with a given name to use in a particular module context. 25 | * 26 | * @author Immortius 27 | */ 28 | public interface ResolutionStrategy { 29 | 30 | /** 31 | * @param modules The set of possible modules to resolve 32 | * @param context The module context of the resolution. 33 | * @return A Set of modules that are relevant given the context 34 | */ 35 | Set resolve(Set modules, Name context); 36 | } 37 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides exceptions used by the asset framework 19 | */ 20 | @API 21 | package org.terasology.gestalt.assets.exceptions; 22 | 23 | import org.terasology.context.annotation.API; 24 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/format/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package contains the interfaces and support for loading asset data from files. 19 | *

20 | * A file format applies information from one or more files to create or alter an {@link org.terasology.gestalt.assets.AssetData AssetData}. 21 | * {@link org.terasology.gestalt.assets.format.AssetFileFormat AssetFileFormat} creates AssetData, while 22 | * {@link org.terasology.gestalt.assets.format.AssetAlterationFileFormat AssetAlterationFileFormat} modifies an existing AssetData. 23 | */ 24 | @API 25 | package org.terasology.gestalt.assets.format; 26 | 27 | import org.terasology.context.annotation.API; 28 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/management/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.assets.management; 18 | 19 | import org.terasology.gestalt.naming.Name; 20 | 21 | /** 22 | * An AutoClosable token for the current module context. Should be closed when the context ends. Compatible with try-with-resource blocks. 23 | * 24 | * @author Immortius 25 | */ 26 | public interface Context extends AutoCloseable { 27 | 28 | /** 29 | * @return The name of the module of the context 30 | */ 31 | Name getContext(); 32 | 33 | @Override 34 | void close(); 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/management/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides classes for managing assets and asset types at a high level. 19 | * Particularly noteworthy: 20 | *

    21 | *
  • AssetTypeManager - manages asset types
  • 22 | *
  • MapAssetTypeManager - a simple implementation of AssetTypeManager
  • 23 | *
  • AssetManager - a simple facade for for working with Assets of all types.
  • 24 | *
25 | */ 26 | package org.terasology.gestalt.assets.management; 27 | 28 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/module/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides annotations for marking asset file formats, producers and types for automatic registration, by asset type managers that support this. 19 | */ 20 | @API 21 | package org.terasology.gestalt.assets.module.annotations; 22 | 23 | import org.terasology.context.annotation.API; 24 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/module/autoreload/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides support for detecting changed asset files and reloading affected assets 19 | */ 20 | package org.terasology.gestalt.assets.module.autoreload; 21 | 22 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/main/java/org/terasology/gestalt/assets/module/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides integration between the asset framework and gestalt-modules. 19 | *

20 | * ModuleAwareAssetTypeManager automatically registers asset types, formats and producers from a module environment, 21 | * manages unloading and reloading assets over environment changes. 22 | *

23 | *

24 | * ModuleAssetDataProducer producing assets based on files within a module - this is set up automatically by ModuleAwareAssetTypeManager. 25 | *

26 | */ 27 | package org.terasology.gestalt.assets.module; 28 | 29 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/org/terasology/gestalt/assets/OptionalAnswer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.assets; 18 | 19 | import org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues; 20 | import org.mockito.invocation.InvocationOnMock; 21 | 22 | import java.util.Optional; 23 | 24 | /** 25 | * @author Immortius 26 | */ 27 | public class OptionalAnswer extends ReturnsEmptyValues { 28 | 29 | @Override 30 | public Object answer(InvocationOnMock invocation) { 31 | Class returnType = invocation.getMethod().getReturnType(); 32 | if (returnType == Optional.class) { 33 | return Optional.empty(); 34 | } 35 | return super.answer(invocation); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/org/terasology/gestalt/assets/Return.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.assets; 18 | 19 | import org.mockito.invocation.InvocationOnMock; 20 | import org.mockito.stubbing.Answer; 21 | 22 | /** 23 | * @author Immortius 24 | */ 25 | public final class Return { 26 | private Return() { 27 | } 28 | 29 | public static Answer firstArgument() { 30 | return new Answer() { 31 | 32 | @Override 33 | @SuppressWarnings("unchecked") 34 | public T answer(InvocationOnMock invocation) { 35 | Object[] args = invocation.getArguments(); 36 | return (T) args[0]; 37 | } 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/book/BookFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.book; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class BookFactory implements AssetFactory { 27 | 28 | @Override 29 | public Book build(ResourceUrn urn, AssetType type, BookData data) { 30 | return new Book(urn, data, type); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/extensions/ExtensionData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.extensions; 18 | 19 | import org.terasology.gestalt.assets.AssetData; 20 | 21 | /** 22 | * @author Immortius 23 | */ 24 | public class ExtensionData implements AssetData { 25 | private String value = ""; 26 | 27 | public ExtensionData() { 28 | } 29 | 30 | public ExtensionData(String value) { 31 | this.value = value; 32 | } 33 | 34 | public String getValue() { 35 | return value; 36 | } 37 | 38 | public void setValue(String value) { 39 | this.value = value; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/extensions/ExtensionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.extensions; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class ExtensionFactory implements AssetFactory { 27 | 28 | @Override 29 | public ExtensionAsset build(ResourceUrn urn, AssetType type, ExtensionData data) { 30 | return new ExtensionAsset(urn, data, type); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/inheritance/AlternateAssetData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.inheritance; 18 | 19 | import org.terasology.gestalt.assets.AssetData; 20 | 21 | /** 22 | * @author Immortius 23 | */ 24 | public class AlternateAssetData implements AssetData { 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/inheritance/AlternateAssetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.inheritance; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class AlternateAssetFactory implements AssetFactory { 27 | @Override 28 | public AlternateAsset build(ResourceUrn urn, AssetType type, AlternateAssetData data) { 29 | return new AlternateAsset(urn, data, type); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/inheritance/ChildAssetData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.inheritance; 18 | 19 | import org.terasology.gestalt.assets.AssetData; 20 | 21 | /** 22 | * @author Immortius 23 | */ 24 | public class ChildAssetData implements AssetData { 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/inheritance/ChildAssetFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.inheritance; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class ChildAssetFactory implements AssetFactory { 27 | @Override 28 | public ChildAsset build(ResourceUrn urn, AssetType type, ChildAssetData data) { 29 | return new ChildAsset(urn, data, type); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/inheritance/ParentAsset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.inheritance; 18 | 19 | import org.terasology.gestalt.assets.Asset; 20 | import org.terasology.gestalt.assets.AssetData; 21 | import org.terasology.gestalt.assets.AssetType; 22 | import org.terasology.gestalt.assets.ResourceUrn; 23 | 24 | /** 25 | * @author Immortius 26 | */ 27 | public abstract class ParentAsset extends Asset { 28 | 29 | public ParentAsset(ResourceUrn urn, AssetType type) { 30 | super(urn, type); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/java/virtualModules/test/stubs/text/TextFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package virtualModules.test.stubs.text; 18 | 19 | import org.terasology.gestalt.assets.AssetFactory; 20 | import org.terasology.gestalt.assets.AssetType; 21 | import org.terasology.gestalt.assets.ResourceUrn; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | public class TextFactory implements AssetFactory { 27 | @Override 28 | public Text build(ResourceUrn urn, AssetType type, TextData data) { 29 | return new Text(urn, data, type); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "test", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/deltaA/deltas/test/text/example.delta: -------------------------------------------------------------------------------- 1 | text->frumple 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/deltaA/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "deltaA", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Provides a delta to apply on top of an asset from the 'test' module", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/moduleA/assets/text/example.txt: -------------------------------------------------------------------------------- 1 | Example text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/moduleA/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "moduleA", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Introduces an asset with the same name as one in the 'test' module", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/moduleB/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "moduleB", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Introduces no assets", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideA/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideA", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Overrides an asset from the 'test' module", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideA/overrides/test/text/example.txt: -------------------------------------------------------------------------------- 1 | Override text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideB/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideB", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Overrides an asset from the 'test' module, that was already overridden by the overrideA module", 8 | "dependencies": [ 9 | { 10 | "id": "overrideA", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideB/overrides/test/text/example.txt: -------------------------------------------------------------------------------- 1 | Different text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideC/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideC", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Overrides an asset from the 'test' module", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideC/overrides/test/text/example.txt: -------------------------------------------------------------------------------- 1 | Final text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideD/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideD", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Overrides an asset from the 'test' module, on top of a delta from DeltaA", 8 | "dependencies": [ 9 | { 10 | "id": "deltaA", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideD/overrides/test/text/example.txt: -------------------------------------------------------------------------------- 1 | Overridden text without delta 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideE/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideE", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Provides an override for a file in the 'test' module, but under a different asset type so it should be ignored", 8 | "dependencies": [ 9 | { 10 | "id": "test", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideE/overrides/test/nontext/example.txt: -------------------------------------------------------------------------------- 1 | Incorrect Text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideSupplement/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideSupplement", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Provides an override with a supplement", 8 | "dependencies": [ 9 | { 10 | "id": "supplementA", 11 | "minVersion": "1.0.0" 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideSupplement/overrides/supplementA/text/example.info: -------------------------------------------------------------------------------- 1 | sweet 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideSupplement/overrides/supplementA/text/example.txt: -------------------------------------------------------------------------------- 1 | This sentence is false 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideWithSupplementOnly/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "overrideWithSupplementOnly", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "dependencies": [ 8 | { 9 | "id": "moduleA", 10 | "minVersion": "1.0.0" 11 | } 12 | ], 13 | "description": "Overrides but only has supplement so should be ignored" 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/overrideWithSupplementOnly/overrides/moduleA/text/example.info: -------------------------------------------------------------------------------- 1 | bold 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/redirectA/assets/text/double.redirect: -------------------------------------------------------------------------------- 1 | redirectA:example 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/redirectA/assets/text/example.redirect: -------------------------------------------------------------------------------- 1 | redirectA:real 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/redirectA/assets/text/real.txt: -------------------------------------------------------------------------------- 1 | The real thing 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/redirectA/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "redirectA", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Contains a redirect from one asset to another" 8 | } 9 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/supplementA/assets/text/example.info: -------------------------------------------------------------------------------- 1 | bold 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/supplementA/assets/text/example.txt: -------------------------------------------------------------------------------- 1 | This sentence is false 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/supplementA/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "supplementA", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | }, 7 | "description": "Provides a supplement to apply on on an asset" 8 | } 9 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/test/assets/books/test_body.txt: -------------------------------------------------------------------------------- 1 | This is the body of the book. 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/test/assets/books/test_header.txt: -------------------------------------------------------------------------------- 1 | Header 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/test/assets/text/example.txt: -------------------------------------------------------------------------------- 1 | Example text 2 | -------------------------------------------------------------------------------- /gestalt-asset-core/src/test/resources/virtualModules/test/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "test", 3 | "version": "1.0.0", 4 | "displayName": { 5 | "en": "Test module" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /gestalt-di/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply(from = "$rootDir/gradle/common.gradle.kts") 4 | 5 | plugins { 6 | `java-library` 7 | } 8 | 9 | tasks.register("gatherJarModules") { 10 | dependsOn( 11 | ":testpack:moduleA:jar", 12 | ":testpack:moduleB:jar", 13 | ":testpack:moduleC:jar", 14 | ":testpack:moduleD:jar" 15 | ) 16 | 17 | from("../testpack/moduleA/build/libs/") 18 | from("../testpack/moduleB/build/libs/") 19 | from("../testpack/moduleC/build/libs/") 20 | from("../testpack/moduleD/build/libs/") 21 | from("../testpack/moduleF/build/libs/") 22 | into("test-modules") 23 | include("*.jar") 24 | } 25 | 26 | // Primary dependencies definition 27 | dependencies { 28 | testAnnotationProcessor(project(":gestalt-inject-java")) 29 | 30 | implementation(libs.slf4j.api) 31 | implementation(libs.guava) 32 | api(project(":gestalt-inject")) 33 | 34 | testImplementation(libs.junit) 35 | testImplementation(libs.logback) 36 | testImplementation(libs.mockito) 37 | 38 | testImplementation(project(":gestalt-module")) 39 | testImplementation(project(":testpack:testpack-api")) 40 | testImplementation(project(":gestalt-entity-system")) 41 | } 42 | 43 | tasks.named("test") { 44 | dependsOn("gatherJarModules") 45 | } 46 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/BeanIntercept.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di; 2 | 3 | import org.terasology.context.AnnotationMetadata; 4 | 5 | import java.util.Optional; 6 | import java.util.stream.Stream; 7 | 8 | /** 9 | * intercepts a bean as its request from the context 10 | * @param 11 | */ 12 | public interface BeanIntercept { 13 | /** 14 | * A single instance request single instance for {@link BeanContext#getBean}. An empty optional is ignored and is request normally from the context. 15 | * 16 | * @param key the bean key associated with the request 17 | * @param annotation The annotation data 18 | * @return the intercepted result 19 | */ 20 | Optional single(BeanKey key, AnnotationMetadata annotation); 21 | 22 | /** 23 | * Multiples instance are request collection for {@link BeanContext#getBeans}. An empty optional is ignored and the request form beankey is processed normally unless handled by another intercept. 24 | * 25 | * @param key the bean key associated with the request 26 | * @param annotation the annotation data 27 | * @return the intercepted result 28 | */ 29 | Optional> collection(BeanKey key, AnnotationMetadata annotation); 30 | } 31 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/BeanScanner.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di; 4 | 5 | /** 6 | * A scanner interface that is used against {@link BeanEnvironment} to resolve definitions 7 | */ 8 | public interface BeanScanner { 9 | void apply(ServiceRegistry registry, BeanEnvironment environment); 10 | } 11 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/exceptions/BeanResolutionException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.exceptions; 4 | 5 | import org.terasology.context.exception.DependencyInjectionException; 6 | import org.terasology.gestalt.di.BeanKey; 7 | 8 | import java.util.stream.Collectors; 9 | import java.util.stream.StreamSupport; 10 | 11 | public class BeanResolutionException extends DependencyInjectionException { 12 | public BeanResolutionException( BeanKey provider) { 13 | super("Failed to Resolve Bean" + provider.toString()); 14 | } 15 | public BeanResolutionException(Iterable providers) { 16 | super("Resolved Multiple Beans: " + StreamSupport.stream(providers.spliterator(), false).map(Object::toString).collect(Collectors.joining(","))); 17 | } 18 | 19 | public BeanResolutionException(Class clazz) { 20 | super("Failed to Resolve Bean" + clazz.toString()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/exceptions/DependencyResolutionException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.exceptions; 4 | 5 | import org.terasology.context.exception.DependencyInjectionException; 6 | 7 | public class DependencyResolutionException extends DependencyInjectionException { 8 | public DependencyResolutionException(Class provider, Class target) { 9 | super("failed to inject dependency " + target.toString() + " into " + provider.toString()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/exceptions/UnknownContextTypeException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.exceptions; 4 | 5 | import org.terasology.context.exception.DependencyInjectionException; 6 | import org.terasology.gestalt.di.BeanContext; 7 | 8 | public class UnknownContextTypeException extends DependencyInjectionException { 9 | public UnknownContextTypeException(BeanContext context) { 10 | super("Unknown context type: " + context.getClass()); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/index/ClassIndex.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.index; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * Index for classes, which provide `gestalt-di`. 7 | * You should gather index via `gestalt-inject-java` annotation processing before use this class. 8 | */ 9 | public interface ClassIndex { 10 | Set getSubtypesOf(String clazzName); 11 | 12 | Set getTypesAnnotatedWith(String annotation); 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/index/CompoundClassIndex.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.index; 2 | 3 | import com.google.common.collect.Lists; 4 | 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * Created for using multiple {@link ClassIndex} at once. 11 | */ 12 | public class CompoundClassIndex implements ClassIndex { 13 | private final List indexes; 14 | 15 | public CompoundClassIndex(List indexes) { 16 | this.indexes = indexes; 17 | } 18 | 19 | public CompoundClassIndex() { 20 | this(Lists.newArrayList()); 21 | } 22 | 23 | public void add(ClassIndex classIndex) { 24 | indexes.add(classIndex); 25 | } 26 | 27 | @Override 28 | public Set getSubtypesOf(String clazzName) { 29 | return indexes.stream() 30 | .flatMap(classIndex -> classIndex.getSubtypesOf(clazzName).stream()) 31 | .collect(Collectors.toSet()); 32 | } 33 | 34 | @Override 35 | public Set getTypesAnnotatedWith(String annotation) { 36 | return indexes.stream() 37 | .flatMap(classIndex -> classIndex.getTypesAnnotatedWith(annotation).stream()) 38 | .collect(Collectors.toSet()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gestalt-di/src/main/java/org/terasology/gestalt/di/instance/BeanProvider.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.instance; 4 | 5 | import org.terasology.gestalt.di.BeanContext; 6 | import org.terasology.gestalt.di.BeanEnvironment; 7 | import org.terasology.gestalt.di.BeanKey; 8 | import org.terasology.context.Lifetime; 9 | 10 | import java.util.Optional; 11 | 12 | /** 13 | * a bean provider provides objects to the {@link BeanContext} 14 | * @param the type 15 | */ 16 | public abstract class BeanProvider implements AutoCloseable { 17 | protected final Lifetime lifetime; 18 | protected final BeanEnvironment environment; 19 | 20 | public BeanProvider(BeanEnvironment environment, Lifetime lifetime) { 21 | this.lifetime = lifetime; 22 | this.environment = environment; 23 | } 24 | 25 | public Lifetime getLifetime() { 26 | return lifetime; 27 | } 28 | 29 | public abstract Optional get(BeanKey identifier, BeanContext current, BeanContext scopedTo); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/AutoClosableTest.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di; 2 | 3 | import org.junit.Test; 4 | import org.terasology.context.Lifetime; 5 | import org.terasology.context.annotation.Service; 6 | 7 | import static org.junit.Assert.assertNotNull; 8 | import static org.junit.Assert.assertTrue; 9 | 10 | public class AutoClosableTest { 11 | 12 | @Service 13 | public static class AutoClosableBean implements AutoCloseable{ 14 | protected boolean isClosed = false; 15 | public AutoClosableBean() { 16 | 17 | } 18 | 19 | @Override 20 | public void close() throws Exception { 21 | isClosed = true; 22 | } 23 | } 24 | 25 | @Test 26 | public void testAutoClose() { 27 | ServiceRegistry registry = new ServiceRegistry(); 28 | registry.with(AutoClosableBean.class, Lifetime.Singleton); 29 | 30 | AutoClosableBean bean = null; 31 | try(BeanContext context = new DefaultBeanContext(registry)) { 32 | bean = context.getBean(AutoClosableBean.class); 33 | } catch (Exception exception) { 34 | exception.printStackTrace(); 35 | } 36 | assertNotNull(bean); 37 | assertTrue(bean.isClosed); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/BeanContextResolutionTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di; 4 | 5 | import org.junit.Test; 6 | import org.terasology.context.Lifetime; 7 | import org.terasology.gestalt.di.beans.ContextDep; 8 | 9 | import java.util.Optional; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertNotNull; 13 | import static org.junit.Assert.assertTrue; 14 | 15 | public class BeanContextResolutionTest { 16 | @Test 17 | public void testContextInject1() { 18 | ServiceRegistry registry = new ServiceRegistry(); 19 | registry.with(ContextDep.class).lifetime(Lifetime.Singleton); 20 | BeanContext beanContext = new DefaultBeanContext(registry); 21 | BeanContext child = beanContext.getNestedContainer(); 22 | 23 | Optional target = child.findBean(ContextDep.class); 24 | assertTrue(target.isPresent()); 25 | assertNotNull(target.get().context); 26 | assertEquals(target.get().context, beanContext); 27 | 28 | } 29 | 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/InheritanceBeanTest.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.terasology.context.Lifetime; 6 | import org.terasology.context.annotation.Service; 7 | 8 | import javax.inject.Inject; 9 | 10 | public class InheritanceBeanTest { 11 | 12 | @Test 13 | public void TestInjectWithInheritance() { 14 | ServiceRegistry registry = new ServiceRegistry(); 15 | registry.with(InheritanceBeanA1.class).lifetime(Lifetime.Singleton); 16 | registry.with(InheritanceBeanA2.class).lifetime(Lifetime.Singleton); 17 | registry.with(InheritanceBeanB2.class).lifetime(Lifetime.Singleton); 18 | 19 | BeanContext cntx = new DefaultBeanContext(registry); 20 | InheritanceBeanB2 b2 = cntx.getBean(InheritanceBeanB2.class); 21 | 22 | Assert.assertNotNull(b2.a1); 23 | Assert.assertNotNull(b2.a2); 24 | } 25 | 26 | 27 | @Service 28 | public static class InheritanceBeanA1 {} 29 | @Service 30 | public static class InheritanceBeanA2 {} 31 | @Service 32 | public static class InheritanceBeanB1 { 33 | @Inject 34 | InheritanceBeanA1 a1; 35 | } 36 | @Service 37 | public static class InheritanceBeanB2 extends InheritanceBeanB1 { 38 | @Inject 39 | InheritanceBeanA2 a2; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/IntrospectedClass.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class IntrospectedClass { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/ProviderInjectTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di; 4 | 5 | import org.junit.Test; 6 | import org.terasology.context.Lifetime; 7 | import org.terasology.context.annotation.Service; 8 | import org.terasology.gestalt.di.beans.Dep1; 9 | 10 | import javax.inject.Inject; 11 | import javax.inject.Provider; 12 | import java.util.Optional; 13 | 14 | import static org.junit.Assert.assertNotNull; 15 | import static org.junit.Assert.assertTrue; 16 | 17 | public class ProviderInjectTest { 18 | 19 | @Service 20 | public static class ProviderInjectBean { 21 | @Inject 22 | Provider dep1; 23 | } 24 | 25 | @Test 26 | public void providerInject() { 27 | ServiceRegistry registry = new ServiceRegistry(); 28 | registry.with(ProviderInjectBean.class).lifetime(Lifetime.Singleton); 29 | // Dep1 should be after dependent bean. it some kind Lazy resolution. 30 | registry.with(Dep1.class).lifetime(Lifetime.Singleton); 31 | 32 | BeanContext cntx = new DefaultBeanContext(registry); 33 | 34 | Optional result = cntx.findBean(ProviderInjectBean.class); 35 | assertTrue(result.isPresent()); 36 | assertNotNull(result.get().dep1.get()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/SupplierInjectionTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di; 4 | 5 | import org.junit.Test; 6 | import org.terasology.context.Lifetime; 7 | import org.terasology.context.annotation.Service; 8 | import org.terasology.gestalt.di.beans.Dep1; 9 | 10 | import javax.inject.Inject; 11 | import java.util.Optional; 12 | 13 | import static org.junit.Assert.assertNotNull; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | public class SupplierInjectionTest { 17 | 18 | @Service 19 | public static class SupplierInjection1 { 20 | @Inject 21 | Dep1 dep1; 22 | } 23 | 24 | @Test 25 | public void supplierInject() { 26 | ServiceRegistry registry = new ServiceRegistry(); 27 | registry.with(Dep1.class).lifetime(Lifetime.Singleton); 28 | registry.with(SupplierInjection1.class).use(SupplierInjection1::new).lifetime(Lifetime.Singleton); 29 | 30 | BeanContext cntx = new DefaultBeanContext(registry); 31 | 32 | Optional result = cntx.findBean(SupplierInjection1.class); 33 | assertTrue(result.isPresent()); 34 | assertNotNull(result.get().dep1); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/AnnotatedClass.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.annotation; 4 | 5 | import javax.inject.Singleton; 6 | 7 | @Singleton 8 | @TestAnnotation 9 | @AnnotationValue(one = "hello world") 10 | public class AnnotatedClass { 11 | } 12 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/AnnotationValue.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.annotation; 4 | 5 | import java.lang.annotation.Retention; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Retention(RUNTIME) 10 | public @interface AnnotationValue { 11 | String one() default "one"; 12 | String two() default ""; 13 | int three() default 3; 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/NestedWithTestQualifier1.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 11 | @Documented 12 | @WithTestQualifier1 13 | public @interface NestedWithTestQualifier1 { 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/SubAnnotation.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.annotation; 4 | 5 | import java.lang.annotation.Retention; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @Retention(RUNTIME) 10 | public @interface SubAnnotation { 11 | } 12 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/TestAnnotation.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.annotation; 4 | 5 | import java.lang.annotation.Retention; 6 | 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | @SubAnnotation 10 | @AnnotationValue(one = "five") 11 | @Retention(RUNTIME) 12 | public @interface TestAnnotation { 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/TestQualifier1.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 12 | @Documented 13 | @Qualifier 14 | public @interface TestQualifier1 { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/TestQualifier2.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 12 | @Documented 13 | @Qualifier 14 | @WithProperties(p1 = "Hello", p2 = 5, p3 = 10, p4 = 5.0) 15 | public @interface TestQualifier2 { 16 | } 17 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/TestQualifier3.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Documented; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 12 | @Documented 13 | @Qualifier 14 | public @interface TestQualifier3 { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/WithProperties.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 11 | @Documented 12 | public @interface WithProperties { 13 | String p1(); 14 | int p2(); 15 | long p3(); 16 | double p4(); 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/annotation/WithTestQualifier1.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.di.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 10 | @TestQualifier1 11 | public @interface WithTestQualifier1 { 12 | } 13 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/ContextDep.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | import org.terasology.gestalt.di.BeanContext; 7 | 8 | import javax.inject.Inject; 9 | 10 | @Service 11 | public class ContextDep { 12 | @Inject 13 | public BeanContext context; 14 | } 15 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/Dep1.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class Dep1 { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/Dep2.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class Dep2 { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/Dep3.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class Dep3 { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/Dep4.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class Dep4 { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/NestedClassDep.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | @Service 8 | public class NestedClassDep { 9 | enum Value { 10 | One, 11 | Two, 12 | Three 13 | } 14 | 15 | @Service 16 | public static class InternalDep { 17 | 18 | } 19 | 20 | public static class InternalDepNonIntrospected { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/ParentDep.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.annotation.Service; 6 | 7 | import javax.inject.Inject; 8 | import javax.inject.Named; 9 | 10 | @Service 11 | public class ParentDep { 12 | @Inject 13 | @Named("dep3") 14 | Dep3 dep; 15 | 16 | @Inject 17 | ParentDep(Dep1 one, Dep2 two) { 18 | 19 | } 20 | 21 | @Inject 22 | public void setDep4(Dep4 d){ 23 | 24 | } 25 | 26 | public Dep3 getDep() { 27 | return dep; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/beans/TestRegistry.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.beans; 4 | 5 | import org.terasology.context.Lifetime; 6 | import org.terasology.gestalt.di.ServiceRegistry; 7 | 8 | public class TestRegistry extends ServiceRegistry { 9 | public TestRegistry(){ 10 | this.with(Dep4.class).use(() -> new Dep4()); 11 | this.with(Dep2.class).use(() -> new Dep2()); 12 | this.with(Dep3.class) 13 | .lifetime(Lifetime.Singleton) 14 | .named("dep3"); 15 | this.with(Dep1.class); 16 | this.with(ParentDep.class); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/Counter1.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | import javax.inject.Inject; 6 | 7 | public class Counter1 implements ICounter, ICounter2{ 8 | private int count = 0; 9 | 10 | @Inject 11 | public Counter1() { 12 | 13 | } 14 | 15 | @Override 16 | public void add() { 17 | count++; 18 | } 19 | 20 | @Override 21 | public int getCount() { 22 | return count; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/Counter2.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | import javax.inject.Inject; 6 | 7 | public class Counter2 implements ICounter { 8 | @Inject 9 | public Counter2() { 10 | 11 | } 12 | private int count = 0; 13 | 14 | @Override 15 | public void add() { 16 | count++; 17 | } 18 | 19 | @Override 20 | public int getCount() { 21 | return count; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/Counter3.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | import javax.inject.Inject; 6 | 7 | public class Counter3 implements ICounter { 8 | 9 | @Inject 10 | public Counter3() { 11 | 12 | } 13 | 14 | @Override 15 | public void add() { 16 | 17 | } 18 | 19 | @Override 20 | public int getCount() { 21 | return 0; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/CounterTester.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | import javax.inject.Inject; 6 | import javax.inject.Named; 7 | 8 | public class CounterTester { 9 | private final ICounter c1; 10 | private final ICounter c2; 11 | 12 | @Inject 13 | public CounterTester(@Named("Counter1") ICounter counter1,@Named("Counter2") ICounter counter2) { 14 | this.c1 = counter1; 15 | this.c2 = counter2; 16 | } 17 | 18 | public void addToCounter1() { 19 | c1.add(); 20 | } 21 | 22 | public void addToCounter2() { 23 | c2.add(); 24 | } 25 | 26 | public int getCounter1Count() { 27 | return c1.getCount(); 28 | } 29 | 30 | public int getCounter2Count() { 31 | return c2.getCount(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/ICounter.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | public interface ICounter { 6 | void add(); 7 | 8 | int getCount(); 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/ICounter2.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | public interface ICounter2 { 6 | } 7 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/injection/beans/SampleQualifier.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.injection.beans; 4 | 5 | import javax.inject.Qualifier; 6 | import javax.inject.Singleton; 7 | import java.lang.annotation.Documented; 8 | import java.lang.annotation.ElementType; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.RetentionPolicy; 11 | import java.lang.annotation.Target; 12 | 13 | @Qualifier 14 | @Singleton 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 17 | @Documented 18 | public @interface SampleQualifier { 19 | } 20 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/scanner/standard/StandardScannerTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.scanner.standard; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.terasology.gestalt.di.BeanContext; 8 | import org.terasology.gestalt.di.DefaultBeanContext; 9 | import org.terasology.gestalt.di.ServiceRegistry; 10 | import org.terasology.gestalt.di.scanner.standard.beans.SingletonBean; 11 | import org.terasology.gestalt.di.scanners.StandardScanner; 12 | 13 | import java.util.Optional; 14 | 15 | public class StandardScannerTest { 16 | @Test 17 | public void testSingletonBeanWithScanner() { 18 | ServiceRegistry serviceRegistry = new ServiceRegistry(); 19 | serviceRegistry.registerScanner(new StandardScanner("org.terasology.gestalt.di.scanner.standard")); 20 | 21 | BeanContext beanContext = new DefaultBeanContext(serviceRegistry); 22 | 23 | Optional bean = beanContext.findBean(SingletonBean.class); 24 | Optional bean2 = beanContext.findBean(SingletonBean.class); 25 | Assert.assertTrue(bean.isPresent()); 26 | Assert.assertTrue(bean2.isPresent()); 27 | Assert.assertSame(bean.get(), bean2.get()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/scanner/standard/beans/SingletonBean.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.scanner.standard.beans; 4 | 5 | import javax.inject.Singleton; 6 | 7 | @Singleton 8 | public class SingletonBean { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-di/src/test/java/org/terasology/gestalt/di/scanner/standard/beans/TransientBean.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.gestalt.di.scanner.standard.beans; 4 | 5 | import org.terasology.context.annotation.Transient; 6 | 7 | @Transient 8 | public class TransientBean { 9 | } 10 | -------------------------------------------------------------------------------- /gestalt-entity-system/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Entity-System 2 | Copyright 2019 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). 6 | -------------------------------------------------------------------------------- /gestalt-entity-system/README.md: -------------------------------------------------------------------------------- 1 | gestalt-entity-system 2 | =================== 3 | 4 | A library providing an entity system. 5 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/component/EmptyComponent.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.entitysystem.component; 2 | 3 | /** 4 | * An abstract component that can be extended from for any component with no mutable elements - so components with no attributes. This avoids needing to implement the copy method. 5 | * EmptyComponent may be used for flagging behavior where no configuration is required. I would suggest this should not come up hugely often, and if you are finding you have a lot 6 | * of empty components you might consider whether they would be better handled by another component having boolean attributes. 7 | *

8 | * Note if this is used for a component with attributes and the copy method is not overwritten then the component will not behave as desired - effectively the entity system will 9 | * not retain any values given to the attributes. 10 | */ 11 | public abstract class EmptyComponent implements Component { 12 | 13 | @Override 14 | public void copyFrom(T other) { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/component/management/ComponentTypeGenerationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.component.management; 18 | 19 | /** 20 | * The exception thrown if there is an error generating a component type for a component 21 | */ 22 | public class ComponentTypeGenerationException extends RuntimeException { 23 | 24 | public ComponentTypeGenerationException() { 25 | } 26 | 27 | public ComponentTypeGenerationException(String message) { 28 | super(message); 29 | } 30 | 31 | public ComponentTypeGenerationException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/component/management/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains classes related to management of components, including generic reflection-like 3 | * accessors, type information and gestalt-module integration for discovery. 4 | */ 5 | package org.terasology.gestalt.entitysystem.component.management; 6 | 7 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/component/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides support for entity Components. Components are the building blocks from 3 | * which all entities are composed - each component should provide a behavior and the configuration 4 | * for that behavior. 5 | */ 6 | package org.terasology.gestalt.entitysystem.component; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/component/store/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides component stores - each component store handles storage of a single type 3 | * of component across entities, by entity id. Different implementations are offered for different 4 | * performance use cases, although if in doubt {@link org.terasology.gestalt.entitysystem.component.store.ArrayComponentStore} 5 | * is probably the reliable go-to. {@link org.terasology.gestalt.entitysystem.component.store.ConcurrentComponentStore} 6 | * can be used to make any component store thread safe, at least in so far as making single actions 7 | * atomic - it doesn't protect against broader concerns such as lost update scenarios. 8 | */ 9 | package org.terasology.gestalt.entitysystem.component.store; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/entity/EntityIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.entity; 18 | 19 | /** 20 | * An entity iterator is used to iterate over a set of Entities. These may also have secondary 21 | * effects when iteratoring, such as retrieving components 22 | */ 23 | public interface EntityIterator { 24 | 25 | /** 26 | * Fetches the next entity 27 | * @return Whether there is another entity 28 | */ 29 | boolean next(); 30 | 31 | /** 32 | * @return The current entity 33 | */ 34 | EntityRef getEntity(); 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/entity/manager/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Entity manager implementation 3 | */ 4 | package org.terasology.gestalt.entitysystem.entity.manager; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/entity/pacakge-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides the core interfaces and classes for working with entities. 3 | * Entities are objects that are identified compositions of components. The most important 4 | * class is EntityRef, which is the interface for working with Entities. 5 | */ 6 | package org.terasology.gestalt.entitysystem.entity; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.event; 18 | 19 | import org.terasology.context.annotation.IndexInherited; 20 | 21 | /** 22 | * Base interface for all events. An event is a notification that sent against an entity - 23 | * event handlers can then pick up and react to the event based on the components 24 | * the entity is composed of. 25 | */ 26 | @IndexInherited 27 | public interface Event { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/EventResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.event; 18 | 19 | /** 20 | * Possible results from processing an event 21 | */ 22 | public enum EventResult { 23 | /** 24 | * Signals that event processing should continue. 25 | */ 26 | CONTINUE, 27 | 28 | /** 29 | * Signals that event processing should halt, but be considered successfully complete. 30 | */ 31 | COMPLETE, 32 | 33 | /** 34 | * Signals that event processing should halt, and should be considered unsuccessful. 35 | */ 36 | CANCEL 37 | } 38 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package contains exceptions related to the event system 3 | */ 4 | package org.terasology.gestalt.entitysystem.event.exception; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Event system implementation related classes, including EventReceiverMethodSupport for registering annotated event methods. 3 | */ 4 | package org.terasology.gestalt.entitysystem.event.impl; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/lifecycle/LifecycleEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.event.lifecycle; 18 | 19 | import org.terasology.gestalt.entitysystem.component.Component; 20 | import org.terasology.gestalt.entitysystem.event.Event; 21 | 22 | import java.util.Set; 23 | 24 | /** 25 | * Base type for Lifecycle events 26 | */ 27 | public interface LifecycleEvent extends Event { 28 | 29 | /** 30 | * @return The component types involved in this lifecycle event 31 | */ 32 | Set> getComponentTypes(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/lifecycle/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains classes related to sending entity/component lifecycle events for when entities are changed. 3 | */ 4 | package org.terasology.gestalt.entitysystem.event.lifecycle; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Support for sending events against entities. Events are delivered to handling methods, filtered by 3 | * the type of event and the components that an entity is composed of. 4 | */ 5 | @API 6 | package org.terasology.gestalt.entitysystem.event; 7 | 8 | import org.terasology.context.annotation.API; -------------------------------------------------------------------------------- /gestalt-entity-system/src/main/java/org/terasology/gestalt/entitysystem/prefab/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Prefabs are entity recipes that can be instantiated. 3 | */ 4 | package org.terasology.gestalt.entitysystem.prefab; -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/TestChildEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | /** 20 | * 21 | */ 22 | public class TestChildEvent extends TestEvent { 23 | public TestChildEvent(String value) { 24 | super(value); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/TestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.event.Event; 20 | 21 | /** 22 | * 23 | */ 24 | public class TestEvent implements Event { 25 | private final String value; 26 | 27 | public TestEvent(String value) { 28 | this.value = value; 29 | } 30 | 31 | public String getValue() { 32 | return value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/TestEventReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.entity.EntityRef; 20 | import org.terasology.gestalt.entitysystem.event.EventResult; 21 | import org.terasology.gestalt.entitysystem.event.ReceiveEvent; 22 | 23 | import modules.test.components.Sample; 24 | 25 | /** 26 | * 27 | */ 28 | public class TestEventReceiver { 29 | 30 | public boolean called = false; 31 | public Sample component; 32 | 33 | @ReceiveEvent 34 | public EventResult testEventListener(TestEvent event, EntityRef entity, Sample sample) { 35 | called = true; 36 | component = sample; 37 | return EventResult.COMPLETE; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/TestSynchEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.event.Event; 20 | import org.terasology.gestalt.entitysystem.event.Synchronous; 21 | 22 | /** 23 | * 24 | */ 25 | @Synchronous 26 | public class TestSynchEvent implements Event { 27 | private final String value; 28 | 29 | public TestSynchEvent(String value) { 30 | this.value = value; 31 | } 32 | 33 | public String getValue() { 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/components/ArrayContainingComponent.java: -------------------------------------------------------------------------------- 1 | package modules.test.components; 2 | 3 | import org.terasology.gestalt.entitysystem.component.Component; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ArrayContainingComponent implements Component { 9 | 10 | public List strings = new ArrayList<>(); 11 | 12 | @Override 13 | public void copyFrom(ArrayContainingComponent other) { 14 | strings.clear(); 15 | strings.addAll(other.strings); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/components/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test.components; 18 | 19 | import org.terasology.gestalt.entitysystem.component.EmptyComponent; 20 | 21 | /** 22 | * 23 | */ 24 | public final class Empty extends EmptyComponent { 25 | public Empty() { 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/modules/test/components/PublicAttributeComponent.java: -------------------------------------------------------------------------------- 1 | package modules.test.components; 2 | 3 | import org.terasology.gestalt.entitysystem.component.Component; 4 | 5 | public class PublicAttributeComponent implements Component { 6 | 7 | public String name = ""; 8 | 9 | @Override 10 | public void copyFrom(PublicAttributeComponent other) { 11 | this.name = other.name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/org/terasology/gestalt/entitysystem/component/management/ComponentTypeFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.entitysystem.component.management; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | import modules.test.components.ArrayContainingComponent; 8 | import modules.test.components.BasicComponent; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public abstract class ComponentTypeFactoryTest { 13 | 14 | public abstract ComponentTypeFactory getFactory(); 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/java/org/terasology/gestalt/entitysystem/component/management/ReflectionComponentManagerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.component.management; 18 | 19 | /** 20 | * 21 | */ 22 | public class ReflectionComponentManagerTest extends ComponentManagerTest { 23 | 24 | public ComponentTypeFactory getComponentTypeFactory() { 25 | return new ReflectionComponentTypeFactory(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/abridged-single.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entity": { 3 | "sample": { 4 | "name": "Test Name" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/external-composition.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "root": { 4 | "sample": { 5 | "name": "Composition Name" 6 | }, 7 | "reference": { 8 | "reference" : "test:single" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/inheritance.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "inherit" : "test:single", 3 | "entities" : { 4 | "root": { 5 | "sample": { 6 | "description" : "New Description" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/lenient-single.prefab: -------------------------------------------------------------------------------- 1 | // Test example showing lenient parsing behavior 2 | { 3 | entities : { 4 | root: { 5 | sample: { 6 | name = "Test Name", 7 | description = "Test Description" 8 | } 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/multi-explicit-root.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "root" : "first", 3 | "entities" : { 4 | "second": { 5 | "sample": { 6 | "name": "Second Entity" 7 | } 8 | }, 9 | "first": { 10 | "sample": { 11 | "name": "Test Name" 12 | }, 13 | "reference": { 14 | "reference": "this:second" 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/multi-root-last.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entities" : { 3 | "second": { 4 | "sample": { 5 | "name": "Second Entity" 6 | } 7 | }, 8 | "root": { 9 | "sample": { 10 | "name": "Test Name" 11 | }, 12 | "reference": { 13 | "reference": "this:second" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/multi.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entities" : { 3 | "root": { 4 | "sample": { 5 | "name": "Test Name" 6 | }, 7 | "reference": { 8 | "reference": "this:second" 9 | } 10 | }, 11 | "second": { 12 | "sample": { 13 | "name": "Second Entity" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/reference-list.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entity": { 3 | "reference": { 4 | "references": [ 5 | "test:single", 6 | "test:single", 7 | "test:multi" 8 | ] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/assets/prefabs/single.prefab: -------------------------------------------------------------------------------- 1 | { 2 | "entities" : { 3 | "root": { 4 | "sample": { 5 | "name": "Test Name", 6 | "description" : "Test Description" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /gestalt-entity-system/src/test/resources/modules/test/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "Test", 3 | "version": "1.0.0", 4 | "displayName": "Test", 5 | "description": "This module contains test classes and assets for gestalt-entity-system" 6 | } 7 | -------------------------------------------------------------------------------- /gestalt-es-perf/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Entity-System 2 | Copyright 2019 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). 6 | -------------------------------------------------------------------------------- /gestalt-es-perf/README.md: -------------------------------------------------------------------------------- 1 | gestalt-es-perf 2 | =================== 3 | 4 | A library providing performant reflection replacement for gestalt-entity-system. This requires Java 7+ or Android API 26+. 5 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/TestChildEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | /** 20 | * 21 | */ 22 | public class TestChildEvent extends TestEvent { 23 | public TestChildEvent(String value) { 24 | super(value); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/TestEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.event.Event; 20 | 21 | /** 22 | * 23 | */ 24 | public class TestEvent implements Event { 25 | private final String value; 26 | 27 | public TestEvent(String value) { 28 | this.value = value; 29 | } 30 | 31 | public String getValue() { 32 | return value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/TestEventReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.entity.EntityRef; 20 | import org.terasology.gestalt.entitysystem.event.EventResult; 21 | import org.terasology.gestalt.entitysystem.event.ReceiveEvent; 22 | 23 | import modules.test.components.Sample; 24 | 25 | /** 26 | * 27 | */ 28 | public class TestEventReceiver { 29 | 30 | public boolean called = false; 31 | public Sample component; 32 | 33 | @ReceiveEvent 34 | public EventResult testEventListener(TestEvent event, EntityRef entity, Sample sample) { 35 | called = true; 36 | component = sample; 37 | return EventResult.COMPLETE; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/TestSynchEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test; 18 | 19 | import org.terasology.gestalt.entitysystem.event.Event; 20 | import org.terasology.gestalt.entitysystem.event.Synchronous; 21 | 22 | /** 23 | * 24 | */ 25 | @Synchronous 26 | public class TestSynchEvent implements Event { 27 | private final String value; 28 | 29 | public TestSynchEvent(String value) { 30 | this.value = value; 31 | } 32 | 33 | public String getValue() { 34 | return value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/components/ArrayContainingComponent.java: -------------------------------------------------------------------------------- 1 | package modules.test.components; 2 | 3 | import org.terasology.gestalt.entitysystem.component.Component; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class ArrayContainingComponent implements Component { 9 | 10 | public List strings = new ArrayList<>(); 11 | 12 | @Override 13 | public void copyFrom(ArrayContainingComponent other) { 14 | strings.clear(); 15 | strings.addAll(other.strings); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/components/Empty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package modules.test.components; 18 | 19 | import org.terasology.gestalt.entitysystem.component.Component; 20 | 21 | /** 22 | * 23 | */ 24 | public final class Empty implements Component { 25 | 26 | public Empty() { 27 | } 28 | 29 | public Empty(Empty other) { 30 | copyFrom(other); 31 | } 32 | 33 | public void copyFrom(Empty other) { 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/modules/test/components/PublicAttributeComponent.java: -------------------------------------------------------------------------------- 1 | package modules.test.components; 2 | 3 | import org.terasology.gestalt.entitysystem.component.Component; 4 | 5 | public class PublicAttributeComponent implements Component { 6 | 7 | public String name = ""; 8 | 9 | @Override 10 | public void copyFrom(PublicAttributeComponent other) { 11 | this.name = other.name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/org/terasology/gestalt/entitysystem/component/management/LambdaComponentTypeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.component.management; 18 | 19 | import org.terasology.gestalt.entitysystem.component.management.perf.ComponentManagerTest; 20 | 21 | /** 22 | * 23 | */ 24 | public class LambdaComponentTypeFactoryTest extends ComponentManagerTest { 25 | 26 | public ComponentTypeFactory getComponentTypeFactory() { 27 | return new LambdaComponentTypeFactory(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/org/terasology/gestalt/entitysystem/component/management/MethodHandleComponentTypeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.component.management; 18 | 19 | import org.terasology.gestalt.entitysystem.component.management.perf.ComponentManagerTest; 20 | 21 | /** 22 | * 23 | */ 24 | public class MethodHandleComponentTypeFactoryTest extends ComponentManagerTest { 25 | 26 | public ComponentTypeFactory getComponentTypeFactory() { 27 | return new MethodHandleComponentTypeFactory(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gestalt-es-perf/src/test/java/org/terasology/gestalt/entitysystem/event/MethodHandleEventRecieverMethodSupportTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.entitysystem.event; 18 | 19 | public class MethodHandleEventRecieverMethodSupportTest extends AbstractEventReceiverMethodSupportTest { 20 | 21 | @Override 22 | protected EventHandlerFactory getEventHandlerFactory() { 23 | return MethodHandleEventHandle::new; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-inject-java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply(from = "$rootDir/gradle/common.gradle.kts") 4 | 5 | plugins { 6 | `java-library` 7 | } 8 | 9 | dependencies { 10 | implementation(project(":gestalt-util")) 11 | implementation(libs.guava) 12 | implementation(libs.gson) 13 | implementation("org.apache.commons:commons-vfs2:2.2") 14 | implementation(libs.slf4j.api) 15 | implementation(libs.android.annotation) 16 | implementation("com.github.zafarkhaja:java-semver:0.10.2") 17 | 18 | testImplementation(project(":testpack:testpack-api")) 19 | testImplementation(libs.junit) 20 | testImplementation(libs.logback) 21 | testImplementation(libs.mockito) 22 | 23 | implementation("com.squareup:javapoet:1.12.0") 24 | implementation("javax.inject:javax.inject:1") 25 | implementation(project(":gestalt-inject")) 26 | } 27 | -------------------------------------------------------------------------------- /gestalt-inject-java/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | org.terasology.gestalt.annotation.processing.BeanDefinitionProcessor 2 | org.terasology.gestalt.annotation.processing.ClassIndexProcessor 3 | org.terasology.gestalt.annotation.processing.ResourceProcessor -------------------------------------------------------------------------------- /gestalt-inject-java/src/test/java/org/terasology/gestalt/support/Parser.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.support; 2 | 3 | import javax.tools.DiagnosticCollector; 4 | import javax.tools.JavaCompiler; 5 | import javax.tools.JavaFileObject; 6 | import javax.tools.StandardJavaFileManager; 7 | import javax.tools.ToolProvider; 8 | import java.util.Locale; 9 | 10 | import static java.nio.charset.StandardCharsets.UTF_8; 11 | 12 | public class Parser { 13 | 14 | public static Iterable generate(JavaFileObject... sources) { 15 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 16 | DiagnosticCollector diagnosticCollector = new DiagnosticCollector<>(); 17 | final StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(diagnosticCollector, Locale.getDefault(), UTF_8); 18 | return null; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gestalt-inject/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply(from = "$rootDir/gradle/common.gradle.kts") 4 | 5 | plugins { 6 | `java-library` 7 | } 8 | 9 | dependencies { 10 | api("javax.inject:javax.inject:1") 11 | implementation(libs.slf4j.api) 12 | implementation(libs.guava) 13 | } 14 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/AnnotationMetadata.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | import java.lang.annotation.Annotation; 6 | import java.util.List; 7 | 8 | /** 9 | * Annotation data that is used to drive avoid reflection. 10 | */ 11 | public interface AnnotationMetadata extends Iterable[]> { 12 | 13 | List> getAnnotationsByStereotype(Class stereotype); 14 | 15 | List> getAnnotationsByStereotype(String stereotype); 16 | 17 | List> findAnnotations(String annotation); 18 | 19 | List> findAnnotations(Class annotation); 20 | 21 | boolean hasAnnotation(Class annotation); 22 | 23 | boolean hasAnnotation(String annotation); 24 | 25 | boolean hasStereotype(Class annotation); 26 | 27 | boolean hasStereotype(String annotation); 28 | 29 | Object getRawSingleValue(String annotation, String field); 30 | } 31 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/BeanDefinition.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | import org.terasology.context.exception.DependencyInjectionException; 6 | 7 | import java.util.Optional; 8 | import java.util.function.Supplier; 9 | 10 | /** 11 | * Definition used to construct dependency. 12 | * 13 | * @param target type 14 | */ 15 | public interface BeanDefinition { 16 | AnnotationMetadata getAnnotationMetadata(); 17 | 18 | default K requiredDependency(Optional wrapper, Supplier exceptionSupplier) { 19 | if(!wrapper.isPresent()) { 20 | throw exceptionSupplier.get(); 21 | } 22 | return wrapper.get(); 23 | } 24 | 25 | Optional build(BeanResolution resolution); 26 | 27 | Optional inject(T instance, BeanResolution resolution); 28 | 29 | Argument[] getArguments(); 30 | 31 | Class[] getTypeArgument(); 32 | 33 | Class targetClass(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/BeanResolution.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | import org.terasology.context.exception.DependencyInjectionException; 6 | 7 | import java.util.Optional; 8 | 9 | /** 10 | * Bean Resolution for building an object 11 | */ 12 | public interface BeanResolution { 13 | 14 | /** 15 | * resolving an objects for injecting into constructor 16 | * @param argument the argument 17 | * @param the type 18 | * @return the result 19 | * @throws DependencyInjectionException 20 | */ 21 | Optional resolveConstructorArgument(Argument argument) throws DependencyInjectionException; 22 | 23 | 24 | /** 25 | * resolving an objects for injecting into a field 26 | * @param argument the argument 27 | * @param the type 28 | * @return the result 29 | * @throws DependencyInjectionException 30 | */ 31 | Optional resolveParameterArgument(Argument argument) throws DependencyInjectionException; 32 | } 33 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/DefaultArgument.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | public class DefaultArgument implements Argument { 6 | 7 | private final Class type; 8 | private final AnnotationMetadata annotationMetadata; 9 | 10 | public DefaultArgument(Class type, AnnotationMetadata annotationMetadata) { 11 | this.type = type; 12 | this.annotationMetadata = annotationMetadata; 13 | } 14 | 15 | @Override 16 | public String getName() { 17 | return type.getSimpleName(); 18 | } 19 | 20 | @Override 21 | public Class getType() { 22 | return type; 23 | } 24 | 25 | @Override 26 | public AnnotationMetadata getAnnotation() { 27 | return this.annotationMetadata; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/FindResourcesClassLoader.java: -------------------------------------------------------------------------------- 1 | package org.terasology.context; 2 | 3 | import java.net.URL; 4 | import java.util.Enumeration; 5 | 6 | public interface FindResourcesClassLoader { 7 | Enumeration findResources(String name); 8 | } 9 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/Lifetime.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | /** 6 | * lifetime scope drives how persistent a bean will and how it will be reused between different scopes. a child scope that redfined a bean will shadow its parents even if a 7 | * parent scope has a singleton objects. 8 | *

- Scoped --> A single instance is defined for every nested scope. (A --> B --> C) a scoped instanced defined at B will create a new single instance in C and B

9 | *

- ScopedToChildren --> A new instance is defined for every nested scope except the one its defined in. (A --> B --> C --> D) a scoped instanced defined at B will create a new single instance in C and D

10 | *

- Singleton --> A single instance is defined and visible to all children.

11 | *

- Transient --> A new object is always returned if requested.

12 | */ 13 | public enum Lifetime { 14 | Scoped, 15 | ScopedToChildren, 16 | Singleton, 17 | Transient 18 | } 19 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/SingleGenericArgument.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context; 4 | 5 | public class SingleGenericArgument implements Argument { 6 | 7 | private final Class type; 8 | private final Class genericType; 9 | private final AnnotationMetadata annotationMetadata; 10 | 11 | public SingleGenericArgument(Class genericType,Class type, AnnotationMetadata annotationMetadata) { 12 | this.type = type; 13 | this.annotationMetadata = annotationMetadata; 14 | this.genericType = genericType; 15 | } 16 | 17 | public Class getGenericType() { 18 | return this.genericType; 19 | } 20 | 21 | @Override 22 | public Class getType() { 23 | return type; 24 | } 25 | 26 | @Override 27 | public AnnotationMetadata getAnnotation() { 28 | return annotationMetadata; 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return type.getSimpleName(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/API.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * The API annotation can be used to mark classes to be available to modules. 13 | */ 14 | 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 17 | @Documented 18 | @Index 19 | public @interface API { 20 | 21 | /** 22 | * @return The permission sets that should be granted access to the marked class 23 | */ 24 | String[] permissionSet() default ""; 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/Index.java: -------------------------------------------------------------------------------- 1 | package org.terasology.context.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * Annotatation for indexing classes. 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.TYPE) 14 | @Documented 15 | public @interface Index { 16 | } 17 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/IndexInherited.java: -------------------------------------------------------------------------------- 1 | package org.terasology.context.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Inherited; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Annotatation for indexing classes. Inherited version. 12 | * Don't works at annotations. 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.TYPE) 16 | @Documented 17 | @Inherited 18 | public @interface IndexInherited { 19 | } 20 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/RegisterSystem.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import javax.inject.Qualifier; 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 14 | @Documented 15 | @Qualifier 16 | public @interface RegisterSystem { 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/Scoped.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 13 | @Documented 14 | public @interface Scoped { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/Service.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 13 | @Documented 14 | public @interface Service { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/Transient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 13 | @Documented 14 | public @interface Transient { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/annotation/UsedByGeneratedCode.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.annotation; 4 | 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ElementType.TYPE, ElementType.PACKAGE}) 13 | @Documented 14 | public @interface UsedByGeneratedCode { 15 | } 16 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/exception/BeanNotFoundException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.exception; 4 | 5 | public class BeanNotFoundException extends DependencyInjectionException{ 6 | public BeanNotFoundException() { 7 | super(); 8 | } 9 | 10 | public BeanNotFoundException(String message) { 11 | super(message); 12 | } 13 | 14 | public BeanNotFoundException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public BeanNotFoundException(Throwable cause) { 19 | super(cause); 20 | } 21 | 22 | protected BeanNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 23 | super(message, cause, enableSuppression, writableStackTrace); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/exception/CloseBeanException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.exception; 4 | 5 | public class CloseBeanException extends DependencyInjectionException{ 6 | public CloseBeanException() { 7 | super(); 8 | } 9 | 10 | public CloseBeanException(String message) { 11 | super(message); 12 | } 13 | 14 | public CloseBeanException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public CloseBeanException(Throwable cause) { 19 | super(cause); 20 | } 21 | 22 | protected CloseBeanException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 23 | super(message, cause, enableSuppression, writableStackTrace); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/exception/DependencyInjectionException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.exception; 4 | 5 | public class DependencyInjectionException extends RuntimeException{ 6 | 7 | public DependencyInjectionException() { 8 | super(); 9 | } 10 | 11 | public DependencyInjectionException(String message) { 12 | super(message); 13 | } 14 | 15 | public DependencyInjectionException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public DependencyInjectionException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | protected DependencyInjectionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 24 | super(message, cause, enableSuppression, writableStackTrace); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/injection/NameQualifier.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.injection; 4 | 5 | import javax.inject.Named; 6 | import java.util.Objects; 7 | 8 | /** 9 | * The value for {@link Named#value()} is tied to the target bean and the lookup is based off of the name of the target. 10 | * @param 11 | */ 12 | public class NameQualifier implements Qualifier { 13 | private final String name; 14 | 15 | public NameQualifier(String name) { 16 | this.name = name; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object o) { 21 | if (this == o) return true; 22 | if (o == null || getClass() != o.getClass()) return false; 23 | NameQualifier that = (NameQualifier) o; 24 | return Objects.equals(name, that.name); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return Objects.hash(name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/injection/Qualifier.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.injection; 4 | 5 | public interface Qualifier { 6 | 7 | /** 8 | * Whether this qualifier contains the given qualifier. 9 | * @param qualifier The qualifier 10 | * @return True it does 11 | */ 12 | default boolean contains(Qualifier qualifier) { 13 | return equals(qualifier); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/injection/StereotypeQualifier.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.injection; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * A annotation that extends {@link Qualifier} and tied to a bean is used help qualify a candidate when injecting. 9 | * @param 10 | */ 11 | public class StereotypeQualifier implements Qualifier { 12 | 13 | private final Class stereotype; 14 | 15 | public StereotypeQualifier(Class stereotype){ 16 | this.stereotype = stereotype; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object o) { 21 | if (this == o) return true; 22 | if (o == null || getClass() != o.getClass()) return false; 23 | StereotypeQualifier that = (StereotypeQualifier) o; 24 | return Objects.equals(stereotype, that.stereotype); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return Objects.hash(stereotype); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gestalt-inject/src/main/java/org/terasology/context/service/ServiceDefinition.java: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | package org.terasology.context.service; 4 | 5 | import java.util.function.Supplier; 6 | 7 | /** 8 | * A service that may or may not be present on the classpath. 9 | * 10 | * @param The service type 11 | */ 12 | public interface ServiceDefinition { 13 | 14 | /** 15 | * @return The full class name of the service 16 | */ 17 | String getName(); 18 | 19 | /** 20 | * @return is the service present 21 | */ 22 | boolean isPresent(); 23 | 24 | /** 25 | * Load the service of throw the given exception. 26 | * 27 | * @param exceptionSupplier The exception supplier 28 | * @param The exception type 29 | * @return The instance 30 | * @throws X The exception concrete type 31 | */ 32 | T orElseThrow(Supplier exceptionSupplier) throws X; 33 | 34 | /** 35 | * @return load the service 36 | */ 37 | T load(); 38 | } 39 | -------------------------------------------------------------------------------- /gestalt-module/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Module 2 | Copyright 2019 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). -------------------------------------------------------------------------------- /gestalt-module/README.md: -------------------------------------------------------------------------------- 1 | gestalt-module 2 | ============== 3 | 4 | This project provides a plugin framework allowing modules - directories or zips of files, or java libraries - that can be loaded at runtime and run in a sandboxed environment. 5 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/i18n/gson/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides gson type adapters for serializing and deserializing i18n classes. 19 | */ 20 | package org.terasology.gestalt.i18n.gson; 21 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/i18n/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides internationalisation supporting classes (i18n is shorthand for internationalisation) 19 | */ 20 | package org.terasology.gestalt.i18n; 21 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/ModuleMetadataLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module; 18 | 19 | import java.io.IOException; 20 | import java.io.Reader; 21 | 22 | /** 23 | * A module metadata loader reads module metadata from a file. 24 | */ 25 | public interface ModuleMetadataLoader { 26 | 27 | /** 28 | * Read module metadata from file. 29 | * 30 | * @param reader Metadata to load 31 | * @return The loaded module metadata. 32 | * @throws IOException If there was an error reading the ModuleMetadata 33 | */ 34 | ModuleMetadata read(Reader reader) throws IOException; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/ModuleServiceRegistry.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.module; 2 | 3 | import org.terasology.gestalt.di.ServiceRegistry; 4 | import org.terasology.gestalt.module.dependencyresolution.DependencyResolver; 5 | import org.terasology.gestalt.module.sandbox.PermissionProviderFactory; 6 | 7 | /** 8 | * A service registry for modules. 9 | */ 10 | public class ModuleServiceRegistry extends ServiceRegistry { 11 | /** 12 | * Constructor 13 | * @param permissionProviderFactory the permissionsproviderfactory 14 | */ 15 | public ModuleServiceRegistry(PermissionProviderFactory permissionProviderFactory) { 16 | with(ModuleMetadataJsonAdapter.class); 17 | with(ModuleFactory.class); 18 | with(TableModuleRegistry.class); 19 | with(DependencyResolver.class); 20 | with(PermissionProviderFactory.class).use(() -> permissionProviderFactory); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/dependencyresolution/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Provides support for determining a compatible set of modules, based on what modules and versions of those modules are available, the desired set of modules, and 19 | * module dependencies. 20 | *

21 | * Important classes: 22 | *

    23 | *
  • {@link org.terasology.gestalt.module.dependencyresolution.DependencyResolver} is the core class for resolving a compatible dependent set
  • 24 | *
  • {@link org.terasology.gestalt.module.dependencyresolution.ResolutionResult} holds the results of dependency resolution
  • 25 | *
26 | */ 27 | package org.terasology.gestalt.module.dependencyresolution; 28 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/exceptions/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Exceptions relating to modules 19 | */ 20 | package org.terasology.gestalt.module.exceptions; 21 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/predicates/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Predicates for use with {@link org.terasology.gestalt.module.ModuleEnvironment}::getSubtypesOf or {@link org.terasology.gestalt.module.ModuleEnvironment}::getTypesAnnotatedWith to further 19 | * filter results. 20 | */ 21 | package org.terasology.gestalt.module.predicates; 22 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/sandbox/BytecodeInjector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.sandbox; 18 | 19 | import javassist.CtClass; 20 | 21 | /** 22 | * An interface for classes that inject or modify byte code in classes during the load process. 23 | * 24 | * @author Immortius 25 | */ 26 | public interface BytecodeInjector { 27 | 28 | /** 29 | * Injects a class during the load process. 30 | * @param cc The class being loaded. 31 | */ 32 | void inject(CtClass cc); 33 | } 34 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/sandbox/ObtainClassloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.sandbox; 18 | 19 | import java.security.PrivilegedAction; 20 | 21 | /** 22 | * PrivilegedAction for obtaining the ClassLoader of a type. 23 | * 24 | * @author Immortius 25 | */ 26 | public class ObtainClassloader implements PrivilegedAction { 27 | private final Class type; 28 | 29 | /** 30 | * Constructor 31 | * @param forType The type to obtain the ClassLoader of. 32 | */ 33 | public ObtainClassloader(Class forType) { 34 | type = forType; 35 | } 36 | 37 | @Override 38 | public ClassLoader run() { 39 | return type.getClassLoader(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/module/sandbox/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Classes relating to securing and sandboxing modules. This allows modules to be restricted to using desired classes and permissions. 19 | */ 20 | package org.terasology.gestalt.module.sandbox; 21 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/naming/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides exceptions for naming classes 19 | */ 20 | @API 21 | package org.terasology.gestalt.naming.exception; 22 | 23 | import org.terasology.context.annotation.API; 24 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/naming/gson/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides gson type adapters for naming classes 19 | */ 20 | package org.terasology.gestalt.naming.gson; 21 | -------------------------------------------------------------------------------- /gestalt-module/src/main/java/org/terasology/gestalt/naming/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * This package provides classes related to naming/identity - such as case-insensitive names, versions and version ranges. 19 | */ 20 | @API 21 | package org.terasology.gestalt.naming; 22 | 23 | import org.terasology.context.annotation.API; 24 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/packageModule/StandaloneClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.packageModule; 18 | 19 | import org.terasology.test.api.IndexForTest; 20 | 21 | @IndexForTest 22 | public class StandaloneClass { 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/resources/ArchiveFileSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.resources; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | 22 | public class ArchiveFileSourceTest extends BaseFileSourceTest { 23 | 24 | private ArchiveFileSource source; 25 | 26 | public ArchiveFileSourceTest() throws IOException { 27 | source = new ArchiveFileSource(new File("src/test/resources/archive.zip"), "content"); 28 | } 29 | 30 | @Override 31 | public ModuleFileSource getFileSource() { 32 | return source; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/resources/ClasspathFileSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.resources; 18 | 19 | import org.junit.BeforeClass; 20 | 21 | public class ClasspathFileSourceTest extends BaseFileSourceTest { 22 | 23 | private static ClasspathFileSource source; 24 | 25 | @BeforeClass 26 | public static void setup() { 27 | source = new ClasspathFileSource("content"); 28 | } 29 | 30 | @Override 31 | public ModuleFileSource getFileSource() { 32 | return source; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/resources/CompositeFileSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.resources; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | 22 | public class CompositeFileSourceTest extends BaseFileSourceTest { 23 | 24 | private CompositeFileSource source; 25 | 26 | public CompositeFileSourceTest() throws IOException { 27 | source = new CompositeFileSource(new DirectoryFileSource(new File("src/test/resources/halfone/content")), new ArchiveFileSource(new File("src/test/resources/halftwo.zip"), "content")); 28 | } 29 | 30 | @Override 31 | public ModuleFileSource getFileSource() { 32 | return source; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/resources/DirectoryFileSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.resources; 18 | 19 | import java.io.File; 20 | 21 | public class DirectoryFileSourceTest extends BaseFileSourceTest { 22 | 23 | private DirectoryFileSource source = new DirectoryFileSource(new File("src/test/resources/content")); 24 | 25 | @Override 26 | public ModuleFileSource getFileSource() { 27 | return source; 28 | } 29 | } -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/sandbox/APIClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.sandbox; 18 | 19 | import org.terasology.context.annotation.API; 20 | 21 | /** 22 | * @author Immortius 23 | */ 24 | @API 25 | public class APIClass { 26 | } 27 | -------------------------------------------------------------------------------- /gestalt-module/src/test/java/org/terasology/gestalt/module/sandbox/NonAPIClassInheritingAPIClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.module.sandbox; 18 | 19 | /** 20 | * @author Immortius 21 | */ 22 | public class NonAPIClassInheritingAPIClass extends APIClass { 23 | } 24 | -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/archive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/archive.zip -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/content/fake.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/content/fake.class -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/content/folder/some.resource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/content/folder/some.resource -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/content/readme.txt: -------------------------------------------------------------------------------- 1 | This is a location used for testing module file sources - these are locations provided by modules 2 | that expose files as content of a module. -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/content/subfolder/subpath/another.resource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/content/subfolder/subpath/another.resource -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/content/subfolder/test.resource: -------------------------------------------------------------------------------- 1 | this space intentionally left blank -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/halfone/content/folder/some.resource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/halfone/content/folder/some.resource -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/halfone/content/readme.txt: -------------------------------------------------------------------------------- 1 | This is a location used for testing module file sources - these are locations provided by modules 2 | that expose files as content of a module. -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/halfone/content/subfolder/subpath/another.resource: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/halfone/content/subfolder/subpath/another.resource -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/halftwo.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gestalt-module/src/test/resources/halftwo.zip -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/hidden.txt: -------------------------------------------------------------------------------- 1 | This should not be found in the module -------------------------------------------------------------------------------- /gestalt-module/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | %msg%n 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gestalt-module/test-modules/moduleE/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleE", 3 | "version": "1.0.0", 4 | "displayName": "Module E", 5 | "description": "This module contains a library" 6 | } 7 | -------------------------------------------------------------------------------- /gestalt-util/NOTICE: -------------------------------------------------------------------------------- 1 | Gestalt-Util 2 | Copyright 2019 Moving Blocks 3 | 4 | This product includes software developed at 5 | Moving Blocks (http://www.movingblocks.net/). -------------------------------------------------------------------------------- /gestalt-util/README.md: -------------------------------------------------------------------------------- 1 | gestalt-util 2 | ============== 3 | 4 | This project provides some utility classes that are generally useful across the gestalt libraries. 5 | -------------------------------------------------------------------------------- /gestalt-util/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply(from = "$rootDir/gradle/common.gradle.kts") 4 | 5 | plugins { 6 | `java-library` 7 | } 8 | 9 | // Primary dependencies definition 10 | dependencies { 11 | implementation(libs.guava) 12 | implementation("com.googlecode.gentyref:gentyref:1.2.0") 13 | implementation(libs.slf4j.api) 14 | implementation(libs.android.annotation) 15 | 16 | // These dependencies are only needed for running tests 17 | testImplementation(libs.junit) 18 | testImplementation(libs.logback) 19 | testImplementation(libs.mockito) 20 | } 21 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/collection/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Provides collections and collection related classes 19 | */ 20 | package org.terasology.gestalt.util.collection; 21 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/io/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Provides file and io related utility classes 19 | */ 20 | package org.terasology.gestalt.util.io; 21 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Provides common utility classes and static method providers. 19 | */ 20 | package org.terasology.gestalt.util; 21 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/reflection/ClassFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.util.reflection; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * Interface for Class factories. These generically generate requested classes. 23 | * 24 | * @author Immortius 25 | */ 26 | public interface ClassFactory { 27 | /** 28 | * Creates an instance of a class. 29 | * @param type The type to instantiate. 30 | * @param The type to return the instantiated object as 31 | * @return An optional that contains the instantiated object if successful 32 | */ 33 | Optional instantiateClass(Class type); 34 | } 35 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/reflection/ParameterProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.gestalt.util.reflection; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * ParameterProvider provides objects of desired types. It is used by the SimpleClassFactory to obtain values to use for constructor parameters. 23 | * 24 | * @author Immortius 25 | */ 26 | public interface ParameterProvider { 27 | 28 | /** 29 | * Returns an object of desired type, if one is available. 30 | * @param type The desired type 31 | * @param The desired type 32 | * @return An optional with a value of the desired type, or empty if no such object is available 33 | */ 34 | Optional get(Class type); 35 | } 36 | -------------------------------------------------------------------------------- /gestalt-util/src/main/java/org/terasology/gestalt/util/reflection/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Provides utility methods related to the use of reflection 19 | */ 20 | package org.terasology.gestalt.util.reflection; 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536m 2 | group=org.terasology.gestalt 3 | version=8.0.0-SNAPSHOT 4 | 5 | # Alternative resolution repo to use - this can be used to ignore "live" artifacts and only accept experimental ones. 6 | # alternativeResolutionRepo=https://artifactory.terasology.io/artifactory/virtual-nanoware-and-remote 7 | 8 | #Where to publish artifacts, if not to the default snapshot/release repos 9 | # Publishing a snapshot to a release-only repo will get an intended but quirky HTTP 409 Conflict error as of Nov 2014 10 | #publishRepo=nanoware-snapshot-local 11 | 12 | # Credentials for publishing to Artifactory. Consider setting in ~/.gradle/gradle.properties 13 | # REMEMBER TO NOT CHECK IN ACTUAL CREDENTIAL FROM HERE! 14 | #mavenUser= 15 | #mavenPass= 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MovingBlocks/gestalt/33d0591b65f694321b4cc82e8a0532a03d40f85a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "gestalt" 2 | 3 | dependencyResolutionManagement { 4 | versionCatalogs { 5 | create("libs") { 6 | library("android-annotation", "com.android.support:support-annotations:28.0.0") 7 | library("gson", "com.google.code.gson:gson:2.8.5") 8 | library("guava", "com.google.guava:guava:27.0.1-android") 9 | library("jcip", "net.jcip:jcip-annotations:1.0") 10 | library("slf4j-api", "org.slf4j:slf4j-api:1.7.25") 11 | // testing 12 | library("junit", "junit:junit:4.12") 13 | library("logback", "ch.qos.logback:logback-classic:1.2.3") 14 | library("mockito", "org.mockito:mockito-core:1.10.19") 15 | } 16 | } 17 | } 18 | 19 | include( 20 | "gestalt-util", 21 | "gestalt-di", 22 | "gestalt-inject-java", 23 | "gestalt-inject", 24 | "testpack:testpack-api", 25 | "gestalt-module", 26 | "testpack:moduleA", 27 | "testpack:moduleB", 28 | "testpack:moduleC", 29 | "testpack:moduleD", 30 | "testpack:moduleF", 31 | "gestalt-asset-core", 32 | "gestalt-entity-system", 33 | "gestalt-es-perf" 34 | ) 35 | if (rootProject.projectDir.resolve("local.properties").exists()) { 36 | include("gestalt-android", "gestalt-android-testbed") 37 | } else { 38 | println("No local.properties file found, bypassing Android elements") 39 | } 40 | -------------------------------------------------------------------------------- /testpack/moduleA/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | jar { 6 | version = '' 7 | } 8 | 9 | dependencies { 10 | implementation project(":testpack:testpack-api") 11 | 12 | annotationProcessor project(":gestalt-inject-java") 13 | implementation project(":gestalt-inject") 14 | } 15 | -------------------------------------------------------------------------------- /testpack/moduleA/src/main/java/org/terasology/moduleA/ModuleAClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.moduleA; 18 | 19 | import org.terasology.test.api.IndexForTest; 20 | 21 | import java.nio.file.Files; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | @IndexForTest 27 | public class ModuleAClass { 28 | 29 | public void standardMethod() { 30 | float a = 10; 31 | float b = 22; 32 | String result = String.format("%f + %f", a, b); 33 | } 34 | 35 | public void requiresIoMethod() throws Exception { 36 | Files.createTempFile("Temp", "txt"); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /testpack/moduleA/src/main/java/org/terasology/moduleA/TextProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.moduleA; 18 | 19 | import org.terasology.test.api.ApiInterface; 20 | 21 | public class TextProducer implements ApiInterface { 22 | @Override 23 | public String apiMethod() { 24 | return "Hello from a JAR"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /testpack/moduleA/src/main/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleA", 3 | "version": "1.0.0", 4 | "displayName": "Module A", 5 | "description": "This is a root module with no dependencies or required permissions" 6 | } 7 | -------------------------------------------------------------------------------- /testpack/moduleB/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | jar { 6 | version = '' 7 | } 8 | 9 | dependencies { 10 | implementation project(":testpack:testpack-api") 11 | 12 | annotationProcessor project(":gestalt-inject-java") 13 | implementation project(":gestalt-inject") 14 | } 15 | -------------------------------------------------------------------------------- /testpack/moduleB/src/main/java/org/module/a/DepA.java: -------------------------------------------------------------------------------- 1 | package org.module.a; 2 | 3 | import javax.inject.Singleton; 4 | 5 | @Singleton 6 | public class DepA { 7 | } 8 | -------------------------------------------------------------------------------- /testpack/moduleB/src/main/java/org/module/a/DepB.java: -------------------------------------------------------------------------------- 1 | package org.module.a; 2 | 3 | import javax.inject.Singleton; 4 | 5 | @Singleton 6 | public class DepB { 7 | } 8 | -------------------------------------------------------------------------------- /testpack/moduleB/src/main/java/org/module/b/DepByInterface.java: -------------------------------------------------------------------------------- 1 | package org.module.b; 2 | 3 | import org.module.TestImplementation1; 4 | 5 | import javax.inject.Singleton; 6 | 7 | @Singleton 8 | public class DepByInterface implements TestImplementation1 { 9 | } 10 | -------------------------------------------------------------------------------- /testpack/moduleB/src/main/java/org/terasology/moduleB/ModuleBPermittedClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.moduleB; 18 | 19 | import org.terasology.test.api.IOInterface; 20 | import org.terasology.test.api.IndexForTest; 21 | 22 | /** 23 | * @author Immortius 24 | */ 25 | @IndexForTest 26 | public class ModuleBPermittedClass implements IOInterface { 27 | 28 | @Override 29 | public float ioMethod() { 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /testpack/moduleB/src/main/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleB", 3 | "version": "1.0.0", 4 | "displayName": "Module B", 5 | "description": "This module has a dependency on A, and requires IO permissions", 6 | "dependencies": [ 7 | { 8 | "id": "ModuleA", 9 | "minVersion": "1.0.0", 10 | "maxVersion": "2.0.0" 11 | } 12 | ], 13 | "requiredPermissions": [ 14 | "io" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /testpack/moduleC/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | jar { 6 | version = '' 7 | } 8 | 9 | dependencies { 10 | implementation project(":testpack:testpack-api") 11 | 12 | annotationProcessor project(":gestalt-inject-java") 13 | implementation project(":gestalt-inject") 14 | } 15 | -------------------------------------------------------------------------------- /testpack/moduleC/src/main/java/org/terasology/moduleC/ModuleCClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.moduleC; 18 | 19 | import org.terasology.test.api.IndexForTest; 20 | 21 | import java.nio.file.Files; 22 | 23 | /** 24 | * @author Immortius 25 | */ 26 | @IndexForTest 27 | public class ModuleCClass { 28 | 29 | public void standardMethod() { 30 | float a = 10; 31 | float b = 22; 32 | String result = String.format("%f + %f", a, b); 33 | } 34 | 35 | public void requiresIoMethod() throws Exception { 36 | Files.createTempFile("Temp", "txt"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /testpack/moduleC/src/main/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleC", 3 | "version": "1.0.0", 4 | "displayName": "Module C", 5 | "description": "This module requires ModuleB, but does not require additional permissions", 6 | "dependencies": [ 7 | { 8 | "id": "ModuleB", 9 | "minVersion": "1.0.0", 10 | "maxVersion": "2.0.0" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /testpack/moduleD/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | jar { 6 | version = '' 7 | } 8 | 9 | dependencies { 10 | implementation project(":testpack:testpack-api") 11 | 12 | annotationProcessor project(":gestalt-inject-java") 13 | implementation project(":gestalt-inject") 14 | } 15 | -------------------------------------------------------------------------------- /testpack/moduleD/src/main/java/org/module/a/DepC.java: -------------------------------------------------------------------------------- 1 | package org.module.a; 2 | 3 | import org.module.Test1Scoped; 4 | 5 | @Test1Scoped 6 | public class DepC { 7 | } 8 | -------------------------------------------------------------------------------- /testpack/moduleD/src/main/java/org/terasology/moduleD/ModuleDRestrictedClass.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.moduleD; 18 | 19 | import org.terasology.test.api.IndexForTest; 20 | import org.terasology.test.api.RestrictedInterface; 21 | 22 | /** 23 | * @author Immortius 24 | */ 25 | @IndexForTest 26 | public class ModuleDRestrictedClass implements RestrictedInterface { 27 | 28 | @Override 29 | public float restrictedMethod() { 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /testpack/moduleD/src/main/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleD", 3 | "version": "1.0.0", 4 | "displayName": "Module D", 5 | "description": "This module tries to use non-permitted classes" 6 | } 7 | -------------------------------------------------------------------------------- /testpack/moduleE/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleE", 3 | "version": "1.0.0", 4 | "displayName": "Module E", 5 | "description": "This module contains a library" 6 | } 7 | -------------------------------------------------------------------------------- /testpack/moduleF/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | jar { 6 | version = '' 7 | } 8 | 9 | dependencies { 10 | implementation project(":gestalt-entity-system") 11 | 12 | annotationProcessor project(":gestalt-inject-java") 13 | implementation project(":gestalt-inject") 14 | } 15 | -------------------------------------------------------------------------------- /testpack/moduleF/src/main/java/org/terasology/gestalt/example/modulef/MyComponent.java: -------------------------------------------------------------------------------- 1 | package org.terasology.gestalt.example.modulef; 2 | 3 | import org.terasology.gestalt.entitysystem.component.Component; 4 | 5 | public class MyComponent implements Component { 6 | private String name = ""; 7 | 8 | public MyComponent() { 9 | 10 | } 11 | 12 | public MyComponent(MyComponent other) { 13 | this.name = other.name; 14 | } 15 | 16 | @Override 17 | public void copyFrom(MyComponent other) { 18 | this.name = other.name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /testpack/moduleF/src/main/resources/module.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ModuleF", 3 | "version": "1.0.0", 4 | "displayName": "Module F", 5 | "description": "This module contains a entity system Component to be loaded and used" 6 | } 7 | -------------------------------------------------------------------------------- /testpack/testpack-api/build.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Terasology Foundation 2 | // SPDX-License-Identifier: Apache-2.0 3 | apply plugin: 'java' 4 | 5 | dependencies { 6 | annotationProcessor project(":gestalt-inject-java") 7 | implementation project(":gestalt-inject") 8 | } 9 | 10 | tasks.compileJava { 11 | java.sourceCompatibility JavaVersion.VERSION_1_8 12 | java.targetCompatibility JavaVersion.VERSION_1_8 13 | } 14 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/module/Test1Scoped.java: -------------------------------------------------------------------------------- 1 | package org.module; 2 | 3 | import javax.inject.Named; 4 | import javax.inject.Singleton; 5 | import java.lang.annotation.Documented; 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Singleton 12 | @Named("Test1") 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.TYPE) 15 | @Documented 16 | public @interface Test1Scoped { 17 | } 18 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/module/TestImplementation1.java: -------------------------------------------------------------------------------- 1 | package org.module; 2 | 3 | public interface TestImplementation1 { 4 | } 5 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/terasology/test/api/ApiInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.test.api; 18 | 19 | import org.terasology.context.annotation.IndexInherited; 20 | 21 | /** 22 | * @author Immortius 23 | */ 24 | @IndexInherited 25 | public interface ApiInterface { 26 | 27 | String apiMethod(); 28 | } 29 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/terasology/test/api/IOInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.test.api; 18 | 19 | /** 20 | * @author Immortius 21 | */ 22 | public interface IOInterface { 23 | 24 | float ioMethod(); 25 | } 26 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/terasology/test/api/IndexForTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.test.api; 18 | 19 | import org.terasology.context.annotation.Index; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * Marks classes to be index for sandbox testing 28 | * 29 | * @author Immortius 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.TYPE) 33 | @Index 34 | public @interface IndexForTest { 35 | } 36 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/java/org/terasology/test/api/RestrictedInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 MovingBlocks 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.terasology.test.api; 18 | 19 | /** 20 | * @author Immortius 21 | */ 22 | public interface RestrictedInterface { 23 | 24 | float restrictedMethod(); 25 | } 26 | -------------------------------------------------------------------------------- /testpack/testpack-api/src/main/resources/module.info: -------------------------------------------------------------------------------- 1 | { 2 | "id" : "Root", 3 | "version" : "1.0.0", 4 | "displayName" : "Root", 5 | "description" : "This is the root module containing api used by other modules" 6 | } 7 | --------------------------------------------------------------------------------