Skip to content

chore(gradle): remove custom startScripts task #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 40 additions & 47 deletions gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import org.gradle.kotlin.dsl.support.unzipTo
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import sc.gradle.ScriptsTask
import java.io.InputStream
import java.util.concurrent.atomic.AtomicBoolean

plugins {
maven
`java-library`
kotlin("jvm") version "1.4.20"
id("org.jetbrains.dokka") version "0.10.1"
id("scripts-task")

id("com.github.ben-manes.versions") version "0.36.0"
id("se.patrikerdes.use-latest-versions") version "0.2.15"
Expand All @@ -36,23 +33,6 @@ val documentedProjects = listOf("sdk", "plugin")
val enableTestClient by extra { versionObject.minor > 0 }
val enableIntegrationTesting = !project.hasProperty("nointegration") && (versionObject.minor > 0 || enableTestClient)

subprojects {
apply(plugin = "java-library")
apply(plugin = "kotlin")
apply(plugin = "com.github.ben-manes.versions")
apply(plugin = "se.patrikerdes.use-latest-versions")

dependencies {
testImplementation(project(":sdk", "testConfig"))
}

tasks {
test {
useJUnitPlatform()
}
}
}

val doAfterEvaluate = ArrayList<(Project) -> Unit>()
tasks {
val startServer by creating {
Expand Down Expand Up @@ -129,6 +109,7 @@ tasks {
dependsOn(deploy)
}

// TODO create a global constant which can be shared with testclient & co - maybe a resource?
val maxGameLength = 150L

val clearTestLogs by creating(Delete::class) {
Expand All @@ -143,12 +124,12 @@ tasks {
val server =
ProcessBuilder(
"java",
"-Dlogback.configurationFile=${project("server").projectDir.resolve("configuration/logback-trace.xml")}",
"-jar", project("server").tasks.jar.get().archiveFile.get().asFile.absolutePath
"-Dlogback.configurationFile=${project(":server").projectDir.resolve("configuration/logback-trace.xml")}",
"-jar", (project(":server").getTasksByName("jar", false).single() as Jar).archiveFile.get().asFile.absolutePath
)
.redirectOutput(testLogDir.resolve("server.log"))
.redirectError(testLogDir.resolve("server-err.log"))
.directory(project("server").buildDir.resolve("runnable"))
.directory(project(":server").buildDir.resolve("runnable"))
.start()
Thread.sleep(400)
val startClient: (Int) -> Process = {
Expand Down Expand Up @@ -212,19 +193,22 @@ tasks {
testLogDir.mkdirs()
val unzipped = tmpDir.resolve("software-challenge-server")
unzipped.deleteRecursively()
Runtime.getRuntime().exec("unzip software-challenge-server.zip -d $unzipped", null, deployDir).waitFor()
unzipTo(unzipped, deployDir.resolve("software-challenge-server.zip"))

println("Testing TestClient...")
val command = mutableListOf("java").apply {
addAll((project(":test-client").getTasksByName("createStartScripts", false).single() as CreateStartScripts).defaultJvmOpts!!)
addAll(arrayOf("--start-server", "--tests", testClientGames.toString(), "--port", "13055"))
}
val testClient =
ProcessBuilder(
project("test-client").tasks.getByName<ScriptsTask>("createStartScripts").content.split(" ")
+ listOf("--start-server", "--tests", testClientGames.toString(), "--port", "13055")
)
.redirectOutput(testLogDir.resolve("test-client.log"))
.redirectError(testLogDir.resolve("test-client-err.log"))
.directory(unzipped).start()
ProcessBuilder(command)
.redirectOutput(testLogDir.resolve("test-client.log"))
.redirectError(testLogDir.resolve("test-client-err.log"))
.directory(unzipped)
.start()
if (testClient.waitFor(maxGameLength * testClientGames, TimeUnit.SECONDS)) {
val value = testClient.exitValue()
// TODO check whether TestClient actually played games
if (value == 0)
println("TestClient successfully tested!")
else
Expand All @@ -251,14 +235,31 @@ tasks {

// == Cross-project configuration ==

allprojects {
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = javaTargetVersion.toString()
freeCompilerArgs = listOf("-Xjvm-default=all")
}
subprojects {
apply(plugin = "java-library")
apply(plugin = "kotlin")
apply(plugin = "com.github.ben-manes.versions")
apply(plugin = "se.patrikerdes.use-latest-versions")

dependencies {
testImplementation(project(":sdk", "testConfig"))
}

tasks {
test {
useJUnitPlatform()
}

withType<KotlinCompile> {
kotlinOptions {
jvmTarget = javaTargetVersion.toString()
freeCompilerArgs = listOf("-Xjvm-default=all")
}
}
}
}

allprojects {
repositories {
jcenter()
maven("http://dist.wso2.org/maven2")
Expand Down Expand Up @@ -312,14 +313,6 @@ allprojects {

// == Utilities ==

fun InputStream.dump(name: String? = null) {
if (name != null)
println("\n$name:")
while (available() > 0)
print(read().toChar())
close()
}

fun Task.dependOnSubprojects() {
if (this.project == rootProject)
doAfterEvaluate.add {
Expand Down
21 changes: 11 additions & 10 deletions helpers/test-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ sourceSets.main {
}

application {
mainClassName = "sc.TestClient"
mainClass.set("sc.TestClient")
}

dependencies {
implementation(project(":plugin"))
// TODO this dependency is only for accessing the Configuration, remove it
implementation(project(":server"))
}

tasks {
val createStartScripts by creating(ScriptsTask::class) {
destinationDir = file("build/libs")
fileName = "start-tests"
content = "java -Dfile.encoding=UTF-8 -Dlogback.configurationFile=logback-tests.xml -jar test-client.jar"
val createStartScripts by creating(CreateStartScripts::class) {
outputDir = jar.get().destinationDirectory.asFile.get()
applicationName = "start-tests"
defaultJvmOpts = listOf("-Dfile.encoding=UTF-8", "-Dlogback.configurationFile=logback-tests.xml")
}

jar {
dependsOn(createStartScripts)
doFirst {
manifest.attributes["Class-Path"] =
configurations.default.get().map { "lib/" + it.name }
.plus("server.jar")
.joinToString(" ")
copy {
from("src/logback-tests.xml")
into("build/libs")
into(destinationDirectory)
}
}
val libs = arrayListOf("plugins/${project.property("game")}.jar", "software-challenge-server.jar", "server.jar")
libs.addAll(configurations.default.get().map { "lib/" + it.name })
manifest.attributes["Class-Path"] = libs.joinToString(" ")
}

run.configure {
Expand Down
7 changes: 4 additions & 3 deletions helpers/test-client/src/sc/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sc.networking.INetworkInterface;
import sc.networking.TcpNetwork;
import sc.networking.clients.XStreamClient;
import sc.plugin2021.util.Constants;
import sc.protocol.requests.*;
import sc.protocol.responses.*;
import sc.server.Configuration;
Expand Down Expand Up @@ -263,7 +262,8 @@ protected void onObject(ProtocolMessage message) {
logger.error("{} crashed, look into {}", player.name, logDir);
exit(2);
}
if (slept > Constants.GAME_TIMEOUT) {
// TODO move timeout to GamePlugin and obtain it
if (slept > 200.000) {
logger.error("The game seems to hang, exiting!");
exit(2);
}
Expand Down Expand Up @@ -363,7 +363,8 @@ private boolean isSignificant() {
players:
for (int i = 0; i < 2; i++) {
double binominalCD = 0.0;
for (int k = 0; k <= players[i].score.getScoreValues().get(0).getValue().intValue() / Constants.WIN_SCORE; k++) {
// TODO use global WIN_SCORE constant instead of hardcoding 2
for (int k = 0; k <= players[i].score.getScoreValues().get(0).getValue().intValue() / 2; k++) {
binominalCD += binominalPD.applyAsDouble(k);
if (binominalCD > significance)
continue players;
Expand Down
2 changes: 1 addition & 1 deletion player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tasks {
from("src")
into("src")
}, copySpec {
from(configurations.default, arrayOf("sdk", "plugin").map { project(":$it").tasks.getByName("sourcesJar").outputs.files })
from(configurations.default, arrayOf("sdk", "plugin").map { project(":$it").getTasksByName("sourcesJar", false).single().outputs.files })
into("lib")
})
if(!project.hasProperty("nodoc")) {
Expand Down
41 changes: 21 additions & 20 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import sc.gradle.ScriptsTask

plugins {
application
}

sourceSets {
main.get().java.srcDir("src")
test.get().java.srcDir("test")
// TODO https://github.com/CAU-Kiel-Tech-Inf/backend/issues/265
distribution
}

application {
mainClassName = "sc.server.Application"
mainClass.set("sc.server.Application")
applicationDefaultJvmArgs = listOf("-Dfile.encoding=UTF-8",
"-XX:+PrintGC", "-XX:+PrintGCDetails", "-XX:+PrintGCDateStamps", "-Xloggc:gc.log")
}

sourceSets {
main.get().java.srcDir("src")
test.get().java.srcDir("test")
}

dependencies {
implementation(project(":sdk"))
api(project(":sdk"))
runtimeOnly(project(":plugin"))

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") // legacy java tests
Expand All @@ -27,10 +27,10 @@ val deployDir: File by project
tasks {
val runnableDir = buildDir.resolve("runnable")

val createStartScripts by creating(ScriptsTask::class) {
destinationDir = runnableDir
fileName = "start"
content = "java -Dfile.encoding=UTF-8 -Dlogback.configurationFile=logback.xml -jar server.jar"
startScripts {
outputDir = runnableDir
applicationName = "start-server"
defaultJvmOpts = listOf("-Dfile.encoding=UTF-8", "-Dlogback.configurationFile=logback.xml")
}

val copyConfig by creating(Copy::class) {
Expand All @@ -43,21 +43,21 @@ tasks {

val makeRunnable by creating(Copy::class) {
group = "distribution"
dependsOn(jar, copyConfig, createStartScripts)
dependsOn(jar, copyConfig, startScripts)
from(configurations.default)
into(runnableDir.resolve("lib"))
}

val deploy by creating(Zip::class) {
group = "distribution"
dependsOn(project(":test-client").tasks.jar, ":player:shadowJar", makeRunnable)
dependsOn(":test-client:jar", ":player:shadowJar", makeRunnable)
destinationDirectory.set(deployDir)
archiveBaseName.set("software-challenge-server")
from(runnableDir)
if(project.property("enableTestClient") as Boolean)
from(project(":test-client").buildDir.resolve("libs"))
doFirst {
from(project(":player").tasks["shadowJar"].outputs)
if(project.property("enableTestClient") as Boolean)
from((project(":test-client").getTasksByName("jar", false).single() as Jar).destinationDirectory)
from(project(":player").getTasksByName("shadowJar", false).single().outputs)
exec {
commandLine("git", "rev-parse", "HEAD")
standardOutput = runnableDir.resolve("version").outputStream()
Expand Down Expand Up @@ -91,9 +91,10 @@ tasks {
}

jar {
destinationDirectory.set(runnableDir)
destinationDirectory.set(runnableDir.resolve("lib"))
doFirst {
manifest.attributes["Class-Path"] = configurations.default.get().joinToString(" ") { "lib/" + it.name }
manifest.attributes["Class-Path"] =
configurations.default.get().joinToString(" ") { "lib/" + it.name }
}
}

Expand Down