Skip to content
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

Finish functional tests migration #1117

Merged
merged 21 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
41 changes: 9 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.android.lint)
alias(libs.plugins.jetbrains.bcv)
alias(libs.plugins.spotless)
groovy // Required for Spock tests.
id("shadow.convention.publish")
id("shadow.convention.deploy")
}
Expand All @@ -30,6 +29,8 @@ kotlin {

lint {
baseline = file("lint-baseline.xml")
ignoreTestSources = true
warningsAsErrors = true
}

spotless {
Expand All @@ -54,15 +55,12 @@ val intiTestRuntimeOnly: Configuration by configurations.getting {
val funcTest: SourceSet by sourceSets.creating
val funcTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.testImplementation.get())
// TODO: this will be removed after we migrated all functional tests to Kotlin.
extendsFrom(intiTestImplementation)
}
val funcTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}

gradlePlugin {
testSourceSets.add(intiTest)
testSourceSets.add(funcTest)
}

Expand All @@ -80,26 +78,14 @@ dependencies {
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertk)
testImplementation(libs.xmlunit)
testImplementation(libs.apache.commonsLang)
testRuntimeOnly(libs.junit.platformLauncher)

funcTestImplementation(libs.spock) {
exclude(group = "org.codehaus.groovy")
exclude(group = "org.hamcrest")
}
funcTestImplementation(sourceSets.main.get().output)
funcTestImplementation(intiTest.output)

intiTestImplementation(libs.okio)
intiTestImplementation(libs.apache.maven.modelBuilder)
intiTestImplementation(libs.apache.maven.repositoryMetadata)
// TODO: this will be removed after we migrated all functional tests to Kotlin.
intiTestImplementation(sourceSets.main.get().output)
intiTestImplementation(libs.moshi)
intiTestImplementation(libs.moshi.kotlin)
funcTestImplementation(libs.apache.maven.modelBuilder)
funcTestImplementation(libs.moshi)
funcTestImplementation(libs.moshi.kotlin)

lintChecks(libs.androidx.gradlePluginLints)
lintChecks(libs.assertk.lint)
}

val integrationTest by tasks.registering(Test::class) {
Expand All @@ -108,10 +94,6 @@ val integrationTest by tasks.registering(Test::class) {
testClassesDirs = intiTest.output.classesDirs
classpath = intiTest.runtimeClasspath

// TODO: this should be moved into functionalTest after we migrated all functional tests to Kotlin.
// Required to enable `IssueExtension` for all tests.
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)

val docsDir = file("src/docs")
// Add src/docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(docsDir)
Expand All @@ -123,6 +105,9 @@ val functionalTest by tasks.registering(Test::class) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
testClassesDirs = funcTest.output.classesDirs
classpath = funcTest.runtimeClasspath

// Required to enable `IssueExtension` for all tests.
systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
}

tasks.check {
Expand All @@ -147,14 +132,6 @@ tasks.withType<Test>().configureEach {
)
}

tasks.whenTaskAdded {
if (name == "lintAnalyzeJvmTest") {
// This task often fails on Windows CI devices.
enabled = !providers.systemProperty("os.name").get().startsWith("Windows") &&
!providers.environmentVariable("CI").isPresent
}
}

