Skip to content

Commit

Permalink
prepare switch over to kotlin, "new" java date formatting (#5195)
Browse files Browse the repository at this point in the history
* qa build.gradle, kotlin, double quotes instead of single.

* build.gradle, prepare kotlin convert.

* qa kotlin, optimize tasks in case they are not executed.

* build.gradle, register the tasks to avoid unnecessary configuration during run.

* build.gradle, use new java.time classes.

* engine/build.gradle, kotlin syntax for dependencies

* engine/build.gradle, kotlin syntax for plugins
  • Loading branch information
soloturn authored Dec 23, 2023
1 parent 0c2b722 commit bf78a58
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 165 deletions.
145 changes: 72 additions & 73 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

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

// Dependencies needed for what our Gradle scripts themselves use. It cannot be included via an external Gradle file :-(
buildscript {
repositories {
Expand Down Expand Up @@ -30,28 +36,21 @@ buildscript {

plugins {
// Needed for extending the "clean" task to also delete custom stuff defined here like natives
id "base"
id("base")

// needs for native platform("org.lwjgl") handling.
id "java-platform"
id("java-platform")

// The root project should not be an eclipse project. It keeps eclipse (4.2) from finding the sub-projects.
//apply plugin: 'eclipse'
id "idea"
//apply plugin: "eclipse"
id("idea")
// For the "Build and run using: Intellij IDEA | Gradle" switch
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"

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


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

// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)
if (!(JavaVersion.current() == JavaVersion.VERSION_17)) {
Expand All @@ -68,14 +67,14 @@ located at ${System.getProperty("java.home")}

// Declare "extra properties" (variables) for the project (and subs) - a Gradle thing that makes them special.
ext {
dirNatives = 'natives'
dirConfigMetrics = 'config/metrics'
templatesDir = file('templates')
dirNatives = "natives"
dirConfigMetrics = "config/metrics"
templatesDir = file("templates")

// Lib dir for use in manifest entries etc (like in :engine). A separate "libsDir" exists, auto-created by Gradle
subDirLibs = 'libs'
subDirLibs = "libs"

LwjglVersion = '3.3.3'
LwjglVersion = "3.3.3"
}


Expand Down Expand Up @@ -103,61 +102,61 @@ dependencies {


// Config for our code analytics lives in a centralized repo: https://github.com/MovingBlocks/TeraConfig
codeMetrics group: 'org.terasology.config', name: 'codemetrics', version: '2.2.0', ext: 'zip'
codeMetrics(group: "org.terasology.config", name: "codemetrics", version: "2.2.0", ext: "zip")

// Natives for JNLua (Kallisti, KComputers)
natives group: 'org.terasology.jnlua', name: 'jnlua_natives', version: '0.1.0-SNAPSHOT', ext: 'zip'
natives(group: "org.terasology.jnlua", name: "jnlua_natives", version: "0.1.0-SNAPSHOT", ext: "zip")

// Natives for JNBullet
natives group: 'org.terasology.jnbullet', name: 'JNBullet', version: '1.0.2', ext: 'zip'
natives(group: "org.terasology.jnbullet", name: "JNBullet", version: "1.0.2", ext: "zip")

}

task extractWindowsNatives(type: Copy) {
tasks.register("extractWindowsNatives", Copy) {
description = "Extracts the Windows natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('natives-windows') ? zipTree(it) : [] }
configurations.natives.collect { it.getName().contains("natives-windows") ? zipTree(it) : [] }
}
into("$dirNatives/windows")
exclude('META-INF/**')
exclude("META-INF/**")
}

task extractMacOSXNatives(type: Copy) {
tasks.register("extractMacOSXNatives", Copy) {
description = "Extracts the OSX natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('natives-macos') ? zipTree(it) : [] }
configurations.natives.collect { it.getName().contains("natives-macos") ? zipTree(it) : [] }
}
into("$dirNatives/macosx")
exclude('META-INF/**')
exclude("META-INF/**")
}

task extractLinuxNatives(type: Copy) {
tasks.register("extractLinuxNatives", Copy) {
description = "Extracts the Linux natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('natives-linux') ? zipTree(it) : [] }
configurations.natives.collect { it.getName().contains("natives-linux") ? zipTree(it) : [] }
}
into("$dirNatives/linux")
exclude('META-INF/**')
exclude("META-INF/**")
}

task extractJNLuaNatives(type: Copy) {
tasks.register("extractJNLuaNatives", Copy) {
description = "Extracts the JNLua natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('jnlua') ? zipTree(it) : [] }
configurations.natives.collect { it.getName().contains("jnlua") ? zipTree(it) : [] }
}
into("$dirNatives")
}

task extractNativeBulletNatives(type: Copy) {
tasks.register("extractNativeBulletNatives", Copy) {
description = "Extracts the JNBullet natives from the downloaded zip"
from {
configurations.natives.collect { it.getName().contains('JNBullet') ? zipTree(it) : [] }
configurations.natives.collect { it.getName().contains("JNBullet") ? zipTree(it) : [] }
}
into("$dirNatives")
}


task extractNatives {
tasks.register("extractNatives") {
description = "Extracts all the native lwjgl libraries from the downloaded zip"
dependsOn extractWindowsNatives
dependsOn extractLinuxNatives
Expand All @@ -170,7 +169,7 @@ task extractNatives {
// Helper tasks //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

task extractConfig(type: Copy) {
tasks.register("extractConfig", Copy) {
description = "Extracts our configuration files from the zip we fetched as a dependency"
from {
configurations.codeMetrics.collect {
Expand Down Expand Up @@ -210,7 +209,7 @@ project(":modules").subprojects.forEach { proj ->
}
}

tasks.named('wrapper') {
tasks.named("wrapper") {
// ALL distributionType because IntelliJ prefers having its sources for analysis and reference.
distributionType = Wrapper.DistributionType.ALL
}
Expand All @@ -224,7 +223,7 @@ tasks.register("copyInMissingTemplates", CopyButNeverOverwrite) {
description = "Copies in placeholders from the /templates dir to project root if not present yet"
from(templatesDir)
into(rootDir)
include('gradle.properties', 'override.cfg')
include("gradle.properties", "override.cfg")
}

tasks.register("jmxPassword", CopyButNeverOverwrite) {
Expand Down Expand Up @@ -252,21 +251,21 @@ idea {

// Exclude Eclipse dirs
// TODO: Update this as Eclipse bin dirs now generate in several deeper spots rather than at top-level

Check warning on line 253 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: Update this as Eclipse bin dirs now generate in several deeper spots rather than at top-level
module.excludeDirs += file('bin')
module.excludeDirs += file('.settings')
module.excludeDirs += file("bin")
module.excludeDirs += file(".settings")
// TODO: Add a single file exclude for facades/PC/Terasology.launch ?

Check warning on line 256 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: Add a single file exclude for facades/PC/Terasology.launch ?

// Exclude special dirs
module.excludeDirs += file('natives')
module.excludeDirs += file('protobuf')
module.excludeDirs += file("natives")
module.excludeDirs += file("protobuf")

// Exclude output dirs
module.excludeDirs += file('configs')
module.excludeDirs += file('logs')
module.excludeDirs += file('saves')
module.excludeDirs += file('screenshots')
module.excludeDirs += file('terasology-server')
module.excludeDirs += file('terasology-2ndclient')
module.excludeDirs += file("configs")
module.excludeDirs += file("logs")
module.excludeDirs += file("saves")
module.excludeDirs += file("screenshots")
module.excludeDirs += file("terasology-server")
module.excludeDirs += file("terasology-2ndclient")

module.downloadSources = true

Expand All @@ -277,55 +276,55 @@ idea {
}

cleanIdea.doLast {
new File('Terasology.iws').delete()
new File("Terasology.iws").delete()
}

// A task to assemble various files into a single zip for distribution as 'build-harness.zip' for module builds
// A task to assemble various files into a single zip for distribution as "build-harness.zip" for module builds
task assembleBuildHarness(type: Zip) {
description 'Assembles a zip of files useful for module development'
description "Assembles a zip of files useful for module development"

dependsOn extractNatives
from('natives'){
include '**/*'
from("natives"){
include "**/*"
// TODO: use output of extractNatives?

Check warning on line 289 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: use output of extractNatives?
// TODO: which module needs natives to build?

Check warning on line 290 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: which module needs natives to build?
into 'natives'
into "natives"
}

dependsOn extractConfig
from('config'){
//include 'gradle/**/*', 'metrics/**/*'
include '**/*'
from("config"){
//include "gradle/**/*", "metrics/**/*"
include "**/*"
// TODO: depend on output of extractConfig?

Check warning on line 298 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: depend on output of extractConfig?
into 'config'
into "config"
}

from('gradle'){
include '**/*' // include all files in 'gradle'
from("gradle"){
include "**/*" // include all files in "gradle"
// TODO: exclude groovy jar?

Check warning on line 304 in build.gradle

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: exclude groovy jar?
into 'gradle'
into "gradle"
}

from('build-logic'){
include 'src/**', '*.kts'
into 'build-logic'
from("build-logic"){
include "src/**", "*.kts"
into "build-logic"
}

from('templates') {
include 'build.gradle'
from("templates") {
include "build.gradle"
}

from('.') {
include 'gradlew'
from(".") {
include "gradlew"
}

// include file 'templates/module.logback-test.xml' as 'src/test/resources/logback-test.xml'
from('templates'){
include 'module.logback-test.xml'
rename 'module.logback-test.xml', 'logback-test.xml'
into 'src/test/resources'
// include file "templates/module.logback-test.xml" as "src/test/resources/logback-test.xml"
from("templates"){
include "module.logback-test.xml"
rename "module.logback-test.xml", "logback-test.xml"
into "src/test/resources"
}

// set the archive name
archiveFileName.set('build-harness.zip')
archiveFileName.set("build-harness.zip")
}
Loading

0 comments on commit bf78a58

Please sign in to comment.