Skip to content

Commit

Permalink
Merge branch 'develop' into test/moveMTE
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert authored May 22, 2022
2 parents 3cf39f5 + 22bf4a4 commit 6508667
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 133 deletions.
8 changes: 6 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ If you would like to contribute code, documentation, or other assets you can do

*When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible.*

Read on for an overview and [check the wiki for more details](https://github.com/MovingBlocks/Terasology/wiki). For questions please join us in our [forum](http://forum.terasology.org/forum/) or on `#terasology` (irc.freenode.net).
Read on for an overview and [check the wiki for more details](https://github.com/MovingBlocks/Terasology/wiki).
For questions please join us in our [forum] or [Discord].

## File an Issue

You can report bugs and feature requests to [GitHub Issues](https://github.com/MovingBlocks/Terasology/issues). As mentioned please look for a similar existing issue before submitting a new one.

For finding easy to do issues to start with look at the [Good First Issue](https://github.com/MovingBlocks/Terasology/labels/Good%20First%20Issue) issues.

We prefer questions and support requests be posted in the [forum](http://forum.terasology.org/forum).
We prefer questions and support requests be posted in the [forum] or [Discord].

__Please provide as much information as possible to help us solve problems and answer questions better!__

[forum]: https://forum.terasology.org/forum/
[Discord]: https://discord.gg/Terasology

## PR Title / Commit Message Guidelines

We try to follow the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0-beta.2/) style for commit messages and pull request titles.
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pipeline {

recordIssues(skipBlames: true, enabledForFailure: true,
tools: [
spotBugs(pattern: '**/build/reports/spotbugs/main/*.xml', useRankAsPriority: true),
spotBugs(pattern: '**/build/reports/spotbugs/*.xml', useRankAsPriority: true),
pmdParser(pattern: '**/build/reports/pmd/*.xml')
])

Expand Down
7 changes: 6 additions & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Terasology Foundation
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

import java.net.URI
Expand All @@ -10,6 +10,7 @@ plugins {
repositories {
mavenCentral()
google() // gestalt uses an annotation package by Google
gradlePluginPortal()

maven {
name = "Terasology Artifactory"
Expand Down Expand Up @@ -40,6 +41,10 @@ dependencies {
// for inspecting modules
implementation("org.terasology.gestalt:gestalt-module:7.1.0")

// plugins we configure
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:4.8.0") // TODO: upgrade with gradle 7.x
implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3")

api(kotlin("test"))
}

Expand Down
3 changes: 2 additions & 1 deletion build-logic/src/main/kotlin/facade.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2021 The Terasology Foundation
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

import org.terasology.gradology.JAR_COLLECTION
import org.terasology.gradology.namedAttribute

plugins {
application
id("terasology-common")
}

val dirNatives: String by rootProject.extra
Expand Down
7 changes: 7 additions & 0 deletions build-logic/src/main/kotlin/terasology-common.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

plugins {
id("terasology-repositories")
id("terasology-metrics")
}
69 changes: 69 additions & 0 deletions build-logic/src/main/kotlin/terasology-metrics.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

import com.github.spotbugs.snom.SpotBugsExtension
import com.github.spotbugs.snom.SpotBugsTask

plugins {
java
checkstyle
pmd
`project-report`
id("com.github.spotbugs")
id("org.sonarqube")
}

dependencies {
"pmd"("net.sourceforge.pmd:pmd-core:6.15.0")
"pmd"("net.sourceforge.pmd:pmd-java:6.15.0")
}

tasks.withType<Test> {
useJUnitPlatform()

// ignoreFailures: Specifies whether the build should break when the verifications performed by this task fail.
ignoreFailures = true
// showStandardStreams: makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
reports {
junitXml.isEnabled = true
}
jvmArgs("-Xms512m", "-Xmx1024m")

// Make sure the natives have been extracted, but only for multi-workspace setups (not for solo module builds)
if (project.name != project(":").name) {
dependsOn(tasks.getByPath(":extractNatives"))
}
}

// The config files here work in both a multi-project workspace (IDEs, running from source) and for solo module builds
// Solo module builds in Jenkins get a copy of the config dir from the engine harness so it still lives at root/config
// TODO: Maybe update other projects like modules to pull the zipped dependency so fewer quirks are needed in Jenkins
configure<CheckstyleExtension> {
isIgnoreFailures = false

val checkstyleDir = rootDir.resolve("config/metrics/checkstyle")
configDirectory.set(checkstyleDir)
setConfigProperties("samedir" to checkstyleDir)
}

configure<PmdExtension> {
isIgnoreFailures = true
ruleSetFiles = files(rootDir.resolve("config/metrics/pmd/pmd.xml"))
// By default, gradle uses both ruleset file AND the rulesets. Override the ruleSets to use only those from the file
ruleSets = listOf()
}

configure<SpotBugsExtension> {
// The version of the spotbugs tool https://github.com/spotbugs/spotbugs
// not necessarily the same as the version of spotbugs-gradle-plugin
toolVersion.set("4.7.0")
ignoreFailures.set(true)
excludeFilter.set(file(rootDir.resolve("config/metrics/findbugs/findbugs-exclude.xml")))
}

tasks.named<SpotBugsTask>("spotbugsMain") {
reports.register("xml") {
enabled = true
}
}
3 changes: 2 additions & 1 deletion build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Terasology Foundation
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

// Simple build file for modules - the one under the Core module is the template, will be copied as needed to modules
Expand All @@ -11,6 +11,7 @@ plugins {
`java-library`
idea
eclipse
id("terasology-common")
}

val moduleMetadata = ModuleMetadataForGradle.forProject(project)
Expand Down
10 changes: 1 addition & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ buildscript {
}

dependencies {
//Spotbugs
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.0.0"

// SonarQube / Cloud scanning
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"

// Protobuf plugin
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.16'

// Our locally included /build-logic
classpath("org.terasology.gradology:build-logic")
}
Expand All @@ -52,6 +43,7 @@ plugins {
// For the "Build and run using: Intellij IDEA | Gradle" switch
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0"

id("com.google.protobuf") version "0.8.16" apply false
id("terasology-repositories")
}

Expand Down
84 changes: 0 additions & 84 deletions config/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'

// Analytics
apply plugin: 'project-report'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.github.spotbugs'
apply plugin: 'jacoco'
apply plugin: 'org.sonarqube'

apply plugin: 'terasology-repositories'

java {
Expand All @@ -28,12 +20,6 @@ tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

dependencies {
pmd('net.sourceforge.pmd:pmd-core:6.15.0')
pmd('net.sourceforge.pmd:pmd-java:6.15.0')
// the FindBugs version is set in the configuration
}

task sourceJar(type: Jar) {
description = "Create a JAR with all sources"
from sourceSets.main.allSource
Expand All @@ -47,76 +33,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
}

// Extra details provided for unit tests
test {
useJUnitPlatform()

// ignoreFailures: Specifies whether the build should break when the verifications performed by this task fail.
ignoreFailures = true
// showStandardStreams: makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
reports {
junitXml.enabled = true
}
// Arguments to include while running tests
jvmArgs '-Xms512m', '-Xmx1024m'

// Make sure the natives have been extracted, but only for multi-workspace setups (not for solo module builds)
if (project.name != project(':').name) {
dependsOn rootProject.extractNatives
}

// Keep in sync with other exclude-lists for Jacoco, e.g., in 'engine-tests/build.gradle'
jacoco.excludes = ["org.terasology.protobuf.*", "*MethodAccess", "*FieldAccess"]
}

jacoco {
toolVersion = "0.8.8"
}

jacocoTestReport {
dependsOn test // Despite doc saying this should be automatic we need to explicitly add it anyway :-(
reports {
// Used to be exec, but that had a binary incompatibility between JaCoCo 0.7.4 and 0.7.5 and issues with some plugins
xml.enabled true
csv.enabled false
html.enabled true
}
}

// The config files here work in both a multi-project workspace (IDEs, running from source) and for solo module builds
// Solo module builds in Jenkins get a copy of the config dir from the engine harness so it still lives at root/config
// TODO: Maybe update other projects like modules to pull the zipped dependency so fewer quirks are needed in Jenkins
checkstyle {
ignoreFailures = false

def checkstyleDir = rootProject.file('config/metrics/checkstyle')
configDirectory = checkstyleDir
configProperties.samedir = checkstyleDir
}

pmd {
ignoreFailures = true
ruleSetFiles = files("$rootDir/config/metrics/pmd/pmd.xml")
// By default, gradle uses both ruleset file AND the rulesets. Override the ruleSets to use only those from the file
ruleSets = []
}

spotbugs {
toolVersion = '4.0.0'
ignoreFailures = true
excludeFilter = new File(rootDir, "config/metrics/findbugs/findbugs-exclude.xml")
}

spotbugsMain {
reports {
xml {
enabled = true
destination = file("$buildDir/reports/spotbugs/main/spotbugs.xml")
}
}
}

tasks.javadoc {
// Disable doclint messages about missing "@param" or "@return" tags.
options.addBooleanOption("Xdoclint:all,-missing", true)
Expand Down
6 changes: 1 addition & 5 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
plugins {
id "java-library"
id "org.jetbrains.gradle.plugin.idea-ext"
id "terasology-common"
}

// Grab all the common stuff like plugins to use, artifact repositories, code analysis config
Expand Down Expand Up @@ -110,9 +111,6 @@ task unitTest(type: Test) {
excludeTags "MteTest", "TteTest"
}
systemProperty("junit.jupiter.execution.timeout.default", "1m")

// Keep in sync with other exclude-lists for Jacoco, e.g., in 'common.gradle'
jacoco.excludes = ["org.terasology.protobuf.*", "*MethodAccess", "*FieldAccess"]
}

task integrationTest(type: Test) {
Expand All @@ -127,8 +125,6 @@ task integrationTest(type: Test) {
includeTags "MteTest", "TteTest"
}
systemProperty("junit.jupiter.execution.timeout.default", "5m")

jacoco.excludes = ["org.terasology.protobuf.*", "*MethodAccess", "*FieldAccess"]
}

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

package org.terasology.engine.registry;
Expand Down Expand Up @@ -82,7 +82,7 @@ private static class ContextImplementation implements Context {
private final Map<Class<?>, Object> map = Maps.newConcurrentMap();

@Override
public <T> T get(Class<? extends T> type) {
public <T> T get(Class<T> type) {
T result = type.cast(map.get(type));
if (result != null) {
return result;
Expand Down
3 changes: 2 additions & 1 deletion engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
plugins {
id "java-library"
id "org.jetbrains.gradle.plugin.idea-ext"
id "com.google.protobuf"
id "terasology-common"
}

apply plugin: 'com.google.protobuf'
// Grab all the common stuff like plugins to use, artifact repositories, code analysis config, etc
apply from: "$rootDir/config/gradle/publish.gradle"

Expand Down
31 changes: 28 additions & 3 deletions engine/src/main/java/org/terasology/engine/context/Context.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright 2021 The Terasology Foundation
// Copyright 2022 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.context;

import org.terasology.gestalt.module.sandbox.API;

import java.util.NoSuchElementException;
import java.util.Optional;

/**
* Provides classes with the utility objects that belong to the context they are running in.
*
Expand All @@ -21,9 +24,31 @@
public interface Context {

/**
* @return the object that is known in this context for this type.
* Get the object that is known in this context for this type.
*/
<T> T get(Class<T> type);

/**
* Get the object that is known in this context for this type. Never null.
*
* @throws NoSuchElementException No instance was registered with that type.
*/
@SuppressWarnings("unused")
default <T> T getValue(Class<T> type) {
T value = get(type);
if (value == null) {
throw new NoSuchElementException(type.toString());
}
return value;
}

/**
* Get the object that is known in this context for this type.
*/
<T> T get(Class<? extends T> type);
@SuppressWarnings("unused")
default <T> Optional<T> getMaybe(Class<T> type) {
return Optional.ofNullable(get(type));
}

/**
* Makes the object known in this context to be the object to work with for the given type.
Expand Down
Loading

0 comments on commit 6508667

Please sign in to comment.