Skip to content

Commit ce3488f

Browse files
committed
gRPC
1 parent 4ca8d08 commit ce3488f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5890
-247
lines changed

.github/workflows/build-and-test.yml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ jobs:
3030
strategy:
3131
fail-fast: false
3232
matrix:
33-
jdk: [8, 11, 19]
34-
env:
35-
main_jdk: 8
33+
jdk: [ 8, 11, 19 ]
3634

3735
steps:
3836
- uses: actions/checkout@v4
@@ -63,8 +61,9 @@ jobs:
6361
REPO_URL="https://gitcode.com/Lipen/arkanalyzer"
6462
DEST_DIR="arkanalyzer"
6563
MAX_RETRIES=10
66-
RETRY_DELAY=3 # Delay between retries in seconds
67-
BRANCH="neo/2025-05-30b"
64+
RETRY_DELAY=3 # Delay between retries in seconds
65+
#BRANCH="neo/2025-05-30b"
66+
BRANCH="lipen/grpc"
6867
6968
for ((i=1; i<=MAX_RETRIES; i++)); do
7069
git clone --depth=1 --branch $BRANCH $REPO_URL $DEST_DIR && break
@@ -85,6 +84,24 @@ jobs:
8584
npm install
8685
npm run build
8786
87+
- name: Start ArkAnalyzer server
88+
run: |
89+
nohup npm --prefix $ARKANALYZER_DIR run server:start > grpc-server.log 2>&1 &
90+
PID=$!
91+
echo $PID > grpc-server.pid
92+
echo "Started gRPC server with PID $PID"
93+
94+
- name: Wait for gRPC server to start
95+
run: |
96+
echo "Waiting for gRPC server to be ready..."
97+
for i in {1..10}; do
98+
nc -z localhost 50051 && echo "Server is up!" && exit 0
99+
sleep 1
100+
done
101+
echo "Server failed to start" >&2
102+
cat grpc-server.log
103+
exit 1
104+
88105
- name: Generate test resources
89106
run: ./gradlew :jacodb-ets:generateTestResources --scan
90107

@@ -113,13 +130,29 @@ jobs:
113130
# path: build/test-results/
114131

115132
- name: Upload Gradle reports
116-
if: (!cancelled()) && matrix.jdk == env.main_jdk
133+
if: (!cancelled())
117134
uses: actions/upload-artifact@v4
118135
with:
119-
name: gradle-reports
136+
name: gradle-reports-jdk${{ matrix.jdk }}
120137
path: '**/build/reports/'
121138
retention-days: 1
122139

