From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- jvmfwk/CppunitTest_jvmfwk_sunversion.mk | 40 + jvmfwk/CustomTarget_jreproperties.mk | 23 + jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk | 38 + jvmfwk/Executable_javaldx.mk | 21 + jvmfwk/IwyuFilter_jvmfwk.yaml | 36 + jvmfwk/Library_jvmfwk.mk | 87 ++ jvmfwk/Makefile | 14 + jvmfwk/Module_jvmfwk.mk | 37 + jvmfwk/Package_jreproperties.mk | 14 + jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk | 16 + jvmfwk/Package_rcfiles.mk | 30 + jvmfwk/README.md | 20 + jvmfwk/distributions/OpenOfficeorg/javavendors.xsd | 61 + .../OpenOfficeorg/javavendors_freebsd.xml | 32 + .../OpenOfficeorg/javavendors_linux.xml | 44 + .../OpenOfficeorg/javavendors_macosx.xml | 38 + .../OpenOfficeorg/javavendors_macosx_aarch64.xml | 11 + .../OpenOfficeorg/javavendors_unx.xml | 29 + .../OpenOfficeorg/javavendors_wnt.xml | 38 + jvmfwk/inc/elements.hxx | 329 +++++ jvmfwk/inc/fwkbase.hxx | 130 ++ jvmfwk/inc/fwkutil.hxx | 77 ++ jvmfwk/inc/libxmlutil.hxx | 101 ++ jvmfwk/inc/vendorbase.hxx | 182 +++ jvmfwk/inc/vendorplugin.hxx | 245 ++++ jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx | 160 +++ .../plugins/sunmajor/pluginlib/JREProperties.java | 62 + jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h | 35 + jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx | 43 + .../plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 900 ++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx | 116 ++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx | 42 + jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx | 303 +++++ jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 1281 ++++++++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/util.hxx | 116 ++ jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx | 14 + jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm | 109 ++ jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx | 197 +++ jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx | 52 + jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx | 49 + jvmfwk/qa/unit/sunversion.cxx | 128 ++ jvmfwk/source/elements.cxx | 971 +++++++++++++++ jvmfwk/source/framework.cxx | 749 ++++++++++++ jvmfwk/source/framework.hxx | 41 + jvmfwk/source/fwkbase.cxx | 524 ++++++++ jvmfwk/source/fwkutil.cxx | 194 +++ jvmfwk/source/javasettings.xsd | 70 ++ jvmfwk/source/javasettings_template.xml | 52 + jvmfwk/source/libxmlutil.cxx | 136 +++ 51 files changed, 8267 insertions(+) create mode 100644 jvmfwk/CppunitTest_jvmfwk_sunversion.mk create mode 100644 jvmfwk/CustomTarget_jreproperties.mk create mode 100644 jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk create mode 100644 jvmfwk/Executable_javaldx.mk create mode 100644 jvmfwk/IwyuFilter_jvmfwk.yaml create mode 100644 jvmfwk/Library_jvmfwk.mk create mode 100644 jvmfwk/Makefile create mode 100644 jvmfwk/Module_jvmfwk.mk create mode 100644 jvmfwk/Package_jreproperties.mk create mode 100644 jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk create mode 100644 jvmfwk/Package_rcfiles.mk create mode 100644 jvmfwk/README.md create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors.xsd create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_macosx.xml create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_macosx_aarch64.xml create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml create mode 100644 jvmfwk/distributions/OpenOfficeorg/javavendors_wnt.xml create mode 100644 jvmfwk/inc/elements.hxx create mode 100644 jvmfwk/inc/fwkbase.hxx create mode 100644 jvmfwk/inc/fwkutil.hxx create mode 100644 jvmfwk/inc/libxmlutil.hxx create mode 100644 jvmfwk/inc/vendorbase.hxx create mode 100644 jvmfwk/inc/vendorplugin.hxx create mode 100644 jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx create mode 100644 jvmfwk/qa/unit/sunversion.cxx create mode 100644 jvmfwk/source/elements.cxx create mode 100644 jvmfwk/source/framework.cxx create mode 100644 jvmfwk/source/framework.hxx create mode 100644 jvmfwk/source/fwkbase.cxx create mode 100644 jvmfwk/source/fwkutil.cxx create mode 100644 jvmfwk/source/javasettings.xsd create mode 100644 jvmfwk/source/javasettings_template.xml create mode 100644 jvmfwk/source/libxmlutil.cxx (limited to 'jvmfwk') diff --git a/jvmfwk/CppunitTest_jvmfwk_sunversion.mk b/jvmfwk/CppunitTest_jvmfwk_sunversion.mk new file mode 100644 index 000000000..8aa6a2c68 --- /dev/null +++ b/jvmfwk/CppunitTest_jvmfwk_sunversion.mk @@ -0,0 +1,40 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,jvmfwk_sunversion)) + +$(eval $(call gb_CppunitTest_add_exception_objects,jvmfwk_sunversion, \ + jvmfwk/qa/unit/sunversion \ +)) + +$(eval $(call gb_CppunitTest_set_include,jvmfwk_sunversion, \ + $$(INCLUDE) \ + -I$(SRCDIR) \ +)) + +$(eval $(call gb_CppunitTest_use_externals,jvmfwk_sunversion, \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,jvmfwk_sunversion, \ + sal \ + salhelper \ +)) + +$(eval $(call gb_CppunitTest_use_library_objects,jvmfwk_sunversion, \ + jvmfwk \ +)) + +ifeq ($(OS),MACOSX) +$(eval $(call gb_CppunitTest_use_system_darwin_frameworks,jvmfwk_sunversion, \ + Foundation \ +)) +endif + +# vim: set noet sw=4 ts=4: diff --git a/jvmfwk/CustomTarget_jreproperties.mk b/jvmfwk/CustomTarget_jreproperties.mk new file mode 100644 index 000000000..da509dbff --- /dev/null +++ b/jvmfwk/CustomTarget_jreproperties.mk @@ -0,0 +1,23 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CustomTarget_CustomTarget,jvmfwk/jreproperties)) + +$(call gb_CustomTarget_get_target,jvmfwk/jreproperties) : $(call gb_CustomTarget_get_workdir,jvmfwk/jreproperties)/JREProperties.class + +$(call gb_CustomTarget_get_workdir,jvmfwk/jreproperties)/JREProperties.class : \ + $(SRCDIR)/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java \ + | $(call gb_CustomTarget_get_workdir,jvmfwk/jreproperties)/.dir + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),JCS,1) + $(call gb_Trace_StartRange,$(subst $(WORKDIR)/,,$@),JCS) + $(call gb_Helper_abbreviate_dirs, \ + cd $(dir $@) && $(call gb_JavaClassSet_JAVACCOMMAND,$(JAVA_TARGET_VER)) $(gb_JavaClassSet_JAVACDEBUG) -d $(dir $@) $^) + $(call gb_Trace_EndRange,$(subst $(WORKDIR)/,,$@),JCS) + +# vim:set shiftwidth=4 tabstop=4 noexpandtab: diff --git a/jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk b/jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk new file mode 100644 index 000000000..bd9621fd2 --- /dev/null +++ b/jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk @@ -0,0 +1,38 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +$(eval $(call gb_CustomTarget_CustomTarget,jvmfwk/jvmfwk3_ini)) + +$(eval $(call gb_CustomTarget_register_targets,jvmfwk/jvmfwk3_ini, \ + $(call gb_Helper_get_rcfile,jvmfwk3) \ +)) + +$(call gb_CustomTarget_get_workdir,jvmfwk/jvmfwk3_ini)/$(call gb_Helper_get_rcfile,jvmfwk3): \ + $(SRCDIR)/jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),$(true),ECH,1) + $(call gb_Trace_StartRange,$(subst $(WORKDIR)/,,$@),ECH) + ( printf '[Bootstrap]\n' && \ + printf 'UNO_JAVA_JFW_VENDOR_SETTINGS=$(if $(filter MACOSX,$(OS)),$${ORIGIN}/../share/misc/,$${ORIGIN}/)javavendors.xml\n' && \ + printf 'UNO_JAVA_JFW_SHARED_DATA=$${URE_OVERRIDE_JAVA_JFW_SHARED_DATA}\n' && \ + printf 'UNO_JAVA_JFW_USER_DATA=$${URE_OVERRIDE_JAVA_JFW_USER_DATA}\n' && \ + printf 'UNO_JAVA_JFW_CLASSPATH_URLS=$${URE_MORE_JAVA_CLASSPATH_URLS}\n' \ + ) > $@ + $(call gb_Trace_EndRange,$(subst $(WORKDIR)/,,$@),ECH) + +# vim: set noet sw=4 ts=4: diff --git a/jvmfwk/Executable_javaldx.mk b/jvmfwk/Executable_javaldx.mk new file mode 100644 index 000000000..ab5ae8abe --- /dev/null +++ b/jvmfwk/Executable_javaldx.mk @@ -0,0 +1,21 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Executable_Executable,javaldx)) + +$(eval $(call gb_Executable_use_libraries,javaldx,\ + jvmfwk \ + sal \ +)) + +$(eval $(call gb_Executable_add_exception_objects,javaldx,\ + jvmfwk/plugins/sunmajor/javaenvsetup/javaldx \ +)) + +# vim:set noet sw=4 ts=4: diff --git a/jvmfwk/IwyuFilter_jvmfwk.yaml b/jvmfwk/IwyuFilter_jvmfwk.yaml new file mode 100644 index 000000000..bfca82b3d --- /dev/null +++ b/jvmfwk/IwyuFilter_jvmfwk.yaml @@ -0,0 +1,36 @@ +--- +assumeFilename: jvmfwk/source/fwkbase.cxx +excludelist: + jvmfwk/inc/fwkutil.hxx: + # Needed on MACOSX + - config_folders.h + # Don't replace with URE impl. detail + - rtl/byteseq.hxx + jvmfwk/inc/vendorbase.hxx: + # OSL_BIGENDIAN is being checked + - osl/endian.h + jvmfwk/source/framework.cxx: + # Don't replace with URE impl. detail + - osl/thread.hxx + jvmfwk/source/fwkbase.cxx: + # Don't replace with URE impl. detail + - osl/thread.hxx + jvmfwk/source/fwkutil.cxx: + # Needed on WIN32 + - sal/log.hxx + jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx: + # Don't replace with URE impl. detail + - rtl/byteseq.hxx + jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx: + # Needed on WIN32 + - o3tl/char16_t2wchar_t.hxx + - string_view + # Don't replace with URE impl. detail + - osl/thread.hxx + # Don't replace with bits/types, needed for sig_atomic_t + - signal.h + jvmfwk/plugins/sunmajor/pluginlib/util.cxx: + # Needed on MACOSX + - config_folders.h + # Don't replace with URE impl. detail + - osl/module.hxx diff --git a/jvmfwk/Library_jvmfwk.mk b/jvmfwk/Library_jvmfwk.mk new file mode 100644 index 000000000..64a6b9d8e --- /dev/null +++ b/jvmfwk/Library_jvmfwk.mk @@ -0,0 +1,87 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Library_Library,jvmfwk)) + +$(eval $(call gb_Library_add_defs,jvmfwk,\ + -DJVMFWK_DLLIMPLEMENTATION \ +)) + +ifneq ($(JVM_ONE_PATH_CHECK),) +$(eval $(call gb_Library_add_defs,jvmfwk,\ + -DJVM_ONE_PATH_CHECK=\"$(JVM_ONE_PATH_CHECK)\" \ +)) +endif + +$(eval $(call gb_Library_set_include,jvmfwk,\ + -I$(SRCDIR)/jvmfwk/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Library_use_api,jvmfwk,\ + udkapi \ +)) + +$(eval $(call gb_Library_use_libraries,jvmfwk,\ + cppu \ + cppuhelper \ + sal \ + salhelper \ +)) + +ifeq ($(OS),ANDROID) +$(eval $(call gb_Library_use_libraries,jvmfwk,\ + lo-bootstrap \ +)) +endif + +ifeq ($(OS),WNT) +$(eval $(call gb_Library_use_system_win32_libs,jvmfwk,\ + advapi32 \ +)) +endif + +$(eval $(call gb_Library_use_externals,jvmfwk,\ + boost_headers \ + libxml2 \ + valgrind \ +)) + +ifeq ($(OS),MACOSX) +$(eval $(call gb_Library_add_cxxflags,jvmfwk,\ + $(gb_OBJCXXFLAGS) \ +)) + +ifeq ($(CPUNAME),X86_64) +$(eval $(call gb_Library_add_objcxxobjects,jvmfwk,\ + jvmfwk/plugins/sunmajor/pluginlib/util_cocoa \ +)) +endif + +$(eval $(call gb_Library_add_libs,jvmfwk,\ + -framework Foundation \ +)) +endif + +$(eval $(call gb_Library_add_exception_objects,jvmfwk,\ + jvmfwk/plugins/sunmajor/pluginlib/otherjre \ + jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin \ + jvmfwk/plugins/sunmajor/pluginlib/sunjre \ + jvmfwk/plugins/sunmajor/pluginlib/sunversion \ + jvmfwk/plugins/sunmajor/pluginlib/util \ + jvmfwk/plugins/sunmajor/pluginlib/vendorbase \ + jvmfwk/plugins/sunmajor/pluginlib/vendorlist \ + jvmfwk/source/elements \ + jvmfwk/source/framework \ + jvmfwk/source/fwkbase \ + jvmfwk/source/fwkutil \ + jvmfwk/source/libxmlutil \ +)) + +# vim:set noet sw=4 ts=4: diff --git a/jvmfwk/Makefile b/jvmfwk/Makefile new file mode 100644 index 000000000..0997e6284 --- /dev/null +++ b/jvmfwk/Makefile @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/jvmfwk/Module_jvmfwk.mk b/jvmfwk/Module_jvmfwk.mk new file mode 100644 index 000000000..802daed57 --- /dev/null +++ b/jvmfwk/Module_jvmfwk.mk @@ -0,0 +1,37 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Module_Module,jvmfwk)) + +ifeq ($(ENABLE_JAVA),TRUE) + +$(eval $(call gb_Module_add_targets,jvmfwk,\ + CustomTarget_jreproperties \ + CustomTarget_jvmfwk_jvmfwk3_ini \ + Library_jvmfwk \ + Package_jreproperties \ + Package_jvmfwk_jvmfwk3_ini \ + Package_rcfiles \ +)) + +ifneq (,$(filter-out MACOSX WNT,$(OS))) +ifneq (,$(filter DESKTOP,$(BUILD_TYPE))) +$(eval $(call gb_Module_add_targets,jvmfwk,\ + Executable_javaldx \ +)) +endif +endif + +$(eval $(call gb_Module_add_check_targets,jvmfwk, \ + CppunitTest_jvmfwk_sunversion \ +)) + +endif + +# vim:set noet sw=4 ts=4: diff --git a/jvmfwk/Package_jreproperties.mk b/jvmfwk/Package_jreproperties.mk new file mode 100644 index 000000000..cd12402c6 --- /dev/null +++ b/jvmfwk/Package_jreproperties.mk @@ -0,0 +1,14 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Package_Package,jvmfwk_jreproperties,$(call gb_CustomTarget_get_workdir,jvmfwk/jreproperties))) + +$(eval $(call gb_Package_add_file,jvmfwk_jreproperties,$(if $(filter MACOSX,$(OS)),$(LIBO_URE_SHARE_JAVA_FOLDER),$(LIBO_URE_LIB_FOLDER))/JREProperties.class,JREProperties.class)) + +# vim:set noet sw=4 ts=4: diff --git a/jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk b/jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk new file mode 100644 index 000000000..51a933cea --- /dev/null +++ b/jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Package_Package,jvmfwk_jvmfwk3_ini,$(call gb_CustomTarget_get_workdir,jvmfwk/jvmfwk3_ini))) + +$(eval $(call gb_Package_add_files,jvmfwk_jvmfwk3_ini,$(LIBO_URE_ETC_FOLDER), \ + $(call gb_Helper_get_rcfile,jvmfwk3) \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/jvmfwk/Package_rcfiles.mk b/jvmfwk/Package_rcfiles.mk new file mode 100644 index 000000000..e7010b970 --- /dev/null +++ b/jvmfwk/Package_rcfiles.mk @@ -0,0 +1,30 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Package_Package,jvmfwk_javavendors,$(SRCDIR)/jvmfwk)) + +ifeq ($(OS),WNT) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_wnt.xml)) +else ifeq ($(OS),FREEBSD) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_freebsd.xml)) +else ifeq ($(OS),MACOSX) +ifeq ($(CPUNAME),AARCH64) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_macosx_aarch64.xml)) +else +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_macosx.xml)) +endif +else ifeq ($(OS),LINUX) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_linux.xml)) +else ifeq ($(OS),AIX) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_linux.xml)) +else +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_unx.xml)) +endif + +# vim:set noet sw=4 ts=4: diff --git a/jvmfwk/README.md b/jvmfwk/README.md new file mode 100644 index 000000000..3f99d9dba --- /dev/null +++ b/jvmfwk/README.md @@ -0,0 +1,20 @@ +# JVM Framework Wrappers + +Wrappers so you can use all the Java Runtime Environments with their slightly incompatible APIs with more ease. + +Used to use an over-engineered "plugin" mechanism although there was only one +"plugin", called "sunmajor", that handles all possible JREs. + +IMPORTANT: The `` element in `vmfwk/distributions/OpenOfficeorg/javavendors_*.xml` files +should only be updated for incompatible changes, not for compatible ones. As stated in the commit +message of in LibreOffice gerrit: + +javavendors\_\*.xml <updated\> should not have been updated... + +Changing `` causes `jfw_startVM` and `jfw_getSelectedJRE` (both +`jvmfwk/source/framework.cxx`) to fail with `JFW_E_INVALID_SETTINGS`, which in turn causes functionality +that requires a JVM to issue a GUI error dialog stating that the user must select a new JRE in the +Options dialog. While that behavior makes sense if a JRE was selected that would no longer be +supported by the modified `javavendors_*.xml`, it is just annoying if an already selected JRE is still +supported. And a compatible change to `javavendors_*.xml` implies that an already selected JRE will +still be supported." diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors.xsd b/jvmfwk/distributions/OpenOfficeorg/javavendors.xsd new file mode 100644 index 000000000..fbc643f71 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors.xsd @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml new file mode 100644 index 000000000..b7776db58 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.xml @@ -0,0 +1,32 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml new file mode 100644 index 000000000..09fcf3733 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml @@ -0,0 +1,44 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx.xml new file mode 100644 index 000000000..a10e366f5 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx.xml @@ -0,0 +1,38 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx_aarch64.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx_aarch64.xml new file mode 100644 index 000000000..329030ccb --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx_aarch64.xml @@ -0,0 +1,11 @@ + + + + 2021-10-19 + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml new file mode 100644 index 000000000..9eab9d832 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml @@ -0,0 +1,29 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + diff --git a/jvmfwk/distributions/OpenOfficeorg/javavendors_wnt.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_wnt.xml new file mode 100644 index 000000000..d37db0a16 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_wnt.xml @@ -0,0 +1,38 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + 1.8.0 + + + diff --git a/jvmfwk/inc/elements.hxx b/jvmfwk/inc/elements.hxx new file mode 100644 index 000000000..3fde096c4 --- /dev/null +++ b/jvmfwk/inc/elements.hxx @@ -0,0 +1,329 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX +#define INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX + +#include + +#include +#include +#include "fwkutil.hxx" +#include +#include +#include +#include + +struct JavaInfo; + +#define NS_JAVA_FRAMEWORK "http://openoffice.org/2004/java/framework/1.0" +#define NS_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance" + +namespace jfw +{ +/** gets the value of the updated element from the javavendors.xml. + */ +OString getElementUpdated(); + +/** create the child elements within the root structure for each platform. + + @param bNeedsSave + [out]If true then the respective structure of elements was added and the + document needs to be saved. + */ +void createSettingsStructure(xmlDoc* document, bool* bNeedsSave); + +/** represents the settings saved in the /java/javaInfo element. + It is used within class NodeJava which determines the settings + file. +*/ +class CNodeJavaInfo +{ +public: + CNodeJavaInfo(); + + /** if true, then javaInfo is empty. When writeToNode is called + then all child elements are deleted. + */ + bool m_bEmptyNode; + /** Contains the value of the element of + the javavendors.xml after loadFromNode was called. + It is not used, when the javaInfo node is written. + see writeToNode + */ + OString sAttrVendorUpdate; + /** contains the nil value of the /java/javaInfo@xsi:nil attribute. + Default is true; + */ + bool bNil; + /** contains the value of the /java/javaInfo@autoSelect attribute. + Default is true. If it is false then the user has modified the JRE + selection by actively choosing a JRE from the options dialog. That is, + the function jfw_setSelectedJRE was called. Contrary, the function + jfw_findAndSelectJRE sets the attribute to true. + */ + bool bAutoSelect; + OUString sVendor; + OUString sLocation; + OUString sVersion; + sal_uInt64 nRequirements; + ::rtl::ByteSequence arVendorData; + + /** reads the node /java/javaInfo. + If javaInfo@xsi:nil = true then member bNil is set to true + and no further elements are read. + */ + void loadFromNode(xmlDoc* pDoc, xmlNode* pJavaInfo); + /** The attribute nil will be set to false. The function gets the value + javaSettings/updated from the javavendors.xml and writes it to + javaInfo@vendorUpdate in javasettings.xml + */ + void writeToNode(xmlDoc* pDoc, xmlNode* pJavaInfo) const; + + /** returns NULL if javaInfo is nil. + */ + std::unique_ptr makeJavaInfo() const; +}; + +/** this class represents the java settings based on a particular + settings file. + + Which settings file is used is determined by the value passed into the + constructor and the values of the bootstrap parameters + UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA. + + The method load reads the data from the settings file. + The method write stores the data into the settings file. + */ +class NodeJava +{ +public: + enum Layer + { + USER, + SHARED + }; + +private: + /** creates settings file and fills it with default values. + + When this function is called then it creates the + settings file at the position determined by the bootstrap parameters + (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA) and m_layer, unless + the file already exists (see createSettingsDocument). + + @return + JFW_E_CONFIG_READWRITE + */ + bool prepareSettingsDocument() const; + + /** helper function for prepareSettingsDocument. + */ + bool createSettingsDocument() const; + + /** returns the system path to the data file which is to be used. The value + depends on the member m_layer and the bootstrap parameters + UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA. + */ + OString getSettingsPath() const; + + /** returns the file URL to the data file which is to be used. See getSettingsPath. + */ + OUString getSettingsURL() const; + + /** Verifies if the respective settings file exist. + */ + static jfw::FileStatus checkSettingsFileStatus(OUString const& sURL); + + /** Determines the layer for which the instance the loads and writes the + data. + */ + Layer m_layer; + + /** User configurable option. /java/enabled + If /java/enabled@xsi:nil == true then the value will be uninitialized + after a call to load(). + */ + std::optional m_enabled; + + /** User configurable option. /java/userClassPath + If /java/userClassPath@xsi:nil == true then the value is uninitialized + after a call to load(). + */ + std::optional m_userClassPath; + /** User configurable option. /java/javaInfo + If /java/javaInfo@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional m_javaInfo; + /** User configurable option. /java/vmParameters + If /java/vmParameters@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional<::std::vector> m_vmParameters; + /** User configurable option. /java/jreLocations + If /java/jreLocations@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional<::std::vector> m_JRELocations; + +public: + explicit NodeJava(Layer theLayer); + + /** sets m_enabled. + /java/enabled@xsi:nil will be set to false when write is called. + */ + void setEnabled(bool bEnabled); + + /** sets m_sUserClassPath. See setEnabled. + */ + void setUserClassPath(const OUString& sClassPath); + + /** sets m_aInfo. See setEnabled. + @param bAutoSelect + true- called by jfw_setSelectedJRE + false called by jfw_findAndSelectJRE + */ + void setJavaInfo(const JavaInfo* pInfo, bool bAutoSelect); + + /** sets the /java/vmParameters/param elements. + When this method all previous values are removed and replaced + by those in arParameters. + /java/vmParameters@xsi:nil will be set to true when write() is + called. + */ + void setVmParameters(std::vector const& arParameters); + + /** adds a location to the already existing locations. + Note: call load() before, then add the location and then call write(). + */ + void addJRELocation(OUString const& sLocation); + + /** writes the data to user settings. + */ + void write() const; + + /** load the values of the settings file. + */ + void load(); + + /** returns the value of the element /java/enabled + */ + const std::optional& getEnabled() const { return m_enabled; } + /** returns the value of the element /java/userClassPath. + */ + const std::optional& getUserClassPath() const { return m_userClassPath; } + + /** returns the value of the element /java/javaInfo. + */ + const std::optional& getJavaInfo() const { return m_javaInfo; } + + /** returns the parameters from the element /java/vmParameters/param. + */ + const std::optional<::std::vector>& getVmParameters() const { return m_vmParameters; } + + /** returns the parameters from the element /java/jreLocations/location. + */ + const std::optional<::std::vector>& getJRELocations() const { return m_JRELocations; } +}; + +/** merges the settings for shared, user and installation during construction. + The class uses a simple merge mechanism for the javasettings.xml files in share and + user. The following elements completely overwrite the corresponding elements + from share: + /java/enabled + /java/userClassPath + /java/vmParameters + /java/jreLocations + /java/javaInfo + + In case of an installation, the shared and user settings are completely + disregarded. + + The locations of the different settings files is obtained through the + bootstrap variables: + UNO_JAVA_JFW_USER_DATA + UNO_JAVA_JFW_SHARED_DATA + + The class also determines useful default values for settings which have not been made. +*/ +class MergedSettings final +{ +private: + MergedSettings& operator=(MergedSettings const&) = delete; + MergedSettings(MergedSettings const&) = delete; + + void merge(const NodeJava& share, const NodeJava& user); + + bool m_bEnabled; + + OUString m_sClassPath; + + ::std::vector m_vmParams; + + ::std::vector m_JRELocations; + + CNodeJavaInfo m_javaInfo; + +public: + MergedSettings(); + ~MergedSettings(); + + /** the default is true. + */ + bool getEnabled() const { return m_bEnabled; } + + const OUString& getUserClassPath() const { return m_sClassPath; } + + ::std::vector getVmParametersUtf8() const; + /** returns a JavaInfo structure representing the node + /java/javaInfo. Every time a new JavaInfo structure is created + which needs to be freed by the caller. + If both, user and share settings are nil, then NULL is returned. + */ + std::unique_ptr createJavaInfo() const; + + /** returns the value of the attribute /java/javaInfo[@vendorUpdate]. + */ + OString const& getJavaInfoAttrVendorUpdate() const { return m_javaInfo.sAttrVendorUpdate; } + +#ifdef _WIN32 + /** returns the javaInfo@autoSelect attribute. + Before calling this function loadFromSettings must be called. + It uses the javaInfo@autoSelect attribute to determine + the return value; + */ + bool getJavaInfoAttrAutoSelect() const; +#endif + + void getVmParametersArray(std::vector* parParameters) const; + + const ::std::vector& getJRELocations() const { return m_JRELocations; } +}; + +struct VersionInfo +{ + ::std::vector vecExcludeVersions; + OUString sMinVersion; + OUString sMaxVersion; +}; + +} //end namespace +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/fwkbase.hxx b/jvmfwk/inc/fwkbase.hxx new file mode 100644 index 000000000..61c3fa500 --- /dev/null +++ b/jvmfwk/inc/fwkbase.hxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_INC_FWKBASE_HXX +#define INCLUDED_JVMFWK_INC_FWKBASE_HXX + +#include + +#include +#include + +#include +#include "libxmlutil.hxx" + +namespace jfw +{ +struct VersionInfo; + +class VendorSettings +{ + CXmlDocPtr m_xmlDocVendorSettings; + CXPathContextPtr m_xmlPathContextVendorSettings; + +public: + VendorSettings(); + + VersionInfo getVersionInformation(std::u16string_view sVendor) const; +}; + +/* The class offers functions to retrieve verified bootstrap parameters. + */ +namespace BootParams +{ +/* Gets the file URL to the JRE which has been determined by the + bootstrap parameter UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME. + + In direct mode either of them must be set. If not an exception is thrown. +*/ +OUString getJREHome(); + +::std::vector getVMParameters(); + +OUString getUserData(); + +OUString getSharedData(); + +/* returns the file URL to the vendor settings xml file. + */ +OUString getVendorSettings(); + +/* User the parameter UNO_JAVA_JFW_CLASSPATH and UNO_JAVA_JFW_ENV_CLASSPATH + to compose a classpath + */ +OString getClasspath(); + +OUString getClasspathUrls(); + +} //end namespace + +enum JFW_MODE +{ + JFW_MODE_APPLICATION, + + JFW_MODE_DIRECT +}; + +JFW_MODE getMode(); + +/** creates the -Djava.class.path option with the complete classpath, including + the paths which are set by UNO_JAVA_JFW_CLASSPATH_URLS. + */ +OString makeClassPathOption(std::u16string_view sUserClassPath); + +OString getSettingsPath(const OUString& sURL); + +/** Get the system path to the javasettings.xml + Converts the URL returned from getUserSettingsURL to a + Systempath. An empty string is returned if the file + does not exist. + @throws FrameworkException + */ +OString getUserSettingsPath(); + +/** Returns the system path of the share settings file. + Returns a valid string or throws an exception. + @throws FrameworkException + */ +OString getSharedSettingsPath(); + +/* returns a valid string or throws an exception. + @throws FrameworkException + */ +OString getVendorSettingsPath(); + +/** Called from writeJavaInfoData. It sets the process identifier. When +java is to be started, then the current id is compared to the one set by +this function. If they are identical then the Java was selected in the +same process. If that Java needs a prepared environment, such as a +LD_LIBRARY_PATH, then it must not be started in this process. +*/ +void setJavaSelected(); + +/** Determines if the currently selected Java was set in this process. + + @see setProcessId() + */ +bool wasJavaSelectedInSameProcess(); +/* Only for application mode. + */ +OUString getApplicationClassPath(); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/fwkutil.hxx b/jvmfwk/inc/fwkutil.hxx new file mode 100644 index 000000000..76d437ae7 --- /dev/null +++ b/jvmfwk/inc/fwkutil.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_SOURCE_FWKUTIL_HXX +#define INCLUDED_JVMFWK_SOURCE_FWKUTIL_HXX + +#include + +#include +#include +#include +#include + +namespace osl { class Mutex; } + +namespace jfw +{ + +/** Returns the file URL of the directory where the framework library + (this library) resides. +*/ +OUString getLibraryLocation(); + +/** provides a bootstrap class which already knows the values from the + jvmfkwrc file. +*/ +const rtl::Bootstrap * Bootstrap(); + +osl::Mutex& FwkMutex(); + +rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData); +rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data); + +OUString getDirFromFile(std::u16string_view usFilePath); + +enum FileStatus +{ + FILE_OK, + FILE_DOES_NOT_EXIST, + FILE_INVALID +}; + +/** checks if the URL is a file. + + If it is a link to a file than + it is resolved. Assuming that the argument + represents a relative URL then FILE_INVALID + is returned. + + + @return + one of the values of FileStatus. + + @exception + Errors occurred during determining if the file exists + */ +FileStatus checkFileURL(const OUString & path); + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/libxmlutil.hxx b/jvmfwk/inc/libxmlutil.hxx new file mode 100644 index 000000000..2599cff50 --- /dev/null +++ b/jvmfwk/inc/libxmlutil.hxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX +#define INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX + +#include + +#include + +#include +#include +#include + +namespace jfw +{ +class CXPathObjectPtr +{ + xmlXPathObject* _object; + CXPathObjectPtr& operator=(const CXPathObjectPtr&) = delete; + CXPathObjectPtr(const CXPathObjectPtr&) = delete; + +public: + CXPathObjectPtr(); + CXPathObjectPtr(xmlXPathObject*); + ~CXPathObjectPtr(); + /** Takes ownership of xmlXPathObject + */ + CXPathObjectPtr& operator=(xmlXPathObject* pObj); + xmlXPathObject* operator->() { return _object; } + operator xmlXPathObject*() const { return _object; } +}; + +class CXPathContextPtr +{ + xmlXPathContext* _object; + + CXPathContextPtr(const jfw::CXPathContextPtr&) = delete; + CXPathContextPtr& operator=(const CXPathContextPtr&) = delete; + +public: + CXPathContextPtr(); + CXPathContextPtr(xmlXPathContextPtr aContext); + CXPathContextPtr& operator=(xmlXPathContextPtr pObj); + ~CXPathContextPtr(); + operator xmlXPathContext*() const { return _object; } +}; + +class CXmlDocPtr +{ + xmlDoc* _object; + + CXmlDocPtr(const CXmlDocPtr&) = delete; + +public: + CXmlDocPtr& operator=(const CXmlDocPtr&); + CXmlDocPtr(); + CXmlDocPtr(xmlDoc* aDoc); + /** Takes ownership of xmlDoc + */ + CXmlDocPtr& operator=(xmlDoc* pObj); + ~CXmlDocPtr(); + operator xmlDoc*() const { return _object; } +}; + +class CXmlCharPtr +{ + xmlChar* _object; + + CXmlCharPtr(const CXmlCharPtr&) = delete; + CXmlCharPtr& operator=(const CXmlCharPtr&) = delete; + +public: + CXmlCharPtr(); + CXmlCharPtr(xmlChar* aDoc); + explicit CXmlCharPtr(std::u16string_view); + ~CXmlCharPtr(); + CXmlCharPtr& operator=(xmlChar* pObj); + operator xmlChar*() const { return _object; } + operator OUString(); + operator OString() { return reinterpret_cast(_object); } +}; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/vendorbase.hxx b/jvmfwk/inc/vendorbase.hxx new file mode 100644 index 000000000..779fc8f7a --- /dev/null +++ b/jvmfwk/inc/vendorbase.hxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX + +#include +#include +#include +#include +#include + +namespace jfw_plugin +{ +//Used by subclasses of VendorBase to build paths to Java runtime +#if defined(JAVA_ARCH) +#define JFW_PLUGIN_ARCH JAVA_ARCH +#elif defined SPARC64 +#define JFW_PLUGIN_ARCH "sparcv9" +#elif defined SPARC +#define JFW_PLUGIN_ARCH "sparc" +#elif defined X86_64 +#define JFW_PLUGIN_ARCH "amd64" +#elif defined ARM64 +#define JFW_PLUGIN_ARCH "arm64" +#elif defined INTEL +#define JFW_PLUGIN_ARCH "i386" +#elif defined POWERPC64 +#define JFW_PLUGIN_ARCH "ppc64" +#elif defined POWERPC +#define JFW_PLUGIN_ARCH "ppc" +#elif defined MIPS +#ifdef OSL_BIGENDIAN +#define JFW_PLUGIN_ARCH "mips" +#else +/* FIXME: do JDKs have some JDK-specific define? This is for +OpenJDK at least, but probably not true for Lemotes JDK */ +#define JFW_PLUGIN_ARCH "mipsel" +#endif +#elif defined MIPS64 +#ifdef OSL_BIGENDIAN +#define JFW_PLUGIN_ARCH "mips64" +#else +#define JFW_PLUGIN_ARCH "mips64el" +#endif +#elif defined S390X +#define JFW_PLUGIN_ARCH "s390x" +#elif defined S390 +#define JFW_PLUGIN_ARCH "s390" +#elif defined ARM +#define JFW_PLUGIN_ARCH "arm" +#elif defined IA64 +#define JFW_PLUGIN_ARCH "ia64" +#elif defined M68K +#define JFW_PLUGIN_ARCH "m68k" +#elif defined HPPA +#define JFW_PLUGIN_ARCH "parisc" +#elif defined AXP +#define JFW_PLUGIN_ARCH "alpha" +#elif defined AARCH64 +#define JFW_PLUGIN_ARCH "aarch64" +#else // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA +#error unknown platform +#endif // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA + +class MalformedVersionException final : public std::exception +{ +public: + virtual ~MalformedVersionException() override; +}; + +class VendorBase : public salhelper::SimpleReferenceObject +{ +public: + VendorBase(); + /* static char const* const * getJavaExePaths(int* size); + + returns relative paths to the java executable as + file URLs. + + For example "bin/java.exe". You need + to implement this function in a derived class, if + the paths differ. this implementation provides for + Windows "bin/java.exe" and for Unix "bin/java". + The paths are relative file URLs. That is, they always + contain '/' even on windows. The paths are relative + to the installation directory of a JRE. + + + The signature of this function must correspond to + getJavaExePaths_func. + */ + + /* static rtl::Reference createInstance(); + + creates an instance of this class. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @param + Key - value pairs of the system properties of the JRE. + */ + + const OUString& getVendor() const; + const OUString& getVersion() const; + const OUString& getHome() const; + const OUString& getRuntimeLibrary() const; + const OUString& getLibraryPath() const; + bool isValidArch() const; + /* determines if prior to running java something has to be done, + like setting the LD_LIBRARY_PATH. This implementation checks + if an LD_LIBRARY_PATH (getLD_LIBRARY_PATH) needs to be set and + if so, needsRestart returns true. + */ + bool needsRestart() const; + + /* compares versions of this vendor. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @return + 0 this.version == sSecond + 1 this.version > sSecond + -1 this.version < sSEcond + + @throw + MalformedVersionException if the version string was not recognized. + */ + virtual int compareVersions(const OUString& sSecond) const = 0; + +protected: + /* called automatically on the instance created by createInstance. + + @return + true - the object could completely initialize. + false - the object could not completely initialize. In this case + it will be discarded by the caller. + */ + bool initialize(const std::vector>& props); + + /* returns relative file URLs to the runtime library. + For example "/bin/client/jvm.dll" + */ + virtual char const* const* getRuntimePaths(int* size) = 0; + + virtual char const* const* getLibraryPaths(int* size) = 0; + + OUString m_sVendor; + OUString m_sVersion; + OUString m_sHome; + OUString m_sRuntimeLibrary; + OUString m_sLD_LIBRARY_PATH; + OUString m_sArch; + + typedef rtl::Reference (*createInstance_func)(); + friend rtl::Reference + createInstance(createInstance_func pFunc, + const std::vector>& properties); +}; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/vendorplugin.hxx b/jvmfwk/inc/vendorplugin.hxx new file mode 100644 index 000000000..4c24903ba --- /dev/null +++ b/jvmfwk/inc/vendorplugin.hxx @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +/** @HTML */ +#ifndef INCLUDED_JVMFWK_INC_VENDORPLUGIN_HXX +#define INCLUDED_JVMFWK_INC_VENDORPLUGIN_HXX + +#include +#include + +#include +#include + +namespace jfw_plugin { class VendorBase; } +namespace rtl { template class Reference; } + +struct JavaInfo; + +namespace jfw { class VendorSettings; } + +/** + @file +

+ This API shall be implemented if one wants to support a Java Runtime + Environment (JRE) of a particular vendor. Because there is currently no + specification which rules the structure and location of JRE installations + and the format of version strings it is not possible to supply a general + implementation for all possible vendors. If an application determines exactly + what version a JRE must have then it relies on certain features and bug + fixes of that version. Because a version 1.4.2_1 from vendor X may contain + different fixes as the same version from vendor Y it is important to see + version and vendor as one entity. One without the other does not guarantee + the existence of a particular set of features or bug fixes. An implementation + of this API may support multiple vendors.

+ */ + +enum class javaPluginError +{ + NONE, + Error, + InvalidArg, + WrongVersionFormat, + FailedVersion, + NoJre, + WrongArch, + VmCreationFailed +}; + + +/** obtains information about installations of Java Runtime Environments (JREs). + +

The function gathers information about available JREs. Only information + about those JREs which match the version requirements are returned. These + requirements are specified by the parameter vendorSettings. +

+

+ The JavaInfo structures returned in parJavaInfo should be ordered + according to their version. The one, representing a JRE with the highest + version should be the first in the array.

+ @param parJavaInfo + [out] if the function runs successfully then parJavaInfo contains + on return a vector of pointers to JavaInfo objects. + + @return + javaPluginError::NONE the function ran successfully.
+ javaPluginError::Error an error occurred during execution.
+ javaPluginError::WrongVersionFormat the version strings in + vendorSettings are not recognized as valid + version strings. + */ +javaPluginError jfw_plugin_getAllJavaInfos( + bool checkJavaHomeAndPath, + jfw::VendorSettings const & vendorSettings, + std::vector> * parJavaInfo, + std::vector> & infos); + +/** obtains information for a JRE at a given location. + +

If the given location belongs to a JRE + and the JRE has a version which meets the requirements as + specified by vendorSettings then + this function shall return a JavaInfo object for this JRE.

+ + @param sLocation + [in] a file URL to the directory of the JRE. + @param ppInfo + [out] if the function runs successfully then ppInfo contains + on return a pointer to a JavaInfo object. + + @return + javaPluginError::NONE the function ran successfully.
+ javaPluginError::Error an error occurred during execution.
+ javaPluginError::InvalidArg an argument was not valid. For example, sLocation + is an empty string.
+ javaPluginError::FailedVersion there is a JRE at the given location but it does not + meet the version requirements. + javaPluginError::NoJre no JRE could be detected at the given location. + */ +javaPluginError jfw_plugin_getJavaInfoByPath( + OUString const& sLocation, + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo); + + +/** obtains information for a JRE referenced by the JAVA_HOME environment variable. + +

If the JAVA_HOME environment variable is set and points to a JRE that + matches the requirements given by vendorSettings (i.e. + the version requirements, if any, for the vendor are met), + then this function shall return a JavaInfo object for this JRE.

+ + @param ppInfo + [out] if the JAVA_HOME environment variable is set and points to a suitable + JRE, then ppInfo contains + on return a pointer to its JavaInfo object. + + @return + javaPluginError::NONE the function ran successfully.
+ javaPluginError::NoJre no suitable JRE could be detected at the given location. However, that + does not mean necessarily that there is no JRE. There could be a JRE but + it does not + meet the version requirements. + */ +javaPluginError jfw_plugin_getJavaInfoFromJavaHome( + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo, + std::vector> & infos); + + +/** obtains information about installations of Java Runtime Environments (JREs) + whose executable is in the PATH. + +

The function gathers information about available JREs which are on the PATH + (PATH environment variable) and meet the version requirements given by + vendorSettings (i.e. + the version requirements, if any, for the vendor are met). +

+

+ The JavaInfo structures returned in vecJavaInfosFromPath should be ordered + according to their occurrence in the PATH. The one that is the first one on the PATH + is also the first element in the vector.

+ @param vecJavaInfosFromPath + [out] if the function runs successfully then vecJavaInfosFromPath + contains on return a vector of pointers to JavaInfo objects. + On return of this function, vecJavaInfosFromPath references + a newly created vector rather than the same vector as before with + the JavaInfo objects inserted into the existing vector. + + @return + javaPluginError::NONE the function ran successfully and at least one JRE + that meets the requirements was found.
+ javaPluginError::NoJre no JavaInfo that meets the version criteria was found + when inspecting the PATH + */ + +javaPluginError jfw_plugin_getJavaInfosFromPath( + jfw::VendorSettings const & vendorSettings, + std::vector> & vecJavaInfosFromPath, + std::vector> & infos); + +/** starts a Java Virtual Machine. + +

The caller should provide all essential JavaVMOptions, such as the + class path (-Djava.class.path=xxx). It is assumed that the caller + knows what JRE is used. Hence the implementation does not need to check + the options for validity. If a user configured the application to + use specific options, such as -X..., then it is in his responsibility to + ensure that the application works properly. The function may add or modify + properties. For example, it may add to the class path property. +

+ The function must ensure, that the VM does not abort the process + during instantiation.

+

+ The function receives a JavaInfo object that was created + by the functions jfw_plugin_getJavaInfoByPath or + jfw_plugin_getAllJavaInfos from the same library. This can be + guaranteed if an application uses exactly one library for one vendor. + Therefore the functions which create the JavaInfo can store all + necessary information which are needed for starting the VM into that + structure.

+ + @param pInfo + [in] the JavaInfo object with information about the JRE. + @param arOptions + [in] the options which are passed into the JNI_CreateJavaVM function. + Can be NULL. + @param nSizeOptions + [in] the number of elements in arOptions. + @param ppVM + [out] the JavaVM pointer of the created VM. + @param ppEnv + [out] the JNIEnv pointer of the created VM. + + @return + javaPluginError::NONE the function ran successfully.
+ javaPluginError::Error an error occurred during execution.
+ JFW_PLUGIN_E_VM_CREATION_FAILED a VM could not be created. The error was caused + by the JRE. + */ +javaPluginError jfw_plugin_startJavaVirtualMachine( + const JavaInfo *pInfo, + const JavaVMOption *arOptions, + sal_Int32 nSizeOptions, + JavaVM ** ppVM, + JNIEnv ** ppEnv); + + +/** checks if the installation of the jre still exists. + + This function checks if the JRE described by pInfo still + exists. The check must be very quick because it is called by javaldx + (Linux, Solaris) at start up. + + @param pInfo + [in] the JavaInfo object with information about the JRE. + @param pp_exist + [out] the parameter is set to either sal_True or sal_False. The value is + only valid if the function returns JFW_E_NONE. + + @return + javaPluginError::NONE the function ran successfully.
+ javaPluginError::Error an error occurred during execution.
+ javaPluginError::InvalidArg pInfo contains invalid data
+ */ +javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, bool *exist); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx new file mode 100644 index 000000000..9a39f2131 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static bool hasOption(char const * szOption, int argc, char** argv); +static OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData); +static bool findAndSelect(std::unique_ptr*); + +#define HELP_TEXT \ +"\njavaldx is necessary to make Java work on some UNIX platforms." \ +"It prints a string to std out that consists of directories which " \ +"have to be included into the LD_LIBRARY_PATH variable.The setting of " \ +"the variable usually occurs in a shell script that runs javaldx.\n" \ +"The directories are from the chosen java installation. \n" \ +"Options are: \n"\ +"--help or -h\n" + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + try + { + if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv)) + { + fprintf(stdout, HELP_TEXT);// default + return 0; + } + bool bEnabled = false; + javaFrameworkError errcode = jfw_getEnabled( & bEnabled); + if (errcode == JFW_E_NONE && !bEnabled) + { + //Do not do any preparation because that may only slow startup time. + fprintf(stdout, "\n"); + return 0; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed!\n"); + return -1; + } + + std::unique_ptr aInfo; + errcode = jfw_getSelectedJRE(&aInfo); + + if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS) + { + fprintf(stderr,"javaldx failed!\n"); + return -1; + } + + if (!aInfo) + { + if (!findAndSelect(&aInfo)) + return -1; + } + else + { + //check if the JRE was not uninstalled + bool bExist = false; + errcode = jfw_existJRE(aInfo.get(), &bExist); + if (errcode == JFW_E_NONE) + { + if (!bExist && !findAndSelect(&aInfo)) + return -1; + } + else + { + fprintf(stderr, "javaldx: Could not determine if JRE still exist\n"); + return -1; + } + } + + OString sPaths = getLD_LIBRARY_PATH(aInfo->arVendorData); + fprintf(stdout, "%s\n", sPaths.getStr()); + } + catch (const std::exception& e) + { + std::cerr << "javaldx failed! " << e.what() << std::endl; + return -1; + } + + return 0; +} + +OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData) +{ + const sal_Unicode* chars = reinterpret_cast(vendorData.getConstArray()); + sal_Int32 len = vendorData.getLength(); + OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + std::u16string_view aToken = o3tl::getToken(sData, 1, '\n', index); + + OString paths = + OUStringToOString(aToken, osl_getThreadTextEncoding()); + return paths; +} + +static bool hasOption(char const * szOption, int argc, char** argv) +{ + bool retVal= false; + for(int i= 1; i < argc; i++) + { + if( ! strcmp(argv[i], szOption)) + { + retVal= true; + break; + } + } + return retVal; +} + +static bool findAndSelect(std::unique_ptr * ppInfo) +{ + javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo); + if (errcode == JFW_E_NO_JAVA_FOUND) + { + fprintf(stderr,"javaldx: Could not find a Java Runtime Environment!\n"); + return false; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed!\n"); + return false; + } + return true; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java new file mode 100644 index 000000000..0d3503af3 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java @@ -0,0 +1,62 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +import java.util.*; + +/** This class prints out the system properties. + + We cannot print the strings directly because of encoding issues. Since + about 1.3.1 one can start java with the option -Dfile.encoding=UTF-8, but + unfortunately this works only with later update - versions (for example, + 1.3.1_07). Therefore we use this scheme. The property string has this form: + name=value + + Every character is cast to an integer which value is printed, followed by a + space. If all characters of the string are printed, then a new line is printed. +*/ +public class JREProperties +{ + public static void main(String[] args) + { + try + { + Properties p = System.getProperties(); + Enumeration e = p.propertyNames(); + while (e.hasMoreElements()) { + String sProp = (String) e.nextElement(); + String sCompleteProp = sProp + "=" + p.getProperty(sProp); + char[] arChars = new char[sCompleteProp.length()]; + sCompleteProp.getChars(0, sCompleteProp.length(), arChars, 0); + for (int c = 0; c < arChars.length; c++) { + System.out.print(String.valueOf((int) arChars[c])); + System.out.print(" "); + } + System.out.print("\n"); + } + } + catch(Exception e) + { + System.err.println(e); + } + + System.exit(0); + } + + + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h new file mode 100644 index 000000000..599c40438 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_DIAGNOSTICS_H +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_DIAGNOSTICS_H + +#include + +#include + +#define JFW_ENSURE(c, m) SAL_WARN_IF(!(c), "jfw", m) + +#define JFW_TRACE0(m) SAL_INFO("jfw.level1", m) + +#define JFW_TRACE2(m) SAL_INFO("jfw.level2", m) + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx new file mode 100644 index 000000000..528af9498 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "otherjre.hxx" + +using ::rtl::Reference; +namespace jfw_plugin +{ + +Reference OtherInfo::createInstance() +{ + return new OtherInfo; +} + + +char const* const* OtherInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { +#if defined(_WIN32) + "bin/java.exe", + "jre/bin/java.exe" +#elif defined UNX + "bin/java", + "jre/bin/java" +#endif + }; + *size = SAL_N_ELEMENTS (ar); + return ar; +} + +char const* const* OtherInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { +#if defined(_WIN32) + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll", + "/bin/classic/jvm.dll", + "/bin/jrockit/jvm.dll", + // Needed by IBM Semeru Runtime, which is an OpenJDK (so should actually use SunInfo) with a + // java.vendor of "IBM Corporation", so using OtherInfo here (cf. gVendorMap in + // jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx): + "/bin/server/jvm.dll" +#elif defined UNX +#ifdef MACOSX + "/../../../../../Frameworks/JavaVM.framework/JavaVM" //as of 1.6.0_22 +#else + "/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so", // for Blackdown AMD64 + "/lib/" JFW_PLUGIN_ARCH "/classic/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/jrockit/libjvm.so", // for Java of BEA Systems + "/bin/classic/libjvm.so", // fallback for older for IBM Java + "/jre/bin/classic/libjvm.so" // fallback for older for IBM Java +#endif +#endif + + }; + *size = SAL_N_ELEMENTS(ar); + return ar; +} + +char const* const* OtherInfo::getLibraryPaths(int* size) +{ + +#if defined(UNX) && !defined(MACOSX) + //mac version does not have a ld library path anymore + static char const * ar[] = { + "/bin", + "/jre/bin", + "/bin/classic", + "/jre/bin/classic", + "/lib/" JFW_PLUGIN_ARCH "/client", + "/lib/" JFW_PLUGIN_ARCH "/server", + "/lib/" JFW_PLUGIN_ARCH "/classic", + "/lib/" JFW_PLUGIN_ARCH "/jrockit", + "/lib/" JFW_PLUGIN_ARCH "/native_threads", + ("/lib/" JFW_PLUGIN_ARCH) + }; + + *size = SAL_N_ELEMENTS(ar); + return ar; +#else + *size = 0; + return nullptr; +#endif +} + +int OtherInfo::compareVersions(const OUString& /*sSecond*/) const +{ + //Need to provide an own algorithm for comparing version. + //Because this function returns always 0, which means the version of + //this JRE and the provided version "sSecond" are equal, one cannot put + //any excludeVersion entries in the javavendors.xml file. + return 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx new file mode 100644 index 000000000..f722234ef --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_OTHERJRE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_OTHERJRE_HXX + +#include + +namespace jfw_plugin +{ +/* Do not forget to put this class in the vendor map in vendorlist.cxx + */ +class OtherInfo : public VendorBase +{ +public: + static char const* const* getJavaExePaths(int* size); + + static rtl::Reference createInstance(); + + virtual char const* const* getRuntimePaths(int* size) override; + virtual char const* const* getLibraryPaths(int* size) override; + virtual int compareVersions(const OUString& sSecond) const override; +}; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx new file mode 100644 index 000000000..03c38c1de --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -0,0 +1,900 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#ifdef _WIN32 +# include +# if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +#endif + +#ifdef ANDROID +# include +#endif + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-attributes" +#endif +#include +#if defined __clang__ +#pragma clang diagnostic pop +#endif + +#include +#include +#include +#include +#include +#include +#include "util.hxx" +#include "sunversion.hxx" +#include "diagnostics.h" + +#if defined MACOSX && defined __x86_64__ +#include "util_cocoa.hxx" +#endif + +#ifdef ANDROID +#include +#else +#if !ENABLE_RUNTIME_OPTIMIZATIONS +#define FORCE_INTERPRETED 1 +#elif defined HAVE_VALGRIND_HEADERS +#include +#define FORCE_INTERPRETED RUNNING_ON_VALGRIND +#else +#define FORCE_INTERPRETED 0 +#endif +#endif + +#if defined LINUX && (defined X86 || defined X86_64) +#include +#endif + +using namespace osl; +using namespace jfw_plugin; + + +namespace { + +#if defined(UNX) && !defined(ANDROID) +OString getPluginJarPath( + std::u16string_view sVendor, + std::u16string_view sLocation, + std::u16string_view sVersion) +{ + OString ret; + OUString sName1("javaplugin.jar"); + OUString sName2("plugin.jar"); + OUString sPath; + if ( sVendor == u"Sun Microsystems Inc." ) + { + SunVersion ver142("1.4.2-ea"); + SunVersion ver150("1.5.0-ea"); + SunVersion ver(sVersion); + OSL_ASSERT(ver142 && ver150 && ver); + + OUString sName; + if (ver < ver142) + { + sName = sName1; + } + else if (ver < ver150) + {//this will cause ea, beta etc. to have plugin.jar in path. + //but this does not harm. 1.5.0-beta < 1.5.0 + sName = sName2; + } + if (!sName.isEmpty()) + { + sName = OUString::Concat(sLocation) + "/lib/" + sName; + OSL_VERIFY( + osl_getSystemPathFromFileURL(sName.pData, & sPath.pData) + == osl_File_E_None); + } + } + else + { + OUString sName(OUString::Concat(sLocation) + "/lib/" + sName1); + OUString sPath1; + OUString sPath2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData) + == osl_File_E_None) + { + sName = OUString::Concat(sLocation) + "/lib/" + sName2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath2.pData) + == osl_File_E_None) + { + sPath = sPath1 + OUStringChar(SAL_PATHSEPARATOR) + sPath2; + } + } + OSL_ASSERT(!sPath.isEmpty()); + } + ret = OUStringToOString(sPath, osl_getThreadTextEncoding()); + + return ret; +} +#endif // UNX + + +std::unique_ptr createJavaInfo( + const rtl::Reference & info) +{ + OUStringBuffer buf(1024); + buf.append(info->getRuntimeLibrary()); + if (!info->getLibraryPath().isEmpty()) + { + buf.append("\n"); + buf.append(info->getLibraryPath()); + buf.append("\n"); + } + OUString sVendorData = buf.makeStringAndClear(); + return std::unique_ptr( + new JavaInfo{ + info->getVendor(), info->getHome(), info->getVersion(), + sal_uInt64(info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0), + rtl::ByteSequence( + reinterpret_cast(sVendorData.pData->buffer), + sVendorData.getLength() * sizeof(sal_Unicode))}); +} + +OUString getRuntimeLib(const rtl::ByteSequence & data) +{ + const sal_Unicode* chars = reinterpret_cast(data.getConstArray()); + sal_Int32 len = data.getLength(); + OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + OUString aToken = sData.getToken( 0, '\n', index); + + return aToken; +} + +jmp_buf jmp_jvm_abort; +sig_atomic_t g_bInGetJavaVM = 0; + +extern "C" void JNICALL abort_handler() +{ + // If we are within JNI_CreateJavaVM then we jump back into getJavaVM + if( g_bInGetJavaVM != 0 ) + { + SAL_WARN("jfw", "JavaVM: JNI_CreateJavaVM called os::abort(), caught by abort_handler"); + longjmp( jmp_jvm_abort, 0); + } +} + +typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *); + +#ifndef ANDROID +int createJvm( + JNI_CreateVM_Type * pCreateJavaVM, JavaVM ** pJavaVM, JNIEnv ** ppEnv, JavaVMInitArgs * vm_args) +{ + /* We set a global flag which is used by the abort handler in order to + determine whether it is should use longjmp to get back into this function. + That is, the abort handler determines if it is on the same stack as this function + and then jumps back into this function. + */ + g_bInGetJavaVM = 1; + jint err; + memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort)); + /* If the setjmp return value is not "0" then this point was reached by a longjmp in the + abort_handler, which was called indirectly by JNI_CreateVM. + */ + if( setjmp( jmp_jvm_abort ) == 0) + { + //returns negative number on failure + err= pCreateJavaVM(pJavaVM, ppEnv, vm_args); + g_bInGetJavaVM = 0; + } + else + // set err to a positive number, so as or recognize that an abort (longjmp) + //occurred + err= 1; + return err; +} +#endif + +/** helper function to check Java version requirements + + This function checks if the Java version of the given VendorBase + meets the given Java version requirements. + + @param aVendorInfo + [in] the object to be inspected whether it meets the version requirements + @param sMinVersion + [in] represents the minimum version of a JRE. The string can be empty. + @param sMaxVersion + [in] represents the maximum version of a JRE. The string can be empty. + @param arExcludeList + [in] contains a list of "bad" versions. JREs which have one of these + versions must not be returned by this function. + + @return + javaPluginError::NONE the function ran successfully and the version requirements are met + javaPluginError::FailedVersion at least one of the version requirements (minVersion, + maxVersion, excludeVersions) was violated + javaPluginError::WrongVersionFormat the version strings in + sMinVersion,sMaxVersion,arExcludeList are not recognized as valid + version strings. + + */ +javaPluginError checkJavaVersionRequirements( + rtl::Reference const & aVendorInfo, + OUString const& sMinVersion, + OUString const& sMaxVersion, + std::vector const & arExcludeList) +{ + if (!aVendorInfo->isValidArch()) + { + return javaPluginError::WrongArch; + } + if (!sMinVersion.isEmpty()) + { + try + { + if (aVendorInfo->compareVersions(sMinVersion) < 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The minVersion was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sMinVersion + " for vendor: " + aVendorInfo->getVendor() + + " .Check minimum Version." ); + return javaPluginError::WrongVersionFormat; + } + } + + if (!sMaxVersion.isEmpty()) + { + try + { + if (aVendorInfo->compareVersions(sMaxVersion) > 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The maxVersion was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sMaxVersion + " for vendor: " + aVendorInfo->getVendor() + + " .Check maximum Version." ); + return javaPluginError::WrongVersionFormat; + } + } + + for (auto const & sExVer: arExcludeList) { + try + { + if (aVendorInfo->compareVersions(sExVer) == 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The excluded version was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sExVer + " for vendor: " + aVendorInfo->getVendor() + + " .Check excluded versions." ); + return javaPluginError::WrongVersionFormat; + } + } + + return javaPluginError::NONE; +} + +} + +javaPluginError jfw_plugin_getAllJavaInfos( + bool checkJavaHomeAndPath, + jfw::VendorSettings const & vendorSettings, + std::vector>* parJavaInfo, + std::vector> & infos) +{ + assert(parJavaInfo); + + //Find all JREs + std::vector > vecInfos = + addAllJREInfos(checkJavaHomeAndPath, infos); + std::vector > vecVerifiedInfos; + + for (auto const& vecInfo : vecInfos) + { + auto const versionInfo = vendorSettings.getVersionInformation(vecInfo->getVendor()); + javaPluginError err = checkJavaVersionRequirements( + vecInfo, versionInfo.sMinVersion, versionInfo.sMaxVersion, versionInfo.vecExcludeVersions); + + if (err == javaPluginError::FailedVersion || err == javaPluginError::WrongArch) + continue; + else if (err == javaPluginError::WrongVersionFormat) + return err; + + vecVerifiedInfos.push_back(vecInfo); + } + //Now vecVerifiedInfos contains all those JREs which meet the version requirements + //Transfer them into the array that is passed out. + parJavaInfo->clear(); + for (auto const& vecVerifiedInfo : vecVerifiedInfos) + { + parJavaInfo->push_back(createJavaInfo(vecVerifiedInfo)); + } + + return javaPluginError::NONE; +} + +javaPluginError jfw_plugin_getJavaInfoByPath( + OUString const& sPath, + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo) +{ + assert(ppInfo != nullptr); + OSL_ASSERT(!sPath.isEmpty()); + if (sPath.isEmpty()) + return javaPluginError::InvalidArg; + + rtl::Reference aVendorInfo = getJREInfoByPath(sPath); + if (!aVendorInfo.is()) + return javaPluginError::NoJre; + + //Check if the detected JRE matches the version requirements + javaPluginError errorcode = javaPluginError::NONE; + auto const versionInfo = vendorSettings.getVersionInformation(aVendorInfo->getVendor()); + errorcode = checkJavaVersionRequirements( + aVendorInfo, versionInfo.sMinVersion, versionInfo.sMaxVersion, versionInfo.vecExcludeVersions); + + if (errorcode == javaPluginError::NONE) + *ppInfo = createJavaInfo(aVendorInfo); + + return errorcode; +} + +javaPluginError jfw_plugin_getJavaInfoFromJavaHome( + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo, + std::vector> & infos) +{ + assert(ppInfo); + + std::vector> infoJavaHome; + addJavaInfoFromJavaHome(infos, infoJavaHome); + + if (infoJavaHome.empty()) + return javaPluginError::NoJre; + assert(infoJavaHome.size() == 1); + + //Check if the detected JRE matches the version requirements + auto const versionInfo = vendorSettings.getVersionInformation(infoJavaHome[0]->getVendor()); + if (checkJavaVersionRequirements( + infoJavaHome[0], + versionInfo.sMinVersion, + versionInfo.sMaxVersion, + versionInfo.vecExcludeVersions) + == javaPluginError::NONE) + { + *ppInfo = createJavaInfo(infoJavaHome[0]); + return javaPluginError::NONE; + } + + return javaPluginError::NoJre; +} + +javaPluginError jfw_plugin_getJavaInfosFromPath( + jfw::VendorSettings const & vendorSettings, + std::vector> & javaInfosFromPath, + std::vector> & infos) +{ + // find JREs from PATH + std::vector> vecInfosFromPath; + addJavaInfosFromPath(infos, vecInfosFromPath); + + std::vector> vecVerifiedInfos; + + // copy infos of JREs that meet version requirements to vecVerifiedInfos + for (auto const& infosFromPath : vecInfosFromPath) + { + auto const versionInfo = vendorSettings.getVersionInformation(infosFromPath->getVendor()); + if (checkJavaVersionRequirements( + infosFromPath, + versionInfo.sMinVersion, + versionInfo.sMaxVersion, + versionInfo.vecExcludeVersions) + == javaPluginError::NONE) + { + vecVerifiedInfos.push_back(createJavaInfo(infosFromPath)); + } + } + + if (vecVerifiedInfos.empty()) + return javaPluginError::NoJre; + + javaInfosFromPath = std::move(vecVerifiedInfos); + + return javaPluginError::NONE; +} + + +#if defined(_WIN32) + +// Load msvcr71.dll using an explicit full path from where it is +// present as bundled with the JRE. In case it is not found where we +// think it should be, do nothing, and just let the implicit loading +// that happens when loading the JVM take care of it. + +static void load_msvcr(std::u16string_view jvm_dll, std::u16string_view msvcr) +{ + // First check if msvcr71.dll is in the same folder as jvm.dll. It + // normally isn't, at least up to 1.6.0_22, but who knows if it + // might be in the future. + std::size_t slash = jvm_dll.rfind('\\'); + + if (slash == std::u16string_view::npos) + { + // Huh, weird path to jvm.dll. Oh well. + SAL_WARN("jfw", "JVM pathname <" << OUString(jvm_dll) << "> w/o backslash"); + return; + } + + if (LoadLibraryW( + o3tl::toW(OUString(OUString::Concat(jvm_dll.substr(0, slash+1)) + msvcr).getStr()))) + return; + + // Then check if msvcr71.dll is in the parent folder of where + // jvm.dll is. That is currently (1.6.0_22) as far as I know the + // normal case. + slash = jvm_dll.rfind('\\', slash); + + if (slash == std::u16string_view::npos) + return; + + (void)LoadLibraryW( + o3tl::toW(OUString(OUString::Concat(jvm_dll.substr(0, slash+1)) + msvcr).getStr())); +} + +// Check if the jvm DLL imports msvcr71.dll, and in that case try +// loading it explicitly. In case something goes wrong, do nothing, +// and just let the implicit loading try to take care of it. +static void do_msvcr_magic(OUString const &jvm_dll) +{ + struct stat st; + + OUString Module; + osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( + jvm_dll, Module); + + if ( osl::FileBase::E_None != nError ) + { + SAL_WARN( + "jfw", "getSystemPathFromFileURL(" << jvm_dll << "): " << +nError); + return; + } + + FILE *f = _wfopen(o3tl::toW(Module.getStr()), L"rb"); + + if (!f) + { + SAL_WARN("jfw", "_wfopen(" << Module << ") failed"); + return; + } + + if (fstat(fileno(f), &st) == -1) + { + SAL_WARN("jfw", "fstat(" << Module << ") failed"); + fclose(f); + return; + } + + PIMAGE_DOS_HEADER dos_hdr = static_cast(malloc(st.st_size)); + assert(dos_hdr); + if (fread(dos_hdr, st.st_size, 1, f) != 1 || + memcmp(dos_hdr, "MZ", 2) != 0 || + dos_hdr->e_lfanew < 0 || + dos_hdr->e_lfanew > static_cast(st.st_size - sizeof(IMAGE_NT_HEADERS))) + { + SAL_WARN("jfw", "analyzing <" << Module << "> failed"); + free(dos_hdr); + fclose(f); + return; + } + + fclose(f); + + IMAGE_NT_HEADERS *nt_hdr = reinterpret_cast(reinterpret_cast(dos_hdr) + dos_hdr->e_lfanew); + + DWORD importsVA = nt_hdr->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; + // first determine Virtual-to-File-address mapping for the section + // that contains the import directory + IMAGE_SECTION_HEADER *sections = IMAGE_FIRST_SECTION(nt_hdr); + ptrdiff_t VAtoPhys = -1; + for (int i = 0; i < nt_hdr->FileHeader.NumberOfSections; ++i) + { + if (sections->VirtualAddress <= importsVA && + importsVA < sections->VirtualAddress + sections->SizeOfRawData) + { + VAtoPhys = static_cast(sections->PointerToRawData) - static_cast(sections->VirtualAddress); + break; + } + ++sections; + } + if (-1 == VAtoPhys) // not found? + { + SAL_WARN("jfw", "analyzing <" << Module << "> failed"); + free(dos_hdr); + return; + } + IMAGE_IMPORT_DESCRIPTOR *imports = + reinterpret_cast(reinterpret_cast(dos_hdr) + importsVA + VAtoPhys); + + while (imports <= reinterpret_cast(reinterpret_cast(dos_hdr) + st.st_size - sizeof (IMAGE_IMPORT_DESCRIPTOR)) && + imports->Name != 0 && + imports->Name + VAtoPhys < static_cast(st.st_size)) + { + static std::u16string_view msvcrts[] = + { + u"msvcr71.dll", + u"msvcr100.dll" + }; + char const* importName = reinterpret_cast(dos_hdr) + imports->Name + VAtoPhys; + sal_Int32 importNameLen = rtl_str_getLength(importName); + for (size_t i = 0; i < SAL_N_ELEMENTS(msvcrts); ++i) + { + if (0 == rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths( + msvcrts[i].data(), msvcrts[i].size(), + importName, importNameLen)) + { + load_msvcr(Module, msvcrts[i]); + free(dos_hdr); + return; + } + } + imports++; + } + + free(dos_hdr); +} + +#endif + +/** starts a Java Virtual Machine. +

