Skip to content

Commit 9a28d55

Browse files
committed
gRPC sample app
1 parent 76f4153 commit 9a28d55

File tree

13 files changed

+544
-0
lines changed

13 files changed

+544
-0
lines changed

samples/grpc-app/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
bin/
16+
!**/src/main/**/bin/
17+
!**/src/test/**/bin/
18+
19+
### IntelliJ IDEA ###
20+
.idea
21+
*.iws
22+
*.iml
23+
*.ipr
24+
out/
25+
!**/src/main/**/out/
26+
!**/src/test/**/out/
27+
28+
### NetBeans ###
29+
/nbproject/private/
30+
/nbbuild/
31+
/dist/
32+
/nbdist/
33+
/.nb-gradle/
34+
35+
### VS Code ###
36+
.vscode/

samples/grpc-app/build.gradle.kts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
plugins {
6+
kotlin("jvm") version "2.1.0"
7+
kotlin("plugin.serialization") version "2.1.0"
8+
id("org.jetbrains.kotlinx.rpc.plugin") version "0.5.0-eap-grpc-1"
9+
id("com.google.protobuf") version "0.9.4"
10+
}
11+
12+
group = "kotlinx.rpc.sample"
13+
version = "0.0.1"
14+
15+
repositories {
16+
mavenCentral()
17+
maven("https://maven.pkg.jetbrains.space/public/p/krpc/grpc")
18+
}
19+
20+
kotlin {
21+
jvmToolchain(11)
22+
}
23+
24+
dependencies {
25+
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-core:0.5.0-eap-grpc-1")
26+
implementation("ch.qos.logback:logback-classic:1.5.16")
27+
implementation("io.grpc:grpc-netty:1.69.0")
28+
}
29+
30+
val buildDirPath: String = project.layout.buildDirectory.get().asFile.absolutePath
31+
32+
protobuf {
33+
protoc {
34+
artifact = "com.google.protobuf:protoc:4.29.3"
35+
}
36+
37+
plugins {
38+
create("kotlinx-rpc") {
39+
artifact = "org.jetbrains.kotlinx:kotlinx-rpc-protobuf-plugin:0.5.0-eap-grpc-1:all@jar"
40+
}
41+
42+
create("grpc") {
43+
artifact = "io.grpc:protoc-gen-grpc-java:1.69.0"
44+
}
45+
46+
create("grpckt") {
47+
artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
48+
}
49+
}
50+
51+
generateProtoTasks {
52+
all().all {
53+
plugins {
54+
create("kotlinx-rpc") {
55+
option("debugOutput=$buildDirPath/protobuf-plugin.log")
56+
option("messageMode=interface")
57+
}
58+
create("grpc")
59+
create("grpckt")
60+
}
61+
}
62+
}
63+
}

samples/grpc-app/gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
kotlin.code.style=official
42.6 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
distributionBase=GRADLE_USER_HOME
6+
distributionPath=wrapper/dists
7+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
8+
networkTimeout=10000
9+
validateDistributionUrl=true
10+
zipStoreBase=GRADLE_USER_HOME
11+
zipStorePath=wrapper/dists

samples/grpc-app/gradlew

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
#!/bin/sh
2+
3+
#
4+
# Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
5+
#
6+
7+
##############################################################################
8+
#
9+
# Gradle start up script for POSIX generated by Gradle.
10+
#
11+
# Important for running:
12+
#
13+
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
14+
# noncompliant, but you have some other compliant shell such as ksh or
15+
# bash, then to run this script, type that shell name before the whole
16+
# command line, like:
17+
#
18+
# ksh Gradle
19+
#
20+
# Busybox and similar reduced shells will NOT work, because this script
21+
# requires all of these POSIX shell features:
22+
# * functions;
23+
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
24+
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
25+
# * compound commands having a testable exit status, especially «case»;
26+
# * various built-in commands including «command», «set», and «ulimit».
27+
#
28+
# Important for patching:
29+
#
30+
# (2) This script targets any POSIX shell, so it avoids extensions provided
31+
# by Bash, Ksh, etc; in particular arrays are avoided.
32+
#
33+
# The "traditional" practice of packing multiple parameters into a
34+
# space-separated string is a well documented source of bugs and security
35+
# problems, so this is (mostly) avoided, by progressively accumulating
36+
# options in "$@", and eventually passing that to Java.
37+
#
38+
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
39+
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
40+
# see the in-line comments for details.
41+
#
42+
# There are tweaks for specific operating systems such as AIX, CygWin,
43+
# Darwin, MinGW, and NonStop.
44+
#
45+
# (3) This script is generated from the Groovy template
46+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
47+
# within the Gradle project.
48+
#
49+
# You can find Gradle at https://github.com/gradle/gradle/.
50+
#
51+
##############################################################################
52+
53+
# Attempt to set APP_HOME
54+
55+
# Resolve links: $0 may be a link
56+
app_path=$0
57+
58+
# Need this for daisy-chained symlinks.
59+
while
60+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
61+
[ -h "$app_path" ]
62+
do
63+
ls=$( ls -ld "$app_path" )
64+
link=${ls#*' -> '}
65+
case $link in #(
66+
/*) app_path=$link ;; #(
67+
*) app_path=$APP_HOME$link ;;
68+
esac
69+
done
70+
71+
# This is normally unused
72+
# shellcheck disable=SC2034
73+
APP_BASE_NAME=${0##*/}
74+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
75+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
76+
77+
# Use the maximum available, or set MAX_FD != -1 to use that value.
78+
MAX_FD=maximum
79+
80+
warn () {
81+
echo "$*"
82+
} >&2
83+
84+
die () {
85+
echo
86+
echo "$*"
87+
echo
88+
exit 1
89+
} >&2
90+
91+
# OS specific support (must be 'true' or 'false').
92+
cygwin=false
93+
msys=false
94+
darwin=false
95+
nonstop=false
96+
case "$( uname )" in #(
97+
CYGWIN* ) cygwin=true ;; #(
98+
Darwin* ) darwin=true ;; #(
99+
MSYS* | MINGW* ) msys=true ;; #(
100+
NONSTOP* ) nonstop=true ;;
101+
esac
102+
103+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
104+
105+
106+
# Determine the Java command to use to start the JVM.
107+
if [ -n "$JAVA_HOME" ] ; then
108+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
109+
# IBM's JDK on AIX uses strange locations for the executables
110+
JAVACMD=$JAVA_HOME/jre/sh/java
111+
else
112+
JAVACMD=$JAVA_HOME/bin/java
113+
fi
114+
if [ ! -x "$JAVACMD" ] ; then
115+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
116+
117+
Please set the JAVA_HOME variable in your environment to match the
118+
location of your Java installation."
119+
fi
120+
else
121+
JAVACMD=java
122+
if ! command -v java >/dev/null 2>&1
123+
then
124+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
125+
126+
Please set the JAVA_HOME variable in your environment to match the
127+
location of your Java installation."
128+
fi
129+
fi
130+
131+
# Increase the maximum file descriptors if we can.
132+
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
133+
case $MAX_FD in #(
134+
max*)
135+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
136+
# shellcheck disable=SC2039,SC3045
137+
MAX_FD=$( ulimit -H -n ) ||
138+
warn "Could not query maximum file descriptor limit"
139+
esac
140+
case $MAX_FD in #(
141+
'' | soft) :;; #(
142+
*)
143+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
144+
# shellcheck disable=SC2039,SC3045
145+
ulimit -n "$MAX_FD" ||
146+
warn "Could not set maximum file descriptor limit to $MAX_FD"
147+
esac
148+
fi
149+
150+
# Collect all arguments for the java command, stacking in reverse order:
151+
# * args from the command line
152+
# * the main class name
153+
# * -classpath
154+
# * -D...appname settings
155+
# * --module-path (only if needed)
156+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
157+
158+
# For Cygwin or MSYS, switch paths to Windows format before running java
159+
if "$cygwin" || "$msys" ; then
160+
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
161+
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
162+
163+
JAVACMD=$( cygpath --unix "$JAVACMD" )
164+
165+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
166+
for arg do
167+
if
168+
case $arg in #(
169+
-*) false ;; # don't mess with options #(
170+
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
171+
[ -e "$t" ] ;; #(
172+
*) false ;;
173+
esac
174+
then
175+
arg=$( cygpath --path --ignore --mixed "$arg" )
176+
fi
177+
# Roll the args list around exactly as many times as the number of
178+
# args, so each arg winds up back in the position where it started, but
179+
# possibly modified.
180+
#
181+
# NB: a `for` loop captures its iteration list before it begins, so
182+
# changing the positional parameters here affects neither the number of
183+
# iterations, nor the values presented in `arg`.
184+
shift # remove old arg
185+
set -- "$@" "$arg" # push replacement arg
186+
done
187+
fi
188+
189+
190+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
191+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
192+
193+
# Collect all arguments for the java command:
194+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
195+
# and any embedded shellness will be escaped.
196+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
197+
# treated as '${Hostname}' itself on the command line.
198+
199+
set -- \
200+
"-Dorg.gradle.appname=$APP_BASE_NAME" \
201+
-classpath "$CLASSPATH" \
202+
org.gradle.wrapper.GradleWrapperMain \
203+
"$@"
204+
205+
# Stop when "xargs" is not available.
206+
if ! command -v xargs >/dev/null 2>&1
207+
then
208+
die "xargs is not available"
209+
fi
210+
211+
# Use "xargs" to parse quoted args.
212+
#
213+
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
214+
#
215+
# In Bash we could simply go:
216+
#
217+
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
218+
# set -- "${ARGS[@]}" "$@"
219+
#
220+
# but POSIX shell has neither arrays nor command substitution, so instead we
221+
# post-process each arg (as a line of input to sed) to backslash-escape any
222+
# character that might be a shell metacharacter, then use eval to reverse
223+
# that process (while maintaining the separation between arguments), and wrap
224+
# the whole thing up as a single "set" statement.
225+
#
226+
# This will of course break if any of these variables contains a newline or
227+
# an unmatched quote.
228+
#
229+
230+
eval "set -- $(
231+
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
232+
xargs -n1 |
233+
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
234+
tr '\n' ' '
235+
)" '"$@"'
236+
237+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)