summaryrefslogtreecommitdiffstats
path: root/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm')
-rw-r--r--jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm109
1 files changed, 109 insertions, 0 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
new file mode 100644
index 000000000..8c745f8d9
--- /dev/null
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+#include <rtl/ustring.hxx>
+
+#include <premac.h>
+#import <Foundation/Foundation.h>
+#include <postmac.h>
+
+#import "util_cocoa.hxx"
+
+using namespace rtl;
+
+bool JvmfwkUtil_isLoadableJVM( OUString const & aURL )
+{
+ bool bRet = false;
+
+ if ( aURL.getLength() )
+ {
+ NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
+
+ NSString *pString = [NSString stringWithCharacters:reinterpret_cast<unichar const *>(aURL.getStr()) length:aURL.getLength()];
+ if ( pString )
+ {
+ // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's
+ // JRE will cause macOS's JavaVM framework to display a dialog and
+ // invoke exit() when loaded via JNI on macOS 10.10
+ NSURL *pURL = [NSURL URLWithString:pString];
+ if ( pURL )
+ pURL = [pURL filePathURL];
+ if ( pURL )
+ pURL = [pURL URLByStandardizingPath];
+ if ( pURL )
+ pURL = [pURL URLByResolvingSymlinksInPath];
+
+ while ( pURL )
+ {
+ // Check if this is a valid bundle
+ NSNumber *pDir = nil;
+ NSURL *pContentsURL = [pURL URLByAppendingPathComponent:@"Contents"];
+ if ( pContentsURL && [pContentsURL getResourceValue:&pDir forKey:NSURLIsDirectoryKey error:nil] && pDir && [pDir boolValue] )
+ {
+ NSBundle *pBundle = [NSBundle bundleWithURL:pURL];
+ if ( pBundle )
+ {
+ // Make sure that this bundle's Info.plist has the
+ // proper JVM keys to supports loading via JNI. If
+ // this bundle is a valid JVM and these keys
+ // are missing, loading the JVM will cause macOS's
+ // JavaVM framework to display a dialog and invoke
+ // exit() when loaded via JNI on macOS 10.10.
+ NSDictionary *pInfo = [pBundle infoDictionary];
+ if ( pInfo )
+ {
+ NSDictionary *pJavaVM = [pInfo objectForKey:@"JavaVM"];
+ if ( pJavaVM && [pJavaVM isKindOfClass:[NSDictionary class]] )
+ {
+ NSArray *pJVMCapabilities = [pJavaVM objectForKey:@"JVMCapabilities"];
+ if ( pJVMCapabilities )
+ {
+ if ( [pJVMCapabilities indexOfObjectIdenticalTo:@"JNI"] == NSNotFound )
+ {
+ if ( [pJVMCapabilities isKindOfClass:[NSMutableArray class]] )
+ {
+ [static_cast<NSMutableArray *>(pJVMCapabilities) addObject:@"JNI"];
+ bRet = true;
+ }
+ else if ( [pJavaVM isKindOfClass:[NSMutableDictionary class]] )
+ {
+ NSMutableArray *pNewJVMCapabilities = [NSMutableArray arrayWithCapacity:[pJVMCapabilities count] + 1];
+ if ( pNewJVMCapabilities )
+ {
+ [pNewJVMCapabilities addObject:@"JNI"];
+ [static_cast<NSMutableDictionary *>(pJavaVM) setObject:pNewJVMCapabilities forKey:@"JVMCapabilities"];
+ bRet = true;
+ }
+ }
+ }
+ else
+ {
+ bRet = true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ NSURL *pOldURL = pURL;
+ pURL = [pURL URLByDeletingLastPathComponent];
+ if ( pURL )
+ {
+ pURL = [pURL URLByStandardizingPath];
+ if ( pURL )
+ {
+ pURL = [pURL URLByResolvingSymlinksInPath];
+ if ( pURL && [pURL isEqual:pOldURL] )
+ pURL = nil;
+ }
+ }
+ }
+ }
+
+ [pPool release];
+ }
+
+ return bRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */