Skip to content

Commit e9d3a0d

Browse files
committed
Unify run/create-expected-result scripts
Standardize result directory handling across all examples by parameterizing run.sh scripts and eliminating code duplication in create-expected-result.sh scripts. Changes: 1. Parameterize result directory in run.sh (29 scripts): - Add result_dir parameter: result_dir="${1:-run-result}" - Setup result directory with cleanup: rm -rf/mkdir -p/touch - Replace hardcoded "run-result/" with "${result_dir}/" - Ensure all tee commands use -a flag for appending - Proper ordering: source ../env.sh before result_dir setup 2. Refactor create-expected-result.sh to use ./run.sh (29 scripts): - Replace duplicated Java command logic with: ./run.sh expected-result - Eliminates code duplication (~184 lines removed) - Ensures consistency between run and expected results - Single source of truth for run logic Benefits: - Consistent pattern across all non-Maven/Gradle examples (35/40) - Eliminated duplicate run logic in create-expected-result scripts - Easier maintenance: changes only needed in one place (run.sh) - Guaranteed consistency between actual runs and expected results Statistics: - 64 files changed: 341 insertions(+), 357 deletions(-) - 35 examples now use parameterized result_dir (87.5%) - All 35 create-expected-result scripts use ./run.sh pattern (100%) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Introduced in the course of support-and-care/maven-support-and-care#137
1 parent 34f8908 commit e9d3a0d

File tree

64 files changed

+341
-357
lines changed

Some content is hidden

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

64 files changed

+341
-357
lines changed

jigsaw-examples/example_addExports_manifest/create-expected-result.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,8 @@ echo "Using Java version:"
1111
"${JAVA_HOME}/bin/java" -version
1212
echo
1313

14-
mkdir -p expected-result
15-
16-
echo "Running Java module and capturing output..."
17-
18-
# Allow access to moda without using the "Add-Exports" entry from MANIFEST.MF
19-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \
20-
--add-exports java.base/jdk.internal.misc=modmain \
21-
--add-exports moda/pkgainternal=modmain \
22-
--module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize > expected-result/run.txt
23-
24-
# Allow access to moda with using the "Add-Exports" entry from MANIFEST.MF
25-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \
26-
--add-modules moda \
27-
--module-path mlib \
28-
-jar mlib/modmain.jar 2>&1 | normalize >> expected-result/run.txt
14+
echo "Running example and capturing output..."
15+
./run.sh expected-result
2916

3017
echo "✅ Expected result saved to expected-result/run.txt"
3118
echo
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/usr/bin/env bash
22
source ../env.sh
33

4-
mkdir -p run-result
4+
5+
result_dir="${1:-run-result}"
6+
7+
rm -rf "${result_dir}"
8+
9+
mkdir -p "${result_dir}"
10+
touch "${result_dir}/run.txt"
11+
512

613
# Allow access to moda without using the "Add-Exports" entry from MANIFEST.MF
714
# shellcheck disable=SC2086 # Option variables should not be quoted
815
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \
916
--add-exports java.base/jdk.internal.misc=modmain \
1017
--add-exports moda/pkgainternal=modmain \
11-
--module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
18+
--module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho
1219

1320
# Allow access to moda with using the "Add-Exports" entry from MANIFEST.MF
1421
# shellcheck disable=SC2086 # Option variables should not be quoted
1522
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} \
1623
--add-modules moda \
1724
--module-path mlib \
18-
-jar mlib/modmain.jar 2>&1 | normalize | tee -a run-result/run.txt | myecho
25+
-jar mlib/modmain.jar 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho
1926

2027

jigsaw-examples/example_addReads_addExports/create-expected-result.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,12 @@ EXAMPLE_NAME="$(basename "$(pwd)")"
77
echo "=== Creating expected result for ${EXAMPLE_NAME} ==="
88
echo
99

10-
# Show Java version for user information
1110
echo "Using Java version:"
1211
"${JAVA_HOME}/bin/java" -version
1312
echo
1413

15-
# Create expected-result directory if it doesn't exist
16-
mkdir -p expected-result
17-
18-
# Run the Java code and capture output
19-
echo "Running Java module and capturing output..."
20-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \
21-
--add-modules modb,modc \
22-
--add-reads modmain=modb \
23-
--add-reads modb=modc \
24-
--add-exports modb/pkgb=modmain \
25-
--add-exports modc/pkgc=modb \
26-
--module modmain/pkgmain.Main 2>&1 | normalize > expected-result/run.txt
14+
echo "Running example and capturing output..."
15+
./run.sh expected-result
2716

2817
echo "✅ Expected result saved to expected-result/run.txt"
2918
echo

jigsaw-examples/example_addReads_addExports/run.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ set -eu -o pipefail
33

44
source ../env.sh
55

6+
result_dir="${1:-run-result}"
7+
8+
rm -rf "${result_dir}"
9+
10+
mkdir -p "${result_dir}"
11+
touch "${result_dir}/run.txt"
12+
13+
614
# Show Java version for user information
715
echo "Using Java version:"
816
"${JAVA_HOME}/bin/java" -version
917
echo
1018

11-
# Create run-result directory if it doesn't exist
12-
mkdir -p run-result
1319

14-
# Run the Java code, save output to run-result/run.txt, and display with highlighting
20+
# Run the Java code, save output to "${result_dir}/run.txt", and display with highlighting
1521
# shellcheck disable=SC2086 # Option variables should not be quoted
1622
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \
1723
--add-modules modb,modc \
1824
--add-reads modmain=modb \
1925
--add-reads modb=modc \
2026
--add-exports modb/pkgb=modmain \
2127
--add-exports modc/pkgc=modb \
22-
--module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
28+
--module modmain/pkgmain.Main 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho

