Skip to content

Commit f86427b

Browse files
authored
Merge pull request #2 from AstroImageJ/config-loading-fix
Fix config file not being read
2 parents 8291f39 + e6a8b37 commit f86427b

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/nativeStub.m

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,18 @@ int main(int argc, char** argv) {
105105
}
106106

107107
jvmVersion = javaInfo[@"JVMVersion"];
108-
jvmOptionsFile = javaInfo[@"JVMOptionsFile"];
109-
bootstrapScript = javaInfo[@"BootstrapScript"];
108+
if(javaInfo[@"JVMOptionsFile"] != nil) {
109+
NSString *jvmOptFileWithPlaceholders = javaInfo[@"JVMOptionsFile"];
110+
jvmOptionsFile = resolvePlaceholders(jvmOptFileWithPlaceholders, javaFolder);
111+
} else {
112+
jvmOptionsFile = info[@"JVMOptionsFile"];
113+
}
114+
if(javaInfo[@"BootstrapScript"] != nil) {
115+
NSString *bootstrapFileWithPlaceholders = javaInfo[@"BootstrapScript"];
116+
bootstrapScript = resolvePlaceholders(bootstrapFileWithPlaceholders, javaFolder);
117+
} else {
118+
bootstrapScript = info[@"BootstrapScript"];
119+
}
110120
} else {
111121
NSLog(@"[%s] [PlistStyle] Oracle", appName);
112122
javaFolder = [[main bundlePath] stringByAppendingPathComponent:@"Contents/Java"];
@@ -151,8 +161,18 @@ int main(int argc, char** argv) {
151161
}
152162

153163
jvmVersion = info[@"JVMVersion"];
154-
jvmOptionsFile = info[@"JVMOptionsFile"];
155-
bootstrapScript = info[@"BootstrapScript"];
164+
if(javaInfo[@"JVMOptionsFile"] != nil) {
165+
NSString *jvmOptFileWithPlaceholders = javaInfo[@"JVMOptionsFile"];
166+
jvmOptionsFile = resolvePlaceholders(jvmOptFileWithPlaceholders, javaFolder);
167+
} else {
168+
jvmOptionsFile = info[@"JVMOptionsFile"];
169+
}
170+
if(javaInfo[@"BootstrapScript"] != nil) {
171+
NSString *bootstrapFileWithPlaceholders = javaInfo[@"BootstrapScript"];
172+
bootstrapScript = resolvePlaceholders(bootstrapFileWithPlaceholders, javaFolder);
173+
} else {
174+
bootstrapScript = info[@"BootstrapScript"];
175+
}
156176
}
157177
if([jvmVersion containsString:@";"]) {
158178
NSArray *stringParts = [jvmVersion componentsSeparatedByString:@";"];
@@ -360,6 +380,10 @@ int main(int argc, char** argv) {
360380
NSString *optionsFile = [[NSString alloc] initWithData:[fileManager contentsAtPath:jvmOptionsFile] encoding:NSUTF8StringEncoding];
361381
NSArray *lines = [optionsFile componentsSeparatedByString:@"\n"];
362382
for(NSString *line in lines) {
383+
// Filter empty lines, otherwise application will fail to start for empty file
384+
if ([line length] == 0) {
385+
continue;
386+
}
363387
if([line hasPrefix:@"#"]) {
364388
continue;
365389
}
@@ -447,7 +471,14 @@ - (NSString *)description {
447471
NSString *result = execute(path, @[@"-version"]);
448472
// The actual version will be between the first two quotes in the result
449473
// We can reasonably ignore all the rest of the output
450-
return [result componentsSeparatedByString:@"\""][1];
474+
NSArray *components = [result componentsSeparatedByString:@"\""];
475+
if (components.count > 1) {
476+
return components[1];
477+
} else {
478+
// Handle unexpected format
479+
NSLog(@"Error: Unexpected version string format: %@", result);
480+
return nil;
481+
}
451482
}
452483

453484
NSString *normalizeJavaVersion(NSString *version) {
@@ -521,4 +552,4 @@ BOOL versionMeetsMaxConstraint(NSString *version, NSString *constraint) {
521552
// no modifier means it must match exactly
522553
return !exceeds && [constraintParts count] == [versionParts count];
523554
}
524-
}
555+
}

0 commit comments

Comments
 (0)