Skip to content

Commit cdd0fdb

Browse files
committed
Merge branch 'main' into java-27
2 parents adcbdd9 + b0e0ef0 commit cdd0fdb

3 files changed

Lines changed: 80 additions & 60 deletions

File tree

‎AGENTS.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# User preferences
2+
3+
- Whenever you change any files, include a suggested Git commit message written entirely in lowercase in your final response. This also applies to changes to this file.
4+
- Providing a commit message does not authorize staging, committing, or pushing changes.

‎scripts/use-java-26-linux.sh‎

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,83 @@
11
#!/usr/bin/env bash
22

3-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
3+
# Sourcing uses the caller's shell, regardless of the shebang.
4+
if { [[ -n "${BASH_VERSION:-}" ]] && [[ "${BASH_SOURCE[0]}" == "$0" ]]; } ||
5+
{ [[ -n "${ZSH_VERSION:-}" ]] && [[ "${ZSH_EVAL_CONTEXT:-}" != *:file ]]; }; then
46
echo "This script must be sourced so it can update the current shell:"
57
echo " source scripts/use-java-26-linux.sh [JAVA_26_HOME]"
68
exit 1
79
fi
810

9-
set_java_home_candidate() {
10-
local candidate="$1"
11+
use_java_26_linux() {
12+
local candidate java_bin remaining entry new_path
1113

12-
if [[ -z "$candidate" ]]; then
13-
return 1
14-
fi
14+
# Discover in a subshell so glob options and helper functions stay local.
15+
candidate="$(
16+
if [[ -n "${ZSH_VERSION:-}" ]]; then
17+
setopt NULL_GLOB
18+
else
19+
shopt -s nullglob
20+
fi
1521
16-
if [[ -x "$candidate/bin/java" ]]; then
17-
local version_output
18-
version_output="$("$candidate/bin/java" --version 2>&1 | head -n 1)"
22+
set_java_home_candidate() {
23+
local candidate="$1" version_output
24+
local version_pattern='^(openjdk|java)[[:space:]]26([[:space:].+-]|$)'
1925
20-
if [[ "$version_output" =~ ^(openjdk|java)[[:space:]]26([[:space:].]|$) ]]; then
21-
export JAVA_HOME="$candidate"
22-
export PATH="$JAVA_HOME/bin:$PATH"
23-
echo "JAVA_HOME=$JAVA_HOME"
24-
java --version
25-
return 0
26-
fi
27-
fi
26+
[[ -n "$candidate" && -x "$candidate/bin/java" && -x "$candidate/bin/javac" ]] || return 1
27+
version_output="$("$candidate/bin/java" --version 2>&1)" || return 1
28+
[[ "$version_output" =~ $version_pattern ]] || return 1
29+
# Keep JAVA_HOME valid after changing directories.
30+
(cd -- "$candidate" && pwd -P)
31+
}
2832
29-
return 1
30-
}
33+
if [[ -n "${1:-}" ]]; then
34+
set_java_home_candidate "$1" && exit 0
35+
echo "The supplied path is not a valid JDK 26 home: $1" >&2
36+
exit 1
37+
fi
3138
32-
java_home_arg="${1:-}"
39+
for candidate in \
40+
"${JAVA26_HOME:-}" \
41+
"${JDK26_HOME:-}" \
42+
/usr/lib/jvm/*26* \
43+
/opt/jdk-26* \
44+
/opt/java/jdk-26* \
45+
/usr/local/jdk-26* \
46+
"${SDKMAN_CANDIDATES_DIR:-${SDKMAN_DIR:-$HOME/.sdkman}/candidates}"/java/26*
47+
do
48+
if set_java_home_candidate "$candidate"; then
49+
exit 0
50+
fi
51+
done
3352
34-
if [[ -n "$java_home_arg" ]]; then
35-
if set_java_home_candidate "$java_home_arg"; then
36-
return 0
37-
fi
53+
echo "Could not find a JDK 26 installation." >&2
54+
echo "Pass the JDK path explicitly, or set JAVA26_HOME or JDK26_HOME first." >&2
55+
exit 1
56+
)" || return 1
3857

39-
echo "The supplied path is not a valid JDK 26 home: $java_home_arg"
40-
return 1
41-
fi
58+
# Move the selected bin directory to the front without duplicating it.
59+
java_bin="$candidate/bin"
60+
remaining="$PATH"
61+
new_path="$java_bin"
62+
while true; do
63+
entry="${remaining%%:*}"
64+
if [[ "$entry" != "$java_bin" ]]; then
65+
new_path="$new_path:$entry"
66+
fi
67+
[[ "$remaining" == *:* ]] || break
68+
remaining="${remaining#*:}"
69+
done
4270

43-
if set_java_home_candidate "${JAVA26_HOME:-}"; then
44-
return 0
45-
fi
71+
export JAVA_HOME="$candidate"
72+
export PATH="$new_path"
73+
echo "JAVA_HOME=$JAVA_HOME"
74+
java --version
75+
}
4676

47-
if set_java_home_candidate "${JDK26_HOME:-}"; then
77+
if use_java_26_linux "$@"; then
78+
unset -f use_java_26_linux
4879
return 0
80+
else
81+
unset -f use_java_26_linux
82+
return 1
4983
fi
50-
51-
shopt -s nullglob
52-
for candidate in \
53-
/usr/lib/jvm/*26* \
54-
/opt/jdk-26* \
55-
/opt/java/jdk-26* \
56-
/usr/local/jdk-26* \
57-
"$HOME"/.sdkman/candidates/java/*26*
58-
do
59-
if set_java_home_candidate "$candidate"; then
60-
shopt -u nullglob
61-
return 0
62-
fi
63-
done
64-
shopt -u nullglob
65-
66-
echo "Could not find a JDK 26 installation."
67-
echo "Pass the JDK path explicitly, or set JAVA26_HOME or JDK26_HOME first."
68-
echo "Checked common Linux locations:"
69-
echo " /usr/lib/jvm/*26*"
70-
echo " /opt/jdk-26*"
71-
echo " /opt/java/jdk-26*"
72-
echo " /usr/local/jdk-26*"
73-
echo " $HOME/.sdkman/candidates/java/*26*"
74-
echo "Example:"
75-
echo " source scripts/use-java-26-linux.sh /usr/lib/jvm/jdk-26.0.2.1"
76-
return 1

‎src/main/java/net/jrodolfo/java_evolution/java01/javabeans/README.md‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@ JavaBeans defined conventions such as no-argument constructors, getter/setter pr
1717
- a no-argument constructor makes the component easy for tools to create
1818
- `getName` and `setName` define a `name` property
1919
- `isActive` and `setActive` define a boolean `active` property
20-
- `addProjectListener` and `removeProjectListener` define an event-set convention
21-
- `Introspector` exposes this metadata through descriptors
20+
- matching `addProjectListener(ProjectListener)` and
21+
`removeProjectListener(ProjectListener)` methods tell JavaBeans that the bean
22+
publishes events to `ProjectListener` objects
23+
- an "event set" means this relationship between an event source and its
24+
listener type; it does not mean `java.util.Set`
25+
- `Introspector` examines JavaBeans naming conventions and returns `BeanInfo`
26+
- `BeanInfo` exposes the information through descriptors such as
27+
`PropertyDescriptor`, `MethodDescriptor`, and `EventSetDescriptor`
28+
29+
A descriptor is simply an object that describes one part of a bean, such as a
30+
property, method, or event set.
2231

2332
The point is not the amount of code in the bean. The point is that tools can discover properties and events without each component implementing a custom metadata API.
2433

0 commit comments

Comments
 (0)