-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.sh
More file actions
143 lines (129 loc) · 3.86 KB
/
hello.sh
File metadata and controls
143 lines (129 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# HelloTool launcher script
# Laptop-friendly defaults with professional argument handling
# Standard directory resolution
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Source validation functions
if [ -f "$DIR/validation.sh" ]; then
source "$DIR/validation.sh"
else
echo "❌ Error: validation.sh not found. Required for proper validation."
exit 1
fi
# Usage function
usage() {
echo "hello.sh - Professional greeting generator launcher"
echo ""
echo "Usage:"
echo " $0 [name] [options]"
echo ""
echo "Arguments:"
echo " name Name to greet (default: World)"
echo ""
echo "Java Options:"
echo " -Xmx<memory> Set maximum heap size (default: 512m)"
echo " -Xms<memory> Set initial heap size (default: 256m)"
echo " -ea Enable assertions (default)"
echo " -da Disable assertions"
echo ""
echo "Tool Options:"
echo " --name=<name> Specify name explicitly"
echo " --verbose, -v Enable verbose output"
echo " --help, -h Show tool help"
echo ""
echo "Launcher Options:"
echo " --launcher-help Show this launcher help"
echo ""
echo "Examples:"
echo " $0 # Hello, World!"
echo " $0 Alice # Hello, Alice!"
echo " $0 --name=Bob --verbose # Verbose greeting for Bob"
echo " $0 Charlie -Xmx1g # Greeting with 1GB heap"
}
# Laptop-friendly defaults (not cluster-scale)
XMX="-Xmx512m" # 512MB max heap - reasonable for laptops
XMS="-Xms256m" # 256MB initial heap
EA="-ea" # Enable assertions by default
VERBOSE=false
# Parse launcher-specific arguments
TOOL_ARGS=()
for arg in "$@"; do
case "$arg" in
--launcher-help)
usage
exit 0
;;
-Xmx*)
XMX="$arg"
;;
-Xms*)
XMS="$arg"
;;
-ea)
EA="-ea"
;;
-da)
EA="-da"
;;
--verbose|-v)
VERBOSE=true
TOOL_ARGS+=("$arg")
;;
*)
# Pass everything else to the tool
TOOL_ARGS+=("$arg")
;;
esac
done
# Comprehensive validation
validate_java_version 8 || exit 1
validate_compiled_classes "$DIR" "hello/HelloTool.class" || exit 1
# Validate memory specifications
for arg in "$@"; do
case "$arg" in
-Xmx*|-Xms*)
validate_memory_spec "$arg" || exit 1
;;
esac
done
# Set classpath
CLASSPATH="$DIR"
# Show execution details if verbose
if [ "$VERBOSE" = true ]; then
echo "🚀 HelloWorld Launcher"
echo " Directory: $DIR"
echo " Classpath: $CLASSPATH"
echo " Memory: $XMS $XMX"
echo " Assertions: $EA"
echo " Tool args: ${TOOL_ARGS[*]}"
echo ""
fi
# Execute the tool
java $XMS $XMX $EA -cp "$CLASSPATH" hello.HelloTool "${TOOL_ARGS[@]}"
# Capture exit code
EXIT_CODE=$?
# Provide helpful error messages for common issues
if [ $EXIT_CODE -ne 0 ]; then
echo "" >&2
echo "🔧 Troubleshooting:" >&2
case $EXIT_CODE in
1)
echo " • Check command-line arguments with --help" >&2
echo " • Verify input parameters are valid" >&2
;;
134)
echo " • Assertion failure detected" >&2
echo " • Try running with -da to disable assertions" >&2
echo " • Check that inputs meet validation requirements" >&2
;;
137)
echo " • Process killed, likely out of memory" >&2
echo " • Try increasing heap size with -Xmx1g or similar" >&2
;;
*)
echo " • Unexpected error occurred" >&2
echo " • Run with --verbose for more details" >&2
;;
esac
fi
exit $EXIT_CODE