Skip to content

Commit 453dc44

Browse files
committed
docs: document javaexec binary and source/git buildpack path
1 parent 534a658 commit 453dc44

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

docs/DEVELOPING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Build the buildpack binaries:
9797
This creates executables in the `bin/` directory:
9898
- `bin/supply` - Staging phase binary (downloads and installs dependencies)
9999
- `bin/finalize` - Finalization phase binary (configures runtime)
100+
- `bin/javaexec` - Shell-free JVM launcher (tokenizes `JAVA_OPTS` without `eval`)
100101

101102
## Project Structure
102103

@@ -118,6 +119,7 @@ java-buildpack/
118119
│ ├── jres/ # JRE implementations (7 providers)
119120
│ ├── supply/cli/ # Supply phase entrypoint
120121
│ ├── finalize/cli/ # Finalize phase entrypoint
122+
│ ├── javaexec/cli/ # Shell-free JVM launcher entrypoint
121123
│ ├── resources/ # Resource configuration files
122124
│ └── integration/ # Integration tests
123125
├── scripts/ # Build and test scripts
@@ -156,6 +158,7 @@ Build for the default platform (Linux):
156158
```
157159
-----> Building supply for linux
158160
-----> Building finalize for linux
161+
-----> Building javaexec for linux
159162
-----> Build complete
160163
```
161164

@@ -193,6 +196,25 @@ go build -mod vendor -o bin/supply src/java/supply/cli/main.go
193196

194197
# Build finalize
195198
go build -mod vendor -o bin/finalize src/java/finalize/cli/main.go
199+
200+
# Build javaexec (shell-free JVM launcher, required at runtime)
201+
go build -mod vendor -o bin/javaexec src/java/javaexec/cli/main.go
202+
```
203+
204+
### Source/Git Buildpack Usage
205+
206+
When deploying with a git URL (`cf push -b https://github.com/.../java-buildpack.git`),
207+
Cloud Foundry runs `bin/finalize` directly from the cloned source. In that mode
208+
`bin/javaexec` does not exist (only packaged buildpacks have it). `bin/finalize`
209+
therefore builds `javaexec` into a temp directory alongside the finalize binary
210+
and passes the path via the `JAVAEXEC_BINARY_PATH` environment variable.
211+
`InstallJavaexecLauncher()` prefers this override and falls back to
212+
`bin/javaexec` for packaged buildpacks.
213+
214+
To verify this path locally (no CF required):
215+
216+
```bash
217+
bash scripts/test-javaexec-source-path.sh
196218
```
197219

198220
## Running Tests

docs/design.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ During the finalize phase (`bin/finalize`), the buildpack:
186186
1. **Finalizes JRE**: Configures JVM options, memory calculator
187187
2. **Finalizes Frameworks**: Adds agent paths, system properties
188188
3. **Finalizes Container**: Generates launch command
189+
4. **Installs `javaexec`**: Copies the shell-free JVM launcher into
190+
`$DEPS_DIR/<idx>/bin/javaexec`. The generated start command invokes it
191+
instead of `eval "exec java $JAVA_OPTS ..."` so that `JAVA_OPTS` is
192+
tokenized without shell interpretation. For source/git buildpack usage
193+
`bin/finalize` builds `javaexec` on the fly and passes its path via
194+
`JAVAEXEC_BINARY_PATH` (see [DEVELOPING.md](DEVELOPING.md#sourcegit-buildpack-usage)).
189195

190196
Components can:
191197
- Read installed dependencies from `$DEPS_DIR/<idx>/`
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Manual smoke test for the bin/finalize source/git buildpack path.
3+
# Simulates what bin/finalize does: build javaexec into a temp dir and pass
4+
# the path via JAVAEXEC_BINARY_PATH. Verifies the binary builds and that
5+
# InstallJavaexecLauncher picks up the override (unit tests cover the logic;
6+
# this confirms the wiring end-to-end on this machine).
7+
set -euo pipefail
8+
9+
BUILDPACK_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
10+
cd "$BUILDPACK_DIR"
11+
12+
tmpdir=$(mktemp -d)
13+
trap 'rm -rf "$tmpdir"' EXIT
14+
15+
echo "==> [1/3] Build javaexec from source (as bin/finalize now does)"
16+
go build -mod=vendor -o "$tmpdir/javaexec" ./src/java/javaexec/cli
17+
echo " OK: $tmpdir/javaexec ($(wc -c < "$tmpdir/javaexec") bytes)"
18+
19+
echo ""
20+
echo "==> [2/3] Build finalize from source"
21+
go build -mod=vendor -o "$tmpdir/finalize" ./src/java/finalize/cli
22+
echo " OK: $tmpdir/finalize"
23+
24+
echo ""
25+
echo "==> [3/3] Unit tests: InstallJavaexecLauncher with JAVAEXEC_BINARY_PATH override"
26+
go test ./src/java/finalize/ -count=1 -v -run "javaexec launcher" 2>&1 | grep -E "PASS|FAIL|RUN|---"
27+
28+
echo ""
29+
echo "PASS: source/git buildpack path works."
30+
echo " bin/finalize builds javaexec and passes it via JAVAEXEC_BINARY_PATH."

src/integration/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ property that must hold in a real container launch:
151151
- **The `javaexec` launcher actually starts the JVM** for the affected containers,
152152
including `Play` (previously `eval exec java $JAVA_OPTS ...`).
153153

154+
**Source/git buildpack path** (`bin/finalize` building `javaexec` on the fly) is
155+
**not covered** by integration tests here: they use a packaged zip where `bin/javaexec`
156+
is pre-built by `scripts/build.sh`. The source/git path is covered by unit tests in
157+
[`../java/finalize/finalize_test.go`](../java/finalize/finalize_test.go) and can be
158+
verified locally with `bash scripts/test-javaexec-source-path.sh`.
159+
154160
## Writing New Tests
155161

156162
To add a new test:

0 commit comments

Comments
 (0)