2020-11-27 15:10:15 +03:00
|
|
|
package ru.mipt.npm.gradle.internal
|
2020-03-16 15:22:16 +03:00
|
|
|
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.kotlin.dsl.findByType
|
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|
|
|
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
2020-11-27 21:00:24 +03:00
|
|
|
import ru.mipt.npm.gradle.DependencyConfiguration
|
|
|
|
import ru.mipt.npm.gradle.FXModule
|
|
|
|
import ru.mipt.npm.gradle.FXPlatform
|
2020-03-16 15:22:16 +03:00
|
|
|
|
|
|
|
val defaultPlatform: FXPlatform = when {
|
|
|
|
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
|
|
|
|
Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC
|
|
|
|
Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX
|
|
|
|
else -> error("Platform not recognized")
|
|
|
|
}
|
|
|
|
|
2020-07-05 14:39:35 +03:00
|
|
|
private fun KotlinDependencyHandler.addFXDependencies(
|
2020-11-27 15:10:15 +03:00
|
|
|
modules: List<FXModule>,
|
2020-03-16 15:22:16 +03:00
|
|
|
configuration: DependencyConfiguration,
|
|
|
|
version: String = "14",
|
|
|
|
platform: FXPlatform = defaultPlatform
|
|
|
|
) {
|
|
|
|
modules.flatMap { it.dependencies.toList() + it }.distinct().forEach {
|
|
|
|
val notation = "org.openjfx:${it.artifact}:$version:${platform.id}"
|
|
|
|
when (configuration) {
|
|
|
|
DependencyConfiguration.API -> api(notation)
|
|
|
|
DependencyConfiguration.IMPLEMENTATION -> implementation(notation)
|
|
|
|
DependencyConfiguration.COMPILE_ONLY -> compileOnly(notation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 15:10:15 +03:00
|
|
|
internal fun Project.useFx(
|
|
|
|
modules: List<FXModule>,
|
2020-03-16 15:22:16 +03:00
|
|
|
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
|
|
|
|
version: String = "14",
|
|
|
|
platform: FXPlatform = defaultPlatform
|
2020-11-27 21:00:24 +03:00
|
|
|
): Unit = afterEvaluate {
|
2020-03-16 15:22:16 +03:00
|
|
|
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
|
|
|
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
|
|
|
|
sourceSets.findByName("jvmMain")?.apply {
|
|
|
|
dependencies {
|
2020-11-27 15:10:15 +03:00
|
|
|
addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
|
2020-03-16 15:22:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
|
|
|
extensions.findByType<KotlinJvmProjectExtension>()?.apply {
|
|
|
|
sourceSets.findByName("main")?.apply {
|
|
|
|
dependencies {
|
2020-11-27 15:10:15 +03:00
|
|
|
addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
|
2020-03-16 15:22:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|