Skip to content

Commit b8ddec9

Browse files
committed
Java Samples
This change adds 8 JVM-related samples to the repository. [resolves paketo-buildpacks#3] Signed-off-by: Ben Hale <[email protected]>
1 parent 9ec3725 commit b8ddec9

File tree

210 files changed

+4733
-0
lines changed

Some content is hidden

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

210 files changed

+4733
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ A collection of sample applications that can be built using Paketo Buildpacks.
99

1010
## Samples
1111

12+
### Java
13+
* [AspectJ](/java/aspectj)
14+
* [Azure Application Insights](/java/application-insights)
15+
* [Gradle DistZip](/java/dist-zip)
16+
* [Gradle](/java/gradle)
17+
* [Maven](/java/maven)
18+
* [Pre-compiled JAR](/java/jar)
19+
* [Scala Akka](/java/akka)
20+
* [WAR](/java/war)
21+
1222
### Node.js
1323
* [NPM](/nodejs/npm)
1424
* [Yarn](/nodejs/yarn)

java/akka/.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
target/
2+
3+
.settings
4+
.project
5+
.classpath
6+
7+
.idea
8+
*.iml
9+
10+
.metals
11+
.bloop
12+

java/akka/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Scala Akka Sample Application
2+
3+
## Building
4+
5+
```bash
6+
pack build applications/akka
7+
```
8+
9+
## Running
10+
11+
```bash
12+
docker run --tty --publish 8080:8080 applications/akka
13+
```
14+
15+
## Viewing
16+
17+
The log output shows the interation of the actors:
18+
19+
```plain
20+
[2020-06-19 14:48:16,054] [INFO] [akka.event.slf4j.Slf4jLogger] [AkkaQuickStart-akka.actor.default-dispatcher-3] [] - Slf4jLogger started
21+
[2020-06-19 14:48:16,123] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-6] [akka://AkkaQuickStart/user/greeter] - Hello Charles!
22+
[2020-06-19 14:48:16,124] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-6] [akka://AkkaQuickStart/user/Charles] - Greeting 1 for Charles
23+
[2020-06-19 14:48:16,126] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-6] [akka://AkkaQuickStart/user/greeter] - Hello Charles!
24+
[2020-06-19 14:48:16,126] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-6] [akka://AkkaQuickStart/user/Charles] - Greeting 2 for Charles
25+
[2020-06-19 14:48:16,127] [INFO] [com.example.Greeter$] [AkkaQuickStart-akka.actor.default-dispatcher-3] [akka://AkkaQuickStart/user/greeter] - Hello Charles!
26+
[2020-06-19 14:48:16,127] [INFO] [com.example.GreeterBot$] [AkkaQuickStart-akka.actor.default-dispatcher-6] [akka://AkkaQuickStart/user/Charles] - Greeting 3 for Charles
27+
```

java/akka/build.sbt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name := "akka-quickstart-scala"
2+
3+
version := "1.0"
4+
5+
scalaVersion := "2.13.1"
6+
7+
lazy val akkaVersion = "2.6.4"
8+
9+
libraryDependencies ++= Seq(
10+
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
11+
"ch.qos.logback" % "logback-classic" % "1.2.3",
12+
"com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion % Test,
13+
"org.scalatest" %% "scalatest" % "3.1.0" % Test
14+
)
15+
16+
enablePlugins(JavaAppPackaging)

java/akka/project/build.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.3.6

java/akka/project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
2+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.0")

java/akka/sbt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
./sbt-dist/bin/sbt "$@"

java/akka/sbt-dist/bin/sbt

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env bash
2+
3+
4+
### ------------------------------- ###
5+
### Helper methods for BASH scripts ###
6+
### ------------------------------- ###
7+
8+
realpath () {
9+
(
10+
TARGET_FILE="$1"
11+
FIX_CYGPATH="$2"
12+
13+
cd "$(dirname "$TARGET_FILE")"
14+
TARGET_FILE=$(basename "$TARGET_FILE")
15+
16+
COUNT=0
17+
while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
18+
do
19+
TARGET_FILE=$(readlink "$TARGET_FILE")
20+
cd "$(dirname "$TARGET_FILE")"
21+
TARGET_FILE=$(basename "$TARGET_FILE")
22+
COUNT=$(($COUNT + 1))
23+
done
24+
25+
# make sure we grab the actual windows path, instead of cygwin's path.
26+
if [[ "x$FIX_CYGPATH" != "x" ]]; then
27+
echo "$(cygwinpath "$(pwd -P)/$TARGET_FILE")"
28+
else
29+
echo "$(pwd -P)/$TARGET_FILE"
30+
fi
31+
)
32+
}
33+
34+
35+
# Uses uname to detect if we're in the odd cygwin environment.
36+
is_cygwin() {
37+
local os=$(uname -s)
38+
case "$os" in
39+
CYGWIN*) return 0 ;;
40+
*) return 1 ;;
41+
esac
42+
}
43+
44+
# TODO - Use nicer bash-isms here.
45+
CYGWIN_FLAG=$(if is_cygwin; then echo true; else echo false; fi)
46+
47+
48+
# This can fix cygwin style /cygdrive paths so we get the
49+
# windows style paths.
50+
cygwinpath() {
51+
local file="$1"
52+
if [[ "$CYGWIN_FLAG" == "true" ]]; then
53+
echo $(cygpath -w $file)
54+
else
55+
echo $file
56+
fi
57+
}
58+
59+
. "$(dirname "$(realpath "$0")")/sbt-launch-lib.bash"
60+
61+
62+
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
63+
declare -r sbt_opts_file=".sbtopts"
64+
declare -r etc_sbt_opts_file="${sbt_home}/conf/sbtopts"
65+
declare -r win_sbt_opts_file="${sbt_home}/conf/sbtconfig.txt"
66+
67+
usage() {
68+
cat <<EOM
69+
Usage: $script_name [options]
70+
71+
-h | -help print this message
72+
-v | -verbose this runner is chattier
73+
-d | -debug set sbt log level to debug
74+
-no-colors disable ANSI color codes
75+
-sbt-create start sbt even if current directory contains no sbt project
76+
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt)
77+
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
78+
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
79+
-mem <integer> set memory options (default: $sbt_mem, which is $(get_mem_opts $sbt_mem))
80+
-no-share use all local caches; no sharing
81+
-no-global uses global caches, but does not use global ~/.sbt directory.
82+
-jvm-debug <port> Turn on JVM debugging, open at the given port.
83+
-batch Disable interactive mode
84+
85+
# sbt version (default: from project/build.properties if present, else latest release)
86+
-sbt-version <version> use the specified version of sbt
87+
-sbt-jar <path> use the specified jar as the sbt launcher
88+
-sbt-rc use an RC version of sbt
89+
-sbt-snapshot use a snapshot version of sbt
90+
91+
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
92+
-java-home <path> alternate JAVA_HOME
93+
94+
# jvm options and output control
95+
JAVA_OPTS environment variable, if unset uses "$java_opts"
96+
SBT_OPTS environment variable, if unset uses "$default_sbt_opts"
97+
.sbtopts if this file exists in the current directory, it is
98+
prepended to the runner args
99+
/etc/sbt/sbtopts if this file exists, it is prepended to the runner args
100+
-Dkey=val pass -Dkey=val directly to the java runtime
101+
-J-X pass option -X directly to the java runtime
102+
(-J is stripped)
103+
-S-X add -X to sbt's scalacOptions (-S is stripped)
104+
105+
In the case of duplicated or conflicting options, the order above
106+
shows precedence: JAVA_OPTS lowest, command line options highest.
107+
EOM
108+
}
109+
110+
111+
112+
process_my_args () {
113+
while [[ $# -gt 0 ]]; do
114+
case "$1" in
115+
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
116+
-no-share) addJava "$noshare_opts" && shift ;;
117+
-no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;;
118+
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
119+
-sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;;
120+
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
121+
-batch) exec </dev/null && shift ;;
122+
123+
-sbt-create) sbt_create=true && shift ;;
124+
125+
*) addResidual "$1" && shift ;;
126+
esac
127+
done
128+
129+
# Now, ensure sbt version is used.
130+
[[ "${sbt_version}XXX" != "XXX" ]] && addJava "-Dsbt.version=$sbt_version"
131+
}
132+
133+
loadConfigFile() {
134+
cat "$1" | sed '/^\#/d' | while read line; do
135+
eval echo $line
136+
done
137+
}
138+
139+
# TODO - Pull in config based on operating system... (MSYS + cygwin should pull in txt file).
140+
# Here we pull in the global settings configuration.
141+
[[ -f "$etc_sbt_opts_file" ]] && set -- $(loadConfigFile "$etc_sbt_opts_file") "$@"
142+
# -- Windows behavior stub'd
143+
# JAVA_OPTS=$(cat "$WDIR/sbtconfig.txt" | sed -e 's/\r//g' -e 's/^#.*$//g' | sed ':a;N;$!ba;s/\n/ /g')
144+
145+
146+
# Pull in the project-level config file, if it exists.
147+
[[ -f "$sbt_opts_file" ]] && set -- $(loadConfigFile "$sbt_opts_file") "$@"
148+
149+
150+
run "$@"
151+

0 commit comments

Comments
 (0)