[Libreoffice-commits] core.git: jvmfwk/Library_jvmfwk.mk jvmfwk/plugins
Patrick Luby
pluby at neooffice.org
Wed Nov 4 01:29:48 PST 2015
jvmfwk/Library_jvmfwk.mk | 14 ++
jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 13 ++
jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx | 3
jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 41 ++++--
jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx | 6
jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm | 129 ++++++++++++++++++++
6 files changed, 195 insertions(+), 11 deletions(-)
New commits:
commit 32bc8ddbf335dd26019edcf12758643b4cff9913
Author: Patrick Luby <pluby at neooffice.org>
Date: Sun Oct 4 18:43:11 2015 +0200
tdf#94716 allow Oracle's JDK to be used on OS X 10.10 and 10.11
Change-Id: Ide9b4beebb407e4ceee30f1d99f29d028c848d8c
Reviewed-on: https://gerrit.libreoffice.org/19131
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Norbert Thiebaud <nthiebaud at gmail.com>
diff --git a/jvmfwk/Library_jvmfwk.mk b/jvmfwk/Library_jvmfwk.mk
index 15f1a26..f3373b7 100644
--- a/jvmfwk/Library_jvmfwk.mk
+++ b/jvmfwk/Library_jvmfwk.mk
@@ -54,6 +54,20 @@ $(eval $(call gb_Library_use_externals,jvmfwk,\
valgrind \
))
+ifeq ($(OS),MACOSX)
+$(eval $(call gb_Library_add_cxxflags,jvmfwk,\
+ $(gb_OBJCXXFLAGS) \
+))
+
+$(eval $(call gb_Library_add_objcxxobjects,jvmfwk,\
+ jvmfwk/plugins/sunmajor/pluginlib/util_cocoa \
+))
+
+$(eval $(call gb_Library_add_libs,jvmfwk,\
+ -framework Foundation \
+))
+endif
+
$(eval $(call gb_Library_add_exception_objects,jvmfwk,\
jvmfwk/plugins/sunmajor/pluginlib/gnujre \
jvmfwk/plugins/sunmajor/pluginlib/otherjre \
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 43556e2..6cd5c19 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -54,6 +54,10 @@
#include "vendorlist.hxx"
#include "diagnostics.h"
+#ifdef MACOSX
+#include "util_cocoa.hxx"
+#endif
+
#ifdef ANDROID
#include <osl/detail/android-bootstrap.h>
#else
@@ -655,7 +659,16 @@ javaPluginError jfw_plugin_startJavaVirtualMachine(
//Check if the Vendor (pInfo->sVendor) is supported by this plugin
if ( ! isVendorSupported(pInfo->sVendor))
return JFW_PLUGIN_E_WRONG_VENDOR;
+#ifdef MACOSX
+ rtl::Reference<VendorBase> aVendorInfo = getJREInfoByPath( OUString( pInfo->sLocation ) );
+ if ( !aVendorInfo.is() || aVendorInfo->compareVersions( OUString( pInfo->sVersion ) ) < 0 )
+ return JFW_PLUGIN_E_VM_CREATION_FAILED;
+#endif
OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData);
+#ifdef MACOSX
+ if ( !JvmfwkUtil_isLoadableJVM( sRuntimeLib ) )
+ return JFW_PLUGIN_E_VM_CREATION_FAILED;
+#endif
JFW_TRACE2("Using Java runtime library: " << sRuntimeLib);
#ifndef ANDROID
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx
index e38ecf8..ecd8efc 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx
@@ -62,7 +62,8 @@ char const* const* SunInfo::getRuntimePaths(int * size)
"/bin/server/jvm.dll"
#elif defined MACOSX && defined X86_64
// Oracle Java 7, under /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
- "/lib/server/libjvm.dylib"
+ "/lib/server/libjvm.dylib",
+ "/lib/jli/libjli.dylib"
#elif defined UNX
"/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so",
"/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so",
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
index eb2d513..3463e74 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
@@ -54,6 +54,9 @@
#include "sunjre.hxx"
#include "vendorlist.hxx"
#include "diagnostics.h"
+#ifdef MACOSX
+#include "util_cocoa.hxx"
+#endif
using namespace osl;
using namespace std;
@@ -435,6 +438,8 @@ bool getJavaProps(const OUString & exePath,
}
#ifdef MACOSX
+ if (!JvmfwkUtil_isLoadableJVM(exePath))
+ return false;
if (sClassPath.endsWith("/"))
sClassPath += "../Resources/java/";
else
@@ -1194,21 +1199,36 @@ void addJavaInfosDirScan(
getAndAddJREInfoByPath("file:////usr/jdk/latest", allInfos, addedInfos);
}
-#elif defined MACOSX && defined X86_64
-
-void addJavaInfosDirScan(
- std::vector<rtl::Reference<VendorBase>> & allInfos,
- std::vector<rtl::Reference<VendorBase>> & addedInfos)
-{
- // Oracle Java 7
- getAndAddJREInfoByPath("file:///Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home", allInfos, addedInfos);
-}
-
#else
void addJavaInfosDirScan(
std::vector<rtl::Reference<VendorBase>> & allInfos,
std::vector<rtl::Reference<VendorBase>> & addedInfos)
{
+#ifdef MACOSX
+ // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's JRE
+ // will cause OS X's JavaVM framework to display a dialog and invoke
+ // exit() when loaded via JNI on OS X 10.10
+ Directory aDir("file:///Library/Java/JavaVirtualMachines");
+ if (aDir.open() == File::E_None)
+ {
+ DirectoryItem aItem;
+ while (aDir.getNextItem(aItem) == File::E_None)
+ {
+ FileStatus aStatus(osl_FileStatus_Mask_FileURL);
+ if (aItem.getFileStatus(aStatus) == File::E_None)
+ {
+ OUString aItemURL( aStatus.getFileURL() );
+ if (aItemURL.getLength())
+ {
+ aItemURL += "/Contents/Home";
+ if (DirectoryItem::get(aItemURL, aItem) == File::E_None)
+ getAndAddJREInfoByPath(aItemURL, allInfos, addedInfos);
+ }
+ }
+ }
+ aDir.close();
+ }
+#else // MACOSX
OUString excMessage = "[Java framework] sunjavaplugin: "
"Error in function addJavaInfosDirScan in util.cxx.";
int cJavaNames= sizeof(g_arJavaNames) / sizeof(char*);
@@ -1322,6 +1342,7 @@ void addJavaInfosDirScan(
}
}
}
+#endif // MACOSX
}
#endif // ifdef SOLARIS
#endif // ifdef UNX
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx
new file mode 100644
index 0000000..9a7c7b9
--- /dev/null
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx
@@ -0,0 +1,6 @@
+#ifndef __UTIL_COCOA_H__
+#define __UTIL_COCOA_H__
+
+bool JvmfwkUtil_isLoadableJVM( OUString aURL );
+
+#endif
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
new file mode 100644
index 0000000..47bab8c
--- /dev/null
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm
@@ -0,0 +1,129 @@
+#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 aURL )
+{
+ bool bRet = false;
+
+ if ( aURL.getLength() )
+ {
+ NSAutoreleasePool *pPool = [[NSAutoreleasePool alloc] init];
+
+ NSString *pString = [NSString stringWithCharacters:aURL.getStr() length:aURL.getLength()];
+ if ( pString )
+ {
+ NSURL *pURL = nil;
+
+ // Ignore all but Oracle's JDK as loading Apple's Java and Oracle's
+ // JRE will cause OS X's JavaVM framework to display a dialog and
+ // invoke exit() when loaded via JNI on OS X 10.10
+ NSURL *pTmpURL = [NSURL URLWithString:pString];
+ if ( pTmpURL )
+ pTmpURL = [pTmpURL filePathURL];
+ if ( pTmpURL )
+ pTmpURL = [pTmpURL URLByStandardizingPath];
+ if ( pTmpURL )
+ pTmpURL = [pTmpURL URLByResolvingSymlinksInPath];
+ if ( pTmpURL )
+ {
+ NSURL *pJVMsDirURL = [NSURL URLWithString:@"file:///Library/Java/JavaVirtualMachines/"];
+ if ( pJVMsDirURL )
+ pJVMsDirURL= [pJVMsDirURL filePathURL];
+ if ( pJVMsDirURL )
+ pJVMsDirURL = [pJVMsDirURL URLByStandardizingPath];
+ // The JVM directory must not contain softlinks or the JavaVM
+ // framework bug will occur so don't resolve softlinks in the
+ // JVM directory
+ if ( pJVMsDirURL )
+ {
+ NSString *pTmpURLString = [pTmpURL absoluteString];
+ NSString *pJVMsDirURLString = [pJVMsDirURL absoluteString];
+ if ( pTmpURLString && pJVMsDirURLString && [pJVMsDirURLString length] )
+ {
+ NSRange aJVMsDirURLRange = [pTmpURLString rangeOfString:pJVMsDirURLString];
+ if ( !aJVMsDirURLRange.location && aJVMsDirURLRange.length )
+ pURL = pTmpURL;
+ }
+ }
+ }
+
+ 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 OS X's
+ // JavaVM framework to display a dialog and invoke
+ // exit() when loaded via JNI on OS X 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]] )
+ {
+ [(NSMutableArray *)pJVMCapabilities addObject:@"JNI"];
+ bRet = true;
+ }
+ else if ( [pJavaVM isKindOfClass:[NSMutableDictionary class]] )
+ {
+ NSMutableArray *pNewJVMCapabilities = [NSMutableArray arrayWithCapacity:[pJVMCapabilities count] + 1];
+ if ( pNewJVMCapabilities )
+ {
+ [pNewJVMCapabilities addObject:@"JNI"];
+ [(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;
+}
More information about the Libreoffice-commits
mailing list