Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kotlin protoc built-in when Java or Kotlin are enabled in a project #87

Merged
merged 50 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3a7246d
Update config
alexander-yevsyukov Oct 15, 2022
6a16306
Add `core` dependencies
alexander-yevsyukov Oct 15, 2022
be4f9df
Simplify dependencies
alexander-yevsyukov Oct 15, 2022
be44f8f
Bump version -> `0.2.19`
alexander-yevsyukov Oct 15, 2022
668b0a6
Bump version -> `0.2.19`
alexander-yevsyukov Oct 15, 2022
321761e
Remove redundant property
alexander-yevsyukov Oct 15, 2022
e2e0554
Add Kotlin proto codegen
alexander-yevsyukov Oct 15, 2022
7dc8a26
Simplify dependencies
alexander-yevsyukov Oct 15, 2022
a763c06
Update numbers
alexander-yevsyukov Oct 15, 2022
3697570
Add `kotlin` built-in
alexander-yevsyukov Oct 15, 2022
9308579
Extract variables
alexander-yevsyukov Oct 17, 2022
698ced8
Extract conventions
alexander-yevsyukov Oct 17, 2022
1c91481
Make `it` clear
alexander-yevsyukov Oct 17, 2022
5f5399c
Bump `base` -> `2.0.0-SNAPSHOT.114`
alexander-yevsyukov Oct 17, 2022
76840a0
Remove redundant configuration
alexander-yevsyukov Oct 17, 2022
12a7c8f
Document default values
alexander-yevsyukov Oct 17, 2022
8b0023b
Open access to source root properties
alexander-yevsyukov Oct 17, 2022
2769cce
Do not handle non-Java source roots
alexander-yevsyukov Oct 17, 2022
1fcb1d4
Force configurations
alexander-yevsyukov Oct 17, 2022
68b88e0
Update numbers
alexander-yevsyukov Oct 17, 2022
ba9ca28
Bump Jackson -> `2.13.4.2`
alexander-yevsyukov Oct 17, 2022
3c310ee
Do not process non-Java files
alexander-yevsyukov Oct 17, 2022
f785e89
Update version numbers
alexander-yevsyukov Oct 17, 2022
ce63e43
Add `kotlin` built-in conditionally
alexander-yevsyukov Oct 17, 2022
7f48651
Optimise imports
alexander-yevsyukov Oct 17, 2022
be148ed
Improve checking for Kotlin plugins
alexander-yevsyukov Oct 17, 2022
bff303b
Extract variables
alexander-yevsyukov Oct 18, 2022
1f79bdb
Document checking for Kotlin in a project
alexander-yevsyukov Oct 18, 2022
89d57d2
Improve dependency name
alexander-yevsyukov Oct 18, 2022
18a7b87
Improve dependency names
alexander-yevsyukov Oct 18, 2022
59640ef
Improve test project name
alexander-yevsyukov Oct 18, 2022
da5dcdb
Disable Android library test
alexander-yevsyukov Oct 18, 2022
76c457c
Update config
alexander-yevsyukov Oct 18, 2022
554c5d8
Force the task dependency
alexander-yevsyukov Oct 18, 2022
ca18c4d
Improve documentation language
alexander-yevsyukov Oct 18, 2022
d8ae325
Document commented out blocks
alexander-yevsyukov Oct 18, 2022
2c31bfc
Fix typo
alexander-yevsyukov Oct 18, 2022
c698979
Add test for java and kotlin dirs
alexander-yevsyukov Oct 18, 2022
7ac2097
Use Kotlin proto DSL
alexander-yevsyukov Oct 18, 2022
da9744f
Fix directory refs.
alexander-yevsyukov Oct 18, 2022
4715195
Use `NoOpRenderer`
alexander-yevsyukov Oct 18, 2022
523ae4b
Update build time
alexander-yevsyukov Oct 18, 2022
8465151
Add properties for checking the source set size
alexander-yevsyukov Oct 18, 2022
55fb593
Do not quit the printing iteration when file not found
alexander-yevsyukov Oct 18, 2022
c7862a5
Do not render sources for empty source file sets
alexander-yevsyukov Oct 18, 2022
b6e227a
Remove the empty set check
alexander-yevsyukov Oct 18, 2022
18aedeb
Improve test name
alexander-yevsyukov Oct 18, 2022
b7c6dcb
Refer to issue
alexander-yevsyukov Oct 19, 2022
ac97675
Fix wording in KDoc
alexander-yevsyukov Oct 19, 2022
9acc605
Add nested `.gitignore`
alexander-yevsyukov Oct 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/detekt-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
)" > ${{ github.workspace }}/detekt.sarif.json

