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()];
26 // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's
27 // JRE will cause OS X's JavaVM framework to display a dialog and
28 // invoke exit() when loaded via JNI on OS X 10.10
29 NSURL *pTmpURL = [NSURL URLWithString:pString];
31 pTmpURL = [pTmpURL filePathURL];
33 pTmpURL = [pTmpURL URLByStandardizingPath];
35 pTmpURL = [pTmpURL URLByResolvingSymlinksInPath];
38 NSURL *pJVMsDirURL = [NSURL URLWithString:@"file:///Library/Java/JavaVirtualMachines/"];
40 pJVMsDirURL= [pJVMsDirURL filePathURL];
42 pJVMsDirURL = [pJVMsDirURL URLByStandardizingPath];
43 // The JVM directory must not contain softlinks or the JavaVM
44 // framework bug will occur so don't resolve softlinks in the
48 NSString *pTmpURLString = [pTmpURL absoluteString];
49 NSString *pJVMsDirURLString = [pJVMsDirURL absoluteString];
50 if ( pTmpURLString && pJVMsDirURLString && [pJVMsDirURLString length] )
52 NSRange aJVMsDirURLRange = [pTmpURLString rangeOfString:pJVMsDirURLString];
53 if ( !aJVMsDirURLRange.location && aJVMsDirURLRange.length )
61 // Check if this is a valid bundle
63 NSURL *pContentsURL = [pURL URLByAppendingPathComponent:@"Contents"];
64 if ( pContentsURL && [pContentsURL getResourceValue:&pDir forKey:NSURLIsDirectoryKey error:nil] && pDir && [pDir boolValue] )
66 NSBundle *pBundle = [NSBundle bundleWithURL:pURL];
69 // Make sure that this bundle's Info.plist has the
70 // proper JVM keys to supports loading via JNI. If
71 // this bundle is a valid JVM and these keys
72 // are missing, loading the JVM will cause OS X's
73 // JavaVM framework to display a dialog and invoke
74 // exit() when loaded via JNI on OS X 10.10.
75 NSDictionary *pInfo = [pBundle infoDictionary];
78 NSDictionary *pJavaVM = [pInfo objectForKey:@"JavaVM"];
79 if ( pJavaVM && [pJavaVM isKindOfClass:[NSDictionary class]] )
81 NSArray *pJVMCapabilities = [pJavaVM objectForKey:@"JVMCapabilities"];
82 if ( pJVMCapabilities )
84 if ( [pJVMCapabilities indexOfObjectIdenticalTo:@"JNI"] == NSNotFound )
86 if ( [pJVMCapabilities isKindOfClass:[NSMutableArray class]] )
88 [static_cast<NSMutableArray *>(pJVMCapabilities) addObject:@"JNI"];
91 else if ( [pJavaVM isKindOfClass:[NSMutableDictionary class]] )
93 NSMutableArray *pNewJVMCapabilities = [NSMutableArray arrayWithCapacity:[pJVMCapabilities count] + 1];
94 if ( pNewJVMCapabilities )
96 [pNewJVMCapabilities addObject:@"JNI"];
97 [static_cast<NSMutableDictionary *>(pJavaVM) setObject:pNewJVMCapabilities forKey:@"JVMCapabilities"];
112 NSURL *pOldURL = pURL;
113 pURL = [pURL URLByDeletingLastPathComponent];
116 pURL = [pURL URLByStandardizingPath];
119 pURL = [pURL URLByResolvingSymlinksInPath];
120 if ( pURL && [pURL isEqual:pOldURL] )
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */