Skip to content

Commit

Permalink
Publish instrumented and composed artifact with variants instead of r…
Browse files Browse the repository at this point in the history
…eplacing the default artifact
  • Loading branch information
hsz committed Jun 7, 2024
1 parent 08f387a commit f59dad2
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Changed

- Resolve Plugin Verifier IDEs using regular IntelliJ Platform dependency resolution
- Publish instrumented and composed artifact with variants instead of replacing the default artifact

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object Constants {
}

object Configurations {
const val INTELLIJ_PLATFORM_COMPOSED_JAR = "intellijPlatformComposedJar"
const val INTELLIJ_PLATFORM_DEPENDENCY = "intellijPlatformDependency"
const val INTELLIJ_PLATFORM_LOCAL = "intellijPlatformLocal"
const val INTELLIJ_PLATFORM = "intellijPlatform"
Expand All @@ -82,6 +83,8 @@ object Constants {
const val TEST_FIXTURES_COMPILE_CLASSPATH = "testFixturesCompileClasspath"

object Attributes {
const val COMPOSED_JAR_NAME = "composed-jar"

val bundledPluginsList = Attribute.of("intellijPlatformBundledPluginsList", Boolean::class.javaObjectType)
val localPluginsNormalized = Attribute.of("intellijPlatformLocalPluginsNormalized", Boolean::class.javaObjectType)
val collected = Attribute.of("intellijPlatformCollected", Boolean::class.javaObjectType)
Expand Down Expand Up @@ -119,6 +122,7 @@ object Constants {
const val IMPLEMENTATION = JvmConstants.IMPLEMENTATION_CONFIGURATION_NAME
const val RUNTIME_CLASSPATH = JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME
const val RUNTIME_ELEMENTS = JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME
const val RUNTIME_ONLY = JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME
const val TEST_COMPILE_CLASSPATH = JvmConstants.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME
const val TEST_COMPILE_ONLY = JvmConstants.TEST_COMPILE_ONLY_CONFIGURATION_NAME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum class IntelliJPlatformType(
) {
AndroidStudio(
code = "AI",
maven = Coordinates("com.google.android.studio", "android-studio"),
maven = null,
binary = Coordinates("com.google.android.studio", "android-studio"),
),
Aqua(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.

package org.jetbrains.intellij.platform.gradle.attributes

import org.gradle.api.attributes.AttributeCompatibilityRule
import org.gradle.api.attributes.CompatibilityCheckDetails
import org.gradle.api.attributes.LibraryElements
import org.jetbrains.intellij.platform.gradle.Constants.Configurations.Attributes

abstract class ComposedJarRule : AttributeCompatibilityRule<LibraryElements> {

override fun execute(details: CompatibilityCheckDetails<LibraryElements>) = details.run {
if (consumerValue?.name == Attributes.COMPOSED_JAR_NAME && producerValue?.name == "jar") {
compatible()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

package org.jetbrains.intellij.platform.gradle.plugins.project

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.*
import org.gradle.api.attributes.*
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.TaskContainer
import org.gradle.kotlin.dsl.add
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
Expand All @@ -23,6 +23,7 @@ import org.jetbrains.intellij.platform.gradle.artifacts.transform.BundledPlugins
import org.jetbrains.intellij.platform.gradle.artifacts.transform.CollectorTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.ExtractorTransformer
import org.jetbrains.intellij.platform.gradle.artifacts.transform.LocalPluginsNormalizationTransformers
import org.jetbrains.intellij.platform.gradle.attributes.ComposedJarRule
import org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformDependenciesExtension
import org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformExtension
import org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformExtension.*
Expand Down Expand Up @@ -62,6 +63,32 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
}

with(project.configurations) configurations@{
create(Configurations.INTELLIJ_PLATFORM_COMPOSED_JAR) {
isCanBeConsumed = true
isCanBeResolved = false

attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EXTERNAL))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(Attributes.COMPOSED_JAR_NAME))
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, JavaVersion.current().majorVersion.toInt())
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(Attribute.of("org.gradle.jvm.environment", String::class.java), "standard-jvm")
attributes.attribute(Attribute.of("org.jetbrains.kotlin.platform.type", String::class.java), "jvm")
}

extendsFrom(
this@configurations[Configurations.External.IMPLEMENTATION],
this@configurations[Configurations.External.RUNTIME_ONLY],
)
}

named(Configurations.External.RUNTIME_CLASSPATH) {
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements::class.java, Attributes.COMPOSED_JAR_NAME))
}
}

val intellijPlatformDependencyConfiguration = create(
name = Configurations.INTELLIJ_PLATFORM_DEPENDENCY,
description = "IntelliJ Platform dependency archive",
Expand Down Expand Up @@ -122,6 +149,10 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
description = "IntelliJ Platform plugin module",
) {
isTransitive = false

attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements::class.java, Attributes.COMPOSED_JAR_NAME))
}
}
create(
name = Configurations.INTELLIJ_PLATFORM_PLUGIN_DEPENDENCY_COLLECTOR,
Expand Down Expand Up @@ -272,6 +303,9 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
attribute(Attributes.bundledPluginsList)
attribute(Attributes.collected)
attribute(Attributes.extracted)
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE) {
compatibilityRules.add(ComposedJarRule::class)
}
}

