Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor/rework-tr…
Browse files Browse the repository at this point in the history
…ansaction-manager-rxjava

# Conflicts:
#	engine/src/main/java/org/terasology/engine/persistence/internal/ReadWriteStorageManager.java
  • Loading branch information
keturn committed May 14, 2022
2 parents fe8d611 + 60b819b commit 9deee11
Show file tree
Hide file tree
Showing 41 changed files with 1,219 additions and 670 deletions.
9 changes: 7 additions & 2 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/dictionaries/kevint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies {
implementation("org.javassist:javassist:3.27.0-GA")
implementation("dom4j:dom4j:1.6.1")

// graph analysis
implementation("org.jgrapht:jgrapht-core:1.5.0")

// for inspecting modules
implementation("org.terasology.gestalt:gestalt-module:7.1.0")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.gradology

import org.gradle.api.internal.file.copy.CopySpecInternal
import org.gradle.api.tasks.Copy


/**
* Copy, but never overwrite any existing file.
*
* Preserves existing files regardless of how up-to-date they are.
*
* Useful for providing boilerplate or defaults.
*/
abstract class CopyButNeverOverwrite : Copy() {

override fun createRootSpec(): CopySpecInternal {
val copySpec = super.createRootSpec()
copySpec.eachFile {
if (this.relativePath.getFile(destinationDir).exists()) {
this.exclude()
}
}
return copySpec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import org.gradle.api.artifacts.ModuleIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.result.UnresolvedDependencyResult
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Provider
import org.jgrapht.Graph
import org.jgrapht.graph.DefaultDirectedGraph
import org.jgrapht.traverse.TopologicalOrderIterator

val ModuleIdentifier.isTerasologyModule: Boolean
get() = group == TERASOLOGY_MODULES_GROUP
Expand Down Expand Up @@ -82,3 +86,62 @@ fun moduleDependencyArtifacts(modulesConfig: Configuration): Iterable<ResolvedAr
}


fun moduleDependencyOrdering(modulesConfig: Configuration): List<String> {
// configurations.resolvedConfiguration is more straightforward if you just want all the artifacts,
// but using `.incoming` lets us turn on lenient mode as well as do more accurate filtering of local modules
val resolvable = modulesConfig.incoming
val artifactView = resolvable.artifactView {
lenient(true)
}

val result = resolvable.resolutionResult
val allDependencies = result.allDependencies
val resolvedDependencies = allDependencies.mapNotNull {
if (it is ResolvedDependencyResult) {
return@mapNotNull it
}
if (it is UnresolvedDependencyResult) {
logger.warn("Dependency {} of {} not resolved:", it.attempted, it.from, it.failure)
} else {
logger.warn(
"Dependency {} of {} not resolved: Unexpected result class {}\n{}",
it.requested,
it.from,
it::class,
it
)
}
null
}

val g: Graph<ResolvedComponentResult, ResolvedDependencyResult> = DefaultDirectedGraph(ResolvedDependencyResult::class.java)


fun isModule(p: ResolvedComponentResult): Boolean {
val projectPath = (p.id as? ProjectComponentIdentifier)?.projectPath
return projectPath?.run {
startsWith(":modules:") || equals(":engine")
} ?: false
}

result.allComponents
.filter(::isModule)
.forEach { g.addVertex(it) }

result.allDependencies
.mapNotNull {
it as? ResolvedDependencyResult
}
.filter {
isModule(it.from) && isModule(it.selected)
}
.forEach {
g.addEdge(it.from, it.selected, it)
}

val nodes = TopologicalOrderIterator(g)
return nodes.asSequence()
.mapNotNull { it.id as? ProjectComponentIdentifier }
.map { it.projectName }
.toList().asReversed()
}
22 changes: 7 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ plugins {

import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.jetbrains.gradle.ext.ActionDelegationConfig
import org.terasology.gradology.CopyButNeverOverwrite

import static org.gradle.internal.logging.text.StyledTextOutput.Style

Expand All @@ -80,7 +81,7 @@ located at ${System.getProperty("java.home")}
ext {
dirNatives = 'natives'
dirConfigMetrics = 'config/metrics'
templatesDir = 'templates'
templatesDir = file('templates')

// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
Expand Down Expand Up @@ -230,19 +231,14 @@ tasks.named('wrapper') {
// General IDE customization //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

task copyInMissingTemplates {
tasks.register("copyInMissingTemplates", CopyButNeverOverwrite) {
description = "Copies in placeholders from the /templates dir to project root if not present yet"
File gradlePropsFile = new File(rootDir, 'gradle.properties')
File OverrideCfgFile = new File(rootDir, 'override.cfg')
if (!gradlePropsFile.exists()) {
new File(rootDir, 'gradle.properties') << new File(templatesDir, 'gradle.properties').text
}
if (!OverrideCfgFile.exists()) {
new File(rootDir, 'override.cfg') << new File(templatesDir, 'override.cfg').text
}
from(templatesDir)
into(rootDir)
include('gradle.properties', 'override.cfg')
}

tasks.register("jmxPassword", Copy) {
tasks.register("jmxPassword", CopyButNeverOverwrite) {
description = "Create config/jmxremote.password from a template."

setFileMode(0600) // passwords must be accessible only by owner
Expand All @@ -253,10 +249,6 @@ tasks.register("jmxPassword", Copy) {
rename("(.*).template", '$1')
into("config")

onlyIf {
// Do not overwrite an existing password file.
!it.destinationDir.toPath().resolve("jmxremote.password").toFile().exists()
}
doLast {
logger.warn("${it.outputs.files.singleFile}/jmxremote.password:100: Edit this to set your password.")
}
Expand Down
2 changes: 2 additions & 0 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ dependencies {

testImplementation('com.google.truth:truth:1.1.3')
testImplementation('com.google.truth.extensions:truth-java8-extension:1.1.3')

implementation("io.projectreactor:reactor-test:3.4.14")
}

task copyResourcesToClasses(type:Copy) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine.math;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SideTest {

@Test
public void testSideInDirection() {
for (Side side : Side.values()) {
assertEquals(side, Side.inDirection(side.direction().x(), side.direction().y(), side.direction().z()));
}
}

@Test
public void testRelativeSides() {
Side side = Side.FRONT;
assertEquals(Side.LEFT, side.getRelativeSide(Direction.LEFT));
assertEquals(Side.RIGHT, side.getRelativeSide(Direction.RIGHT));
assertEquals(Side.TOP, side.getRelativeSide(Direction.UP));
assertEquals(Side.BOTTOM, side.getRelativeSide(Direction.DOWN));
assertEquals(Side.FRONT, side.getRelativeSide(Direction.FORWARD));
assertEquals(Side.BACK, side.getRelativeSide(Direction.BACKWARD));
}

@Test
public void testGetFlag() {
Assertions.assertEquals(0x01, Side.TOP.getFlag());
Assertions.assertEquals(0x02, Side.LEFT.getFlag());
Assertions.assertEquals(0x04, Side.FRONT.getFlag());
Assertions.assertEquals(0x08, Side.BOTTOM.getFlag());
Assertions.assertEquals(0x10, Side.RIGHT.getFlag());
Assertions.assertEquals(0x20, Side.BACK.getFlag());
}

@Test
public void testToFlags() {
Assertions.assertEquals(Side.TOP.getFlag() | Side.LEFT.getFlag(), Side.toFlags(Side.TOP, Side.LEFT));
Assertions.assertEquals(Side.TOP.getFlag() | Side.RIGHT.getFlag(), Side.toFlags(Side.TOP, Side.RIGHT));
Assertions.assertEquals(Side.TOP.getFlag(), Side.toFlags(Side.TOP, Side.TOP));
Assertions.assertEquals(Side.BACK.getFlag() | Side.BOTTOM.getFlag(), Side.toFlags(Side.BACK, Side.BOTTOM));

Assertions.assertEquals(
Side.TOP.getFlag() | Side.LEFT.getFlag() | Side.FRONT.getFlag() | Side.BOTTOM.getFlag() | Side.RIGHT.getFlag() | Side.BACK.getFlag(),
Side.toFlags(Side.TOP, Side.LEFT, Side.FRONT, Side.BOTTOM, Side.RIGHT, Side.BACK));
}
}
Loading

0 comments on commit 9deee11

Please sign in to comment.