jigsaw-examples/example_addReads_addExports_reflection/create-expected-result.sh

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,12 @@ EXAMPLE_NAME="$(basename "$(pwd)")"
77
echo "=== Creating expected result for ${EXAMPLE_NAME} ==="
88
echo
99

10-
# Show Java version for user information
1110
echo "Using Java version:"
1211
"${JAVA_HOME}/bin/java" -version
1312
echo
1413

15-
# Create expected-result directory if it doesn't exist
16-
mkdir -p expected-result
17-
18-
# Run the Java code and capture output
19-
echo "Running Java module and capturing output..."
20-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \
21-
--add-modules modb \
22-
--add-exports modb/pkgb=modmain \
23-
--module modmain/pkgmain.Main 2>&1 | normalize > expected-result/run.txt
14+
echo "Running example and capturing output..."
15+
./run.sh expected-result
2416

2517
echo "✅ Expected result saved to expected-result/run.txt"
2618
echo

jigsaw-examples/example_addReads_addExports_reflection/run.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
source ../env.sh
33

44
# Show Java version for user information
5+
6+
result_dir="${1:-run-result}"
7+
8+
rm -rf "${result_dir}"
9+
10+
mkdir -p "${result_dir}"
11+
touch "${result_dir}/run.txt"
12+
513
echo "Using Java version:"
614
"${JAVA_HOME}/bin/java" -version
715
echo
816

9-
# Create run-result directory if it doesn't exist
10-
mkdir -p run-result
1117

1218
# note: not done here (but via api in modmain, see Main.java#26) as a replacement for --add-reads modmain=modb
1319
# note: not done here (but via api in modmain, see Main.java#30) as a replacement for --add-exports modb/pkgbinternal=modmain
@@ -16,4 +22,4 @@ mkdir -p run-result
1622
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib \
1723
--add-modules modb \
1824
--add-exports modb/pkgb=modmain \
19-
--module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
25+
--module modmain/pkgmain.Main 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho

jigsaw-examples/example_annotations/create-expected-result.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ EXAMPLE_NAME="$(basename "$(pwd)")"
77
echo "=== Creating expected result for ${EXAMPLE_NAME} ==="
88
echo
99

10-
# Show Java version for user information
1110
echo "Using Java version:"
1211
"${JAVA_HOME}/bin/java" -version
1312
echo
1413

15-
# Create expected-result directory if it doesn't exist
16-
mkdir -p expected-result
17-
18-
# Run the Java code and capture output
19-
echo "Running Java module and capturing output..."
20-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize > expected-result/run.txt
14+
echo "Running example and capturing output..."
15+
./run.sh expected-result
2116

2217
echo "✅ Expected result saved to expected-result/run.txt"
2318
echo

jigsaw-examples/example_annotations/run.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ set -eu -o pipefail
33

44
source ../env.sh
55

6+
result_dir="${1:-run-result}"
7+
8+
rm -rf "${result_dir}"
9+
10+
mkdir -p "${result_dir}"
11+
touch "${result_dir}/run.txt"
12+
13+
614
# Show Java version for user information
715
echo "Using Java version:"
816
"${JAVA_HOME}/bin/java" -version
917
echo
1018

11-
# Create run-result directory if it doesn't exist
12-
mkdir -p run-result
1319

14-
# Run the Java code, save output to run-result/run.txt, and display with highlighting
20+
# Run the Java code, save output to "${result_dir}/run.txt", and display with highlighting
1521
# shellcheck disable=SC2086 # Option variables should not be quoted
16-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
22+
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho

jigsaw-examples/example_derived_private-package-protected/create-expected-result.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ EXAMPLE_NAME="$(basename "$(pwd)")"
77
echo "=== Creating expected result for ${EXAMPLE_NAME} ==="
88
echo
99

10-
# Show Java version for user information
1110
echo "Using Java version:"
1211
"${JAVA_HOME}/bin/java" -version
1312
echo
1413

15-
# Create expected-result directory if it doesn't exist
16-
mkdir -p expected-result
17-
18-
# Run the Java code and capture output
19-
echo "Running Java module and capturing output..."
20-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize > expected-result/run.txt
14+
echo "Running example and capturing output..."
15+
./run.sh expected-result
2116

2217
echo "✅ Expected result saved to expected-result/run.txt"
2318
echo

jigsaw-examples/example_derived_private-package-protected/run.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ set -eu -o pipefail
33

44
source ../env.sh
55

6+
result_dir="${1:-run-result}"
7+
8+
rm -rf "${result_dir}"
9+
10+
mkdir -p "${result_dir}"
11+
touch "${result_dir}/run.txt"
12+
13+
614
# Show Java version for user information
715
echo "Using Java version:"
816
"${JAVA_HOME}/bin/java" -version
917
echo
1018

11-
# Create run-result directory if it doesn't exist
12-
mkdir -p run-result
1319

14-
# Run the Java code, save output to run-result/run.txt, and display with highlighting
20+
# Run the Java code, save output to "${result_dir}/run.txt", and display with highlighting
1521
# shellcheck disable=SC2086 # Option variables should not be quoted
16-
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee run-result/run.txt | myecho
22+
"${JAVA_HOME}/bin/java" ${JAVA_OPTIONS} --module-path mlib --module modmain/pkgmain.Main 2>&1 | normalize | tee -a "${result_dir}/run.txt" | myecho

0 commit comments

Comments
 (0)