IDEA-340378 prefer new non-blocking API

GitOrigin-RevId: c60e46b2b70a15c38066ab48fca74dcbf2fb8447
This commit is contained in:
Vladimir Krivosheev
2023-12-11 09:32:05 +01:00
committed by intellij-monorepo-bot
parent c2928c1e2f
commit ef23128e7b
8 changed files with 58 additions and 50 deletions

View File

@@ -1,8 +1,9 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.jetbrains.intellij.build.IdeaProjectLoaderUtil
import org.jetbrains.intellij.build.TestingTasks
import org.jetbrains.intellij.build.impl.createCompilationContext
import org.jetbrains.intellij.build.impl.createCompilationContextBlocking
/**
* Compiles the sources and runs tests from 'community' project. Look at [org.jetbrains.intellij.build.TestingOptions] to see which
@@ -17,11 +18,13 @@ object CommunityRunTestsBuildTarget {
@JvmStatic
fun main(args: Array<String>) {
val communityHome = IdeaProjectLoaderUtil.guessCommunityHome(javaClass)
val context = createCompilationContextBlocking(
communityHome = communityHome,
projectHome = communityHome.communityRoot,
defaultOutputRoot = communityHome.communityRoot.resolve("out/tests")
)
TestingTasks.create(context).runTests(defaultMainModule = "intellij.idea.community.main")
runBlocking(Dispatchers.Default) {
val context = createCompilationContext(
communityHome = communityHome,
projectHome = communityHome.communityRoot,
defaultOutputRoot = communityHome.communityRoot.resolve("out/tests")
)
TestingTasks.create(context).runTests(defaultMainModule = "intellij.idea.community.main")
}
}
}

View File

@@ -70,7 +70,7 @@ interface CompilationTasks {
/**
* [compileModules] is called if required
*/
fun buildProjectArtifacts(artifactNames: Set<String>)
suspend fun buildProjectArtifacts(artifactNames: Set<String>)
fun resolveProjectDependencies()

View File

