Skip to content

Commit ff68310

Browse files
authored
Merge pull request #1 from netifi/add-protobuf-generator
migrate protobuf generator and fix interface mismatch within core met…
2 parents 71c330e + 20fb3e4 commit ff68310

13 files changed

+4054
-21
lines changed

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ project(':metrics-idl') {
4747

4848
apply from: file('../gradle/java.gradle')
4949
}
50+
51+
project(':protobuf-rpc') {
52+
description = 'RSocket RPC Protobuf Generator'
53+
ext.artifactName = 'protobuf-rpc'
54+
55+
}

core/build.gradle

+18-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ targetCompatibility = 1.8
77

88
dependencies {
99
compile project (':frames')
10+
compile project (':protobuf-rpc')
1011
compile 'io.opentracing:opentracing-api:0.31.0'
1112
compile 'javax.inject:javax.inject:1'
1213
compile 'com.google.protobuf:protobuf-java:3.6.0'
@@ -20,23 +21,31 @@ dependencies {
2021
testCompile 'io.zipkin.reporter2:zipkin-sender-okhttp3:2.7.6'
2122
}
2223

24+
25+
def protocPluginBaseName = "rsocket-rpc-java-${osdetector.os}-${osdetector.arch}"
26+
def javaPluginPath = "$rootDir/protobuf-rpc/build/exe/java_plugin/$protocPluginBaseName"
27+
2328
protobuf {
2429
generatedFilesBaseDir = "${projectDir}/src/generated"
2530

2631
protoc {
2732
artifact = 'com.google.protobuf:protoc:3.6.0'
2833
}
29-
34+
plugins {
35+
rsocketRpc {
36+
path = javaPluginPath
37+
}
38+
}
3039
generateProtoTasks {
3140
all().each { task ->
32-
task.enabled = true
33-
34-
task.builtins {
35-
// Generates C++ code in the output folder:
36-
//cpp { }
37-
38-
// Avoid generating Java files:
39-
java {}
41+
task.dependsOn ':protobuf-rpc:java_pluginExecutable'
42+
// Recompile protos when the codegen has been changed
43+
task.inputs.file javaPluginPath
44+
// Recompile protos when build.gradle has been changed, because
45+
// it's possible the version of protoc has been changed.
46+
task.inputs.file "${rootProject.projectDir}/build.gradle"
47+
task.plugins {
48+
rsocketRpc {}
4049
}
4150
}
4251
}

core/src/main/java/io/rsocket/rpc/metrics/MetricsExporter.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
import io.micrometer.core.instrument.distribution.HistogramSnapshot;
55
import io.micrometer.core.instrument.distribution.ValueAtPercentile;
66
import io.netty.buffer.Unpooled;
7-
import io.rsocket.rpc.metrics.om.*;
87
import io.rsocket.rpc.metrics.om.Meter;
8+
import io.rsocket.rpc.metrics.om.MeterId;
9+
import io.rsocket.rpc.metrics.om.MeterMeasurement;
10+
import io.rsocket.rpc.metrics.om.MeterStatistic;
11+
import io.rsocket.rpc.metrics.om.MeterTag;
12+
import io.rsocket.rpc.metrics.om.MeterType;
13+
import io.rsocket.rpc.metrics.om.MetricsSnapshot;
14+
import io.rsocket.rpc.metrics.om.MetricsSnapshotHandler;
15+
import io.rsocket.rpc.metrics.om.Skew;
916
import java.time.Duration;
1017
import java.util.ArrayList;
1118
import java.util.List;

core/src/main/java/io/rsocket/rpc/metrics/MetricsSnapshotHandler.java

-10
This file was deleted.

protobuf-rpc/build.gradle

+286
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
plugins {
2+
id 'com.google.protobuf'
3+
id 'cpp'
4+
id 'java'
5+
id 'idea'
6+
}
7+
8+
apply plugin: 'com.jfrog.bintray'
9+
apply plugin: 'maven'
10+
apply plugin: 'maven-publish'
11+
12+
task ciVersion {
13+
description = "Creates a continuous-delivery friendly version number for the service"
14+
15+
def releaseType = project.hasProperty('releaseType') ? project.property('releaseType') : System.getenv('RELEASE_TYPE')
16+
def commitHash = project.hasProperty('commitHash') ? project.property('commitHash') : System.getenv('COMMIT_HASH')
17+
18+
if (releaseType == 'release' || releaseType == 'r') {
19+
project.version = project.version
20+
} else if (releaseType == 'releaseCandidate' || releaseType == 'rc') {
21+
project.version = "${project.version}-RC".toString()
22+
} else if (releaseType == 'snapshot' || releaseType == 's') {
23+
if (commitHash) {
24+
project.version = "${project.version}-SNAPSHOT-${commitHash}".toString()
25+
} else {
26+
project.version = "${project.version}-SNAPSHOT".toString()
27+
}
28+
} else {
29+
logger.info("Property 'releaseType' was not specified. Defaulting to 'snapshot'")
30+
if (commitHash) {
31+
project.version = "${project.version}-SNAPSHOT-${commitHash}".toString()
32+
} else {
33+
project.version = "${project.version}-SNAPSHOT".toString()
34+
}
35+
}
36+
37+
println "Setting CI Version for '${project.name}': ${version}"
38+
}
39+
build.dependsOn ciVersion
40+
41+
def pluginPrefix = "rsocket-rpc-java-${osdetector.os}-${osdetector.arch}"
42+
def pluginName = "${pluginPrefix}.exe"
43+
def artifactStagingPath = "$buildDir/artifacts" as File
44+
def pathToPlugin = "${artifactStagingPath.getPath()}/${pluginName}"
45+
46+
repositories {
47+
jcenter()
48+
maven {
49+
url = 'https://dl.bintray.com/netifi/netifi-oss'
50+
}
51+
}
52+
53+
sourceCompatibility = 1.8
54+
targetCompatibility = 1.8
55+
56+
dependencies {
57+
compileOnly 'io.projectreactor:reactor-core:3.1.7.RELEASE'
58+
compileOnly 'com.google.protobuf:protobuf-java:3.6.0'
59+
compileOnly 'javax.inject:javax.inject:1'
60+
}
61+
62+
protobuf {
63+
generatedFilesBaseDir = "${projectDir}/src/generated"
64+
65+
protoc {
66+
artifact = 'com.google.protobuf:protoc:3.6.0'
67+
}
68+
plugins {
69+
rsocketRpc {
70+
path = pathToPlugin
71+
}
72+
}
73+
generateProtoTasks {
74+
all().each { task ->
75+
task.dependsOn ':protobuf-rpc:java_pluginExecutable'
76+
task.inputs.file "$pathToPlugin"
77+
task.inputs.file "${rootProject.projectDir}/build.gradle"
78+
task.plugins {
79+
rsocketRpc {}
80+
}
81+
}
82+
}
83+
}
84+
85+
// Adds space-delimited arguments from the environment variable env to the
86+
// argList.
87+
def addEnvArgs = { env, argList ->
88+
def value = System.getenv(env)
89+
if (value != null) {
90+
value.split(' +').each() { it -> argList.add(it) }
91+
}
92+
}
93+
94+
// Adds corresponding "-l" option to the argList if libName is not found in
95+
// LDFLAGS. This is only used for Mac because when building for uploadArchives
96+
// artifacts, we add the ".a" files directly to LDFLAGS and without "-l" in
97+
// order to get statically linked, otherwise we add the libraries through "-l"
98+
// so that they can be searched for in default search paths.
99+
def addLibraryIfNotLinked = { libName, argList ->
100+
def ldflags = System.env.LDFLAGS
101+
if (ldflags == null || !ldflags.contains('lib' + libName + '.a')) {
102+
argList.add('-l' + libName)
103+
}
104+
}
105+
106+
String arch = rootProject.hasProperty('targetArch') ? rootProject.targetArch : osdetector.arch
107+
boolean vcDisable = rootProject.hasProperty('vcDisable') ? rootProject.vcDisable : false
108+
109+
model {
110+
toolChains {
111+
// If you have both VC and Gcc installed, VC will be selected, unless you
112+
// set 'vcDisable=true'
113+
if (!vcDisable) {
114+
visualCpp(VisualCpp) {
115+
}
116+
}
117+
gcc(Gcc) {
118+
target("ppcle_64")
119+
}
120+
clang(Clang) {
121+
}
122+
}
123+
124+
platforms {
125+
x86_32 {
126+
architecture "x86"
127+
}
128+
x86_64 {
129+
architecture "x86_64"
130+
}
131+
ppcle_64 {
132+
architecture "ppcle_64"
133+
}
134+
}
135+
136+
components {
137+
java_plugin(NativeExecutableSpec) {
138+
if (arch in ['x86_32', 'x86_64', 'ppcle_64']) {
139+
// If arch is not within the defined platforms, we do not specify the
140+
// targetPlatform so that Gradle will choose what is appropriate.
141+
targetPlatform arch
142+
}
143+
baseName "$pluginPrefix"
144+
}
145+
}
146+
147+
binaries {
148+
all {
149+
if (toolChain in Gcc || toolChain in Clang) {
150+
cppCompiler.define("RSOCKET_RPC_VERSION", version)
151+
cppCompiler.args "--std=c++0x"
152+
addEnvArgs("CXXFLAGS", cppCompiler.args)
153+
addEnvArgs("CPPFLAGS", cppCompiler.args)
154+
if (osdetector.os == "osx") {
155+
cppCompiler.args "-mmacosx-version-min=10.7", "-stdlib=libc++"
156+
addLibraryIfNotLinked('protoc', linker.args)
157+
addLibraryIfNotLinked('protobuf', linker.args)
158+
} else if (osdetector.os == "windows") {
159+
linker.args "-static", "-lprotoc", "-lprotobuf", "-static-libgcc", "-static-libstdc++",
160+
"-s"
161+
} else {
162+
// Link protoc, protobuf, libgcc and libstdc++ statically.
163+
// Link other (system) libraries dynamically.
164+
// Clang under OSX doesn't support these options.
165+
linker.args "-Wl,-Bstatic", "-lprotoc", "-lprotobuf", "-static-libgcc",
166+
"-static-libstdc++",
167+
"-Wl,-Bdynamic", "-lpthread", "-s"
168+
}
169+
addEnvArgs("LDFLAGS", linker.args)
170+
} else if (toolChain in VisualCpp) {
171+
cppCompiler.define("RSOCKET_RPC_VERSION", version)
172+
cppCompiler.args "/EHsc", "/MT"
173+
if (rootProject.hasProperty('vcProtobufInclude')) {
174+
cppCompiler.args "/I${rootProject.vcProtobufInclude}"
175+
}
176+
linker.args "libprotobuf.lib", "libprotoc.lib"
177+
if (rootProject.hasProperty('vcProtobufLibs')) {
178+
linker.args "/LIBPATH:${rootProject.vcProtobufLibs}"
179+
}
180+
}
181+
}
182+
}
183+
}
184+
185+
task buildArtifacts(type: Copy) {
186+
println 'generating artifacts'
187+
dependsOn 'java_pluginExecutable'
188+
from("$buildDir/exe/java_plugin") {
189+
if (osdetector.os != 'windows') {
190+
rename pluginPrefix, '$0.exe'
191+
}
192+
}
193+
into artifactStagingPath
194+
}
195+
196+
compileJava.dependsOn ':protobuf-rpc:buildArtifacts'
197+
compileJava.dependsOn ':protobuf-rpc:generateProto'
198+
199+
clean {
200+
delete protobuf.generatedFilesBaseDir
201+
}
202+
203+
artifacts {
204+
archives("$pathToPlugin" as File) {
205+
classifier osdetector.os + "-" + osdetector.arch
206+
type "exe"
207+
extension "exe"
208+
builtBy buildArtifacts
209+
}
210+
}
211+
212+
//publishing {
213+
// publications {
214+
// maven(MavenPublication) {
215+
// artifactId "${project.ext.artifactName}"
216+
// artifact(pathToPlugin) {
217+
// classifier osdetector.os + "-" + osdetector.arch
218+
// builtBy buildArtifacts
219+
// }
220+
// }
221+
// }
222+
//}
223+
224+
225+
if ("$version".contains('SNAPSHOT') || "$version".contains('RC')) {
226+
publishing {
227+
publications {
228+
maven(MavenPublication) {
229+
artifactId "${project.ext.artifactName}"
230+
artifact(pathToPlugin) {
231+
classifier osdetector.os + "-" + osdetector.arch
232+
builtBy buildArtifacts
233+
}
234+
}
235+
}
236+
repositories {
237+
maven {
238+
url = version.contains('SNAPSHOT') ? 'https://artifactory.netifiinc.com/artifactory/libs-snapshot-local' : 'https://artifactory.netifiinc.com/artifactory/libs-release-local'
239+
credentials {
240+
username = project.hasProperty('netifiArtifactoryUsername') ? project.property('netifiArtifactoryUsername') : System.getenv('NETIFI_ARTIFACTORY_USERNAME')
241+
password = project.hasProperty('netifiArtifactoryPassword') ? project.property('netifiArtifactoryPassword') : System.getenv('NETIFI_ARTIFACTORY_PASSWORD')
242+
}
243+
}
244+
}
245+
}
246+
} else {
247+
publishing {
248+
publications {
249+
maven(MavenPublication) {
250+
artifactId "${project.ext.artifactName}"
251+
artifact(pathToPlugin) {
252+
classifier osdetector.os + "-" + osdetector.arch
253+
builtBy buildArtifacts
254+
}
255+
}
256+
}
257+
}
258+
259+
bintray {
260+
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
261+
key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : System.getenv('f')
262+
263+
publications = ['maven']
264+
265+
//dryRun = true
266+
publish = (osdetector.os == 'osx')
267+
override = true
268+
269+
pkg {
270+
repo = 'netifi-oss'
271+
name = "${artifactName}".toString()
272+
userOrg = 'netifi'
273+
desc = "${project.description}"
274+
websiteUrl = 'https://github.com/netifi/rsocket-rpc-java'
275+
issueTrackerUrl = 'https://github.com/netifi/rsocket-rpc-java/issues'
276+
vcsUrl = 'https://github.com/netifi/rsocket-rpc-java.git'
277+
licenses = ['Apache-2.0']
278+
githubRepo = 'netifi/rsocket-rpc-java'
279+
githubReleaseNotesFile = 'CHANGELOG.md'
280+
281+
version {
282+
name = "$project.version".toString()
283+
}
284+
}
285+
}
286+
}

0 commit comments

Comments
 (0)