Skip to content

Commit

Permalink
Added bundledModule() dependency extension helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hsz committed Sep 16, 2024
1 parent 05388f9 commit 60d72b4
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions api/IntelliJPlatformGradlePlugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) = 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<String>) = 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<List<String>>) = delegate.addIntelliJPlatformBundledModuleDependencies(
bundledModulesProvider = ids,
)

/**
* Adds a dependency on a local IntelliJ Platform plugin.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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<List<String>>,
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.
*
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,6 +137,10 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
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,
Expand Down Expand Up @@ -213,6 +218,7 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
extendsFrom(
intellijPlatformPluginConfiguration,
intellijPlatformBundledPluginsConfiguration,
intellijPlatformBundledModulesConfiguration,
)
}

Expand Down

0 comments on commit 60d72b4

Please sign in to comment.