Skip to content

Commit

Permalink
release: version 5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert committed Aug 8, 2021
2 parents ed97ec6 + 36fc91b commit 33a0f28
Show file tree
Hide file tree
Showing 58 changed files with 973 additions and 456 deletions.
9 changes: 8 additions & 1 deletion build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ configure<SourceSetContainer> {

configurations {
all {
resolutionStrategy.preferProjectModules()
resolutionStrategy {
preferProjectModules()
// always pick reflections fork
dependencySubstitution {
@Suppress("UnstableApiUsage")
substitute(module("org.reflections:reflections")).using(module("org.terasology:reflections:0.9.12-MB"))
}
}
}
}

Expand Down
27 changes: 14 additions & 13 deletions config/groovy/common.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,20 @@ class common {
} else {
itemsRetrieved << itemName
def targetUrl = "https://github.com/${githubTargetHome}/${itemName}"
if (!isUrlValid(targetUrl)) {
println "Can't retrieve $itemType from $targetUrl - URL appears invalid. Typo? Not created yet?"
try {
println "Retrieving $itemType $itemName from $targetUrl"
if (githubTargetHome != githubDefaultHome) {
println "Doing a retrieve from a custom remote: $githubTargetHome - will name it as such plus add the $githubDefaultHome remote as '$defaultRemote'"
Grgit.clone dir: targetDir, uri: targetUrl, remote: githubTargetHome
println "Primary clone operation complete, about to add the '$defaultRemote' remote for the $githubDefaultHome org address"
addRemote(itemName, defaultRemote, "https://github.com/${githubDefaultHome}/${itemName}")
} else {
Grgit.clone dir: targetDir, uri: targetUrl
}
} catch (GrgitException exception) {
println color("Unable to clone $itemName, Skipping: ${exception.getMessage()}", Ansi.RED)
return
}
println "Retrieving $itemType $itemName from $targetUrl"
if (githubTargetHome != githubDefaultHome) {
println "Doing a retrieve from a custom remote: $githubTargetHome - will name it as such plus add the $githubDefaultHome remote as '$defaultRemote'"
Grgit.clone dir: targetDir, uri: targetUrl, remote: githubTargetHome
println "Primary clone operation complete, about to add the '$defaultRemote' remote for the $githubDefaultHome org address"
addRemote(itemName, defaultRemote, "https://github.com/${githubDefaultHome}/${itemName}")
} else {
Grgit.clone dir: targetDir, uri: targetUrl
}

// This step allows the item type to check the newly cloned item and add in extra template stuff
itemTypeScript.copyInTemplateFiles(targetDir)
Expand Down Expand Up @@ -222,8 +223,8 @@ class common {
def targetUrl = remotes.find {
it.name == defaultRemote
}?.url
if (targetUrl == null || !isUrlValid(targetUrl)) {
println color("While updating $itemName found its '$defaultRemote' remote invalid or its URL unresponsive: $targetUrl", Ansi.RED)
if (targetUrl == null) {
println color("While updating $itemName remote `$defaultRemote` is not found.", Ansi.RED)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import java.util.Set;

/**
* Setup an empty Terasology environment
*
* Set up an empty Terasology environment.
* <p>
* Not for use outside {@code engine-tests}. Modules should use ModuleTestingEnvironment.
*/
public class Environment {
class Environment {

private static final Logger logger = LoggerFactory.getLogger(Environment.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
/**
* Setup a headless ( = no graphics ) environment.
* Based on TerasologyTestingEnvironment code.
*
* <p>
* <b>Deprecated</b> for use outside of {@code engine-tests}; modules should use ModuleTestingEnvironment.
*/
public class HeadlessEnvironment extends Environment {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine;

import org.terasology.gestalt.naming.Name;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.world.BlockEntityRegistry;
import org.terasology.engine.world.WorldProvider;
Expand All @@ -12,10 +11,14 @@
import org.terasology.engine.world.internal.EntityAwareWorldProvider;
import org.terasology.engine.world.internal.WorldProviderCore;
import org.terasology.engine.world.internal.WorldProviderWrapper;
import org.terasology.gestalt.naming.Name;

/**
* Environment with a MapWorldProvider and BlockManager. Useful to get headless environment with a generated world.
*
* @deprecated Use ModuleTestingEnvironment.
*/
@Deprecated
public class WorldProvidingHeadlessEnvironment extends HeadlessEnvironment {

public WorldProvidingHeadlessEnvironment(Name... modules) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id" : "unittest",
"version" : "5.0.0",
"version" : "5.1.0",
"displayName" : "Terasology Engine Test",
"description" : "Engine unit test content"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

package org.terasology.engine.core.module;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleFactory;
import org.terasology.gestalt.module.ModuleMetadata;
import org.terasology.gestalt.module.sandbox.API;
import org.terasology.gestalt.naming.Name;
Expand All @@ -15,17 +15,29 @@

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;

import static com.google.common.truth.Truth8.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ClasspathCompromisingModuleFactoryTest {
static final Class<?> someClassOutsideTheModule = ClasspathCompromisingModuleFactory.class;
static final String METADATA_NAME = "module.json";

ClasspathCompromisingModuleFactory factory;

@BeforeEach
public void newFactory() {
factory = new ClasspathCompromisingModuleFactory();
factory.setDefaultLibsSubpath("build/libs");
}

@Test
public void directoryModuleContainsClass() {
ModuleFactory factory = new ClasspathCompromisingModuleFactory();

// This test assumes that the unittest module is under the current working directory (`engine-test/`)
File engineTestDirectory = new File(System.getProperty("user.dir", "."));
ModuleMetadata metadata = new ModuleMetadata(new Name("unittest"), new Version("1.0.0"));
Expand All @@ -42,8 +54,6 @@ public void directoryModuleContainsClass() {
@Test
@Disabled("TODO: need a jar module containing classes")
public void archiveModuleContainsClass() throws IOException {
ModuleFactory factory = new ClasspathCompromisingModuleFactory();

Module module = factory.createArchiveModule(new File("FIXME.jar"));

Class<?> someClassInTheModule = module.getModuleManifest().getTypesAnnotatedWith(API.class).iterator().next();
Expand All @@ -60,4 +70,31 @@ public void directoryModuleContainsClassLoadedFromJar() {
// - m/build/libs/foo.jar
// load m as directory module while foo.jar is on classpath
}

@Test
public void canGetPathFromJarResource() throws MalformedURLException {
// A jar file on the classpath but not in a local build directory.
URL jarUrl = new URL("jar:file:/example/Terasology/cachedModules/CoreAssets-2.3.0-SNAPSHOT.jar!/module.json");
Path expectedPath = Paths.get("/example/Terasology/cachedModules/CoreAssets-2.3.0-SNAPSHOT.jar");

assertThat(factory.canonicalModuleLocation(METADATA_NAME, jarUrl)).isEqualTo(expectedPath);
}

@Test
public void canGetPathFromLocalJarBuild() throws MalformedURLException {
// A jar file on the classpath that is a build directory in a local development workspace
URL jarUrl = new URL("jar:file:/example/Terasology/modules/CoreAssets/build/libs/CoreAssets-2.3.0-SNAPSHOT.jar!/module.json");
Path expectedPath = Paths.get("/example/Terasology/modules/CoreAssets");

assertThat(factory.canonicalModuleLocation(METADATA_NAME, jarUrl)).isEqualTo(expectedPath);
}

@Test
public void canGetPathFromFilesystemResource() throws MalformedURLException {
// A directory on the classpath that is a build directory in a local development workspace
URL fileUrl = new URL("file:/example/Terasology/modules/Health/build/classes/module.json");
Path expectedPath = Paths.get("/example/Terasology/modules/Health");

assertThat(factory.canonicalModuleLocation(METADATA_NAME, fileUrl)).isEqualTo(expectedPath);
}
}
12 changes: 11 additions & 1 deletion engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,24 @@ configurations {
}
}

configurations.all {
resolutionStrategy {
// always pick reflections fork
dependencySubstitution {
substitute(module("org.reflections:reflections")).using(module("org.terasology:reflections:0.9.12-MB"))
}
}
}

// Primary dependencies definition
dependencies {
// Storage and networking
api group: 'com.google.guava', name: 'guava', version: '30.1-jre'
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
api group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
implementation group: 'io.netty', name: 'netty-all', version: '4.1.53.Final'
implementation group: 'io.netty', name: 'netty-all', version: '4.1.65.Final'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '2.6.1'
implementation group: 'org.lz4', name: 'lz4-java', version: '1.8.0'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
// Javax for protobuf due to @Generated - needed on Java 9 or newer Javas
// TODO: Can likely replace with protobuf Gradle task and omit the generated source files instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.terasology.engine.core.subsystem.common.ThreadManagerSubsystem;
import org.terasology.engine.core.subsystem.common.TimeSubsystem;
import org.terasology.engine.core.subsystem.common.WorldGenerationSubsystem;
import org.terasology.engine.core.subsystem.rendering.ModuleRenderingSubsystem;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.entitySystem.prefab.internal.PojoPrefab;
import org.terasology.engine.i18n.I18nSubsystem;
Expand Down Expand Up @@ -175,7 +174,6 @@ public TerasologyEngine(TimeSubsystem timeSubsystem, Collection<EngineSubsystem>
this.allSubsystems.add(new GameSubsystem());
this.allSubsystems.add(new I18nSubsystem());
this.allSubsystems.add(new TelemetrySubSystem());
this.allSubsystems.add(new ModuleRenderingSubsystem());

// add all subsystem as engine module part. (needs for ECS classes loaded from external subsystems)
allSubsystems.stream().map(Object::getClass).forEach(this::addToClassesOnClasspathsToAddToEngine);
Expand Down Expand Up @@ -489,7 +487,6 @@ public boolean tick() {
}

Iterator<Float> updateCycles = timeSubsystem.getEngineTime().tick();
CoreRegistry.setContext(currentState.getContext());
rootContext.get(NetworkSystem.class).setContext(currentState.getContext());

for (EngineSubsystem subsystem : allSubsystems) {
Expand Down Expand Up @@ -586,6 +583,7 @@ private void switchState(GameState newState) {
if (currentState != null) {
currentState.dispose();
}
CoreRegistry.setContext(newState.getContext());
currentState = newState;
LoggingContext.setGameState(newState);
newState.init(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void handleSwitchToGameEnvironment(Context context) {
autoConfigManager.loadConfigsIn(context);

ModuleAwareAssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);

/*
* The registering of the prefab formats is done in this method, because it needs to be done before
* the environment of the asset manager gets changed.
Expand All @@ -116,6 +115,7 @@ public void handleSwitchToGameEnvironment(Context context) {
* existing then yet.
*/
unregisterPrefabFormats(assetTypeManager);

registeredPrefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary);
assetTypeManager.getAssetFileDataProducer(assetTypeManager
.getAssetType(Prefab.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine.core.modes;

import org.terasology.engine.context.Context;
import org.terasology.engine.core.ComponentSystemManager;
import org.terasology.engine.core.bootstrap.EntitySystemSetupUtil;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.entity.internal.EngineEntityManager;
import org.terasology.engine.entitySystem.event.internal.EventSystem;
import org.terasology.engine.logic.console.Console;
import org.terasology.engine.logic.console.ConsoleImpl;
import org.terasology.engine.logic.console.ConsoleSystem;
import org.terasology.engine.logic.console.commands.CoreCommands;
import org.terasology.engine.logic.players.LocalPlayer;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.recording.DirectionAndOriginPosRecorderList;
import org.terasology.engine.recording.RecordAndReplayCurrentStatus;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.rendering.nui.NUIManager;
import org.terasology.engine.rendering.nui.internal.NUIManagerInternal;
import org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer;
import org.terasology.nui.canvas.CanvasRenderer;

import static com.google.common.base.Verify.verifyNotNull;

public abstract class AbstractState implements GameState {
protected Context context;
protected EngineEntityManager entityManager;
protected EventSystem eventSystem;
protected ComponentSystemManager componentSystemManager;

protected void initEntityAndComponentManagers() {
verifyNotNull(context);
CoreRegistry.setContext(context);

// let's get the entity event system running
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);

eventSystem = context.get(EventSystem.class);
context.put(Console.class, new ConsoleImpl(context));

NUIManager nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
context.put(NUIManager.class, nuiManager);

componentSystemManager = new ComponentSystemManager(context);
context.put(ComponentSystemManager.class, componentSystemManager);

componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
}

protected static void createLocalPlayer(Context context) {
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
LocalPlayer localPlayer = new LocalPlayer();
localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class),
context.get(RecordAndReplayCurrentStatus.class));
context.put(LocalPlayer.class, localPlayer);
localPlayer.setClientEntity(localPlayerEntity);
}

@Override
public void dispose(boolean shuttingDown) {
// Apparently this can be disposed of before it is completely initialized? Probably only during
// crashes, but crashing again during shutdown complicates the diagnosis.
if (eventSystem != null) {
eventSystem.process();
}
if (componentSystemManager != null) {
componentSystemManager.shutdown();
}
if (entityManager != null) {
entityManager.clear();
}
}

@Override
public Context getContext() {
return context;
}
}
Loading

0 comments on commit 33a0f28

Please sign in to comment.