From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- jvmfwk/CustomTarget_jreproperties.mk | 23 + jvmfwk/CustomTarget_jvmfwk_jvmfwk3_ini.mk | 38 + jvmfwk/Executable_javaldx.mk | 21 + jvmfwk/IwyuFilter_jvmfwk.yaml | 33 + jvmfwk/Library_jvmfwk.mk | 86 ++ jvmfwk/Makefile | 14 + jvmfwk/Module_jvmfwk.mk | 33 + jvmfwk/Package_jreproperties.mk | 14 + jvmfwk/Package_jvmfwk_jvmfwk3_ini.mk | 16 + jvmfwk/Package_rcfiles.mk | 26 + jvmfwk/README | 15 + jvmfwk/distributions/OpenOfficeorg/javavendors.xsd | 61 + .../OpenOfficeorg/javavendors_freebsd.xml | 38 + .../OpenOfficeorg/javavendors_linux.xml | 50 + .../OpenOfficeorg/javavendors_macosx.xml | 41 + .../OpenOfficeorg/javavendors_unx.xml | 32 + .../OpenOfficeorg/javavendors_wnt.xml | 41 + jvmfwk/inc/elements.hxx | 330 +++++ jvmfwk/inc/fwkbase.hxx | 132 ++ jvmfwk/inc/fwkutil.hxx | 95 ++ jvmfwk/inc/libxmlutil.hxx | 99 ++ jvmfwk/inc/vendorbase.hxx | 186 +++ jvmfwk/inc/vendorplugin.hxx | 245 ++++ jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx | 158 +++ .../plugins/sunmajor/pluginlib/JREProperties.java | 62 + jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h | 35 + jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx | 281 +++++ jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx | 50 + jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx | 45 + .../plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 895 ++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx | 118 ++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx | 44 + jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx | 417 +++++++ jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 1278 ++++++++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/util.hxx | 116 ++ jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx | 14 + jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm | 133 ++ jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx | 196 +++ jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx | 55 + jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx | 49 + jvmfwk/source/elements.cxx | 975 +++++++++++++++ jvmfwk/source/framework.cxx | 718 +++++++++++ jvmfwk/source/framework.hxx | 41 + jvmfwk/source/fwkbase.cxx | 510 ++++++++ jvmfwk/source/fwkutil.cxx | 166 +++ jvmfwk/source/javasettings.xsd | 70 ++ jvmfwk/source/javasettings_template.xml | 52 + jvmfwk/source/libxmlutil.cxx | 136 +++ 50 files changed, 8513 insertions(+) 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 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_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/gnujre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx 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/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/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..13097cc8e --- /dev/null +++ b/jvmfwk/IwyuFilter_jvmfwk.yaml @@ -0,0 +1,33 @@ +--- +assumeFilename: jvmfwk/source/fwkbase.cxx +blacklist: + 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 + # 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 diff --git a/jvmfwk/Library_jvmfwk.mk b/jvmfwk/Library_jvmfwk.mk new file mode 100644 index 000000000..eede8f450 --- /dev/null +++ b/jvmfwk/Library_jvmfwk.mk @@ -0,0 +1,86 @@ +# -*- 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) \ +)) + +$(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 \ + 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..396ed21de --- /dev/null +++ b/jvmfwk/Module_jvmfwk.mk @@ -0,0 +1,33 @@ +# -*- 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 + +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..7864d628b --- /dev/null +++ b/jvmfwk/Package_rcfiles.mk @@ -0,0 +1,26 @@ +# -*- 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) +$(eval $(call gb_Package_add_file,jvmfwk_javavendors,$(LIBO_URE_MISC_FOLDER)/javavendors.xml,distributions/OpenOfficeorg/javavendors_macosx.xml)) +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 b/jvmfwk/README new file mode 100644 index 000000000..7cb338e14 --- /dev/null +++ b/jvmfwk/README @@ -0,0 +1,15 @@ +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 "javavendors_*.xml 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..89ffc08ff --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_freebsd.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_linux.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml new file mode 100644 index 000000000..ad9d287a6 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_linux.xml @@ -0,0 +1,50 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 1.8.0 + + + 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..23d648510 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_macosx.xml @@ -0,0 +1,41 @@ + + + + 2019-07-26 + + + 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_unx.xml b/jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml new file mode 100644 index 000000000..4e721521b --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_unx.xml @@ -0,0 +1,32 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 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..1e2e1f060 --- /dev/null +++ b/jvmfwk/distributions/OpenOfficeorg/javavendors_wnt.xml @@ -0,0 +1,41 @@ + + + + 2019-07-26 + + + 1.8.0 + + + 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..800ecaf69 --- /dev/null +++ b/jvmfwk/inc/elements.hxx @@ -0,0 +1,330 @@ +/* -*- 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< OUString> 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< OUString> > m_vmParameters; + /** User configurable option. /java/jreLocations + If /java/jreLocaltions@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional< ::std::vector< OUString> > 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< OUString> & 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< OUString> > & getVmParameters() const { return m_vmParameters;} + + /** returns the parameters from the element /java/jreLocations/location. + */ + const std::optional< ::std::vector< OUString> > & 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< OUString> m_vmParams; + + ::std::vector< OUString> 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< OString> 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< OUString> & getJRELocations() const { return m_JRELocations;} +}; + + +struct VersionInfo +{ + ::std::vector< OUString> 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..6428083e2 --- /dev/null +++ b/jvmfwk/inc/fwkbase.hxx @@ -0,0 +1,132 @@ +/* -*- 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 "libxmlutil.hxx" + +namespace jfw +{ + +struct VersionInfo; + +class VendorSettings +{ + CXmlDocPtr m_xmlDocVendorSettings; + CXPathContextPtr m_xmlPathContextVendorSettings; + +public: + VendorSettings(); + + std::optional getVersionInformation(const OUString & 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< OString> 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(OUString const & 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..60ffa9fe8 --- /dev/null +++ b/jvmfwk/inc/fwkutil.hxx @@ -0,0 +1,95 @@ +/* -*- 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 +#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. +*/ +struct Bootstrap : + public ::rtl::StaticWithInit< const rtl::Bootstrap *, Bootstrap > { + const rtl::Bootstrap * operator () () { + OUStringBuffer buf(256); + buf.append(getLibraryLocation()); +#ifdef MACOSX + // For some reason the jvmfwk3rc file is traditionally in + // LIBO_URE_ETC_FOLDER + buf.append( "/../" LIBO_URE_ETC_FOLDER ); +#endif + buf.append(SAL_CONFIGFILE("/jvmfwk3")); + OUString sIni = buf.makeStringAndClear(); + ::rtl::Bootstrap * bootstrap = new ::rtl::Bootstrap(sIni); + SAL_INFO("jfw.level2", "Using configuration file " << sIni); + return bootstrap; + } +}; + +struct FwkMutex: public ::rtl::Static {}; + +rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData); +rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data); + +OUString getDirFromFile(const OUString& 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..31332f3ce --- /dev/null +++ b/jvmfwk/inc/libxmlutil.hxx @@ -0,0 +1,99 @@ +/* -*- 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 + +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(const OUString &); + ~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..df536bc34 --- /dev/null +++ b/jvmfwk/inc/vendorbase.hxx @@ -0,0 +1,186 @@ +/* -*- 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 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. + */ + virtual bool initialize( + 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..f7c295ec1 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx @@ -0,0 +1,158 @@ +/* -*- 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 + + +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. + 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; + OUString aToken = sData.getToken( 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/gnujre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx new file mode 100644 index 000000000..19cc9bf5d --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx @@ -0,0 +1,281 @@ +/* -*- 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 "gnujre.hxx" +#include "util.hxx" + +using namespace std; +using namespace osl; +using ::rtl::Reference; + +namespace jfw_plugin +{ + +Reference GnuInfo::createInstance() +{ + return new GnuInfo; +} + +char const* const* GnuInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { + "gij", + "bin/gij", + "gij-4.3", + "bin/gij-4.3", + "gij-4.2", + "bin/gij-4.2", + "gij-4.1", + "bin/gij-4.1" + }; + *size = SAL_N_ELEMENTS (ar); + return ar; +} + +#if defined(MIPS) && defined(OSL_LITENDIAN) +#define GCJ_JFW_PLUGIN_ARCH "mipsel" +#elif defined(MIPS64) && defined(OSL_LITENDIAN) +#define GCJ_JFW_PLUGIN_ARCH "mips64el" +#else +#define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH +#endif + +char const* const* GnuInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { + "/libjvm.so", + "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so", + "/gcj-4.1.1/libjvm.so", + "/gcj-4.3-90/libjvm.so", + "/gcj-4.2-81/libjvm.so", + "/gcj-4.2/libjvm.so", + "/gcj-4.2.1/libjvm.so", + "/gcj-4.2.2/libjvm.so", + "/gcj-4.2.3/libjvm.so", + "/gcj-4.1-71/libjvm.so", + "/gcj-4_1/libjvm.so", + "/gcj-4.1/libjvm.so", + "/libgcj.so.81", + "/libgcj.so.80", + "/libgcj.so.8", + "/libgcj.so.71", + "/libgcj.so.70", + "/libgcj.so.7", + "/libgcj.so.6" + }; + *size = SAL_N_ELEMENTS(ar); + return ar; +} + +char const* const* GnuInfo::getLibraryPaths(int* /*size*/) +{ + return nullptr; +} + +bool GnuInfo::initialize(vector > props) +{ + //get java.vendor, java.version, java.home + //from system properties + + OUString sJavaLibraryPath; + OUString const sVendorProperty("java.vendor"); + OUString const sVersionProperty("java.version"); + OUString const sJavaHomeProperty("java.home"); + OUString const sJavaLibraryPathProperty("java.library.path"); + OUString const sGNUHomeProperty("gnu.classpath.home.url"); + + bool bVersion = false; + bool bVendor = false; + bool bHome = false; + bool bJavaHome = false; + bool bJavaLibraryPath = false; + + for (auto const& prop : props) + { + if(! bVendor && sVendorProperty == prop.first) + { + m_sVendor = prop.second; + bVendor = true; + } + else if (!bVersion && sVersionProperty == prop.first) + { + m_sVersion = prop.second; + bVersion = true; + } + else if (!bHome && sGNUHomeProperty == prop.first) + { + m_sHome = prop.second; + bHome = true; + } + else if (!bJavaHome && sJavaHomeProperty == prop.first) + { + OUString fileURL; + if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) == + osl_File_E_None) + { + //make sure that the drive letter have all the same case + //otherwise file:///c:/jre and file:///C:/jre produce two + //different objects!!! + if (makeDriveLetterSame( & fileURL)) + { + m_sJavaHome = fileURL; + bJavaHome = true; + } + } + } + else if (!bJavaLibraryPath && sJavaLibraryPathProperty == prop.first) + { + sal_Int32 nIndex = 0; + osl_getFileURLFromSystemPath(prop.second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); + bJavaLibraryPath = true; + } + if (bVendor && bVersion && bHome && bJavaHome && bJavaLibraryPath) { + break; + } + } + if (!bVersion || !bVendor || !bHome) + return false; + + if (m_sJavaHome.isEmpty()) + m_sJavaHome = "file:///usr/lib"; + + // init m_sRuntimeLibrary + OSL_ASSERT(!m_sHome.isEmpty()); + //call virtual function to get the possible paths to the runtime library. + + int size = 0; + char const* const* arRtPaths = getRuntimePaths( & size); + vector libpaths = getVectorFromCharArray(arRtPaths, size); + + bool bRt = false; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + + if (!bRt) + { + m_sHome = m_sJavaHome; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + + // try to find it by the java.library.path property + if (!bRt && m_sJavaHome != sJavaLibraryPath) + { + m_sHome = sJavaLibraryPath; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + +#ifdef X86_64 + //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead + if (!bRt && m_sJavaHome != "file:///usr/lib") + { + m_sHome = "file:///usr/lib64"; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } +#endif + + if (!bRt) + return false; + + // init m_sLD_LIBRARY_PATH + OSL_ASSERT(!m_sHome.isEmpty()); + size = 0; + char const * const * arLDPaths = getLibraryPaths( & size); + vector ld_paths = getVectorFromCharArray(arLDPaths, size); + + bool bLdPath = true; + int c = 0; + for (auto const& ld_path : ld_paths) + { + OUString usAbsUrl= m_sHome + ld_path; + // convert to system path + OUString usSysPath; + if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) + { + + if(c > 0) + m_sLD_LIBRARY_PATH+= OUStringChar(SAL_PATHSEPARATOR); + m_sLD_LIBRARY_PATH+= usSysPath; + } + else + { + bLdPath = false; + break; + } + ++c; + } + return bLdPath; +} + +int GnuInfo::compareVersions(const OUString&) const +{ + return 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx new file mode 100644 index 000000000..4826ea720 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx @@ -0,0 +1,50 @@ +/* -*- 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_GNUJRE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_GNUJRE_HXX + +#include + +namespace jfw_plugin +{ + +class GnuInfo: public VendorBase +{ +private: + OUString m_sJavaHome; +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 bool initialize( + std::vector > props) override; + virtual int compareVersions(const OUString& sSecond) const override; + +}; + +} +#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..8a10d39a8 --- /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 namespace std; + +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", + "/bin/server/jvm.dll" // needed by Azul +#elif defined UNX +#ifdef MACOSX + "/../../../../../Frameworks/JavaVM.framework/JavaVM", //as of 1.6.0_22 + "/lib/server/libjvm.dylib" // needed by Azul +#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..57b3a5e39 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx @@ -0,0 +1,45 @@ +/* -*- 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..abe47b567 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -0,0 +1,895 @@ +/* -*- 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 +# 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 +#include +#include +#include +#include +#include +#include +#include "util.hxx" +#include "sunversion.hxx" +#include "diagnostics.h" + +#ifdef MACOSX +#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 std; +using namespace jfw_plugin; + + +namespace { + +struct PluginMutex: public ::rtl::Static {}; + +#if defined(UNX) && !defined(ANDROID) +OString getPluginJarPath( + const OUString & sVendor, + const OUString& sLocation, + const OUString& sVersion) +{ + OString ret; + OUString sName1("javaplugin.jar"); + OUString sName2("plugin.jar"); + OUString sPath; + if ( sVendor == "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 = sLocation + "/lib/" + sName; + OSL_VERIFY( + osl_getSystemPathFromFileURL(sName.pData, & sPath.pData) + == osl_File_E_None); + } + } + else + { + OUString sName(sLocation + "/lib/" + sName1); + OUString sPath1; + OUString sPath2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData) + == osl_File_E_None) + { + sName = 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 ) + { + fprintf(stderr, "JavaVM: JNI_CreateJavaVM called os::abort(), caught by abort_handler in javavm.cxx\n"); + 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 + vector > vecInfos = + addAllJREInfos(checkJavaHomeAndPath, infos); + vector > vecVerifiedInfos; + + for (auto const& vecInfo : vecInfos) + { + if (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; + if (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 (!versionInfo + || (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 + vector> vecInfosFromPath; + addJavaInfosFromPath(infos, vecInfosFromPath); + + 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 (!versionInfo + || (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(OUString const & jvm_dll, OUStringLiteral 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. + sal_Int32 slash = jvm_dll.lastIndexOf('\\'); + + if (slash == -1) + { + // Huh, weird path to jvm.dll. Oh well. + SAL_WARN("jfw", "JVM pathname <" + jvm_dll + "> w/o backslash"); + return; + } + + if (LoadLibraryW( + o3tl::toW(OUString(jvm_dll.copy(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.lastIndexOf('\\', slash); + + if (slash == -1) + return; + + (void)LoadLibraryW( + o3tl::toW(OUString(jvm_dll.copy(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 OUStringLiteral msvcrts[] = + { + "msvcr71.dll", + "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_str_compareIgnoreAsciiCase_WithLength( + importName, importNameLen, + msvcrts[i].data, msvcrts[i].size)) + { + 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) +{ + assert(pInfo != nullptr); + assert(ppVm != nullptr); + assert(ppEnv != nullptr); + osl::MutexGuard guard(PluginMutex::get()); + 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); +#ifdef MACOSX + 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()); + fprintf(stderr,"[Java framework]sunjavaplugin" SAL_DLLEXTENSION + "Java runtime library: %s does not export symbol %s !\n", + sLib.getStr(), sSymbol.getStr()); + 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