-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
121 lines (101 loc) · 3.81 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
121 lines (101 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import com.google.protobuf.gradle.proto
import java.io.BufferedReader
import java.io.FileInputStream
import java.io.InputStreamReader
plugins {
// Configures how dependencies are managed, aka versions used etc
`dependency-conventions`
// Configures the common java settings (version, jars, manifest, locking etc)
`java-common-conventions`
// Configures the integration tests that can be run
`integration-test-conventions`
// For generating the java classes from the proto files
id("com.google.protobuf")
}
dependencies {
implementation("org.slf4j:slf4j-api")
implementation("com.google.protobuf:protobuf-java")
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-joda")
implementation("io.netty:netty-all")
implementation("org.erlang.otp:jinterface")
implementation("commons-codec:commons-codec")
// because of uses of javax.xml.bind.DatatypeConverter
implementation("javax.xml.bind:jaxb-api")
//Test dependencies
testImplementation("org.mockito:mockito-core")
testImplementation("org.powermock:powermock-api-mockito2")
testImplementation("org.powermock:powermock-module-junit4")
testImplementation("org.powermock:powermock-reflect")
testImplementation("org.hamcrest:hamcrest-core")
testImplementation("com.jayway.awaitility:awaitility")
}
/**
* ---------------------------------------------
* Base Config
* ---------------------------------------------
*/
group = "com.basho.riak"
base {
// Sets the name of the jar
archivesName.set("riak-client")
}
/**
* ---------------------------------------------
* Protobuf Generation
* ---------------------------------------------
*/
// Make then use the internal configuration for dependencies
configurations.getByName("compileProtoPath").extendsFrom(configurations.getByName("internal"))
configurations.getByName("testCompileProtoPath").extendsFrom(configurations.getByName("internal"))
sourceSets {
main {
proto {
// Configure it to point at the shared .proto files for the git submodule
srcDir("${rootProject.projectDir}/riak_pb/src/")
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.+"
}
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
// Generate the RiakMessageCodes.java file from the riak_pb_messages.csv file
tasks.register("generateMessageCodes") {
doLast {
val inputFile = File("${rootProject.projectDir}/riak_pb/src/riak_pb_messages.csv")
val outputFile = File("${rootProject.projectDir}/src/main/java/com/basho/riak/protobuf/RiakMessageCodes.java")
val inputStream = FileInputStream(inputFile)
val bufferedReader = BufferedReader(InputStreamReader(inputStream))
val outputContent = StringBuilder()
outputContent.append(
"""package com.basho.riak.protobuf;
/**
* WARNING: AUTO-GENERATED CODE. DO NOT EDIT THIS FILE.
*/
public final class RiakMessageCodes {
"""
)
val prefix = "\tpublic static final byte MSG_"
val cast = "(byte)"
bufferedReader.lines()
.filter { !it.isNullOrEmpty() }
.forEach { line ->
val csv = line.split(",")
val constName = csv[1].replaceFirst("^Rpb".toRegex(), "")
outputContent.append(prefix).append(constName).append(" = ");
val code = Integer.valueOf(csv[0])
if (code > 127) {
outputContent.append(cast)
}
outputContent.append(csv[0]).append(";\n")
}
outputContent.append("\n}")
outputFile.writeText(outputContent.toString())
logger.lifecycle("New file has been created: $outputFile")
}
}