1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 #include <rtl/ustring.hxx>
6 #import <Foundation/Foundation.h>
9 #import "util_cocoa.hxx"
13 bool JvmfwkUtil_isLoadableJVM( OUString const & aURL )
17 if ( aURL.getLength() )
19 NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
21 NSString *pString = [NSString stringWithCharacters:reinterpret_cast<unichar const *>(aURL.getStr()) length:aURL.getLength()];
24 // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's
25 // JRE will cause macOS's JavaVM framework to display a dialog and
26 // invoke exit() when loaded via JNI on macOS 10.10
27 NSURL *pURL = [NSURL URLWithString:pString];
29 pURL = [pURL filePathURL];
31 pURL = [pURL URLByStandardizingPath];
33 pURL = [pURL URLByResolvingSymlinksInPath];
37 // Check if this is a valid bundle
39 NSURL *pContentsURL = [pURL URLByAppendingPathComponent:@"Contents"];
40 if ( pContentsURL && [pContentsURL getResourceValue:&pDir forKey:NSURLIsDirectoryKey error:nil] && pDir && [pDir boolValue] )
42 NSBundle *pBundle = [NSBundle bundleWithURL:pURL];
45 // Make sure that this bundle's Info.plist has the
46 // proper JVM keys to supports loading via JNI. If
47 // this bundle is a valid JVM and these keys
48 // are missing, loading the JVM will cause macOS's
49 // JavaVM framework to display a dialog and invoke
50 // exit() when loaded via JNI on macOS 10.10.
51 NSDictionary *pInfo = [pBundle infoDictionary];
54 NSDictionary *pJavaVM = [pInfo objectForKey:@"JavaVM"];
55 if ( pJavaVM && [pJavaVM isKindOfClass:[NSDictionary class]] )
57 NSArray *pJVMCapabilities = [pJavaVM objectForKey:@"JVMCapabilities"];
58 if ( pJVMCapabilities )
60 if ( [pJVMCapabilities indexOfObjectIdenticalTo:@"JNI"] == NSNotFound )
62 if ( [pJVMCapabilities isKindOfClass:[NSMutableArray class]] )
64 [static_cast<NSMutableArray *>(pJVMCapabilities) addObject:@"JNI"];
67 else if ( [pJavaVM isKindOfClass:[NSMutableDictionary class]] )
69 NSMutableArray *pNewJVMCapabilities = [NSMutableArray arrayWithCapacity:[pJVMCapabilities count] + 1];
70 if ( pNewJVMCapabilities )
72 [pNewJVMCapabilities addObject:@"JNI"];
73 [static_cast<NSMutableDictionary *>(pJavaVM) setObject:pNewJVMCapabilities forKey:@"JVMCapabilities"];
88 NSURL *pOldURL = pURL;
89 pURL = [pURL URLByDeletingLastPathComponent];
92 pURL = [pURL URLByStandardizingPath];
95 pURL = [pURL URLByResolvingSymlinksInPath];
96 if ( pURL && [pURL isEqual:pOldURL] )
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */