Skip to content

Commit 5d6862f

Browse files
author
Ganeshwara Hananda
authored
Implement Maven's artifacts.snapshot update script (#146)
We have implemented a script to update Maven's `artifacts.snapshot` file. Usage example: ``` $ bazel run @graknlabs_dependencies//library/maven:update ------------------------- Regenerating a new '/Users/lolski/grakn.ai/graknlabs/grakn/dependencies/maven/snapshot' from WORKSPACE... DONE! '/Users/lolski/grakn.ai/graknlabs/grakn/dependencies/maven/snapshot' updated: 4 dependencies added, 1 dependencies removed. Added dependencies: - @maven//:com_boundary_high_scale_lib - @maven//:com_boundary_high_scale_lib_1_0_6 - @maven//:com_github_jbellis_jamm - @maven//:org_ow2_asm_asm_5_0_4 Removed dependencies: - @maven//:io_dropwizard_metrics_metrics_jvm_3_1_2 ------------------------- ```
1 parent 2bb18e7 commit 5d6862f

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ load("//builder/java:deps.bzl", java_deps = "deps")
4949
java_deps()
5050
load("//library/maven:rules.bzl", "maven")
5151

52+
# Load Kotlin
53+
load("//builder/kotlin:deps.bzl", kotlin_deps = "deps")
54+
kotlin_deps()
55+
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
56+
kotlin_repositories()
57+
kt_register_toolchains()
58+
5259
# Load NodeJS
5360
load("//builder/nodejs:deps.bzl", nodejs_deps = "deps")
5461
nodejs_deps()

builder/kotlin/BUILD

Whitespace-only changes.

builder/kotlin/deps.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
def deps():
4+
http_archive(
5+
name = "io_bazel_rules_kotlin",
6+
urls = ["https://github.com/bazelbuild/rules_kotlin/archive/legacy-1.3.0.zip"],
7+
type = "zip",
8+
strip_prefix = "rules_kotlin-legacy-1.3.0",
9+
sha256 = "4fd769fb0db5d3c6240df8a9500515775101964eebdf85a3f9f0511130885fde",
10+
)

library/maven/BUILD

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright (C) 2020 Grakn Labs
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU Affero General Public License as
6+
# published by the Free Software Foundation, either version 3 of the
7+
# License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Affero General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
#
17+
18+
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_binary")
19+
20+
kt_jvm_binary(
21+
name = "update",
22+
main_class = "library.maven.UpdateKt",
23+
srcs = ["update.kt"],
24+
)

library/maven/update.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package library.maven
2+
3+
import java.nio.file.Files
4+
import java.nio.file.Paths
5+
6+
fun main() {
7+
val baseDir = Paths.get(System.getenv("BUILD_WORKSPACE_DIRECTORY"))
8+
val snapshotCommand = listOf("bazel", "query", "@maven//...")
9+
val snapshotFile = baseDir.resolve("dependencies").resolve("maven").resolve("snapshot")
10+
11+
println("-------------------------")
12+
println("Regenerating a new '$snapshotFile' from WORKSPACE...")
13+
val snapshotOld = if (snapshotFile.toFile().exists()) Files.readAllLines(snapshotFile).toSortedSet() else sortedSetOf()
14+
val snapshotUpdateProc = ProcessBuilder().directory(baseDir.toFile()).command(snapshotCommand).start()
15+
val snapshotNew = snapshotUpdateProc.inputStream
16+
.use { inStr -> inStr.reader().readLines() }
17+
.toSortedSet()
18+
Files.write(snapshotFile, snapshotNew.joinToString(System.lineSeparator()).toByteArray())
19+
if (snapshotUpdateProc.exitValue() != 0) {
20+
throw RuntimeException("'$snapshotCommand' failed with exit code '${snapshotUpdateProc.exitValue()}'")
21+
}
22+
23+
val added = snapshotNew.minus(snapshotOld)
24+
val removed = snapshotOld.minus(snapshotNew)
25+
println("DONE! '$snapshotFile' updated: ${added.count()} dependencies added, ${removed.count()} dependencies removed.")
26+
print("Added dependencies:")
27+
if (added.isNotEmpty()) {
28+
println()
29+
added.forEach { dep -> println(" - $dep") }
30+
}
31+
else {
32+
println(" none.")
33+
}
34+
print("Removed dependencies:")
35+
if (removed.isNotEmpty()) {
36+
println()
37+
removed.forEach { dep -> println(" - $dep") }
38+
}
39+
else {
40+
println(" none.")
41+
}
42+
println("-------------------------")
43+
}

0 commit comments

Comments
 (0)