karthik-0306 opened a new pull request, #12740:
URL: https://github.com/apache/seatunnel/pull/12740
### Purpose of this pull request
Related to #12707 (pip-installable SeaTunnel launcher).
This PR adds the first small building block for that work: a helper that
finds Java on the user's machine and checks that it is new enough. Today
`seatunnel.sh` has no Java version check, so someone running Java 8 gets a
confusing `UnsupportedClassVersionError` from the JVM. This helper lets the
future launcher fail early with a clear message instead.
What `detect_java(min_version=11)` does:
1. Looks for Java in `$JAVA_HOME/bin/java` first, then falls back to `java`
on `PATH`.
2. Runs `java -version` and reads the major version. It handles the old
format (`1.8.0_292` is Java 8) and the new formats (`11.0.2`, `17`, `21.0.1`,
`17-ea`).
3. Returns a small `JavaInfo(executable, major_version)` object, so the
launcher can reuse both the path and the version without parsing anything again.
4. Raises `JavaDetectionError` if Java is missing, older than `min_version`,
its output can't be read, or running it fails or times out. Every message
states what was found (or that nothing was found) and guides the user to set
`JAVA_HOME` or install `JDK {min_version}+` (default 11+).
Design note: If `JAVA_HOME` is set but has no Java binary in it, the helper
raises an error instead of quietly falling back to `PATH`. A typo in
`JAVA_HOME` would otherwise be ignored, and the user could end up on a
different Java than intended. `PATH` is only consulted when `JAVA_HOME` is
unset or empty. Happy to adapt this if reviewers prefer a fallback.
Scope: This adds two new files under `tools/seatunnel-python-sdk`. It is not
exported from `seatunnel/__init__.py`, and `seatunnel.sh` and the engine are
untouched. Adding the same check to `seatunnel.sh` could be handled in a
separate change.
### Does this PR introduce _any_ user-facing change?
No. It is an internal helper that nothing calls yet, and it is not part of
the SDK's public API.
### How was this patch tested?
Added 20 new unit tests in
`tools/seatunnel-python-sdk/tests/test_java_detector.py`. They mock the `java
-version` output, so no real JDK is needed. They cover:
- Old and new version formats: `1.7.0_80`, `1.8.0_292`, `11`, `11.0.2`,
`17.0.1`, `17-ea`, `21.0.1`
- `JAVA_HOME` used before `PATH`, and a bad `JAVA_HOME` failing without
falling back to `PATH`
- Java missing, Java too old, unreadable output, a non-zero exit code, a
timeout, and an `OSError`
- Extra JVM noise lines such as `Picked up JAVA_TOOL_OPTIONS` or `NOTE:
Picked up JDK_JAVA_OPTIONS`, and a version printed on stdout instead of stderr
- A custom `min_version`, with all error messages using that value instead
of a hardcoded 11
To run them (from `tools/seatunnel-python-sdk/`):
```bash
python -m pytest tests/ -v
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]