# Uploads results to GitHub repository using the upload-sarif action
- uses: github/codeql-action/upload-sarif@v1
- uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: ${{ github.workspace }}/detekt.sarif.json
Expand Down
14 changes: 8 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.spine.internal.dependency.Dokka
import io.spine.internal.dependency.ErrorProne
import io.spine.internal.dependency.JUnit
import io.spine.internal.dependency.Spine
import io.spine.internal.dependency.Truth
import io.spine.internal.gradle.RunBuild
import io.spine.internal.gradle.applyGitHubPackages
Expand All @@ -54,10 +55,9 @@ buildscript {

apply(from = "$rootDir/version.gradle.kts")

val mcJavaVersion: String by extra

val spine = io.spine.internal.dependency.Spine(project)
dependencies {
classpath("io.spine.tools:spine-mc-java-plugins:${mcJavaVersion}:all")
classpath(spine.mcJavaPlugin)
classpath(io.spine.internal.dependency.Protobuf.GradlePlugin.lib)
}
}
Expand Down Expand Up @@ -90,6 +90,8 @@ spinePublishing {
artifactPrefix = "protodata-"
}

val spine = Spine(project)

val coreVersion: String by extra
val baseVersion: String by extra
allprojects {
Expand All @@ -110,8 +112,8 @@ allprojects {
resolutionStrategy {
force(
io.spine.internal.dependency.Grpc.protobufPlugin,
"io.spine:spine-base:$baseVersion",
"io.spine:spine-server:$coreVersion"
spine.base,
spine.server
)
}
}
Expand All @@ -132,7 +134,7 @@ subprojects {
ErrorProne.apply {
errorprone(core)
}
testImplementation("io.spine.tools:spine-testutil-server:$coreVersion")
testImplementation(spine.core.testUtilServer)
testImplementation(kotlin("test-junit5"))
Truth.libs.forEach { testImplementation(it) }
testRuntimeOnly(JUnit.runner)
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/deps-between-tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ fun Project.configureTaskDependencies() {
afterEvaluate {
"compileKotlin".dependOn("launchProtoDataMain")
"compileTestKotlin".dependOn("launchProtoDataTest")
"sourcesJar".dependOn("generateProto")
"sourcesJar".dependOn("launchProtoDataMain")
"sourcesJar".dependOn("createVersionFile")
"dokkaHtml".dependOn("generateProto")
"dokkaHtml".dependOn("launchProtoDataMain")
"dokkaJavadoc".dependOn("launchProtoDataMain")
"publishPluginJar".dependOn("createVersionFile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ package io.spine.internal.dependency
@Suppress("unused")
object Jackson {
const val version = "2.13.2"
// Use rc-1 to address https://github.com/SpineEventEngine/ProtoData/security/dependabot/6
const val databindVersion = "2.14.0-rc1"
const val databindVersion = "2.13.2.2"
// https://github.com/FasterXML/jackson-core
const val core = "com.fasterxml.jackson.core:jackson-core:${version}"
// https://github.com/FasterXML/jackson-databind
Expand Down
217 changes: 217 additions & 0 deletions buildSrc/src/main/kotlin/io/spine/internal/dependency/Spine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
* Copyright 2022, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.internal.dependency

import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.extra

/**
* Dependencies on Spine modules.
*
* @constructor
* Creates a new instance of `Spine` taking the property values
* of versions from the given project's extra properties.
*/
@Suppress("unused")
class Spine(p: ExtensionAware) {

/**
* Default versions for the modules of Spine, unless they are
* configured in `versions.gradle.kts`.
*/
object DefaultVersion {

/**
* The default version of `base` to use.
* @see [Spine.base]
*/
const val base = "2.0.0-SNAPSHOT.112"

/**
* The default version of `core-java` to use.
* @see [Spine.core.client]
* @see [Spine.core.server]
*/
const val core = "2.0.0-SNAPSHOT.114"

/**
* The version of `model-compiler` to use.
* @see [Spine.modelCompiler]
*/
const val mc = "2.0.0-SNAPSHOT.90"

/**
* The version of `mc-java` to use.
*/
const val mcJava = "2.0.0-SNAPSHOT.102"

/**
* The version of `base-types` to use.
* @see [Spine.baseTypes]
*/
const val baseTypes = "2.0.0-SNAPSHOT.108"

/**
* The version of `time` to use.
* @see [Spine.time]
*/
const val time = "2.0.0-SNAPSHOT.108"

/**
* The version of `tool-base` to use.
* @see [Spine.toolBase]
*/
const val toolBase = "2.0.0-SNAPSHOT.109"

/**
* The version of `validation` to use.
* @see [Spine.validation]
*/
const val validation = "2.0.0-SNAPSHOT.32"
}

companion object {
const val group = "io.spine"
const val toolsGroup = "io.spine.tools"

/**
* The version of ProtoData to be used in the project.
*
* We do it here instead of `versions.gradle.kts` because we later use
* it in a `plugins` section in a build script.
*
* @see [ProtoData]
*/
const val protoDataVersion = "0.2.18"
}

val base = "$group:spine-base:${p.baseVersion}"
val testlib = "$toolsGroup:spine-testlib:${p.baseVersion}"

@Deprecated("Please use `validation.runtime`", replaceWith = ReplaceWith("validation.runtime"))
val validate = "$group:spine-validate:${p.baseVersion}"

val baseTypes = "$group:spine-base-types:${p.baseTypesVersion}"

val time = "$toolsGroup:spine-testlib:${p.timeVersion}"

val toolBase = "$toolsGroup:spine-tool-base:${p.toolBaseVersion}"
val pluginBase = "$toolsGroup:spine-plugin-base:${p.toolBaseVersion}"
val pluginTestlib = "$toolsGroup:spine-plugin-testlib:${p.toolBaseVersion}"

val modelCompiler = "$toolsGroup:spine-model-compiler:${p.mcVersion}"

val mcJavaPlugin = "io.spine.tools:spine-mc-java-plugins:${p.mcJavaVersion}:all"

val validation = Validation(p)

val core = Core(p)
val client = core.client // Added for brevity.
val server = core.server // Added for brefity.

private val ExtensionAware.baseVersion: String
get() = "baseVersion".asExtra(this, DefaultVersion.base)

private val ExtensionAware.baseTypesVersion: String
get() = "baseTypesVersion".asExtra(this, DefaultVersion.baseTypes)

private val ExtensionAware.timeVersion: String
get() = "timeVersion".asExtra(this, DefaultVersion.time)

private val ExtensionAware.mcVersion: String
get() = "mcVersion".asExtra(this, DefaultVersion.mc)

private val ExtensionAware.mcJavaVersion: String
get() = "mcJavaVersion".asExtra(this, DefaultVersion.mcJava)

private val ExtensionAware.toolBaseVersion: String
get() = "toolBaseVersion".asExtra(this, DefaultVersion.toolBase)

/**
* Dependencies on Spine validation modules.
*
* See [`SpineEventEngine/validation`](https://github.com/SpineEventEngine/validation/).
*/
class Validation(p: ExtensionAware) {

companion object {
const val group = "io.spine.validation"
}

val runtime = "$group:spine-validation-java-runtime:${p.validationVersion}"
val java = "$group:spine-validation-java:${p.validationVersion}"
val model = "$group:spine-validation-model:${p.validationVersion}"
val config = "$group:spine-validation-configuration:${p.validationVersion}"

private val ExtensionAware.validationVersion: String
get() = "validationVersion".asExtra(this, DefaultVersion.validation)
}

/**
* Dependencies on ProtoData modules.
*
* See [`SpineEventEngine/ProtoData`](https://github.com/SpineEventEngine/ProtoData/).
*/
object ProtoData {

const val pluginId = "io.spine.protodata"

const val version = protoDataVersion
const val pluginLib = "$group:protodata:$version"
}

/**
* Dependencies on `core-java` modules.
*
* See [`SpineEventEngine/core-java`](https://github.com/SpineEventEngine/core-java/).
*/
class Core(p: ExtensionAware) {
val core = "$group:spine-core:${p.coreVersion}"
Fixed Show fixed Hide fixed
val client = "$group:spine-client:${p.coreVersion}"
val server = "$group:spine-server:${p.coreVersion}"
val testUtilServer = "$toolsGroup:spine-testutil-server:${p.coreVersion}"

private val ExtensionAware.coreVersion: String
get() = "coreVersion".asExtra(this, DefaultVersion.core)
}
}

/**
* Obtains the value of the extension property named as this string from the given project.
*
* @param p the project declaring extension properties
* @param defaultValue
* the default value to return, if the project does not have such a property.
* If `null` then rely on the property declaration, even if this would cause an error.
*/
private fun String.asExtra(p: ExtensionAware, defaultValue: String? = null): String {
return if (p.extra.has(this) || defaultValue == null) {
p.extra[this] as String
} else {
defaultValue
}
}
Loading