+ The function shall ensure, that the VM does not abort the process + during instantiation. +

+ */ +javaPluginError jfw_plugin_startJavaVirtualMachine( + const JavaInfo *pInfo, + const JavaVMOption* arOptions, + sal_Int32 cOptions, + JavaVM ** ppVm, + JNIEnv ** ppEnv) +{ + static osl::Mutex aPluginMutex; + assert(pInfo != nullptr); + assert(ppVm != nullptr); + assert(ppEnv != nullptr); + osl::MutexGuard guard(aPluginMutex); + javaPluginError errorcode = javaPluginError::NONE; +#ifdef MACOSX + rtl::Reference aVendorInfo = getJREInfoByPath( pInfo->sLocation ); + if ( !aVendorInfo.is() || aVendorInfo->compareVersions( pInfo->sVersion ) < 0 ) + return javaPluginError::VmCreationFailed; +#endif + OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData); +#if defined MACOSX && defined __x86_64__ + if ( !JvmfwkUtil_isLoadableJVM( sRuntimeLib ) ) + return javaPluginError::VmCreationFailed; +#endif + JFW_TRACE2("Using Java runtime library: " << sRuntimeLib); + +#ifndef ANDROID + // On linux we load jvm with RTLD_GLOBAL. This is necessary for debugging, because + // libjdwp.so need a symbol (fork1) from libjvm which it only gets if the jvm is loaded + // with RTLD_GLOBAL. On Solaris libjdwp.so is correctly linked with libjvm.so + osl::Module moduleRt; +#if defined(LINUX) + if (!moduleRt.load(sRuntimeLib, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_NOW)) +#elif defined MACOSX + // Must be SAL_LOADMODULE_GLOBAL when e.g. specifying a + // -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 option to + // JDK 1.8.0_121 at least, as JNI_CreateJavaVM -> Threads::create_vm -> + // JvmtiExport::post_vm_initialized -> cbEarlyVMInit -> initialize -> + // util_initialize -> sun.misc.VMSupport.getAgentProperties -> + // Java_sun_misc_VMSupport_initAgentProperties -> + // JDK_FindJvmEntry("JVM_INitAgentProperties") -> + // dlsym(RTLD_DEFAULT, "JVM_INitAgentProperties"): + if (!moduleRt.load(sRuntimeLib, SAL_LOADMODULE_GLOBAL)) +#else +#if defined(_WIN32) + do_msvcr_magic(sRuntimeLib); +#endif + if (!moduleRt.load(sRuntimeLib)) +#endif + { + JFW_ENSURE(false, + "[Java framework]sunjavaplugin" SAL_DLLEXTENSION + " could not load Java runtime library: \n" + + sRuntimeLib + "\n"); + JFW_TRACE0("Could not load Java runtime library: " << sRuntimeLib); + return javaPluginError::VmCreationFailed; + } + +#if defined UNX && !defined MACOSX + //Setting the JAVA_HOME is needed for awt + OUString sPathLocation; + osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation, sPathLocation); + osl_setEnvironment(OUString("JAVA_HOME").pData, sPathLocation.pData); +#endif + + OUString sSymbolCreateJava("JNI_CreateJavaVM"); + + JNI_CreateVM_Type * pCreateJavaVM = + reinterpret_cast(moduleRt.getFunctionSymbol(sSymbolCreateJava)); + if (!pCreateJavaVM) + { + OSL_ASSERT(false); + OString sLib = OUStringToOString( + sRuntimeLib, osl_getThreadTextEncoding()); + OString sSymbol = OUStringToOString( + sSymbolCreateJava, osl_getThreadTextEncoding()); + SAL_WARN("jfw", "Java runtime library: " << sLib << " does not export symbol " << sSymbol); + return javaPluginError::VmCreationFailed; + } + moduleRt.release(); + + // Valgrind typically emits many false errors when executing JIT'ed JVM + // code, so force the JVM into interpreted mode: + bool addForceInterpreted = FORCE_INTERPRETED > 0; + + // Some testing with Java 1.4 showed that JavaVMOption.optionString has to + // be encoded with the system encoding (i.e., osl_getThreadTextEncoding): + JavaVMInitArgs vm_args; + + struct Option { + Option(OString const & theOptionString, void * theExtraInfo): + optionString(theOptionString), extraInfo(theExtraInfo) + {} + + OString optionString; + void * extraInfo; + }; + std::vector