ExtractorTransformer.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import org.jetbrains.intellij.platform.gradle.Constants.Configurations
import org.jetbrains.intellij.platform.gradle.Constants.Tasks
import org.jetbrains.intellij.platform.gradle.tasks.compaion.JarCompanion
import org.jetbrains.intellij.platform.gradle.utils.extensionProvider
import org.jetbrains.kotlin.gradle.utils.named

@CacheableTask
abstract class ComposedJarTask : Jar() {
Expand All @@ -21,9 +21,6 @@ abstract class ComposedJarTask : Jar() {
project.registerTask<ComposedJarTask>(Tasks.COMPOSED_JAR) {
val jarTaskProvider = project.tasks.named<Jar>(Tasks.External.JAR)
val instrumentedJarTaskProvider = project.tasks.named<Jar>(Tasks.INSTRUMENTED_JAR)
val apiElementsConfiguration = project.configurations[Configurations.External.API_ELEMENTS]
val archivesConfiguration = project.configurations[Configurations.External.ARCHIVES]
val runtimeElementsConfiguration = project.configurations[Configurations.External.RUNTIME_ELEMENTS]
val intellijPlatformPluginModuleConfiguration = project.configurations[Configurations.INTELLIJ_PLATFORM_PLUGIN_MODULE]

val sourceTaskProvider = project.extensionProvider.flatMap {
Expand All @@ -48,15 +45,7 @@ abstract class ComposedJarTask : Jar() {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
JarCompanion.applyPluginManifest(this)

// Remove the default artifact exported by the current module and replace it with the final one provided by the task.
listOf(
apiElementsConfiguration,
archivesConfiguration,
runtimeElementsConfiguration,
).forEach { configuration ->
configuration.artifacts.removeIf { it.classifier == JarCompanion.CLASSIFIER }
project.artifacts.add(configuration.name, archiveFile)
}
project.artifacts.add(Configurations.INTELLIJ_PLATFORM_COMPOSED_JAR, this)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import org.jetbrains.intellij.platform.gradle.utils.extensionProvider
class JarCompanion {

companion object : Registrable {
const val CLASSIFIER = "base"

override fun register(project: Project) =
project.registerTask<Jar>(Tasks.External.JAR, configureWithType = false) {
archiveBaseName.convention(project.extensionProvider.flatMap { it.projectName })
archiveClassifier.convention(CLASSIFIER)
archiveClassifier.convention("base")
applyPluginManifest(this)

exclude("**/classpath.index")
Expand Down

0 comments on commit f59dad2

Please sign in to comment.