140+
- name: Upload gRPC server logs
141+
if: (!cancelled())
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: grpc-server-log-jdk${{ matrix.jdk }}
145+
path: grpc-server.log
146+
147+
- name: Kill gRPC server
148+
if: always()
149+
run: |
150+
if [ -f grpc-server.pid ]; then
151+
PID=$(cat grpc-server.pid)
152+
echo "Killing gRPC server with PID $PID"
153+
kill $PID || echo "Process already terminated"
154+
fi
155+
123156
lifecycleTests:
124157
name: Run lifecycle tests
125158
runs-on: ubuntu-latest

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ allprojects {
147147
license {
148148
include("**/*.kt")
149149
include("**/*.java")
150+
exclude { it.file.startsWith(layout.buildDirectory.asFile.get()) }
150151
header(rootProject.file("docs/copyright/COPYRIGHT_HEADER.txt"))
151152
}
152153
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 121 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ object Versions {
66
const val asm = "9.7.1"
77
const val dokka = "1.9.20" // note: must be compatible with kotlin version
88
const val gradle_download = "5.3.0"
9+
const val gradle_node = "7.1.0"
10+
const val gradle_protobuf = "0.9.5"
911
const val gradle_versions = "0.47.0"
10-
11-
// hikaricp version compatible with Java 8
12-
const val hikaricp = "4.0.3"
13-
12+
const val grpc = "1.72.0"
13+
const val grpc_kotlin = "1.4.3"
1414
const val guava = "31.1-jre"
15+
const val hikaricp = "4.0.3" // compatible with Java 8
1516
const val javax_activation = "1.1"
1617
const val javax_mail = "1.4.7"
1718
const val javax_servlet_api = "2.5"
@@ -24,23 +25,25 @@ object Versions {
2425
const val junit = "5.9.2"
2526
const val kotlin = "2.1.0"
2627
const val kotlin_logging = "1.8.3"
28+
const val kotlin_metadata = kotlin
2729
const val kotlinx_benchmark = "0.4.6"
2830
const val kotlinx_cli = "0.3.5"
2931
const val kotlinx_collections_immutable = "0.3.5"
3032
const val kotlinx_coroutines = "1.6.4"
31-
const val kotlin_metadata = kotlin
3233
const val kotlinx_serialization = "1.8.0"
34+
const val ktor = "3.1.3"
3335
const val licenser = "0.6.1"
36+
const val lmdb_java = "0.9.0"
3437
const val mockk = "1.13.3"
38+
const val protobuf = "4.30.2"
39+
const val rocks_db = "9.1.1"
3540
const val sarif4k = "0.5.0"
3641
const val shadow = "8.1.1"
37-
const val slf4j = "1.7.36"
42+
const val slf4j = "2.0.17"
3843
const val soot_utbot_fork = "4.4.0-FORK-2"
3944
const val sootup = "1.0.0"
4045
const val sqlite = "3.41.2.2"
4146
const val xodus = "2.0.1"
42-
const val rocks_db = "9.1.1"
43-
const val lmdb_java = "0.9.0"
4447

4548
// libs for tests only
4649
const val jgit_test_only_version = "5.9.0.202009080501-r"
@@ -144,11 +147,6 @@ object Libs {
144147
)
145148

146149
// https://github.com/Kotlin/kotlinx.serialization
147-
val kotlinx_serialization_core = dep(
148-
group = "org.jetbrains.kotlinx",
149-
name = "kotlinx-serialization-core",
150-
version = Versions.kotlinx_serialization
151-
)
152150
val kotlinx_serialization_json = dep(
153151
group = "org.jetbrains.kotlinx",
154152
name = "kotlinx-serialization-json",
@@ -159,6 +157,11 @@ object Libs {
159157
name = "kotlinx-serialization-cbor",
160158
version = Versions.kotlinx_serialization
161159
)
160+
val kotlinx_serialization_protobuf = dep(
161+
group = "org.jetbrains.kotlinx",
162+
name = "kotlinx-serialization-protobuf",
163+
version = Versions.kotlinx_serialization
164+
)
162165

163166
// https://github.com/Kotlin/kotlinx-benchmark
164167
val kotlinx_benchmark_runtime = dep(
@@ -339,6 +342,99 @@ object Libs {
339342
name = "commons-compress",
340343
version = Versions.commons_compress_test_only_version
341344
)
345+
346+
// https://protobuf.dev/
347+
val protobuf_protoc = dep(
348+
group = "com.google.protobuf",
349+
name = "protoc",
350+
version = Versions.protobuf
351+
)
352+
val protobuf_java = dep(
353+
group = "com.google.protobuf",
354+
name = "protobuf-java",
355+
version = Versions.protobuf
356+
)
357+
val protobuf_kotlin = dep(
358+
group = "com.google.protobuf",
359+
name = "protobuf-kotlin",
360+
version = Versions.protobuf
361+
)
362+
363+
// https://github.com/grpc/grpc-java
364+
val grpc_api = dep(
365+
group = "io.grpc",
366+
name = "grpc-api",
367+
version = Versions.grpc
368+
)
369+
val grpc_protobuf = dep(
370+
group = "io.grpc",
371+
name = "grpc-protobuf",
372+
version = Versions.grpc
373+
)
374+
val grpc_protoc_gen = dep(
375+
group = "io.grpc",
376+
name = "protoc-gen-grpc-java",
377+
version = Versions.grpc
378+
)
379+
val grpc_netty_shaded = dep(
380+
group = "io.grpc",
381+
name = "grpc-netty-shaded",
382+
version = Versions.grpc
383+
)
384+
385+
// https://github.com/grpc/grpc-kotlin
386+
val grpc_kotlin_stub = dep(
387+
group = "io.grpc",
388+
name = "grpc-kotlin-stub",
389+
version = Versions.grpc_kotlin
390+
)
391+
val grpc_protoc_gen_kotlin = dep(
392+
group = "io.grpc",
393+
name = "protoc-gen-grpc-kotlin",
394+
version = Versions.grpc_kotlin
395+
)
396+
397+
// https://github.com/ktorio/ktor
398+
val ktor_client_core = dep(
399+
group = "io.ktor",
400+
name = "ktor-client-core",
401+
version = Versions.ktor
402+
)
403+
val ktor_client_cio = dep(
404+
group = "io.ktor",
405+
name = "ktor-client-cio",
406+
version = Versions.ktor
407+
)
408+
val ktor_client_content_negotiation = dep(
409+
group = "io.ktor",
410+
name = "ktor-client-content-negotiation",
411+
version = Versions.ktor
412+
)
413+
val ktor_server_core = dep(
414+
group = "io.ktor",
415+
name = "ktor-server-core",
416+
version = Versions.ktor
417+
)
418+
val ktor_server_netty = dep(
419+
group = "io.ktor",
420+
name = "ktor-server-netty",
421+
version = Versions.ktor
422+
)
423+
val ktor_server_content_negotiation = dep(
424+
group = "io.ktor",
425+
name = "ktor-server-content-negotiation",
426+
version = Versions.ktor
427+
)
428+
val ktor_serialization_kotlinx_json = dep(
429+
group = "io.ktor",
430+
name = "ktor-serialization-kotlinx-json",
431+
version = Versions.ktor
432+
)
433+
val ktor_serialization_kotlinx_protobuf = dep(
434+
group = "io.ktor",
435+
name = "ktor-serialization-kotlinx-protobuf",
436+
version = Versions.ktor
437+
)
342438
}
343439

344440
object Plugins {
@@ -357,6 +453,18 @@ object Plugins {
357453
id = "de.undercouch.download"
358454
)
359455

456+
// https://github.com/node-gradle/gradle-node-plugin
457+
object GradleNode : ProjectPlugin(
458+
version = Versions.gradle_node,
459+
id = "com.github.node-gradle.node"
460+
)
461+
462+
// https://github.com/google/protobuf-gradle-plugin
463+
object GradleProtobuf : ProjectPlugin(
464+
version = Versions.gradle_protobuf,
465+
id = "com.google.protobuf"
466+
)
467+
360468
// https://github.com/ben-manes/gradle-versions-plugin
361469
object GradleVersions : ProjectPlugin(
362470
version = Versions.gradle_versions,

jacodb-ets/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
arkanalyzer
12
/src/test/resources/samples/etsir
23
/src/test/resources/projects
34

jacodb-ets/build.gradle.kts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
import com.github.gradle.node.npm.task.NpmTask
12
import java.io.FileNotFoundException
23

34
plugins {
45
kotlin("plugin.serialization")
5-
`java-test-fixtures`
6+
id(Plugins.GradleNode)
67
}
78

89
dependencies {
910
api(project(":jacodb-api-common"))
11+
api(project(":jacodb-ets:grpc-client"))
12+
api(project(":jacodb-ets:grpc-server"))
1013

1114
implementation(Libs.kotlin_logging)
1215
implementation(Libs.slf4j_simple)
1316
implementation(Libs.kotlinx_serialization_json)
17+
implementation(Libs.kotlinx_serialization_protobuf)
1418
implementation(Libs.kotlinx_coroutines_core)
1519
implementation(Libs.jdot)
20+
implementation(Libs.ktor_client_core)
21+
implementation(Libs.ktor_client_cio)
22+
implementation(Libs.ktor_client_content_negotiation)
23+
implementation(Libs.ktor_serialization_kotlinx_json)
24+
implementation(Libs.ktor_serialization_kotlinx_protobuf)
1625

1726
testImplementation(kotlin("test"))
1827
testImplementation(Libs.mockk)
@@ -21,6 +30,16 @@ dependencies {
2130
testFixturesImplementation(Libs.junit_jupiter_api)
2231
}
2332

33+
node {
34+
download = true
35+
nodeProjectDir.set(file("arkanalyzer"))
36+
}
37+
38+
tasks.register<NpmTask>("startArkAnalyzerServer") {
39+
dependsOn(tasks.npmInstall)
40+
args = listOf("run", "server")
41+
}
42+
2443
// Example usage:
2544
// ```
2645
// export ARKANALYZER_DIR=~/dev/arkanalyzer
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
dependencies {
2+
api(project(":jacodb-ets:protos"))
3+
4+
implementation(Libs.kotlin_logging)
5+
implementation(Libs.slf4j_simple)
6+
7+
testImplementation(kotlin("test"))
8+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2022 UnitTestBot contributors (utbot.org)
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.jacodb.ets.grpc
18+
19+
import io.grpc.ManagedChannel
20+
import io.grpc.ManagedChannelBuilder
21+
22+
const val DEFAULT_PORT = 50051
23+
24+
fun grpcChannel(
25+
host: String = "localhost",
26+
port: Int = DEFAULT_PORT,
27+
setup: ManagedChannelBuilder<*>.() -> Unit = {},
28+
): ManagedChannel {
29+
return ManagedChannelBuilder.forAddress(host, port)
30+
.usePlaintext()
31+
.apply(setup)
32+
.build()
33+
}

0 commit comments

Comments
 (0)