Skip to content

Commit

Permalink
Introduce TestFrameworkType for testFramework(type, version) depe…
Browse files Browse the repository at this point in the history
…ndencies helper; initial excludes of testFramework transitive dependencies
  • Loading branch information
hsz committed Feb 29, 2024
1 parent 46f4570 commit 78836dc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.exclude
import org.jetbrains.intellij.platform.gradle.BuildFeature
import org.jetbrains.intellij.platform.gradle.Constants.Configurations
import org.jetbrains.intellij.platform.gradle.Constants.JETBRAINS_MARKETPLACE_MAVEN_GROUP
Expand Down Expand Up @@ -657,17 +658,32 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor(
fun zipSigner(version: Provider<String>) = addZipSignerDependency(version)

/**
* Adds a dependency on the `test-framework` library required for testing plugins.
* Adds a dependency on the `test-framework` library or its variant, required for testing plugins.
*
* By default, the version is determined by the IntelliJ Platform build number.
* There are multiple variants available next to the [TestFrameworkType.Default], which provide additional classes for testing specific modules, like:
* Maven, JavaScript, Go, Jave, ReSharper, etc.
*
* The version, if absent, is determined by the IntelliJ Platform build number.
* If the exact version is unavailable, the closest one is used, found by scanning all releases.
* */
fun testFramework(version: String = VERSION_CURRENT) = addTestFrameworkDependency(providers.provider { version })
*
* @param type test framework variant type
* @param version library version
*/
fun testFramework(type: TestFrameworkType = TestFrameworkType.Default, version: String = VERSION_CURRENT) =
addTestFrameworkDependency(providers.provider { type }, providers.provider { version })

/**
* Adds a dependency on the `test-framework` library required for testing plugins.
*
* There are multiple variants available next to the [TestFrameworkType.Default], which provide additional classes for testing specific modules, like:
* Maven, JavaScript, Go, Jave, ReSharper, etc.
*
* If the exact version is unavailable, the closest one is used, found by scanning all releases.
*
* @param type test framework variant type
* @param version library version
*/
fun testFramework(version: Provider<String>) = addTestFrameworkDependency(version)
fun testFramework(type: Provider<TestFrameworkType>, version: Provider<String>) = addTestFrameworkDependency(type, version)

/**
* Adds a Java Compiler dependency for code instrumentation.
Expand Down Expand Up @@ -934,29 +950,34 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor(
* This dependency belongs to IntelliJ Platform repositories.
*/
private fun addTestFrameworkDependency(
typeProvider: Provider<TestFrameworkType>,
versionProvider: Provider<String>,
configurationName: String = Configurations.INTELLIJ_PLATFORM_TEST_DEPENDENCIES,
action: DependencyAction = {},
) = dependencies.addProvider(
configurationName,
versionProvider.map { version ->
) = configurations.getByName(configurationName).dependencies.addLater(
typeProvider.zip(versionProvider) { type, version ->
val productInfo = configurations.getByName(Configurations.INTELLIJ_PLATFORM).productInfo()
val resolveClosest = BuildFeature.USE_CLOSEST_JAVA_COMPILER_VERSION.getValue(providers).get()

dependencies.create(
group = "com.jetbrains.intellij.platform",
name = "test-framework",
group = type.groupId,
name = type.artifactId,
version = when (version) {
VERSION_CURRENT -> when {
resolveClosest -> TestFrameworkClosestVersionResolver(productInfo).resolve().version
resolveClosest -> TestFrameworkClosestVersionResolver(productInfo, type).resolve().version
else -> productInfo.buildNumber
}

else -> version
},
)
}
).apply {
exclude("org.jetbrains.teamcity")
exclude("ai.grazie.utils")
exclude("ai.grazie.spell")
exclude("ai.grazie.nlp")
exclude("ai.grazie.model")
}.apply(action)
},
action,
)
}

Expand Down Expand Up @@ -1045,6 +1066,23 @@ private fun arch(newFormat: Boolean): String {
}
}

enum class TestFrameworkType(
val groupId: String,
val artifactId: String,
) {
Common("com.jetbrains.intellij.platform", "test-framework-common"),
Core("com.jetbrains.intellij.platform", "test-framework-core"),
Default("com.jetbrains.intellij.platform", "test-framework"),
Go("com.jetbrains.intellij.go", "go-test-framework"),
Ruby("com.jetbrains.intellij.idea", "ruby-test-framework"),
Java("com.jetbrains.intellij.java", "java-test-framework"),
JavaScript("com.jetbrains.intellij.javascript", "javascript-test-framework"),
JUnit5("com.jetbrains.intellij.platform", "test-framework-junit5"),
Maven("com.jetbrains.intellij.maven", "maven-test-framework"),
ReSharper("com.jetbrains.intellij.resharper", "resharper-test-framework"),
;
}

/**
* Type alias for a lambda function that takes a [Dependency] and performs some actions on it.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import org.gradle.api.provider.ProviderFactory
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.maven
import org.jetbrains.intellij.platform.gradle.BuildFeature
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.Constants.Configurations
import org.jetbrains.intellij.platform.gradle.Constants.Extensions
import org.jetbrains.intellij.platform.gradle.Constants.Locations
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.model.toPublication
import java.net.URI
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
package org.jetbrains.intellij.platform.gradle.resolvers.closestVersion

import org.jetbrains.intellij.platform.gradle.Constants.Locations
import org.jetbrains.intellij.platform.gradle.extensions.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.model.ProductInfo
import org.jetbrains.intellij.platform.gradle.utils.toVersion

class TestFrameworkClosestVersionResolver(private val productInfo: ProductInfo) : ClosestVersionResolver(
class TestFrameworkClosestVersionResolver(private val productInfo: ProductInfo, type: TestFrameworkType) : ClosestVersionResolver(
subject = "Test Framework",
url = "${Locations.INTELLIJ_REPOSITORY}/releases/com/jetbrains/intellij/platform/test-framework/maven-metadata.xml",
url = "${Locations.INTELLIJ_REPOSITORY}/releases/${type.groupId.replace('.', '/')}/${type.artifactId}/maven-metadata.xml",
) {

override fun resolve() = inMaven(productInfo.buildNumber.toVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import org.gradle.api.tasks.UntrackedTask
import org.gradle.api.tasks.testing.Test
import org.jetbrains.intellij.platform.gradle.Constants.PLUGIN_GROUP_NAME
import org.jetbrains.intellij.platform.gradle.tasks.aware.*
import org.jetbrains.intellij.platform.gradle.utils.asPath
import kotlin.io.path.absolutePathString

/**
* Runs plugin tests against the currently selected IntelliJ Platform with the built plugin loaded.
Expand All @@ -34,7 +32,7 @@ import kotlin.io.path.absolutePathString
* ```
*/
@UntrackedTask(because = "Should always run")
abstract class TestIdeTask : Test(), CustomIntelliJPlatformVersionAware, SandboxAware, CoroutinesJavaAgentAware, PluginAware, RuntimeAware {
abstract class TestIdeTask : Test(), CoroutinesJavaAgentAware, CustomIntelliJPlatformVersionAware, PluginAware, RuntimeAware, SandboxAware {

init {
group = PLUGIN_GROUP_NAME
Expand All @@ -47,6 +45,4 @@ abstract class TestIdeTask : Test(), CustomIntelliJPlatformVersionAware, Sandbox

super.executeTests()
}

override fun getExecutable() = runtimeExecutable.asPath.absolutePathString()
}

0 comments on commit 78836dc

Please sign in to comment.