@@ -1,4 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
package org.jetbrains.intellij.build
import org.jetbrains.intellij.build.impl.TestingTasksImpl
@@ -25,15 +27,15 @@ interface TestingTasks {
* @param defaultMainModule the main module to be used if [TestingOptions.mainModule] is not specified
* @param rootExcludeCondition if not `null`, tests from modules which sources are fit this predicate will be skipped
*/
fun runTests(additionalJvmOptions: List<String> = emptyList(),
additionalSystemProperties: Map<String, String> = emptyMap(),
defaultMainModule: String? = null,
rootExcludeCondition: ((Path) -> Boolean)? = null)
suspend fun runTests(additionalJvmOptions: List<String> = java.util.List.of(),
additionalSystemProperties: Map<String, String> = java.util.Map.of(),
defaultMainModule: String? = null,
rootExcludeCondition: ((Path) -> Boolean)? = null)
/**
* Run all tests annotated with [com.intellij.testFramework.SkipInHeadlessEnvironment]
*/
fun runTestsSkippedInHeadlessEnvironment()
suspend fun runTestsSkippedInHeadlessEnvironment()
fun createSnapshotsDirectory(): Path

View File

@@ -625,10 +625,10 @@ private suspend fun compileModulesForDistribution(context: BuildContext): Distri
return distState
}
private fun buildProjectArtifacts(platform: PlatformLayout,
enabledPluginModules: Set<String>,
compilationTasks: CompilationTasks,
context: BuildContext) {
private suspend fun buildProjectArtifacts(platform: PlatformLayout,
enabledPluginModules: Set<String>,
compilationTasks: CompilationTasks,
context: BuildContext) {
val artifactNames = LinkedHashSet<String>()
artifactNames.addAll(platform.includedArtifacts.keys)
getPluginLayoutsByJpsModuleNames(modules = enabledPluginModules, productLayout = context.productProperties.productLayout)

View File

@@ -13,6 +13,7 @@ import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.trace.Span
import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus.Internal
import org.jetbrains.annotations.ApiStatus.Obsolete
import org.jetbrains.intellij.build.*
import org.jetbrains.intellij.build.TraceManager.spanBuilder
import org.jetbrains.intellij.build.dependencies.BuildDependenciesCommunityRoot
@@ -41,7 +42,7 @@ import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.name
@JvmOverloads
@Obsolete
fun createCompilationContextBlocking(communityHome: BuildDependenciesCommunityRoot,
projectHome: Path,
defaultOutputRoot: Path,

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.intellij.build.impl
import com.intellij.platform.diagnostic.telemetry.helpers.useWithScope
import com.intellij.platform.diagnostic.telemetry.helpers.useWithScopeBlocking
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.trace.Span
@@ -17,7 +18,7 @@ class CompilationTasksImpl(private val context: CompilationContext) : Compilatio
}
}
override fun buildProjectArtifacts(artifactNames: Set<String>) {
override suspend fun buildProjectArtifacts(artifactNames: Set<String>) {
if (artifactNames.isEmpty()) {
return
}
@@ -28,8 +29,8 @@ class CompilationTasksImpl(private val context: CompilationContext) : Compilatio
}
spanBuilder("build project artifacts")
.setAttribute(AttributeKey.stringArrayKey("artifactNames"), artifactNames.toList())
.useWithScopeBlocking {
.setAttribute(AttributeKey.stringArrayKey("artifactNames"), java.util.List.copyOf(artifactNames))
.useWithScope {
jps.buildArtifacts(artifactNames, buildIncludedModules = false)
}
}

View File

@@ -3,6 +3,7 @@ package org.jetbrains.intellij.build.impl
import com.intellij.devkit.runtimeModuleRepository.jps.build.RuntimeModuleRepositoryBuildConstants
import com.intellij.platform.diagnostic.telemetry.helpers.use
import com.intellij.platform.diagnostic.telemetry.helpers.useWithScope
import com.intellij.platform.diagnostic.telemetry.helpers.useWithScopeBlocking
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.Attributes
@@ -153,12 +154,7 @@ internal class JpsCompilationRunner(private val context: CompilationContext) {
canceledStatus = canceledStatus)
}
@Deprecated("", ReplaceWith("buildArtifacts(artifactNames = artifactNames, buildIncludedModules = true)"))
fun buildArtifacts(artifactNames: Set<String>) {
buildArtifacts(artifactNames = artifactNames, buildIncludedModules = true)
}
fun buildArtifacts(artifactNames: Set<String>, buildIncludedModules: Boolean) {
suspend fun buildArtifacts(artifactNames: Set<String>, buildIncludedModules: Boolean) {
val artifacts = getArtifactsWithIncluded(artifactNames)
val missing = artifactNames.filter { name ->
artifacts.none { it.name == name }
@@ -214,24 +210,24 @@ internal class JpsCompilationRunner(private val context: CompilationContext) {
}
// FIXME: workaround for sporadically missing build artifacts, to be investigated
private fun compileMissingArtifactsModules(artifacts: Collection<JpsArtifact>) {
private suspend fun compileMissingArtifactsModules(artifacts: Collection<JpsArtifact>) {
val modules = getModulesIncludedInArtifacts(artifacts)
require(modules.isNotEmpty()) {
"No modules found for artifacts ${artifacts.map { it.name }}"
}
artifacts.forEach {
context.compilationData.builtArtifacts.remove(it.name)
for (artifact in artifacts) {
context.compilationData.builtArtifacts.remove(artifact.name)
}
context.messages.block("Compiling modules for missing artifacts: ${modules.joinToString()}") {
spanBuilder("Compiling modules for missing artifacts: ${modules.joinToString()}").useWithScope {
runBuild(moduleSet = modules,
allModules = false,
artifactNames = artifacts.map { it.name },
includeTests = false,
resolveProjectDependencies = false)
}
artifacts.forEach {
if (it.outputFilePath?.let(Path::of)?.let(Files::exists) == false) {
context.messages.error("${it.name} is expected to be built at ${it.outputFilePath}")
for (artifact in artifacts) {
if (artifact.outputFilePath?.let(Path::of)?.let(Files::exists) == false) {
context.messages.error("${artifact.name} is expected to be built at ${artifact.outputFilePath}")
}
}
}

View File

@@ -16,7 +16,6 @@ import io.opentelemetry.api.common.AttributeKey
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.jetbrains.intellij.build.*
import org.jetbrains.intellij.build.CompilationTasks.Companion.create
import org.jetbrains.intellij.build.TraceManager.spanBuilder
import org.jetbrains.intellij.build.causal.CausalProfilingOptions
import org.jetbrains.intellij.build.io.runProcess
@@ -75,10 +74,10 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
.toList()
}
override fun runTests(additionalJvmOptions: List<String>,
additionalSystemProperties: Map<String, String>,
defaultMainModule: String?,
rootExcludeCondition: ((Path) -> Boolean)?) {
override suspend fun runTests(additionalJvmOptions: List<String>,
additionalSystemProperties: Map<String, String>,
defaultMainModule: String?,
rootExcludeCondition: ((Path) -> Boolean)?) {
if (options.isTestDiscoveryEnabled && options.isPerformanceTestsOnly) {
context.messages.buildStatus("Skipping performance testing with Test Discovery, {build.status.text}")
return
@@ -90,7 +89,7 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
val runConfigurations = loadTestRunConfigurations()
try {
val compilationTasks = create(context)
val compilationTasks = CompilationTasks.create(context)
options.beforeRunProjectArtifacts?.splitToSequence(';')?.filterNotTo(HashSet(), String::isEmpty)?.let {
compilationTasks.buildProjectArtifacts(it)
}
@@ -101,7 +100,8 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
compilationTasks.buildProjectArtifacts(runConfigurations.flatMapTo(LinkedHashSet()) { it.requiredArtifacts })
}
else {
compilationTasks.compileModules(listOf("intellij.tools.testsBootstrap"), listOfNotNull(mainModule, "intellij.platform.buildScripts"))
compilationTasks.compileModules(listOf("intellij.tools.testsBootstrap"),
listOfNotNull(mainModule, "intellij.platform.buildScripts"))
}
}
catch (e: Exception) {
@@ -361,7 +361,7 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
Files.createDirectories(classpathFile.parent)
// this is required to collect tests both on class and module paths
Files.writeString(classpathFile, testRoots.mapNotNull(toStringConverter).joinToString(separator = "\n"))
@Suppress("NAME_SHADOWING")
@Suppress("NAME_SHADOWING")
val systemProperties = systemProperties.toMutableMap()
systemProperties.putIfAbsent("classpath.file", classpathFile.toString())
testPatterns?.let { systemProperties.putIfAbsent("intellij.build.test.patterns", it) }
@@ -551,8 +551,8 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
}
}
override fun runTestsSkippedInHeadlessEnvironment() {
create(context).compileAllModulesAndTests()
override suspend fun runTestsSkippedInHeadlessEnvironment() {
CompilationTasks.create(context).compileAllModulesAndTests()
val tests = spanBuilder("loading all tests annotated with @SkipInHeadlessEnvironment").use { loadTestsSkippedInHeadlessEnvironment() }
for (it in tests) {
options.batchTestIncludes = it.getFirst()
@@ -643,10 +643,15 @@ internal class TestingTasksImpl(private val context: CompilationContext, private
// Run JUnit 4 and 5 whole test classes separately
if (options.isDedicatedRuntimePerClassEnabled && jUnit4And5TestMethods.isNotEmpty()) {
val exitCode = runJUnit5Engine(
systemProperties, jvmArgs, envVariables, bootstrapClasspath, null, testClasspath,
qName, null)
noTests = noTests && exitCode == NO_TESTS_ERROR
val exitCode = runJUnit5Engine(systemProperties = systemProperties,
jvmArgs = jvmArgs,
envVariables = envVariables,
bootstrapClasspath = bootstrapClasspath,
modulePath = null,
testClasspath = testClasspath,
suiteName = qName,
methodName = null)
noTests = exitCode == NO_TESTS_ERROR
}
// Run JUnit 4 and 5 test methods separately if any
else if (jUnit4And5TestMethods.isNotEmpty()) {