Skip to content

Commit

Permalink
PrepareSandboxTask enhancements, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Nov 16, 2023
1 parent 55fa698 commit 3394d1f
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 102 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ testGradleVersion=
testGradleArguments=
testIntelliJType=IC
testIntelliJVersion=2022.3.3
testMarkdownPluginVersion=221.5787.39
testMarkdownPluginVersion=223.8617.3
#org.gradle.caching=true
#org.gradle.parallel=true
# Dokka is incompatible with the configuration cache https://github.com/Kotlin/dokka/issues/1217
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object IntelliJPluginConstants {

const val PLUGIN_GROUP_NAME = "intellij"
const val JETBRAINS_RUNTIME_VENDOR = "JetBrains"
const val JETBRAINS_MARKETPLACE_MAVEN_GROUP = "com.jetbrains.plugins"
const val JAVA_TEST_FIXTURES_PLUGIN_ID = "java-test-fixtures"
const val KOTLIN_GRADLE_PLUGIN_ID = "org.jetbrains.kotlin.jvm"
const val KOTLIN_STDLIB_DEFAULT_DEPENDENCY_PROPERTY_NAME = "kotlin.stdlib.default.dependency"
Expand All @@ -33,7 +34,10 @@ object IntelliJPluginConstants {
const val INTELLIJ_PLATFORM_DEPENDENCY = "intellijPlatformDependency"
const val INTELLIJ_PLATFORM_LOCAL_INSTANCE = "intellijPlatformLocalInstance"
const val INTELLIJ_PLATFORM = "intellijPlatform"
const val INTELLIJ_PLATFORM_PLUGINS = "intellijPlatformPlugins"
const val INTELLIJ_PLATFORM_PLUGINS_EXTRACTED = "intellijPlatformPluginsExtracted"
const val INTELLIJ_PLATFORM_BUNDLED_PLUGINS = "intellijPlatformBundledPlugins"
const val INTELLIJ_PLATFORM_BUNDLED_PLUGINS_LIST = "intellijPlatformBundledPluginsList"
const val INTELLIJ_PLATFORM_DEPENDENCIES = "intellijPlatformDependencies"
const val INTELLIJ_PLATFORM_PRODUCT_INFO = "intellijPlatformProductInfo"
const val INTELLIJ_PLUGIN_VERIFIER = "intellijPluginVerifier"
Expand All @@ -43,7 +47,7 @@ object IntelliJPluginConstants {
const val TEST_FIXTURES_COMPILE_ONLY = "testFixturesCompileOnly"

object Attributes {
val bundledPlugins = Attribute.of("intellijPlatformBundledPlugins", Boolean::class.javaObjectType)
val bundledPluginsList = Attribute.of("intellijPlatformBundledPluginsList", Boolean::class.javaObjectType)
val collected = Attribute.of("intellijPlatformCollected", Boolean::class.javaObjectType)
val extracted = Attribute.of("intellijPlatformExtracted", Boolean::class.javaObjectType)
val productInfo = Attribute.of("intellijPlatformProductInfo", Boolean::class.javaObjectType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.pathString

@DisableCachingByDefault(because = "Not worth caching")
abstract class BundledPluginsTransformer : TransformAction<TransformParameters.None> {
abstract class BundledPluginsListTransformer : TransformAction<TransformParameters.None> {

@get:Classpath
@get:InputArtifact
Expand Down Expand Up @@ -83,25 +83,25 @@ abstract class BundledPluginsTransformer : TransformAction<TransformParameters.N
}
}

internal fun DependencyHandler.applyBundledPluginsTransformer() {
internal fun DependencyHandler.applyBundledPluginsListTransformer() {
// ZIP archives fetched from the IntelliJ Maven repository
artifactTypes.maybeCreate(ZIP_TYPE)
.attributes
.attribute(Attributes.bundledPlugins, false)
.attribute(Attributes.bundledPluginsList, false)

// Local IDEs pointed with intellijPlatformLocal dependencies helper
artifactTypes.maybeCreate(ArtifactTypeDefinition.DIRECTORY_TYPE)
.attributes
.attribute(Attributes.bundledPlugins, false)
.attribute(Attributes.bundledPluginsList, false)

registerTransform(BundledPluginsTransformer::class) {
registerTransform(BundledPluginsListTransformer::class) {
from
.attribute(Attributes.extracted, true)
.attribute(Attributes.collected, false)
.attribute(Attributes.bundledPlugins, false)
.attribute(Attributes.bundledPluginsList, false)
to
.attribute(Attributes.extracted, true)
.attribute(Attributes.collected, false)
.attribute(Attributes.bundledPlugins, true)
.attribute(Attributes.bundledPluginsList, true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.gradle.api.tasks.Classpath
import org.gradle.kotlin.dsl.registerTransform
import org.gradle.work.DisableCachingByDefault
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Configurations.Attributes
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.JETBRAINS_MARKETPLACE_MAVEN_GROUP
import org.jetbrains.intellij.platform.gradle.asPath
import org.jetbrains.intellij.platform.gradle.collectIntelliJPlatformDependencyJars
import kotlin.io.path.forEachDirectoryEntry
Expand All @@ -32,12 +33,12 @@ abstract class CollectorTransformer : TransformAction<TransformParameters.None>
override fun transform(outputs: TransformOutputs) {
val input = inputArtifact.asPath

if (input.name.startsWith("org")) { // FIXME
if (input.name.startsWith(JETBRAINS_MARKETPLACE_MAVEN_GROUP)) {
// Plugin dependency
input.forEachDirectoryEntry {
it.resolve("lib")
input.forEachDirectoryEntry { entry ->
entry.resolve("lib")
.listDirectoryEntries("*.jar")
.forEach { file -> outputs.file(file) }
.forEach { outputs.file(it) }
}
} else {
// TODO: check if the given directory is IDEA — i.e. by checking if there's product-info.json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.gradle.kotlin.dsl.registerTransform
import org.gradle.work.DisableCachingByDefault
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Configurations.Attributes
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.JETBRAINS_MARKETPLACE_MAVEN_GROUP
import org.jetbrains.intellij.platform.gradle.asPath
import java.io.File.separator
import javax.inject.Inject
Expand Down Expand Up @@ -64,14 +65,13 @@ abstract class ExtractorTransformer @Inject constructor(
.takeIf { groupId == "com.jetbrains" && artifactId == "jbr" }
},
{
val marketplaceGroup = "com.jetbrains.plugins"
val channel = when {
groupId == marketplaceGroup -> ""
groupId.endsWith(".$marketplaceGroup") -> groupId.dropLast(marketplaceGroup.length + 1)
groupId == JETBRAINS_MARKETPLACE_MAVEN_GROUP -> ""
groupId.endsWith(".$JETBRAINS_MARKETPLACE_MAVEN_GROUP") -> groupId.dropLast(JETBRAINS_MARKETPLACE_MAVEN_GROUP.length + 1)
else -> null
}
// "$artifactId-$version" + "@$channel".takeIf { channel.isNotEmpty() }.orEmpty()
null

"$groupId-$artifactId-$version" + "@$channel".takeUnless { channel.isNullOrEmpty() }.orEmpty()
},
)
.firstNotNullOfOrNull { it() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ internal fun DependencyHandler.applyProductInfoTransformer() {

registerTransform(ProductInfoTransformer::class) {
from
.attribute(Attributes.bundledPlugins, false)
.attribute(Attributes.bundledPluginsList, false)
.attribute(Attributes.collected, false)
.attribute(Attributes.extracted, true)
.attribute(Attributes.productInfo, false)
to
.attribute(Attributes.bundledPlugins, false)
.attribute(Attributes.bundledPluginsList, false)
.attribute(Attributes.collected, false)
.attribute(Attributes.extracted, true)
.attribute(Attributes.productInfo, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.create
import org.jetbrains.intellij.platform.gradle.*
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Configurations
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.JETBRAINS_MARKETPLACE_MAVEN_GROUP
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Locations
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.MINIMAL_SUPPORTED_INTELLIJ_PLATFORM_VERSION
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.VERSION_LATEST
Expand Down Expand Up @@ -173,27 +174,27 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor(
id: Provider<String>,
version: Provider<String>,
channel: Provider<String>,
configurationName: String = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES,
configurationName: String = Configurations.INTELLIJ_PLATFORM_PLUGINS,
action: DependencyAction = {},
) = addIntelliJPlatformPlugin(id, version, channel, configurationName, action)

fun plugin(
id: String,
version: String,
channel: String = "",
configurationName: String = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES,
configurationName: String = Configurations.INTELLIJ_PLATFORM_PLUGINS,
action: DependencyAction = {},
) = plugin(providers.provider { id }, providers.provider { version }, providers.provider { channel }, configurationName, action)

fun bundledPlugin(
id: Provider<String>,
configurationName: String = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES,
configurationName: String = Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS,
action: DependencyAction = {},
) = addIntelliJPlatformBundledPlugin(id, configurationName, action)

fun bundledPlugin(
id: String,
configurationName: String = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES,
configurationName: String = Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS,
action: DependencyAction = {},
) = bundledPlugin(providers.provider { id }, configurationName, action)

Expand Down Expand Up @@ -315,8 +316,8 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor(
val version = versionProvider.get()

val group = when (channel) {
"default", "", null -> "com.jetbrains.plugins"
else -> "$channel.com.jetbrains.plugins"
"default", "", null -> JETBRAINS_MARKETPLACE_MAVEN_GROUP
else -> "$channel.$JETBRAINS_MARKETPLACE_MAVEN_GROUP"
}

dependencies.create(
Expand All @@ -335,11 +336,10 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor(
) = dependencies.addProvider(
configurationName,
idProvider.map { id ->
val productInfo = configurations.getByName(Configurations.INTELLIJ_PLATFORM).single().toPath().productInfo()
val productInfo = configurations.getByName(Configurations.INTELLIJ_PLATFORM_PRODUCT_INFO).single().toPath().productInfo()
val type = IntelliJPlatformType.fromCode(productInfo.productCode)

val bundledPlugins = configurations.getByName(Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS).single().toPath().bundledPlugins()
val bundledPlugin = bundledPlugins.plugins.find { it.id == id }.throwIfNull { throw Exception("Bundled plugin '$id' does not exist") }
val bundledPluginsList = configurations.getByName(Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS_LIST).single().toPath().bundledPlugins()
val bundledPlugin = bundledPluginsList.plugins.find { it.id == id }.throwIfNull { throw Exception("Bundled plugin '$id' does not exist") }
val artifactPath = bundledPlugin.let { Path.of(it.path) }
val jars = artifactPath.resolve("lib").listDirectoryEntries("*.jar")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Extensions
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.JAVA_TEST_FIXTURES_PLUGIN_ID
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.PLUGIN_BASE_ID
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Sandbox
import org.jetbrains.intellij.platform.gradle.artifacts.transform.applyBundledPluginsTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.applyBundledPluginsListTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.applyCollectorTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.applyExtractorTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.applyProductInfoTransformer
Expand Down Expand Up @@ -68,12 +68,32 @@ abstract class IntelliJPlatformBasePlugin : IntelliJPlatformAbstractProjectPlugi
}
}

create(
val intellijPlatformPluginsConfiguration = create(
name = Configurations.INTELLIJ_PLATFORM_PLUGINS,
description = "IntelliJ Platform plugins",
)
val intellijPlatformPluginsConfigurationExtracted = create(
name = Configurations.INTELLIJ_PLATFORM_PLUGINS_EXTRACTED,
description = "IntelliJ Platform plugins extracted",
) {
attributes {
attribute(Attributes.extracted, true)
}

extendsFrom(intellijPlatformPluginsConfiguration)
}

val intellijPlatformBundledPluginsConfiguration = create(
name = Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS,
description = "IntelliJ Platform bundled plugins",
)

create(
name = Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS_LIST,
description = "IntelliJ Platform bundled plugins list",
) {
attributes {
attribute(Attributes.bundledPlugins, true)
attribute(Attributes.bundledPluginsList, true)
}

extendsFrom(intellijPlatformConfiguration)
Expand Down Expand Up @@ -128,7 +148,12 @@ abstract class IntelliJPlatformBasePlugin : IntelliJPlatformAbstractProjectPlugi
val intellijPlatformDependenciesConfiguration = create(
name = Configurations.INTELLIJ_PLATFORM_DEPENDENCIES,
description = "IntelliJ Platform extra dependencies",
)
) {
extendsFrom(
intellijPlatformPluginsConfigurationExtracted,
intellijPlatformBundledPluginsConfiguration,
)
}

fun Configuration.extend() = extendsFrom(
intellijPlatformConfiguration,
Expand All @@ -144,7 +169,7 @@ abstract class IntelliJPlatformBasePlugin : IntelliJPlatformAbstractProjectPlugi

with(dependencies) {
attributesSchema {
attribute(Attributes.bundledPlugins)
attribute(Attributes.bundledPluginsList)
attribute(Attributes.collected)
attribute(Attributes.extracted)
attribute(Attributes.productInfo)
Expand All @@ -161,7 +186,7 @@ abstract class IntelliJPlatformBasePlugin : IntelliJPlatformAbstractProjectPlugi
configurations.getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME),
)
applyProductInfoTransformer()
applyBundledPluginsTransformer()
applyBundledPluginsListTransformer()
}

configureExtension<IntelliJPlatformExtension>(Extensions.INTELLIJ_PLATFORM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.jvm.Jvm
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the
import org.gradle.work.DisableCachingByDefault
import org.jdom2.Element
import org.jetbrains.intellij.platform.gradle.*
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Configurations
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.PLUGIN_GROUP_NAME
import org.jetbrains.intellij.platform.gradle.IntelliJPluginConstants.Tasks
import org.jetbrains.intellij.platform.gradle.dependency.PluginDependency
Expand Down Expand Up @@ -70,9 +70,9 @@ abstract class PrepareSandboxTask : Sync(), SandboxAware {
*
* Default value: [IntelliJPluginExtension.getPluginDependenciesList]
*/
@get:Input
@get:Optional
abstract val pluginDependencies: ListProperty<PluginDependency>
@get:InputFiles
@get:Classpath
abstract val pluginsClasspath: ConfigurableFileCollection

/**
* Default sandbox destination directory.
Expand All @@ -82,7 +82,7 @@ abstract class PrepareSandboxTask : Sync(), SandboxAware {

@get:InputFiles
@get:Classpath
abstract val runtimeClasspathFiles: Property<FileCollection>
abstract val runtimeClasspath: ConfigurableFileCollection

private val usedNames = mutableMapOf<String, Path>()

Expand Down Expand Up @@ -189,6 +189,7 @@ abstract class PrepareSandboxTask : Sync(), SandboxAware {

// val downloadPluginTaskProvider = project.tasks.named<DownloadRobotServerPluginTask>(IntelliJPluginConstants.DOWNLOAD_ROBOT_SERVER_PLUGIN_TASK_NAME)
val runtimeConfiguration = project.configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)
val intellijPlatformPluginsConfiguration = project.configurations.getByName(Configurations.INTELLIJ_PLATFORM_PLUGINS_EXTRACTED)
val jarTaskProvider = project.tasks.named<Jar>(JavaPlugin.JAR_TASK_NAME)
val extension = project.the<IntelliJPlatformExtension>()

Expand All @@ -215,26 +216,27 @@ abstract class PrepareSandboxTask : Sync(), SandboxAware {
pluginJar.convention(pluginJarProvider)
defaultDestinationDir.convention(sandboxPluginsDirectory)
// librariesToIgnore.convention(ideaDependencyJarFiles)
// pluginDependencies.convention(project.provider {
// extension.getPluginDependenciesList(project)
// })
runtimeClasspathFiles.convention(runtimeConfiguration)
pluginsClasspath.from(intellijPlatformPluginsConfiguration)
runtimeClasspath.from(runtimeConfiguration)

intoChild(pluginName.map { "$it/lib" })
.from(runtimeClasspathFiles.map { files ->
val librariesToIgnore = librariesToIgnore.get().toSet() + Jvm.current().toolsJar
val pluginDirectories = pluginDependencies.get().map { it.artifact }

listOf(pluginJar.asFile.get()) + files.filter { file ->
!(librariesToIgnore.contains(file) || pluginDirectories.any { p ->
file.toPath() == p || file.canonicalPath.startsWith("$p${File.separator}")
})
}
})
// .from(runtimeClasspath.filter { file ->
// val librariesToIgnore = librariesToIgnore.get().toSet() + Jvm.current().toolsJar
// val pluginDirectories = pluginDependencies.files
//
// !(librariesToIgnore.contains(file) || pluginDirectories.any { p ->
// file.toPath() == p || file.canonicalPath.startsWith("$p${File.separator}")
// })
// })
.from(runtimeClasspath)
.from(pluginJar)
.eachFile {
name = ensureName(file.toPath())
}

from(pluginsClasspath)

dependsOn(intellijPlatformPluginsConfiguration)
dependsOn(runtimeConfiguration)
dependsOn(jarTaskProvider)
// dependsOn(instrumentedJarTaskProvider)
Expand Down
Loading

0 comments on commit 3394d1f

Please sign in to comment.