Skip to content

Commit eda991b

Browse files
committed
gRPC
1 parent 77b83e4 commit eda991b

Some content is hidden

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

65 files changed

+6799
-252
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ jobs:
147147
npm install
148148
npm run build
149149
150+
- name: Start ArkAnalyzer server
151+
run: |
152+
nohup npm --prefix $ARKANALYZER_DIR run server:start > grpc-server.log 2>&1 &
153+
PID=$!
154+
echo $PID > grpc-server.pid
155+
echo "Started gRPC server with PID $PID"
156+
157+
- name: Wait for gRPC server to start
158+
run: |
159+
echo "Waiting for gRPC server to be ready..."
160+
for i in {1..10}; do
161+
nc -z localhost 50051 && echo "Server is up!" && exit 0
162+
sleep 1
163+
done
164+
echo "Server failed to start" >&2
165+
cat grpc-server.log
166+
exit 1
167+
150168
- name: Run ETS tests
151169
run: ./gradlew --scan :jacodb-ets:generateTestResources :jacodb-ets:test
152170

@@ -169,6 +187,22 @@ jobs:
169187
name: gradle-reports-ets
170188
path: '**/build/reports/'
171189

190+
- name: Upload gRPC server logs
191+
if: (!cancelled())
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: grpc-server-log
195+
path: grpc-server.log
196+
197+
- name: Kill gRPC server
198+
if: always()
199+
run: |
200+
if [ -f grpc-server.pid ]; then
201+
PID=$(cat grpc-server.pid)
202+
echo "Killing gRPC server with PID $PID"
203+
kill $PID || echo "Process already terminated"
204+
fi
205+
172206
publish-test-results:
173207
name: "Publish test results"
174208
needs: [ ci-core, ci-lifecycle, ci-ets ]

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,
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import java.io.Reader
2+
import java.time.Duration
3+
import java.util.concurrent.TimeUnit
4+
import kotlin.concurrent.thread
5+
6+
object ProcessUtil {
7+
data class Result(
8+
val exitCode: Int,
9+
val stdout: String,
10+
val stderr: String,
11+
val isTimeout: Boolean, // true if the process was terminated due to timeout
12+
)
13+
14+
fun run(
15+
command: List<String>,
16+
input: String? = null,
17+
timeout: Duration? = null,
18+
builder: ProcessBuilder.() -> Unit = {},
19+
): Result {
20+
val reader = input?.reader() ?: "".reader()
21+
return run(command, reader, timeout, builder)
22+
}
23+
24+
fun run(
25+
command: List<String>,
26+
input: Reader,
27+
timeout: Duration? = null,
28+
builder: ProcessBuilder.() -> Unit = {},
29+
): Result {
30+
val process = ProcessBuilder(command).apply(builder).start()
31+
return communicate(process, input, timeout)
32+
}
33+
34+
private fun communicate(
35+
process: Process,
36+
input: Reader,
37+
timeout: Duration?,
38+
): Result {
39+
// Handle process input (stdin)
40+
val stdinThread = thread {
41+
process.outputStream.bufferedWriter().use { writer ->
42+
input.copyTo(writer)
43+
writer.flush()
44+
}
45+
}
46+
47+
// Capture process output (stdout)
48+
val stdout = StringBuilder()
49+
val stdoutThread = thread {
50+
process.inputStream.bufferedReader().useLines { lines ->
51+
lines.forEach { stdout.appendLine(it) }
52+
}
53+
}
54+
55+
// Capture process error output (stderr)
56+
val stderr = StringBuilder()
57+
val stderrThread = thread {
58+
process.errorStream.bufferedReader().useLines { lines ->
59+
lines.forEach { stderr.appendLine(it) }
60+
}
61+
}
62+
63+
// Start all threads
64+
stdinThread.start()
65+
stdoutThread.start()
66+
stderrThread.start()
67+
68+
// Wait for completion
69+
val isTimeout = if (timeout != null) {
70+
!process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS)
71+
} else {
72+
process.waitFor()
73+
false
74+
}
75+
76+
// If timeout occurred, destroy the process forcibly
77+
if (isTimeout) {
78+
process.destroyForcibly()
79+
}
80+
81+
// Wait for stream threads to finish
82+
stdinThread.join()
83+
stdoutThread.join()
84+
stderrThread.join()
85+
86+
return Result(
87+
exitCode = if (isTimeout) -1 else process.exitValue(),
88+
stdout = stdout.toString(),
89+
stderr = stderr.toString(),
90+
isTimeout = isTimeout
91+
)
92+
}
93+
}

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

0 commit comments

Comments
 (0)