-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/gh-action-release
- Loading branch information
Showing
35 changed files
with
619 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
app/src/main/kotlin/org/virtuslab/bazelsteward/app/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
kt_jvm_library( | ||
name = "app", | ||
library( | ||
srcs = glob(["**/*.kt"]), | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//common", | ||
"//config", | ||
"//core", | ||
"//github", | ||
"//maven", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_cli_jvm", | ||
], | ||
) | ||
|
||
lint(srcs = glob(["**/*.kt"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
app/src/test/kotlin/org/virtuslab/bazelsteward/app/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
kt_junit5_test( | ||
name = "app", | ||
size = "small", | ||
unit_tests( | ||
srcs = glob(["**/*.kt"]), | ||
test_package = "org.virtuslab.bazelsteward.app", | ||
deps = [ | ||
"//app/src/main/kotlin/org/virtuslab/bazelsteward/app", | ||
], | ||
) | ||
|
||
lint(srcs = glob(["**/*.kt"])) |
6 changes: 1 addition & 5 deletions
6
common/src/main/kotlin/org/virtuslab/bazelsteward/common/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
kt_jvm_library( | ||
name = "common", | ||
library( | ||
srcs = glob(["**/*.kt"]), | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//core", | ||
], | ||
) | ||
|
||
lint(srcs = glob(["**/*.kt"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
alias( | ||
name = "config", | ||
actual = "//config/src/main", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
library( | ||
srcs = glob(["kotlin/**/*.kt"]), | ||
resources = glob( | ||
["resources/**"], | ||
), | ||
deps = [ | ||
"//maven", | ||
"@maven//:com_fasterxml_jackson_dataformat_jackson_dataformat_yaml", | ||
"@maven//:com_fasterxml_jackson_module_jackson_module_kotlin", | ||
"@maven//:com_networknt_json_schema_validator", | ||
"@maven//:io_arrow_kt_arrow_core", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_jdk8", | ||
"@maven//:org_slf4j_slf4j_nop", | ||
], | ||
) |
63 changes: 63 additions & 0 deletions
63
config/src/main/kotlin/org/virtuslab/bazelsteward/config/BazelStewardConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.virtuslab.bazelsteward.config | ||
|
||
import com.fasterxml.jackson.annotation.JsonSetter | ||
import com.fasterxml.jackson.annotation.Nulls | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.networknt.schema.JsonSchemaFactory | ||
import com.networknt.schema.SpecVersion | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.virtuslab.bazelsteward.maven.MavenLibraryId | ||
import java.nio.file.Path | ||
import kotlin.io.path.exists | ||
|
||
data class Configuration( | ||
@JsonSetter(nulls = Nulls.AS_EMPTY) | ||
val maven: MavenConfig = MavenConfig() | ||
) | ||
|
||
data class MavenConfig( | ||
@JsonSetter(nulls = Nulls.AS_EMPTY) | ||
val ruledDependencies: List<MavenDependency> = emptyList() | ||
) | ||
|
||
data class MavenDependency( | ||
val id: MavenLibraryId, | ||
val versioning: String | ||
) | ||
|
||
class BazelStewardConfiguration(repoRoot: Path) { | ||
|
||
private val configFilePath = repoRoot.resolve(".bazel-steward.yaml") | ||
|
||
suspend fun get(): Configuration { | ||
|
||
return withContext(Dispatchers.IO) { | ||
val schemaContent = javaClass.classLoader.getResource("bazel-steward-schema.json")?.readText() | ||
?: throw Exception("Could not find schema to validate configuration file") | ||
val schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909).getSchema(schemaContent) | ||
|
||
runCatching { | ||
if (!configFilePath.exists()) return@withContext Configuration() | ||
val configContent = configFilePath.toFile() | ||
.readLines() | ||
.filterNot { it.startsWith("#") } | ||
.joinToString("\n") | ||
.ifEmpty { return@withContext Configuration() } | ||
val yamlReader = ObjectMapper(YAMLFactory()) | ||
yamlReader.registerModule(KotlinModule()) | ||
val validationResult = schema.validate(yamlReader.readTree(configContent)) | ||
if (validationResult.isNotEmpty()) { | ||
throw Exception(validationResult.joinToString(System.lineSeparator()) { it.message.removePrefix("$.") }) | ||
} else { | ||
yamlReader.readValue(configContent, Configuration::class.java) | ||
} | ||
}.getOrElse { | ||
println("Could not parse $configFilePath file!") | ||
throw it | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"maven": { | ||
"properties": { | ||
"ruledDependencies": { | ||
"type": ["array", "null"], | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "object", | ||
"properties": { | ||
"group": { | ||
"type": "string" | ||
}, | ||
"artifact": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["group", "artifact"] | ||
}, | ||
"versioning": { | ||
"type": "string", | ||
"anyOf": [{"enum": ["loose", "semver"]}, {"pattern": "^regex:"}] | ||
} | ||
}, | ||
"required": ["id", "versioning"] | ||
} | ||
} | ||
}, | ||
"required": ["ruledDependencies"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
unit_tests( | ||
srcs = glob(["kotlin/**/*.kt"]), | ||
resources = glob( | ||
["resources/**"], | ||
), | ||
test_package = "org.virtuslab.bazelsteward.config", | ||
deps = [ | ||
"//config/src/main", | ||
"@maven//:commons_io_commons_io", | ||
], | ||
) |
56 changes: 56 additions & 0 deletions
56
config/src/test/kotlin/org/virtuslab/bazelsteward/config/BazelStewardConfigurationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.virtuslab.bazelsteward.config | ||
|
||
import io.kotest.common.runBlocking | ||
import org.apache.commons.io.FileUtils | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
import org.virtuslab.bazelsteward.maven.MavenLibraryId | ||
import java.io.File | ||
|
||
class BazelStewardConfigurationTest { | ||
|
||
@Test | ||
fun `should throw an exception when maven object in config file is not correct`(@TempDir tempDir: File) { | ||
copyConfigFileToTempLocation(tempDir, ".bazel-steward-fail.yaml") | ||
Assertions.assertThatThrownBy { runBlocking { BazelStewardConfiguration(tempDir.toPath()).get() } } | ||
.hasMessage( | ||
listOf( | ||
"maven.ruledDependencies[0].id.group: is missing but it is required", | ||
"maven.ruledDependencies[0].id.artifact: is missing but it is required", | ||
"maven.ruledDependencies[1].versioning: does not have a value in the enumeration [loose, semver]", | ||
"maven.ruledDependencies[1].versioning: does not match the regex pattern ^regex:", | ||
"maven.ruledDependencies[2].id.group: integer found, string expected" | ||
).joinToString(System.lineSeparator()) | ||
) | ||
} | ||
|
||
@Test | ||
fun `should create default configuration when config file is not declared`(@TempDir tempDir: File) { | ||
val configuration = runBlocking { BazelStewardConfiguration(tempDir.toPath()).get() } | ||
Assertions.assertThat(configuration).isEqualTo(Configuration()) | ||
} | ||
|
||
@Test | ||
fun `should create configuration when config file is correct`(@TempDir tempDir: File) { | ||
copyConfigFileToTempLocation(tempDir, ".bazel-steward-correct.yaml") | ||
val configuration = runBlocking { BazelStewardConfiguration(tempDir.toPath()).get() } | ||
val expectedConfiguration = Configuration( | ||
MavenConfig( | ||
listOf( | ||
MavenDependency(MavenLibraryId("commons-io", "commons-io"), "loose"), | ||
MavenDependency(MavenLibraryId("io.get-coursier", "interface"), "semver"), | ||
MavenDependency(MavenLibraryId("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8"), "regex:(?<major>\\d+)") | ||
) | ||
) | ||
) | ||
Assertions.assertThat(configuration).isEqualTo(expectedConfiguration) | ||
} | ||
|
||
private fun copyConfigFileToTempLocation(tempDir: File, configFileName: String) { | ||
FileUtils.copyURLToFile( | ||
javaClass.classLoader.getResource(configFileName), | ||
File(tempDir, ".bazel-steward.yaml") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
maven: | ||
ruledDependencies: | ||
- | ||
id: | ||
group: "commons-io" | ||
artifact: "commons-io" | ||
versioning: "loose" | ||
- | ||
id: | ||
group: "io.get-coursier" | ||
artifact: "interface" | ||
versioning: "semver" | ||
- | ||
id: | ||
group: "org.jetbrains.kotlinx" | ||
artifact: "kotlinx-coroutines-jdk8" | ||
versioning: "regex:(?<major>\\d+)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
maven: | ||
ruledDependencies: | ||
- | ||
id: | ||
grouop: "commons-io" | ||
artifactt: "commons-io" | ||
versioning: "loose" | ||
- | ||
id: | ||
group: "io.get-coursier" | ||
artifact: "interface" | ||
versioning: "semverr" | ||
- | ||
id: | ||
group: 2 | ||
artifact: "kotlinx-coroutines-jdk8" | ||
versioning: "regex:(?<major>\\d+)(?<minor>\\.\\d+)?(?<patch>\\.\\d+)?$" |
6 changes: 1 addition & 5 deletions
6
core/src/main/kotlin/org/virtuslab/bazelsteward/core/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
kt_jvm_library( | ||
name = "core", | ||
library( | ||
srcs = glob(["**/*.kt"]), | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@maven//:io_arrow_kt_arrow_core", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_jdk8", | ||
], | ||
) | ||
|
||
lint(srcs = glob(["**/*.kt"])) |
Oops, something went wrong.