Skip to content

Commit 7e1fd66

Browse files
demiurg906Space Team
authored andcommitted
[Build] Remove the projectTest utility from the global scope of build files
Now all test tasks should be created using the ` project-tests-convention` convention plugin.
1 parent 8af4516 commit 7e1fd66

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

repo/gradle-build-conventions/project-tests-convention/src/main/kotlin/ProjectTestsExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ abstract class ProjectTestsExtension(val project: Project) {
203203
if (jUnitMode == JUnitMode.JUnit5 && parallel != null) {
204204
project.logger.error("JUnit5 tests are parallel by default and its configured with `junit-platform.properties`, please remove `parallel=$parallel` argument")
205205
}
206-
return project.projectTest(
206+
return project.createGeneralTestTask(
207207
taskName,
208208
parallel ?: false,
209209
jUnitMode,

repo/gradle-build-conventions/utilities/src/main/kotlin/testTasks.kt renamed to repo/gradle-build-conventions/project-tests-convention/src/main/kotlin/generalTestTask.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

6-
import com.sun.management.OperatingSystemMXBean
76
import org.gradle.api.Project
8-
import org.gradle.api.file.Directory
97
import org.gradle.api.file.FileCollection
108
import org.gradle.api.file.FileSystemOperations
119
import org.gradle.api.file.RegularFileProperty
1210
import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter
1311
import org.gradle.api.model.ObjectFactory
14-
import org.gradle.api.provider.Provider
15-
import org.gradle.api.tasks.ClasspathNormalizer
16-
import org.gradle.api.tasks.InputFile
17-
import org.gradle.api.tasks.PathSensitive
18-
import org.gradle.api.tasks.PathSensitivity
19-
import org.gradle.api.tasks.TaskProvider
12+
import org.gradle.api.tasks.*
2013
import org.gradle.api.tasks.testing.Test
2114
import org.gradle.kotlin.dsl.dependencies
2215
import org.gradle.kotlin.dsl.newInstance
@@ -27,19 +20,17 @@ import org.gradle.process.CommandLineArgumentProvider
2720
import java.io.File
2821
import java.lang.Character.isLowerCase
2922
import java.lang.Character.isUpperCase
30-
import java.lang.management.ManagementFactory
3123
import java.nio.file.Files
3224
import java.nio.file.Path
3325
import javax.inject.Inject
34-
import kotlin.collections.forEach
3526

3627

3728
// Mixing JUnit4 and Junit5 in one module proved to be problematic, consider using separate modules instead
3829
enum class JUnitMode {
3930
JUnit4, JUnit5
4031
}
4132

42-
abstract class MuteWithDatabaseArgumentProvider @Inject constructor(objects: ObjectFactory) : CommandLineArgumentProvider {
33+
private abstract class MuteWithDatabaseArgumentProvider @Inject constructor(objects: ObjectFactory) : CommandLineArgumentProvider {
4334
@get:InputFile
4435
@get:PathSensitive(PathSensitivity.NONE)
4536
val mutesFile: RegularFileProperty = objects.fileProperty()
@@ -48,7 +39,7 @@ abstract class MuteWithDatabaseArgumentProvider @Inject constructor(objects: Obj
4839
listOf("-Dorg.jetbrains.kotlin.test.mutes.file=${mutesFile.get().asFile.canonicalPath}")
4940
}
5041

51-
fun Test.muteWithDatabase() {
42+
private fun Test.muteWithDatabase() {
5243
jvmArgumentProviders.add(
5344
project.objects.newInstance<MuteWithDatabaseArgumentProvider>().apply {
5445
mutesFile.fileValue(File(project.rootDir, "tests/mute-common.csv"))
@@ -62,7 +53,7 @@ fun Test.muteWithDatabase() {
6253
* Workaround for TW-92736
6354
* TC parallelTests.excludesFile may contain invalid entries leading to skipping large groups of tests.
6455
*/
65-
fun Test.cleanupInvalidExcludePatternsForTCParallelTests(excludesFilePath: String) {
56+
private fun Test.cleanupInvalidExcludePatternsForTCParallelTests(excludesFilePath: String) {
6657
val candidateTestClassNames = mutableSetOf<String>()
6758
candidateClassFiles.visit {
6859
if (!isDirectory && name.endsWith(".class")) {
@@ -88,7 +79,7 @@ fun Test.cleanupInvalidExcludePatternsForTCParallelTests(excludesFilePath: Strin
8879
* @param parallel is redundant if @param jUnit5Enabled is true, because
8980
* JUnit5 supports parallel test execution by itself, without gradle help
9081
*/
91-
fun Project.projectTest(
82+
internal fun Project.createGeneralTestTask(
9283
taskName: String = "test",
9384
parallel: Boolean = false,
9485
jUnitMode: JUnitMode,
@@ -292,18 +283,9 @@ fun Project.projectTest(
292283
}.apply { configure(body) }
293284
}
294285

295-
val defaultMaxMemoryPerTestWorkerMb = 1600
296-
val reservedMemoryMb = 9000 // system processes, gradle daemon, kotlin daemon, etc ...
286+
private val defaultMaxMemoryPerTestWorkerMb = 1600
297287

298-
val totalMaxMemoryForTestsMb: Int
299-
get() {
300-
val mxbean = ManagementFactory.getOperatingSystemMXBean() as OperatingSystemMXBean
301-
return (mxbean.totalPhysicalMemorySize / 1048576 - reservedMemoryMb).toInt()
302-
}
303-
304-
val Test.commandLineIncludePatterns: Set<String>
288+
private val Test.commandLineIncludePatterns: Set<String>
305289
get() = (filter as? DefaultTestFilter)?.commandLineIncludePatterns.orEmpty()
306290

307291
private inline fun String.isFirstChar(f: (Char) -> Boolean) = isNotEmpty() && f(first())
308-
309-
fun Project.ideaHomePathForTests(): Provider<Directory> = rootProject.layout.buildDirectory.dir("ideaHomeForTests")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
import com.sun.management.OperatingSystemMXBean
7+
import org.gradle.api.Project
8+
import org.gradle.api.file.Directory
9+
import org.gradle.api.provider.Provider
10+
import java.lang.management.ManagementFactory
11+
12+
private val reservedMemoryMb = 9000 // system processes, gradle daemon, kotlin daemon, etc ...
13+
14+
val totalMaxMemoryForTestsMb: Int
15+
get() {
16+
val mxbean = ManagementFactory.getOperatingSystemMXBean() as OperatingSystemMXBean
17+
return (mxbean.totalPhysicalMemorySize / 1048576 - reservedMemoryMb).toInt()
18+
}
19+
20+
fun Project.ideaHomePathForTests(): Provider<Directory> = rootProject.layout.buildDirectory.dir("ideaHomeForTests")

0 commit comments

Comments
 (0)