From 60d72b44f52bccc22f8b54c0687ac15c27659fef Mon Sep 17 00:00:00 2001 From: Jakub Chrzanowski Date: Mon, 16 Sep 2024 21:34:02 +0200 Subject: [PATCH] Added `bundledModule()` dependency extension helpers --- CHANGELOG.md | 1 + api/IntelliJPlatformGradlePlugin.api | 6 ++ .../intellij/platform/gradle/Constants.kt | 1 + .../IntelliJPlatformDependenciesExtension.kt | 45 +++++++++++++++ .../IntelliJPlatformDependenciesHelper.kt | 57 ++++++++++++++++++- .../project/IntelliJPlatformBasePlugin.kt | 8 ++- 6 files changed, 115 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd6350527..fc404985b3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added `PrepareSandboxTask.pluginName` for easier accessing of the plugin directory name - Allow for using non-installer IDEs for plugin verification [#1715](../../issues/1715) +- Added `bundledModule()` dependency extension helpers ### Fixed diff --git a/api/IntelliJPlatformGradlePlugin.api b/api/IntelliJPlatformGradlePlugin.api index 9d9dbb2a72..a28079c9bd 100644 --- a/api/IntelliJPlatformGradlePlugin.api +++ b/api/IntelliJPlatformGradlePlugin.api @@ -15,6 +15,7 @@ public final class org/jetbrains/intellij/platform/gradle/Constants$Components { public final class org/jetbrains/intellij/platform/gradle/Constants$Configurations { public static final field INSTANCE Lorg/jetbrains/intellij/platform/gradle/Constants$Configurations; + public static final field INTELLIJ_PLATFORM_BUNDLED_MODULES Ljava/lang/String; public static final field INTELLIJ_PLATFORM_BUNDLED_PLUGINS Ljava/lang/String; public static final field INTELLIJ_PLATFORM_COMPOSED_JAR Ljava/lang/String; public static final field INTELLIJ_PLATFORM_DEPENDENCIES Ljava/lang/String; @@ -473,6 +474,11 @@ public abstract class org/jetbrains/intellij/platform/gradle/extensions/IntelliJ public static synthetic fun aqua$default (Lorg/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesExtension;Lorg/gradle/api/provider/Provider;ZILjava/lang/Object;)V public final fun bundledLibrary (Ljava/lang/String;)V public final fun bundledLibrary (Lorg/gradle/api/provider/Provider;)V + public final fun bundledModule (Ljava/lang/String;)V + public final fun bundledModule (Lorg/gradle/api/provider/Provider;)V + public final fun bundledModules (Ljava/util/List;)V + public final fun bundledModules (Lorg/gradle/api/provider/Provider;)V + public final fun bundledModules ([Ljava/lang/String;)V public final fun bundledPlugin (Ljava/lang/String;)V public final fun bundledPlugin (Lorg/gradle/api/provider/Provider;)V public final fun bundledPlugins (Ljava/util/List;)V diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt index 31be2c91ea..8fb62b5609 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/Constants.kt @@ -69,6 +69,7 @@ object Constants { const val INTELLIJ_PLATFORM_PLUGIN_MODULE = "intellijPlatformPluginModule" const val INTELLIJ_PLATFORM_PLUGIN = "intellijPlatformPlugin" const val INTELLIJ_PLATFORM_BUNDLED_PLUGINS = "intellijPlatformBundledPlugins" + const val INTELLIJ_PLATFORM_BUNDLED_MODULES = "intellijPlatformBundledModules" const val INTELLIJ_PLATFORM_DEPENDENCIES = "intellijPlatformDependencies" const val INTELLIJ_PLATFORM_JAVA_COMPILER = "intellijPlatformJavaCompiler" const val INTELLIJ_PLATFORM_TEST_DEPENDENCIES = "intellijPlatformTestDependencies" diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesExtension.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesExtension.kt index c690a94850..093b109912 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesExtension.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesExtension.kt @@ -992,6 +992,51 @@ abstract class IntelliJPlatformDependenciesExtension @Inject constructor( bundledPluginsProvider = ids, ) + /** + * Adds a dependency on a bundled IntelliJ Platform module. + * + * @param id The bundled module identifier. + */ + fun bundledModule(id: String) = delegate.addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider = delegate.provider { listOf(id) }, + ) + + /** + * Adds a dependency on a bundled IntelliJ Platform module. + * + * @param id The provider of the bundled module identifier. + */ + fun bundledModule(id: Provider) = delegate.addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider = id.map { listOf(it) }, + ) + + /** + * Adds a dependency on a bundled IntelliJ Platform modules. + * + * @param ids The bundled module identifiers. + */ + fun bundledModules(vararg ids: String) = delegate.addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider = delegate.provider { ids.asList() }, + ) + + /** + * Adds a dependency on a bundled IntelliJ Platform modules. + * + * @param ids The bundled module identifiers. + */ + fun bundledModules(ids: List) = delegate.addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider = delegate.provider { ids }, + ) + + /** + * Adds a dependency on a bundled IntelliJ Platform modules. + * + * @param ids The bundled module identifiers. + */ + fun bundledModules(ids: Provider>) = delegate.addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider = ids, + ) + /** * Adds a dependency on a local IntelliJ Platform plugin. * diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt index 51a18a5242..67df5ee2ea 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/extensions/IntelliJPlatformDependenciesHelper.kt @@ -272,9 +272,9 @@ class IntelliJPlatformDependenciesHelper( }) /** - * A base method for adding a dependency on a plugin for IntelliJ Platform. + * A base method for adding a dependency on an IntelliJ Platform bundled plugin. * - * @param bundledPluginsProvider The provider of the list containing triples with plugin identifier, version, and channel. + * @param bundledPluginsProvider The provider of the list containing bundled plugin identifiers. * @param configurationName The name of the configuration to add the dependency to. * @param action The action to be performed on the dependency. Defaults to an empty action. */ @@ -293,6 +293,28 @@ class IntelliJPlatformDependenciesHelper( .onEach(action) }) + /** + * A base method for adding a dependency on an IntelliJ Platform bundled module. + * + * @param bundledModulesProvider The provider of the list containing bundled module identifiers. + * @param configurationName The name of the configuration to add the dependency to. + * @param action The action to be performed on the dependency. Defaults to an empty action. + */ + internal fun addIntelliJPlatformBundledModuleDependencies( + bundledModulesProvider: Provider>, + configurationName: String = Configurations.INTELLIJ_PLATFORM_BUNDLED_MODULES, + action: DependencyAction = {}, + ) = configurations[configurationName].dependencies.addAllLater(provider { + val bundledModules = bundledModulesProvider.orNull + requireNotNull(bundledModules) { "The `intellijPlatform.bundledModules` dependency helper was called with no `bundledModules` value provided." } + + bundledModules + .map(String::trim) + .filter(String::isNotEmpty) + .map { dependencies.createIntelliJPlatformBundledModule(it) } + .onEach(action) + }) + /** * A base method for adding a dependency on a local plugin for IntelliJ Platform. * @@ -701,6 +723,37 @@ class IntelliJPlatformDependenciesHelper( ) } + /** + * Creates a dependency for an IntelliJ platform bundled module. + * + * @param id The ID of the bundled module. + */ + private fun DependencyHandler.createIntelliJPlatformBundledModule(id: String): Dependency { + val bundledModule = productInfo.get().layout + .find { layout -> layout.name == id } + .let { requireNotNull(it) { "Specified bundledModule '$id' doesn't exist." } } + val platformPath = platformPath.get() + val artifactPaths = bundledModule.classPath.map { path -> platformPath.resolve(path).toIvyArtifact() } + val version = baseVersion.orElse(productInfo.map { it.version }).map { "$it+${platformPath.hash}" }.get() + + writeIvyModule(Dependencies.BUNDLED_MODULE_GROUP, id, version) { + IvyModule( + info = IvyModule.Info( + organisation = Dependencies.BUNDLED_MODULE_GROUP, + module = id, + revision = version, + ), + publications = artifactPaths, + ) + } + + return create( + group = Dependencies.BUNDLED_MODULE_GROUP, + name = id, + version = version, + ) + } + /** * Collects all dependencies on plugins or modules of the current [IdePlugin]. * The [path] parameter is a list of already traversed entities, used to avoid circular dependencies when walking recursively. diff --git a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/plugins/project/IntelliJPlatformBasePlugin.kt b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/plugins/project/IntelliJPlatformBasePlugin.kt index eeffc1b095..eee920d47c 100644 --- a/src/main/kotlin/org/jetbrains/intellij/platform/gradle/plugins/project/IntelliJPlatformBasePlugin.kt +++ b/src/main/kotlin/org/jetbrains/intellij/platform/gradle/plugins/project/IntelliJPlatformBasePlugin.kt @@ -6,7 +6,8 @@ import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaPlugin -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.get import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.plugins.ide.idea.model.IdeaModel import org.jetbrains.intellij.platform.gradle.Constants.CACHE_DIRECTORY @@ -136,6 +137,10 @@ abstract class IntelliJPlatformBasePlugin : Plugin { name = Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS, description = "IntelliJ Platform bundled plugins", ) + val intellijPlatformBundledModulesConfiguration = create( + name = Configurations.INTELLIJ_PLATFORM_BUNDLED_MODULES, + description = "IntelliJ Platform bundled modules", + ) val jetbrainsRuntimeDependencyConfiguration = create( name = Configurations.JETBRAINS_RUNTIME_DEPENDENCY, @@ -213,6 +218,7 @@ abstract class IntelliJPlatformBasePlugin : Plugin { extendsFrom( intellijPlatformPluginConfiguration, intellijPlatformBundledPluginsConfiguration, + intellijPlatformBundledModulesConfiguration, ) }