diff --git a/gradle/build.gradle.kts b/gradle/build.gradle.kts index 64818dc69..80a05373f 100644 --- a/gradle/build.gradle.kts +++ b/gradle/build.gradle.kts @@ -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" @@ -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 { @@ -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) { @@ -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 = { @@ -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("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 @@ -251,14 +235,31 @@ tasks { // == Cross-project configuration == -allprojects { - tasks.withType { - 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 { + kotlinOptions { + jvmTarget = javaTargetVersion.toString() + freeCompilerArgs = listOf("-Xjvm-default=all") + } + } + } +} + +allprojects { repositories { jcenter() maven("http://dist.wso2.org/maven2") @@ -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 { diff --git a/helpers/test-client/build.gradle.kts b/helpers/test-client/build.gradle.kts index 3a9311ed1..9717faaf2 100644 --- a/helpers/test-client/build.gradle.kts +++ b/helpers/test-client/build.gradle.kts @@ -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 { diff --git a/helpers/test-client/src/sc/TestClient.java b/helpers/test-client/src/sc/TestClient.java index b596d8585..002a6567f 100644 --- a/helpers/test-client/src/sc/TestClient.java +++ b/helpers/test-client/src/sc/TestClient.java @@ -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; @@ -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); } @@ -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; diff --git a/player/build.gradle.kts b/player/build.gradle.kts index d472a86fa..1c8c96049 100644 --- a/player/build.gradle.kts +++ b/player/build.gradle.kts @@ -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")) { diff --git a/server/build.gradle.kts b/server/build.gradle.kts index b15cd4053..5b71eee7b 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -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 @@ -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) { @@ -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() @@ -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 } } }