Skip to content

Commit f5065c3

Browse files
author
gkbrown
committed
Localize JavaAppLauncher error messages.
git-svn-id: https://svn.java.net/svn/appbundler~svn@28 07572b26-92e5-4d45-f66a-c18421440a21
1 parent 0d04d59 commit f5065c3

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

appbundler/native/main.m

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#define JVM_OPTIONS_KEY "JVMOptions"
3636
#define JVM_ARGUMENTS_KEY "JVMArguments"
3737

38+
#define UNSPECIFIED_ERROR "An unknown error occurred."
39+
3840
#define APP_ROOT_PREFIX "$APP_ROOT"
3941

4042
#define LIBJLI_DYLIB "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib"
@@ -61,7 +63,11 @@ int main(int argc, char *argv[]) {
6163
launch(argv[0]);
6264
result = 0;
6365
} @catch (NSException *exception) {
64-
NSLog(@"%@: %@", exception, [exception callStackSymbols]);
66+
NSAlert *alert = [[NSAlert alloc] init];
67+
[alert setAlertStyle:NSCriticalAlertStyle];
68+
[alert setMessageText:[exception reason]];
69+
[alert runModal];
70+
6571
result = 1;
6672
}
6773

@@ -91,7 +97,9 @@ int launch(char *commandName) {
9197
NSError *bundleLoadError = nil;
9298
Boolean runtimeBundleLoaded = CFBundleLoadExecutableAndReturnError(runtimeBundle, (CFErrorRef *)&bundleLoadError);
9399
if (bundleLoadError != nil || !runtimeBundleLoaded) {
94-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"Could not load JRE from %@.", bundleLoadError];
100+
[[NSException exceptionWithName:@JAVA_LAUNCH_ERROR
101+
reason:NSLocalizedString(@"JRELoadError", @UNSPECIFIED_ERROR)
102+
userInfo:nil] raise];
95103
}
96104

97105
jli_LaunchFxnPtr = CFBundleGetFunctionPointerForName(runtimeBundle, CFSTR("JLI_Launch"));
@@ -103,13 +111,17 @@ int launch(char *commandName) {
103111
}
104112

105113
if (jli_LaunchFxnPtr == NULL) {
106-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"Could not get function pointer for JLI_Launch."];
114+
[[NSException exceptionWithName:@JAVA_LAUNCH_ERROR
115+
reason:NSLocalizedString(@"JRENotFound", @UNSPECIFIED_ERROR)
116+
userInfo:nil] raise];
107117
}
108118

109119
// Get the main class name
110120
NSString *mainClassName = [infoDictionary objectForKey:@JVM_MAIN_CLASS_NAME_KEY];
111121
if (mainClassName == nil) {
112-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"%@ is required.", @JVM_MAIN_CLASS_NAME_KEY];
122+
[[NSException exceptionWithName:@JAVA_LAUNCH_ERROR
123+
reason:NSLocalizedString(@"MainClassNameRequired", @UNSPECIFIED_ERROR)
124+
userInfo:nil] raise];
113125
}
114126

115127
// Set the class path
@@ -120,7 +132,9 @@ int launch(char *commandName) {
120132
NSFileManager *defaultFileManager = [NSFileManager defaultManager];
121133
NSArray *javaDirectoryContents = [defaultFileManager contentsOfDirectoryAtPath:javaPath error:nil];
122134
if (javaDirectoryContents == nil) {
123-
[NSException raise:@JAVA_LAUNCH_ERROR format:@"Could not enumerate Java directory contents."];
135+
[[NSException exceptionWithName:@JAVA_LAUNCH_ERROR
136+
reason:NSLocalizedString(@"JavaDirectoryNotFound", @UNSPECIFIED_ERROR)
137+
userInfo:nil] raise];
124138
}
125139

126140
for (NSString *file in javaDirectoryContents) {
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
"JRENotFound" = "A Java runtime environment could not be located."
1+
"JRELoadError" = "Could not load JRE.";
2+
"JRENotFound" = "A Java runtime environment could not be located.";
3+
"MainClassNameRequired" = "Main class name is required.";
4+
"JavaDirectoryNotFound" = "Could not enumerate Java directory contents.";

0 commit comments

Comments
 (0)