From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- jvmfwk/inc/elements.hxx | 329 ++++++++++++++++++++++++++++++++++++++++++++ jvmfwk/inc/fwkbase.hxx | 130 +++++++++++++++++ jvmfwk/inc/fwkutil.hxx | 77 +++++++++++ jvmfwk/inc/libxmlutil.hxx | 101 ++++++++++++++ jvmfwk/inc/vendorbase.hxx | 185 +++++++++++++++++++++++++ jvmfwk/inc/vendorplugin.hxx | 245 +++++++++++++++++++++++++++++++++ 6 files changed, 1067 insertions(+) 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 (limited to 'jvmfwk/inc') diff --git a/jvmfwk/inc/elements.hxx b/jvmfwk/inc/elements.hxx new file mode 100644 index 0000000000..3fde096c44 --- /dev/null +++ b/jvmfwk/inc/elements.hxx @@ -0,0 +1,329 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX +#define INCLUDED_JVMFWK_SOURCE_ELEMENTS_HXX + +#include + +#include +#include +#include "fwkutil.hxx" +#include +#include +#include +#include + +struct JavaInfo; + +#define NS_JAVA_FRAMEWORK "http://openoffice.org/2004/java/framework/1.0" +#define NS_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance" + +namespace jfw +{ +/** gets the value of the updated element from the javavendors.xml. + */ +OString getElementUpdated(); + +/** create the child elements within the root structure for each platform. + + @param bNeedsSave + [out]If true then the respective structure of elements was added and the + document needs to be saved. + */ +void createSettingsStructure(xmlDoc* document, bool* bNeedsSave); + +/** represents the settings saved in the /java/javaInfo element. + It is used within class NodeJava which determines the settings + file. +*/ +class CNodeJavaInfo +{ +public: + CNodeJavaInfo(); + + /** if true, then javaInfo is empty. When writeToNode is called + then all child elements are deleted. + */ + bool m_bEmptyNode; + /** Contains the value of the element of + the javavendors.xml after loadFromNode was called. + It is not used, when the javaInfo node is written. + see writeToNode + */ + OString sAttrVendorUpdate; + /** contains the nil value of the /java/javaInfo@xsi:nil attribute. + Default is true; + */ + bool bNil; + /** contains the value of the /java/javaInfo@autoSelect attribute. + Default is true. If it is false then the user has modified the JRE + selection by actively choosing a JRE from the options dialog. That is, + the function jfw_setSelectedJRE was called. Contrary, the function + jfw_findAndSelectJRE sets the attribute to true. + */ + bool bAutoSelect; + OUString sVendor; + OUString sLocation; + OUString sVersion; + sal_uInt64 nRequirements; + ::rtl::ByteSequence arVendorData; + + /** reads the node /java/javaInfo. + If javaInfo@xsi:nil = true then member bNil is set to true + and no further elements are read. + */ + void loadFromNode(xmlDoc* pDoc, xmlNode* pJavaInfo); + /** The attribute nil will be set to false. The function gets the value + javaSettings/updated from the javavendors.xml and writes it to + javaInfo@vendorUpdate in javasettings.xml + */ + void writeToNode(xmlDoc* pDoc, xmlNode* pJavaInfo) const; + + /** returns NULL if javaInfo is nil. + */ + std::unique_ptr makeJavaInfo() const; +}; + +/** this class represents the java settings based on a particular + settings file. + + Which settings file is used is determined by the value passed into the + constructor and the values of the bootstrap parameters + UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA. + + The method load reads the data from the settings file. + The method write stores the data into the settings file. + */ +class NodeJava +{ +public: + enum Layer + { + USER, + SHARED + }; + +private: + /** creates settings file and fills it with default values. + + When this function is called then it creates the + settings file at the position determined by the bootstrap parameters + (UNO_JAVA_JFW_USER_DATA, UNO_JAVA_JFW_SHARED_DATA) and m_layer, unless + the file already exists (see createSettingsDocument). + + @return + JFW_E_CONFIG_READWRITE + */ + bool prepareSettingsDocument() const; + + /** helper function for prepareSettingsDocument. + */ + bool createSettingsDocument() const; + + /** returns the system path to the data file which is to be used. The value + depends on the member m_layer and the bootstrap parameters + UNO_JAVA_JFW_USER_DATA and UNO_JAVA_JFW_SHARED_DATA. + */ + OString getSettingsPath() const; + + /** returns the file URL to the data file which is to be used. See getSettingsPath. + */ + OUString getSettingsURL() const; + + /** Verifies if the respective settings file exist. + */ + static jfw::FileStatus checkSettingsFileStatus(OUString const& sURL); + + /** Determines the layer for which the instance the loads and writes the + data. + */ + Layer m_layer; + + /** User configurable option. /java/enabled + If /java/enabled@xsi:nil == true then the value will be uninitialized + after a call to load(). + */ + std::optional m_enabled; + + /** User configurable option. /java/userClassPath + If /java/userClassPath@xsi:nil == true then the value is uninitialized + after a call to load(). + */ + std::optional m_userClassPath; + /** User configurable option. /java/javaInfo + If /java/javaInfo@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional m_javaInfo; + /** User configurable option. /java/vmParameters + If /java/vmParameters@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional<::std::vector> m_vmParameters; + /** User configurable option. /java/jreLocations + If /java/jreLocations@xsi:nil == true then the value is uninitialized + after a call to load. + */ + std::optional<::std::vector> m_JRELocations; + +public: + explicit NodeJava(Layer theLayer); + + /** sets m_enabled. + /java/enabled@xsi:nil will be set to false when write is called. + */ + void setEnabled(bool bEnabled); + + /** sets m_sUserClassPath. See setEnabled. + */ + void setUserClassPath(const OUString& sClassPath); + + /** sets m_aInfo. See setEnabled. + @param bAutoSelect + true- called by jfw_setSelectedJRE + false called by jfw_findAndSelectJRE + */ + void setJavaInfo(const JavaInfo* pInfo, bool bAutoSelect); + + /** sets the /java/vmParameters/param elements. + When this method all previous values are removed and replaced + by those in arParameters. + /java/vmParameters@xsi:nil will be set to true when write() is + called. + */ + void setVmParameters(std::vector const& arParameters); + + /** adds a location to the already existing locations. + Note: call load() before, then add the location and then call write(). + */ + void addJRELocation(OUString const& sLocation); + + /** writes the data to user settings. + */ + void write() const; + + /** load the values of the settings file. + */ + void load(); + + /** returns the value of the element /java/enabled + */ + const std::optional& getEnabled() const { return m_enabled; } + /** returns the value of the element /java/userClassPath. + */ + const std::optional& getUserClassPath() const { return m_userClassPath; } + + /** returns the value of the element /java/javaInfo. + */ + const std::optional& getJavaInfo() const { return m_javaInfo; } + + /** returns the parameters from the element /java/vmParameters/param. + */ + const std::optional<::std::vector>& getVmParameters() const { return m_vmParameters; } + + /** returns the parameters from the element /java/jreLocations/location. + */ + const std::optional<::std::vector>& getJRELocations() const { return m_JRELocations; } +}; + +/** merges the settings for shared, user and installation during construction. + The class uses a simple merge mechanism for the javasettings.xml files in share and + user. The following elements completely overwrite the corresponding elements + from share: + /java/enabled + /java/userClassPath + /java/vmParameters + /java/jreLocations + /java/javaInfo + + In case of an installation, the shared and user settings are completely + disregarded. + + The locations of the different settings files is obtained through the + bootstrap variables: + UNO_JAVA_JFW_USER_DATA + UNO_JAVA_JFW_SHARED_DATA + + The class also determines useful default values for settings which have not been made. +*/ +class MergedSettings final +{ +private: + MergedSettings& operator=(MergedSettings const&) = delete; + MergedSettings(MergedSettings const&) = delete; + + void merge(const NodeJava& share, const NodeJava& user); + + bool m_bEnabled; + + OUString m_sClassPath; + + ::std::vector m_vmParams; + + ::std::vector m_JRELocations; + + CNodeJavaInfo m_javaInfo; + +public: + MergedSettings(); + ~MergedSettings(); + + /** the default is true. + */ + bool getEnabled() const { return m_bEnabled; } + + const OUString& getUserClassPath() const { return m_sClassPath; } + + ::std::vector getVmParametersUtf8() const; + /** returns a JavaInfo structure representing the node + /java/javaInfo. Every time a new JavaInfo structure is created + which needs to be freed by the caller. + If both, user and share settings are nil, then NULL is returned. + */ + std::unique_ptr createJavaInfo() const; + + /** returns the value of the attribute /java/javaInfo[@vendorUpdate]. + */ + OString const& getJavaInfoAttrVendorUpdate() const { return m_javaInfo.sAttrVendorUpdate; } + +#ifdef _WIN32 + /** returns the javaInfo@autoSelect attribute. + Before calling this function loadFromSettings must be called. + It uses the javaInfo@autoSelect attribute to determine + the return value; + */ + bool getJavaInfoAttrAutoSelect() const; +#endif + + void getVmParametersArray(std::vector* parParameters) const; + + const ::std::vector& getJRELocations() const { return m_JRELocations; } +}; + +struct VersionInfo +{ + ::std::vector vecExcludeVersions; + OUString sMinVersion; + OUString sMaxVersion; +}; + +} //end namespace +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/fwkbase.hxx b/jvmfwk/inc/fwkbase.hxx new file mode 100644 index 0000000000..61c3fa5001 --- /dev/null +++ b/jvmfwk/inc/fwkbase.hxx @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_INC_FWKBASE_HXX +#define INCLUDED_JVMFWK_INC_FWKBASE_HXX + +#include + +#include +#include + +#include +#include "libxmlutil.hxx" + +namespace jfw +{ +struct VersionInfo; + +class VendorSettings +{ + CXmlDocPtr m_xmlDocVendorSettings; + CXPathContextPtr m_xmlPathContextVendorSettings; + +public: + VendorSettings(); + + VersionInfo getVersionInformation(std::u16string_view sVendor) const; +}; + +/* The class offers functions to retrieve verified bootstrap parameters. + */ +namespace BootParams +{ +/* Gets the file URL to the JRE which has been determined by the + bootstrap parameter UNO_JAVA_JFW_JREHOME or UNO_JAVA_JFW_ENV_JREHOME. + + In direct mode either of them must be set. If not an exception is thrown. +*/ +OUString getJREHome(); + +::std::vector getVMParameters(); + +OUString getUserData(); + +OUString getSharedData(); + +/* returns the file URL to the vendor settings xml file. + */ +OUString getVendorSettings(); + +/* User the parameter UNO_JAVA_JFW_CLASSPATH and UNO_JAVA_JFW_ENV_CLASSPATH + to compose a classpath + */ +OString getClasspath(); + +OUString getClasspathUrls(); + +} //end namespace + +enum JFW_MODE +{ + JFW_MODE_APPLICATION, + + JFW_MODE_DIRECT +}; + +JFW_MODE getMode(); + +/** creates the -Djava.class.path option with the complete classpath, including + the paths which are set by UNO_JAVA_JFW_CLASSPATH_URLS. + */ +OString makeClassPathOption(std::u16string_view sUserClassPath); + +OString getSettingsPath(const OUString& sURL); + +/** Get the system path to the javasettings.xml + Converts the URL returned from getUserSettingsURL to a + Systempath. An empty string is returned if the file + does not exist. + @throws FrameworkException + */ +OString getUserSettingsPath(); + +/** Returns the system path of the share settings file. + Returns a valid string or throws an exception. + @throws FrameworkException + */ +OString getSharedSettingsPath(); + +/* returns a valid string or throws an exception. + @throws FrameworkException + */ +OString getVendorSettingsPath(); + +/** Called from writeJavaInfoData. It sets the process identifier. When +java is to be started, then the current id is compared to the one set by +this function. If they are identical then the Java was selected in the +same process. If that Java needs a prepared environment, such as a +LD_LIBRARY_PATH, then it must not be started in this process. +*/ +void setJavaSelected(); + +/** Determines if the currently selected Java was set in this process. + + @see setProcessId() + */ +bool wasJavaSelectedInSameProcess(); +/* Only for application mode. + */ +OUString getApplicationClassPath(); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/fwkutil.hxx b/jvmfwk/inc/fwkutil.hxx new file mode 100644 index 0000000000..76d437ae76 --- /dev/null +++ b/jvmfwk/inc/fwkutil.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_SOURCE_FWKUTIL_HXX +#define INCLUDED_JVMFWK_SOURCE_FWKUTIL_HXX + +#include + +#include +#include +#include +#include + +namespace osl { class Mutex; } + +namespace jfw +{ + +/** Returns the file URL of the directory where the framework library + (this library) resides. +*/ +OUString getLibraryLocation(); + +/** provides a bootstrap class which already knows the values from the + jvmfkwrc file. +*/ +const rtl::Bootstrap * Bootstrap(); + +osl::Mutex& FwkMutex(); + +rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData); +rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data); + +OUString getDirFromFile(std::u16string_view usFilePath); + +enum FileStatus +{ + FILE_OK, + FILE_DOES_NOT_EXIST, + FILE_INVALID +}; + +/** checks if the URL is a file. + + If it is a link to a file than + it is resolved. Assuming that the argument + represents a relative URL then FILE_INVALID + is returned. + + + @return + one of the values of FileStatus. + + @exception + Errors occurred during determining if the file exists + */ +FileStatus checkFileURL(const OUString & path); + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/libxmlutil.hxx b/jvmfwk/inc/libxmlutil.hxx new file mode 100644 index 0000000000..2599cff505 --- /dev/null +++ b/jvmfwk/inc/libxmlutil.hxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX +#define INCLUDED_JVMFWK_INC_LIBXMLUTIL_HXX + +#include + +#include + +#include +#include +#include + +namespace jfw +{ +class CXPathObjectPtr +{ + xmlXPathObject* _object; + CXPathObjectPtr& operator=(const CXPathObjectPtr&) = delete; + CXPathObjectPtr(const CXPathObjectPtr&) = delete; + +public: + CXPathObjectPtr(); + CXPathObjectPtr(xmlXPathObject*); + ~CXPathObjectPtr(); + /** Takes ownership of xmlXPathObject + */ + CXPathObjectPtr& operator=(xmlXPathObject* pObj); + xmlXPathObject* operator->() { return _object; } + operator xmlXPathObject*() const { return _object; } +}; + +class CXPathContextPtr +{ + xmlXPathContext* _object; + + CXPathContextPtr(const jfw::CXPathContextPtr&) = delete; + CXPathContextPtr& operator=(const CXPathContextPtr&) = delete; + +public: + CXPathContextPtr(); + CXPathContextPtr(xmlXPathContextPtr aContext); + CXPathContextPtr& operator=(xmlXPathContextPtr pObj); + ~CXPathContextPtr(); + operator xmlXPathContext*() const { return _object; } +}; + +class CXmlDocPtr +{ + xmlDoc* _object; + + CXmlDocPtr(const CXmlDocPtr&) = delete; + +public: + CXmlDocPtr& operator=(const CXmlDocPtr&); + CXmlDocPtr(); + CXmlDocPtr(xmlDoc* aDoc); + /** Takes ownership of xmlDoc + */ + CXmlDocPtr& operator=(xmlDoc* pObj); + ~CXmlDocPtr(); + operator xmlDoc*() const { return _object; } +}; + +class CXmlCharPtr +{ + xmlChar* _object; + + CXmlCharPtr(const CXmlCharPtr&) = delete; + CXmlCharPtr& operator=(const CXmlCharPtr&) = delete; + +public: + CXmlCharPtr(); + CXmlCharPtr(xmlChar* aDoc); + explicit CXmlCharPtr(std::u16string_view); + ~CXmlCharPtr(); + CXmlCharPtr& operator=(xmlChar* pObj); + operator xmlChar*() const { return _object; } + operator OUString(); + operator OString() { return reinterpret_cast(_object); } +}; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/inc/vendorbase.hxx b/jvmfwk/inc/vendorbase.hxx new file mode 100644 index 0000000000..210b2f1da2 --- /dev/null +++ b/jvmfwk/inc/vendorbase.hxx @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX + +#include +#include +#include +#include +#include + +namespace jfw_plugin +{ +//Used by subclasses of VendorBase to build paths to Java runtime +#if defined(JAVA_ARCH) +#define JFW_PLUGIN_ARCH JAVA_ARCH +#elif defined SPARC64 +#define JFW_PLUGIN_ARCH "sparcv9" +#elif defined SPARC +#define JFW_PLUGIN_ARCH "sparc" +#elif defined X86_64 +#define JFW_PLUGIN_ARCH "amd64" +#elif defined ARM64 +#define JFW_PLUGIN_ARCH "arm64" +#elif defined INTEL +#define JFW_PLUGIN_ARCH "i386" +#elif defined POWERPC64 +#define JFW_PLUGIN_ARCH "ppc64" +#elif defined POWERPC +#define JFW_PLUGIN_ARCH "ppc" +#elif defined MIPS +#ifdef OSL_BIGENDIAN +#define JFW_PLUGIN_ARCH "mips" +#else +/* FIXME: do JDKs have some JDK-specific define? This is for +OpenJDK at least, but probably not true for Lemotes JDK */ +#define JFW_PLUGIN_ARCH "mipsel" +#endif +#elif defined MIPS64 +#ifdef OSL_BIGENDIAN +#define JFW_PLUGIN_ARCH "mips64" +#else +#define JFW_PLUGIN_ARCH "mips64el" +#endif +#elif defined RISCV64 +#define JFW_PLUGIN_ARCH "riscv64" +#elif defined S390X +#define JFW_PLUGIN_ARCH "s390x" +#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" +#elif defined LOONGARCH64 +#define JFW_PLUGIN_ARCH "loongarch64" +#else // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA, LOONGARCH64 +#error unknown platform +#endif // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA, LOONGARCH64 + +class MalformedVersionException final : public std::exception +{ +public: + virtual ~MalformedVersionException() override; +}; + +class VendorBase : public salhelper::SimpleReferenceObject +{ +public: + VendorBase(); + /* static char const* const * getJavaExePaths(int* size); + + returns relative paths to the java executable as + file URLs. + + For example "bin/java.exe". You need + to implement this function in a derived class, if + the paths differ. this implementation provides for + Windows "bin/java.exe" and for Unix "bin/java". + The paths are relative file URLs. That is, they always + contain '/' even on windows. The paths are relative + to the installation directory of a JRE. + + + The signature of this function must correspond to + getJavaExePaths_func. + */ + + /* static rtl::Reference createInstance(); + + creates an instance of this class. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @param + Key - value pairs of the system properties of the JRE. + */ + + const OUString& getVendor() const; + const OUString& getVersion() const; + const OUString& getHome() const; + const OUString& getRuntimeLibrary() const; + const OUString& getLibraryPath() const; + bool isValidArch() const; + /* determines if prior to running java something has to be done, + like setting the LD_LIBRARY_PATH. This implementation checks + if an LD_LIBRARY_PATH (getLD_LIBRARY_PATH) needs to be set and + if so, needsRestart returns true. + */ + bool needsRestart() const; + + /* compares versions of this vendor. MUST be overridden + in a derived class. + #################################################### + OVERRIDE in derived class + ################################################### + @return + 0 this.version == sSecond + 1 this.version > sSecond + -1 this.version < sSEcond + + @throw + MalformedVersionException if the version string was not recognized. + */ + virtual int compareVersions(const OUString& sSecond) const = 0; + +protected: + /* called automatically on the instance created by createInstance. + + @return + true - the object could completely initialize. + false - the object could not completely initialize. In this case + it will be discarded by the caller. + */ + bool initialize(const std::vector>& props); + + /* returns relative file URLs to the runtime library. + For example "/bin/client/jvm.dll" + */ + virtual char const* const* getRuntimePaths(int* size) = 0; + + virtual char const* const* getLibraryPaths(int* size) = 0; + + typedef rtl::Reference (*createInstance_func)(); + friend rtl::Reference + createInstance(createInstance_func pFunc, + const std::vector>& properties); + +private: + OUString m_sVendor; + OUString m_sVersion; + OUString m_sHome; + OUString m_sRuntimeLibrary; + OUString m_sLD_LIBRARY_PATH; + OUString m_sArch; +}; +} + +#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 0000000000..4c24903baa --- /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: */ -- cgit v1.2.3