tasks.clean {
val includedBuilds = gradle.includedBuilds
dependsOn(includedBuilds.map { it.task(path) })
Expand Down
10 changes: 2 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
[versions]
maven = "3.9.9"
moshi = "1.15.2"

[libraries]
apache-ant = "org.apache.ant:ant:1.10.15"
apache-commonsIo = "commons-io:commons-io:2.18.0"
apache-commonsLang = "org.apache.commons:commons-lang3:3.17.0"
apache-log4j = "org.apache.logging.log4j:log4j-core:2.24.3"
apache-maven-modelBuilder = { module = "org.apache.maven:maven-model-builder", version.ref = "maven" }
apache-maven-repositoryMetadata = { module = "org.apache.maven:maven-repository-metadata", version.ref = "maven" }
apache-maven-modelBuilder = "org.apache.maven:maven-model-builder:3.9.9"
asm = "org.ow2.asm:asm-commons:9.7.1"
jdependency = "org.vafer:jdependency:2.11"
jdom2 = "org.jdom:jdom2:2.0.6.1"
plexus-utils = "org.codehaus.plexus:plexus-utils:4.0.2"
plexus-xml = "org.codehaus.plexus:plexus-xml:4.0.4"
xmlunit = "org.xmlunit:xmlunit-legacy:2.10.0"
okio = "com.squareup.okio:okio:3.10.2"
moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" }
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" }

Expand All @@ -26,18 +22,16 @@ jetbrains-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:2.0.0"
node = "com.github.node-gradle:gradle-node-plugin:7.1.0"

androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha03"
assertk-lint = "com.jzbrooks:assertk-lint:1.4.0"
# Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless.
ktlint = "com.pinterest.ktlint:ktlint-cli:1.5.0"

spock = "org.spockframework:spock-core:2.3-groovy-3.0"
junit-bom = "org.junit:junit-bom:5.11.4"
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit-platformLauncher = { module = "org.junit.platform:junit-platform-launcher" }
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"

[plugins]
kotlin = "org.jetbrains.kotlin.jvm:2.1.0"
kotlin-jvm = "org.jetbrains.kotlin.jvm:2.1.0"
android-lint = "com.android.lint:8.8.0"
jetbrains-bcv = "org.jetbrains.kotlinx.binary-compatibility-validator:0.17.0"
spotless = "com.diffplug.spotless:7.0.1"
8 changes: 4 additions & 4 deletions lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="30"
line="31"
column="1"/>
</issue>

Expand All @@ -118,7 +118,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="31"
line="32"
column="1"/>
</issue>

Expand All @@ -129,7 +129,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="32"
line="33"
column="1"/>
</issue>

Expand All @@ -140,7 +140,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt"
line="33"
line="34"
column="1"/>
</issue>

Expand Down
2 changes: 0 additions & 2 deletions src/funcTest/.editorconfig

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.jengelman.gradle.plugins.shadow

import assertk.all
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.containsAtLeast
import assertk.assertions.exists
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEmpty
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr
import com.github.jengelman.gradle.plugins.shadow.util.isRegular
import kotlin.io.path.appendText
import kotlin.io.path.readText
import kotlin.io.path.writeText
Expand Down Expand Up @@ -36,23 +38,33 @@ class ApplicationTest : BasePluginTest() {

val result = run(runShadowTask)

assertThat(result.output).contains("Running application with JDK 17")
assertThat(result.output).contains("TestApp: Hello World! (foo)")

val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")
assertThat(installedJar).containsEntries(
"a.properties",
"a2.properties",
"myapp/Main.class",
assertThat(result.output).contains(
"Running application with JDK 17",
"TestApp: Hello World! (foo)",
)
assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class"))
.isEqualTo("myapp.Main")

path("build/install/myapp-shadow/bin/myapp").let { startScript ->
assertThat(startScript).exists()
assertThat(startScript.readText()).contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar")
assertThat(startScript.readText()).contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"")
assertThat(startScript.readText()).contains("exec \"\$JAVACMD\" \"\$@\"")
assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).useAll {
containsEntries(
"a.properties",
"a2.properties",
"myapp/Main.class",
)
getMainAttr("Main-Class").isEqualTo("myapp.Main")
}

assertThat(path("build/install/myapp-shadow/bin/myapp")).all {
exists()
transform { it.readText() }.contains(
"CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar",
"-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"",
"exec \"\$JAVACMD\" \"\$@\"",
)
}
assertThat(path("build/install/myapp-shadow/bin/myapp.bat")).all {
exists()
transform { it.readText() }.contains(
"set CLASSPATH=%APP_HOME%\\lib\\myapp-1.0-all.jar",
)
}
}

Expand All @@ -71,7 +83,7 @@ class ApplicationTest : BasePluginTest() {
val zip = path("build/distributions/myapp-shadow-1.0.zip")
assertThat(zip).exists()

val entries = ZipFile(zip.toFile()).entries.toList().map { it.name }
val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name }
assertThat(entries).containsAtLeast(
"myapp-shadow-1.0/lib/myapp-1.0-all.jar",
"myapp-shadow-1.0/lib/a-1.0.jar",
Expand All @@ -84,7 +96,7 @@ class ApplicationTest : BasePluginTest() {

run(ShadowApplicationPlugin.SHADOW_INSTALL_TASK_NAME)

assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar").entries().toList()).isNotEmpty()
assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular()
}

private fun prepare(
Expand Down
Loading
Loading