-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrun-hdfview.sh
More file actions
executable file
·332 lines (292 loc) · 9.81 KB
/
run-hdfview.sh
File metadata and controls
executable file
·332 lines (292 loc) · 9.81 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
# HDFView Launcher Script
# Validates environment and launches an already-built HDFView application
#
# Build the project first using: mvn clean package -DskipTests
#
# Usage:
# ./run-hdfview.sh # Launch with direct JAR (default)
# ./run-hdfview.sh --debug # Launch with debug logging
# ./run-hdfview.sh --choose # Interactive mode to choose launch method
# ./run-hdfview.sh --maven # Launch with Maven exec:java
# ./run-hdfview.sh --validate # Just validate environment
#
# Requirements:
# - Java 21+
# - Maven 3.6+ (only for --maven mode)
# - HDF5 and HDF4 native libraries (configured in build.properties)
# - HDFView must be built before running this script
#
# Environment variables:
# HDFVIEW_DEBUG=1 # Enable debug logging
set -e # Exit on any error
echo "=== HDFView Environment Check & Launcher ==="
echo
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored messages
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if we're in the right directory
if [[ ! -f "pom.xml" ]] || [[ ! -f "build.properties" ]]; then
print_error "Please run this script from the HDFView project root directory"
print_error "Expected files: pom.xml, build.properties"
exit 1
fi
print_success "Found project files (pom.xml, build.properties)"
# Function to load properties file (converts dots to underscores for bash)
load_properties() {
local prop_file=$1
while IFS='=' read -r key value; do
# Skip comments and empty lines
[[ "$key" =~ ^[[:space:]]*# ]] && continue
[[ -z "$key" ]] && continue
# Trim whitespace from key and value
key=$(echo "$key" | xargs)
value=$(echo "$value" | xargs)
# Skip if still empty after trimming
[[ -z "$key" ]] && continue
# Replace dots with underscores for bash variable names
key=$(echo "$key" | tr '.' '_')
# Export as environment variable
export "$key=$value"
done < "$prop_file"
}
# Load build.properties for validation
if [[ -f "build.properties" ]]; then
print_status "Loading build.properties..."
load_properties "build.properties"
print_success "build.properties loaded"
else
print_error "build.properties file not found!"
exit 1
fi
# Validate Java version
print_status "Checking Java version..."
JAVA_VERSION=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2 | cut -d'.' -f1)
if [[ "$JAVA_VERSION" -ge 21 ]]; then
print_success "Java $JAVA_VERSION detected (Java 21+ required)"
else
print_error "Java 21+ required, found Java $JAVA_VERSION"
exit 1
fi
# Validate Maven
print_status "Checking Maven..."
if command -v mvn &> /dev/null; then
MVN_VERSION=$(mvn -version | head -n 1 | awk '{print $3}')
print_success "Maven $MVN_VERSION found"
else
print_error "Maven not found in PATH"
exit 1
fi
# Check HDF5 libraries (required)
print_status "Checking HDF5 libraries..."
if [[ -n "$hdf5_lib_dir" ]] && [[ -d "$hdf5_lib_dir" ]]; then
print_success "HDF5 library directory found: $hdf5_lib_dir"
# Check for specific HDF5 files
HDF5_FOUND=0
for file in libhdf5.so libhdf5.dylib hdf5.dll libhdf5.a; do
if [[ -f "$hdf5_lib_dir/$file" ]]; then
print_success "Found HDF5 library: $file"
HDF5_FOUND=1
break
fi
done
if [[ $HDF5_FOUND -eq 0 ]]; then
print_warning "HDF5 library files not found in $hdf5_lib_dir"
print_warning "Application may fail to load HDF5 files"
fi
else
print_error "HDF5 library directory not configured or missing: $hdf5_lib_dir"
print_error "Set hdf5.lib.dir in build.properties"
exit 1
fi
# Check HDF5 plugins
if [[ -n "$hdf5_plugin_dir" ]] && [[ -d "$hdf5_plugin_dir" ]]; then
print_success "HDF5 plugin directory found: $hdf5_plugin_dir"
else
print_warning "HDF5 plugin directory not found: $hdf5_plugin_dir"
print_warning "Some HDF5 features may be limited"
fi
# Check HDF4 libraries (optional)
print_status "Checking HDF4 libraries (optional)..."
if [[ -n "$hdf_lib_dir" ]] && [[ -d "$hdf_lib_dir" ]]; then
print_success "HDF4 library directory found: $hdf_lib_dir"
else
print_warning "HDF4 library directory not found: $hdf_lib_dir"
print_warning "HDF4 support will be disabled"
fi
# Check if repository dependencies are installed
print_status "Checking Maven repository dependencies..."
if [[ ! -d "$HOME/.m2/repository/jarhdf/jarhdf" ]]; then
print_error "HDF dependencies not found in Maven repository"
print_error "Build the project first: mvn clean package -DskipTests"
exit 1
else
print_success "Maven repository dependencies found"
fi
# Check if project needs building
print_status "Checking build status..."
HDFVIEW_JAR=$(find libs -name "hdfview-*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" 2>/dev/null | head -n 1)
if [[ ! -d "hdfview/target" ]] || [[ -z "$HDFVIEW_JAR" ]]; then
print_error "HDFView not built - missing hdfview/target or libs/hdfview-*.jar"
print_error "Build the project first: mvn clean package -DskipTests"
exit 1
else
print_success "HDFView JAR found: $(basename "$HDFVIEW_JAR")"
fi
# Check SWT dependencies
print_status "Checking SWT platform support..."
PLATFORM=$(uname -s)
case "$PLATFORM" in
Linux)
print_success "Linux platform detected - SWT GTK support available"
;;
Darwin)
print_success "macOS platform detected - SWT Cocoa support available"
;;
CYGWIN*|MINGW*|MSYS*)
print_success "Windows platform detected - SWT Win32 support available"
;;
*)
print_warning "Unknown platform: $PLATFORM - SWT support may be limited"
;;
esac
echo
print_status "Environment validation complete!"
echo
# Set up runtime environment
export LD_LIBRARY_PATH="$hdf5_lib_dir:$hdf_lib_dir:$LD_LIBRARY_PATH"
export HDF5_PLUGIN_PATH="$hdf5_plugin_dir"
# JVM arguments for proper module access
JVM_ARGS=(
"--add-opens" "java.base/java.lang=ALL-UNNAMED"
"--add-opens" "java.base/java.time=ALL-UNNAMED"
"--add-opens" "java.base/java.time.format=ALL-UNNAMED"
"--add-opens" "java.base/java.util=ALL-UNNAMED"
"--enable-native-access=jarhdf5"
"--enable-native-access=jarhdf"
"-Djava.library.path=$hdf5_lib_dir:$hdf_lib_dir"
)
# Add macOS-specific JVM arguments
if [[ "$PLATFORM" == "Darwin" ]]; then
JVM_ARGS+=(
"-XstartOnFirstThread"
"-Xdock:name=HDFView"
)
print_status "Added macOS-specific JVM arguments (-XstartOnFirstThread, -Xdock:name)"
fi
# Parse command line arguments
SLF4J_IMPL="nop" # Default: no logging
LAUNCH_MODE="jar" # Default: direct JAR execution
for arg in "$@"; do
case $arg in
--debug)
SLF4J_IMPL="simple"
;;
--choose)
LAUNCH_MODE="choose"
;;
--maven)
LAUNCH_MODE="maven"
;;
--validate)
LAUNCH_MODE="validate"
;;
esac
done
# Check environment variable for debug
if [[ "$HDFVIEW_DEBUG" == "1" ]]; then
SLF4J_IMPL="simple"
fi
# Show logging status
if [[ "$SLF4J_IMPL" == "simple" ]]; then
print_status "Debug logging enabled (slf4j-simple)"
else
print_status "Logging disabled (slf4j-nop). Use --debug or HDFVIEW_DEBUG=1 to enable."
fi
# Launch options
if [[ "$LAUNCH_MODE" == "choose" ]]; then
echo
echo "Choose launch method:"
echo "1. Maven exec:java"
echo "2. Direct JAR execution (recommended)"
echo "3. Just validate environment (no launch)"
echo
read -p "Enter choice [1-3]: " CHOICE
else
# Map launch mode to choice number
case $LAUNCH_MODE in
maven)
CHOICE=1
;;
jar)
CHOICE=2
;;
validate)
CHOICE=3
;;
esac
fi
case $CHOICE in
1)
print_status "Launching HDFView via Maven..."
echo "Command: mvn exec:java -Dexec.mainClass=\"hdf.view.HDFView\" -pl hdfview"
echo
mvn exec:java -Dexec.mainClass="hdf.view.HDFView" -pl hdfview
;;
2)
print_status "Launching HDFView via direct JAR execution..."
if [[ -z "$HDFVIEW_JAR" ]]; then
print_error "JAR file not found. Build the project first."
exit 1
fi
if [[ ! -d "hdfview/target/lib" ]]; then
print_error "Dependencies not found: hdfview/target/lib"
print_error "Build the project first: mvn clean package -DskipTests"
exit 1
fi
# Build classpath, excluding slf4j-nop or slf4j-simple based on debug mode
CLASSPATH="$HDFVIEW_JAR"
for jar in hdfview/target/lib/*.jar; do
jarname=$(basename "$jar")
if [[ "$SLF4J_IMPL" == "simple" ]]; then
# Skip nop, include simple
[[ "$jarname" == slf4j-nop* ]] && continue
else
# Skip simple, include nop
[[ "$jarname" == slf4j-simple* ]] && continue
fi
CLASSPATH="$CLASSPATH:$jar"
done
echo "Command: java ${JVM_ARGS[*]} -cp \"...\" hdf.view.HDFView"
echo
java "${JVM_ARGS[@]}" -cp "$CLASSPATH" hdf.view.HDFView
;;
3)
print_success "Environment validation complete. Ready to run HDFView!"
echo
echo "To launch manually:"
echo "Option 1 (Maven): mvn exec:java -Dexec.mainClass=\"hdf.view.HDFView\" -pl hdfview"
echo "Option 2 (JAR): java ${JVM_ARGS[*]} -cp \"$HDFVIEW_JAR:hdfview/target/lib/*\" hdf.view.HDFView"
;;
*)
print_error "Invalid choice. Exiting."
exit 1
;;
esac
print_success "Script completed!"