summaryrefslogtreecommitdiffstats
path: root/jvmfwk/inc
diff options
context:
space:
mode:
Diffstat (limited to 'jvmfwk/inc')
-rw-r--r--jvmfwk/inc/elements.hxx330
-rw-r--r--jvmfwk/inc/fwkbase.hxx132
-rw-r--r--jvmfwk/inc/fwkutil.hxx95
-rw-r--r--jvmfwk/inc/libxmlutil.hxx99
-rw-r--r--jvmfwk/inc/vendorbase.hxx186
-rw-r--r--jvmfwk/inc/vendorplugin.hxx245
6 files changed, 1087 insertions, 0 deletions
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 <sal/config.h>
+
+#include <memory>
+#include <vector>
+#include "fwkutil.hxx"
+#include <rtl/ustring.hxx>
+#include <rtl/byteseq.hxx>
+#include <libxml/parser.h>
+#include <optional>
+
+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 <updated> 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<JavaInfo> 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<sal_Bool> 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<CNodeJavaInfo> 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<OUString> 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<sal_Bool> & 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<CNodeJavaInfo> & 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<JavaInfo> 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<OUString> * 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 <sal/config.h>
+
+#include <optional>
+
+#include <rtl/ustring.hxx>
+#include "libxmlutil.hxx"
+
+namespace jfw
+{
+
+struct VersionInfo;
+
+class VendorSettings
+{
+ CXmlDocPtr m_xmlDocVendorSettings;
+ CXPathContextPtr m_xmlPathContextVendorSettings;
+
+public:
+ VendorSettings();
+
+ std::optional<VersionInfo> 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 <config_folders.h>
+
+#include <sal/config.h>
+#include <sal/log.hxx>
+#include <rtl/bootstrap.hxx>
+#include <rtl/instance.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/byteseq.hxx>
+
+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<osl::Mutex, FwkMutex> {};
+
+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 <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <rtl/ustring.hxx>
+
+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<char*>(_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 <rtl/ustring.hxx>
+#include <rtl/ref.hxx>
+#include <osl/endian.h>
+#include <salhelper/simplereferenceobject.hxx>
+#include <vector>
+
+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<VendorBase> 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<std::pair<OUString, OUString> > 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<VendorBase> (* createInstance_func) ();
+ friend rtl::Reference<VendorBase> createInstance(
+ createInstance_func pFunc,
+ const std::vector<std::pair<OUString, OUString> >& 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 <rtl/ustring.hxx>
+#include <jni.h>
+
+#include <memory>
+#include <vector>
+
+namespace jfw_plugin { class VendorBase; }
+namespace rtl { template <class reference_type> class Reference; }
+
+struct JavaInfo;
+
+namespace jfw { class VendorSettings; }
+
+/**
+ @file
+ <p>
+ 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. </p>
+ */
+
+enum class javaPluginError
+{
+ NONE,
+ Error,
+ InvalidArg,
+ WrongVersionFormat,
+ FailedVersion,
+ NoJre,
+ WrongArch,
+ VmCreationFailed
+};
+
+
+/** obtains information about installations of Java Runtime Environments (JREs).
+
+ <p>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 <code>vendorSettings</code>.
+ </p>
+ <p>
+ The JavaInfo structures returned in <code>parJavaInfo</code> should be ordered
+ according to their version. The one, representing a JRE with the highest
+ version should be the first in the array. </p>
+ @param parJavaInfo
+ [out] if the function runs successfully then <code>parJavaInfo</code> contains
+ on return a vector of pointers to <code>JavaInfo</code> objects.
+
+ @return
+ javaPluginError::NONE the function ran successfully.</br>
+ javaPluginError::Error an error occurred during execution.</br>
+ javaPluginError::WrongVersionFormat the version strings in
+ <code>vendorSettings</code> are not recognized as valid
+ version strings.
+ */
+javaPluginError jfw_plugin_getAllJavaInfos(
+ bool checkJavaHomeAndPath,
+ jfw::VendorSettings const & vendorSettings,
+ std::vector<std::unique_ptr<JavaInfo>> * parJavaInfo,
+ std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
+
+/** obtains information for a JRE at a given location.
+
+ <p>If the given location belongs to a JRE
+ and the JRE has a version which meets the requirements as
+ specified by <code>vendorSettings</code> then
+ this function shall return a JavaInfo object for this JRE.</p>
+
+ @param sLocation
+ [in] a file URL to the directory of the JRE.
+ @param ppInfo
+ [out] if the function runs successfully then <code>ppInfo</code> contains
+ on return a pointer to a <code>JavaInfo</code> object.
+
+ @return
+ javaPluginError::NONE the function ran successfully.</br>
+ javaPluginError::Error an error occurred during execution.</br>
+ javaPluginError::InvalidArg an argument was not valid. For example, sLocation
+ is an empty string.</br>
+ 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<JavaInfo> * ppInfo);
+
+
+/** obtains information for a JRE referenced by the JAVA_HOME environment variable.
+
+ <p>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.</p>
+
+ @param ppInfo
+ [out] if the JAVA_HOME environment variable is set and points to a suitable
+ JRE, then <code>ppInfo</code> contains
+ on return a pointer to its <code>JavaInfo</code> object.
+
+ @return
+ javaPluginError::NONE the function ran successfully.</br>
+ 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<JavaInfo> * ppInfo,
+ std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
+
+
+/** obtains information about installations of Java Runtime Environments (JREs)
+ whose executable is in the PATH.
+
+ <p>The function gathers information about available JREs which are on the PATH
+ (PATH environment variable) and meet the version requirements given by
+ <code>vendorSettings</code> (i.e.
+ the version requirements, if any, for the vendor are met).
+ </p>
+ <p>
+ The JavaInfo structures returned in <code>vecJavaInfosFromPath</code> 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.</p>
+ @param vecJavaInfosFromPath
+ [out] if the function runs successfully then <code>vecJavaInfosFromPath</code>
+ contains on return a vector of pointers to <code>JavaInfo</code> objects.
+ On return of this function, <code>vecJavaInfosFromPath</code> references
+ a newly created vector rather than the same vector as before with
+ the <code>JavaInfo</code> objects inserted into the existing vector.
+
+ @return
+ javaPluginError::NONE the function ran successfully and at least one JRE
+ that meets the requirements was found.</br>
+ 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<std::unique_ptr<JavaInfo>> & vecJavaInfosFromPath,
+ std::vector<rtl::Reference<jfw_plugin::VendorBase>> & infos);
+
+/** starts a Java Virtual Machine.
+
+ <p>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.
+ <p>
+ The function must ensure, that the VM does not abort the process
+ during instantiation.</p>
+ <p>
+ The function receives a <code>JavaInfo</code> object that was created
+ by the functions <code>jfw_plugin_getJavaInfoByPath</code> or
+ <code>jfw_plugin_getAllJavaInfos</code> from the same library. This can be
+ guaranteed if an application uses exactly one library for one vendor.
+ Therefore the functions which create the <code>JavaInfo</code> can store all
+ necessary information which are needed for starting the VM into that
+ structure. </p>
+
+ @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 <code>arOptions</code>.
+ @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.</br>
+ javaPluginError::Error an error occurred during execution.</br>
+ 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.</br>
+ javaPluginError::Error an error occurred during execution.</br>
+ javaPluginError::InvalidArg pInfo contains invalid data</br>
+ */
+javaPluginError jfw_plugin_existJRE(const JavaInfo *pInfo, bool *exist);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */