Dev #5

Merged
altavir merged 24 commits from dev into master 2020-12-28 09:44:15 +03:00
10 changed files with 227 additions and 162 deletions
Showing only changes of commit 3416598434 - Show all commits

View File

@ -19,13 +19,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `ru.mipt.npm.base` -> `ru.mipt.npm.project`. - `ru.mipt.npm.base` -> `ru.mipt.npm.project`.
- Move publishing out of general extension and apply it to project plugin instead. - Move publishing out of general extension and apply it to project plugin instead.
- Platform plugins are now simple references to common plugin - Platform plugins are now simple references to common plugin
- FX configuration moved to extension
- Moved internals to internals
### Deprecated ### Deprecated
- Support of `kaml` and `snake-yaml` in favor of `yamlKt` - Support of `kaml` and `snake-yaml` in favor of `yamlKt`
- Publish plugin
### Removed ### Removed
### Fixed ### Fixed
### Security ### Security

View File

@ -6,7 +6,7 @@ plugins {
} }
group = "ru.mipt.npm" group = "ru.mipt.npm"
version = "0.7.0-fix" version = "0.7.0"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
@ -40,11 +40,13 @@ gradlePlugin {
description = "The generalized kscience plugin that works in conjunction with any kotlin plugin" description = "The generalized kscience plugin that works in conjunction with any kotlin plugin"
implementationClass = "ru.mipt.npm.gradle.KScienceCommonPlugin" implementationClass = "ru.mipt.npm.gradle.KScienceCommonPlugin"
} }
create("kscience.project"){ create("kscience.project"){
id = "ru.mipt.npm.project" id = "ru.mipt.npm.project"
description = "The root plugin for multimodule project infrastructure" description = "The root plugin for multimodule project infrastructure"
implementationClass = "ru.mipt.npm.gradle.KScienceProjectPlugin" implementationClass = "ru.mipt.npm.gradle.KScienceProjectPlugin"
} }
create("kscience.publish") { create("kscience.publish") {
id = "ru.mipt.npm.publish" id = "ru.mipt.npm.publish"
description = "The publication plugin for bintray and github" description = "The publication plugin for bintray and github"

View File

@ -10,6 +10,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import ru.mipt.npm.gradle.internal.applyRepos
import ru.mipt.npm.gradle.internal.applySettings
import ru.mipt.npm.gradle.internal.fromDependencies
open class KScienceCommonPlugin : Plugin<Project> { open class KScienceCommonPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {

View File

@ -7,9 +7,40 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import ru.mipt.npm.gradle.internal.configurePublishing
import ru.mipt.npm.gradle.internal.defaultPlatform
import ru.mipt.npm.gradle.internal.useCommonDependency
import ru.mipt.npm.gradle.internal.useFx
class KScienceExtension(val project: Project) { class KScienceExtension(val project: Project) {
enum class FXModule(val artifact: String, vararg val dependencies: FXModule) {
BASE("javafx-base"),
GRAPHICS("javafx-graphics", BASE),
CONTROLS("javafx-controls", GRAPHICS, BASE),
FXML("javafx-fxml", BASE),
MEDIA("javafx-media", GRAPHICS, BASE),
SWING("javafx-swing", GRAPHICS, BASE),
WEB("javafx-web", CONTROLS, GRAPHICS, BASE)
}
enum class FXPlatform(val id: String) {
WINDOWS("win"),
LINUX("linux"),
MAC("mac")
}
enum class DependencyConfiguration {
API,
IMPLEMENTATION,
COMPILE_ONLY
}
enum class DependencySourceSet(val setName: String, val suffix: String) {
MAIN("main", "Main"),
TEST("test", "Test")
}
fun useCoroutines( fun useCoroutines(
version: String = KScienceVersions.coroutinesVersion, version: String = KScienceVersions.coroutinesVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
@ -64,6 +95,13 @@ class KScienceExtension(val project: Project) {
plugins.apply("org.jetbrains.dokka") plugins.apply("org.jetbrains.dokka")
} }
fun useFx(
vararg modules: FXModule,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "14",
platform: FXPlatform = defaultPlatform
) = project.useFx(modules.toList(), configuration, version, platform)
/** /**
* Mark this module as an application module. JVM application should be enabled separately * Mark this module as an application module. JVM application should be enabled separately
*/ */
@ -91,6 +129,10 @@ class KScienceExtension(val project: Project) {
} }
} }
} }
fun publish() {
project.configurePublishing()
}
} }
internal fun Project.registerKScienceExtension() { internal fun Project.registerKScienceExtension() {

View File

@ -2,135 +2,12 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension import ru.mipt.npm.gradle.internal.configurePublishing
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
open class KSciencePublishPlugin : Plugin<Project> { open class KSciencePublishPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.plugins.withId("ru.mipt.npm.kscience") {
plugins.apply("maven-publish") project.configurePublishing()
// plugins.withId("org.jetbrains.kotlin.jvm"){
// extensions.findByType<JavaPluginExtension>()?.apply {
// withSourcesJar()
// //withJavadocJar()
// }
// }
afterEvaluate {
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
return@afterEvaluate
}
project.configure<PublishingExtension> {
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
}
}
} }
} }

View File

@ -3,6 +3,10 @@ package ru.mipt.npm.gradle
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories import org.gradle.kotlin.dsl.repositories
import ru.mipt.npm.gradle.KScienceExtension.DependencyConfiguration
import ru.mipt.npm.gradle.KScienceExtension.DependencySourceSet
import ru.mipt.npm.gradle.internal.useCommonDependency
import ru.mipt.npm.gradle.internal.useDependency
class SerializationTargets( class SerializationTargets(
val sourceSet: DependencySourceSet, val sourceSet: DependencySourceSet,

View File

@ -1,4 +1,4 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle.internal
import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.dsl.RepositoryHandler

View File

@ -1,4 +1,4 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle.internal
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.configure
@ -6,17 +6,8 @@ import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import ru.mipt.npm.gradle.KScienceExtension.DependencyConfiguration
enum class DependencyConfiguration { import ru.mipt.npm.gradle.KScienceExtension.DependencySourceSet
API,
IMPLEMENTATION,
COMPILE_ONLY
}
enum class DependencySourceSet(val setName: String, val suffix: String) {
MAIN("main", "Main"),
TEST("test", "Test")
}
internal fun Project.useDependency( internal fun Project.useDependency(
vararg pairs: Pair<String, String>, vararg pairs: Pair<String, String>,

View File

@ -1,4 +1,4 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle.internal
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project import org.gradle.api.Project
@ -6,22 +6,7 @@ import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import ru.mipt.npm.gradle.KScienceExtension.*
enum class FXModule(val artifact: String, vararg val dependencies: FXModule) {
BASE("javafx-base"),
GRAPHICS("javafx-graphics", BASE),
CONTROLS("javafx-controls", GRAPHICS, BASE),
FXML("javafx-fxml", BASE),
MEDIA("javafx-media", GRAPHICS, BASE),
SWING("javafx-swing", GRAPHICS, BASE),
WEB("javafx-web", CONTROLS, GRAPHICS, BASE)
}
enum class FXPlatform(val id: String) {
WINDOWS("win"),
LINUX("linux"),
MAC("mac")
}
val defaultPlatform: FXPlatform = when { val defaultPlatform: FXPlatform = when {
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
@ -31,7 +16,7 @@ val defaultPlatform: FXPlatform = when {
} }
private fun KotlinDependencyHandler.addFXDependencies( private fun KotlinDependencyHandler.addFXDependencies(
vararg modules: FXModule, modules: List<FXModule>,
configuration: DependencyConfiguration, configuration: DependencyConfiguration,
version: String = "14", version: String = "14",
platform: FXPlatform = defaultPlatform platform: FXPlatform = defaultPlatform
@ -46,8 +31,8 @@ private fun KotlinDependencyHandler.addFXDependencies(
} }
} }
fun Project.useFx( internal fun Project.useFx(
vararg modules: FXModule, modules: List<FXModule>,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "14", version: String = "14",
platform: FXPlatform = defaultPlatform platform: FXPlatform = defaultPlatform
@ -56,7 +41,7 @@ fun Project.useFx(
extensions.findByType<KotlinMultiplatformExtension>()?.apply { extensions.findByType<KotlinMultiplatformExtension>()?.apply {
sourceSets.findByName("jvmMain")?.apply { sourceSets.findByName("jvmMain")?.apply {
dependencies { dependencies {
addFXDependencies(*modules, configuration = configuration, version = version, platform = platform) addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
} }
} }
} }
@ -66,7 +51,7 @@ fun Project.useFx(
extensions.findByType<KotlinJvmProjectExtension>()?.apply { extensions.findByType<KotlinJvmProjectExtension>()?.apply {
sourceSets.findByName("main")?.apply { sourceSets.findByName("main")?.apply {
dependencies { dependencies {
addFXDependencies(*modules, configuration = configuration, version = version, platform = platform) addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
} }
} }
} }

View File

@ -0,0 +1,157 @@
package ru.mipt.npm.gradle.internal
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
internal fun Project.configurePublishing() {
if (plugins.findPlugin("maven-publish") == null) {
plugins.apply("maven-publish")
}
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
return
}
project.configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin = extensions.findByType<KotlinJsProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class){
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("kotlinJs", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class){
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("kotlinJvm", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
}
}