diff options
Diffstat (limited to 'jvmfwk/source')
-rw-r--r-- | jvmfwk/source/elements.cxx | 4 | ||||
-rw-r--r-- | jvmfwk/source/framework.cxx | 273 | ||||
-rw-r--r-- | jvmfwk/source/fwkbase.cxx | 18 | ||||
-rw-r--r-- | jvmfwk/source/fwkbase.hxx | 129 | ||||
-rw-r--r-- | jvmfwk/source/libxmlutil.cxx | 2 | ||||
-rw-r--r-- | jvmfwk/source/libxmlutil.hxx | 98 |
6 files changed, 111 insertions, 413 deletions
diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx index ec77f7ab1cae..4a9477c41db1 100644 --- a/jvmfwk/source/elements.cxx +++ b/jvmfwk/source/elements.cxx @@ -27,9 +27,9 @@ #include <osl/mutex.hxx> #include <osl/file.hxx> #include <fwkutil.hxx> -#include "fwkbase.hxx" +#include <fwkbase.hxx> #include "framework.hxx" -#include "libxmlutil.hxx" +#include <libxmlutil.hxx> #include <osl/thread.hxx> #include <algorithm> #include <libxml/parser.h> diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index a748d77cff37..8d870fd335ae 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -35,7 +35,7 @@ #include "framework.hxx" #include <fwkutil.hxx> #include <elements.hxx> -#include "fwkbase.hxx" +#include <fwkbase.hxx> namespace { @@ -59,8 +59,6 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI osl::MutexGuard guard(jfw::FwkMutex::get()); jfw::VendorSettings aVendorSettings; - std::vector<OUString> vecVendors = - aVendorSettings.getSupportedVendors(); //Add the JavaInfos found by jfw_plugin_getAllJavaInfos to the vector std::vector<std::unique_ptr<JavaInfo>> vecInfo; //get the list of paths to jre locations which have been @@ -68,69 +66,47 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI const jfw::MergedSettings settings; const std::vector<OUString>& vecJRELocations = settings.getJRELocations(); - //Use every plug-in library to get Java installations. - for (auto const & vendor: vecVendors) - { - jfw::VersionInfo versionInfo = - aVendorSettings.getVersionInformation(vendor); + //Use all plug-in libraries to get Java installations. + std::vector<std::unique_ptr<JavaInfo>> arInfos; + std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos; + javaPluginError plerr = jfw_plugin_getAllJavaInfos( + true, + aVendorSettings, + & arInfos, + infos); - //get all installations of one vendor according to minVersion, - //maxVersion and excludeVersions - std::vector<std::unique_ptr<JavaInfo>> arInfos; - std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos; - javaPluginError plerr = jfw_plugin_getAllJavaInfos( - true, - vendor, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions, - & arInfos, - infos); + if (plerr != javaPluginError::NONE) + return JFW_E_ERROR; - if (plerr != javaPluginError::NONE) - return JFW_E_ERROR; + for (auto & j: arInfos) + vecInfo.push_back(std::move(j)); - for (auto & j: arInfos) - vecInfo.push_back(std::move(j)); + //Check if any plugin can detect JREs at the location + // of the paths added by jfw_addJRELocation + //Check every manually added location + for (auto const & ii: vecJRELocations) + { + std::unique_ptr<JavaInfo> aInfo; + plerr = jfw_plugin_getJavaInfoByPath( + ii, + aVendorSettings, + &aInfo); + if (plerr == javaPluginError::NoJre) + continue; + if (plerr == javaPluginError::FailedVersion) + continue; + else if (plerr != javaPluginError::NONE) + return JFW_E_ERROR; - //Check if the current plugin can detect JREs at the location - // of the paths added by jfw_addJRELocation - //Check every manually added location - for (auto const & ii: vecJRELocations) + // Was this JRE already added? + if (std::none_of( + vecInfo.begin(), vecInfo.end(), + [&aInfo](std::unique_ptr<JavaInfo> const & info) { + return areEqualJavaInfo( + info.get(), aInfo.get()); + })) { - std::unique_ptr<JavaInfo> aInfo; - plerr = jfw_plugin_getJavaInfoByPath( - ii, - vendor, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions, - &aInfo); - if (plerr == javaPluginError::NoJre) - continue; - if (plerr == javaPluginError::FailedVersion) - continue; - else if (plerr != javaPluginError::NONE) - return JFW_E_ERROR; - - // Was this JRE already added? Different plugins could detect - // the same JRE. Also make sure vecInfo contains only JavaInfos - // for the vendors for which there is a javaSelection/plugins/ - // library entry in the javavendors.xml; jfw_getJavaInfoByPath - // can return a JavaInfo of any vendor: - if ((std::none_of( - vecInfo.begin(), vecInfo.end(), - [&aInfo](std::unique_ptr<JavaInfo> const & info) { - return areEqualJavaInfo( - info.get(), aInfo.get()); - })) - && (std::find( - vecVendors.begin(), vecVendors.end(), - aInfo->sVendor) - != vecVendors.end())) - { - vecInfo.push_back(std::move(aInfo)); - } + vecInfo.push_back(std::move(aInfo)); } } @@ -304,7 +280,6 @@ javaFrameworkError jfw_startVM( g_pJavaVM = pVm; *ppVM = pVm; } - OSL_ASSERT(plerr != javaPluginError::WrongVendor); } catch (const jfw::FrameworkException& e) { @@ -343,25 +318,13 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) // get list of vendors for Java installations jfw::VendorSettings aVendorSettings; - std::vector<OUString> vecVendors = - aVendorSettings.getSupportedVendors(); - - // save vendors and respective version requirements pair-wise in a vector - std::vector<std::pair<OUString, jfw::VersionInfo>> versionInfos; - for (auto const & vendor : vecVendors) - { - jfw::VersionInfo versionInfo = - aVendorSettings.getVersionInformation(vendor); - - versionInfos.emplace_back(vendor, versionInfo); - } std::vector<rtl::Reference<jfw_plugin::VendorBase>> infos; // first inspect Java installation that the JAVA_HOME // environment variable points to (if it is set) if (jfw_plugin_getJavaInfoFromJavaHome( - versionInfos, &aCurrentInfo, infos) + aVendorSettings, &aCurrentInfo, infos) == javaPluginError::NONE) { // compare features @@ -379,7 +342,7 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) { std::vector<std::unique_ptr<JavaInfo>> vecJavaInfosFromPath; if (jfw_plugin_getJavaInfosFromPath( - versionInfos, vecJavaInfosFromPath, infos) + aVendorSettings, vecJavaInfosFromPath, infos) == javaPluginError::NONE) { for (auto & pJInfo: vecJavaInfosFromPath) @@ -405,31 +368,20 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) // if no suitable Java installation has been found yet: - // first iterate over all vendors to find a suitable Java installation, + // first use jfw_plugin_getAllJavaInfos to find a suitable Java installation, // then try paths that have been added manually if (!bInfoFound) { - //Use every vendor to get Java installations. At the first usable - //Java the loop will break - for (auto const & vendor : vecVendors) + //get all installations + std::vector<std::unique_ptr<JavaInfo>> arInfos; + javaPluginError plerr = jfw_plugin_getAllJavaInfos( + false, + aVendorSettings, + & arInfos, + infos); + + if (plerr == javaPluginError::NONE) { - jfw::VersionInfo versionInfo = - aVendorSettings.getVersionInformation(vendor); - - //get all installations of one vendor according to minVersion, - //maxVersion and excludeVersions - std::vector<std::unique_ptr<JavaInfo>> arInfos; - javaPluginError plerr = jfw_plugin_getAllJavaInfos( - false, - vendor, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions, - & arInfos, - infos); - - if (plerr != javaPluginError::NONE) - continue; //iterate over all installations to find the best which has //all features for (auto & pJInfo: arInfos) @@ -442,7 +394,6 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) //the just found Java implements all required features //currently there is only accessibility!!! aCurrentInfo = std::move(pJInfo); - bInfoFound = true; break; } else if (!aCurrentInfo) @@ -452,12 +403,8 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) aCurrentInfo = std::move(pJInfo); } } - - if (bInfoFound) - break; - //All Java installations found by the current plug-in lib - //do not provide the required features. Try the next plug-in } + if (!aCurrentInfo) {//The plug-ins did not find a suitable Java. Now try the paths which have been //added manually. @@ -466,53 +413,41 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) //node.loadFromSettings(); const std::vector<OUString> & vecJRELocations = settings.getJRELocations(); - //use every plug-in to determine the JavaInfo objects - for (auto const & vendor : vecVendors) + //use all plug-ins to determine the JavaInfo objects + for (auto const & JRELocation : vecJRELocations) { - jfw::VersionInfo versionInfo = - aVendorSettings.getVersionInformation(vendor); - - for (auto const & JRELocation : vecJRELocations) + std::unique_ptr<JavaInfo> aInfo; + javaPluginError err = jfw_plugin_getJavaInfoByPath( + JRELocation, + aVendorSettings, + &aInfo); + if (err == javaPluginError::NoJre) + continue; + if (err == javaPluginError::FailedVersion) + continue; + else if (err !=javaPluginError::NONE) + return JFW_E_ERROR; + + if (aInfo) { - std::unique_ptr<JavaInfo> aInfo; - javaPluginError err = jfw_plugin_getJavaInfoByPath( - JRELocation, - vendor, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions, - &aInfo); - if (err == javaPluginError::NoJre) - continue; - if (err == javaPluginError::FailedVersion) - continue; - else if (err !=javaPluginError::NONE) - return JFW_E_ERROR; - - if (aInfo) + // compare features + // If the user does not require any features (nFeatureFlags = 0) + // then the first installation is used + if ((aInfo->nFeatures & nFeatureFlags) == nFeatureFlags) { - // compare features - // If the user does not require any features (nFeatureFlags = 0) - // then the first installation is used - if ((aInfo->nFeatures & nFeatureFlags) == nFeatureFlags) - { - //the just found Java implements all required features - //currently there is only accessibility!!! - aCurrentInfo = std::move(aInfo); - bInfoFound = true; - break; - } - else if (!aCurrentInfo) - { - // We remember the very first installation in - // aCurrentInfo: - aCurrentInfo = std::move(aInfo); - } + //the just found Java implements all required features + //currently there is only accessibility!!! + aCurrentInfo = std::move(aInfo); + break; } - }//end iterate over paths - if (bInfoFound) - break; - }// end iterate plug-ins + else if (!aCurrentInfo) + { + // We remember the very first installation in + // aCurrentInfo: + aCurrentInfo = std::move(aInfo); + } + } + }//end iterate over paths } } if (aCurrentInfo) @@ -623,43 +558,21 @@ javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr osl::MutexGuard guard(jfw::FwkMutex::get()); jfw::VendorSettings aVendorSettings; - std::vector<OUString> vecVendors = - aVendorSettings.getSupportedVendors(); - //Use every plug-in library to determine if the path represents a - //JRE. If a plugin recognized it then the loop will break - for (auto const & vendor : vecVendors) - { - jfw::VersionInfo versionInfo = - aVendorSettings.getVersionInformation(vendor); - - //ask the plugin if this is a JRE. - //If so check if it meets the version requirements. - //Only if it does return a JavaInfo - javaPluginError plerr = jfw_plugin_getJavaInfoByPath( - pPath, - vendor, - versionInfo.sMinVersion, - versionInfo.sMaxVersion, - versionInfo.vecExcludeVersions, - ppInfo); + //ask all plugins if this is a JRE. + //If so check if it meets the version requirements. + //Only if it does return a JavaInfo + javaPluginError plerr = jfw_plugin_getJavaInfoByPath( + pPath, + aVendorSettings, + ppInfo); - if (plerr == javaPluginError::NONE) - { - break; - } - else if(plerr == javaPluginError::FailedVersion) - {//found JRE but it has the wrong version - ppInfo->reset(); - errcode = JFW_E_FAILED_VERSION; - break; - } - else if (plerr == javaPluginError::NoJre) - {// plugin does not recognize this path as belonging to JRE - continue; - } - OSL_ASSERT(false); + if(plerr == javaPluginError::FailedVersion) + {//found JRE but it has the wrong version + ppInfo->reset(); + errcode = JFW_E_FAILED_VERSION; } + OSL_ASSERT(plerr == javaPluginError::NONE || plerr == javaPluginError::NoJre); if (!*ppInfo && errcode != JFW_E_FAILED_VERSION) errcode = JFW_E_NOT_RECOGNIZED; } diff --git a/jvmfwk/source/fwkbase.cxx b/jvmfwk/source/fwkbase.cxx index db91bdeb38f4..73d7925f8707 100644 --- a/jvmfwk/source/fwkbase.cxx +++ b/jvmfwk/source/fwkbase.cxx @@ -29,7 +29,7 @@ #include "framework.hxx" #include <fwkutil.hxx> #include <elements.hxx> -#include "fwkbase.hxx" +#include <fwkbase.hxx> using namespace osl; @@ -116,11 +116,23 @@ VendorSettings::VendorSettings(): } } -VersionInfo VendorSettings::getVersionInformation(const OUString & sVendor) const +boost::optional<VersionInfo> VendorSettings::getVersionInformation(const OUString & sVendor) const { OSL_ASSERT(!sVendor.isEmpty()); - VersionInfo aVersionInfo; OString osVendor = OUStringToOString(sVendor, RTL_TEXTENCODING_UTF8); + CXPathObjectPtr pathObject; + pathObject = xmlXPathEvalExpression( + reinterpret_cast<xmlChar const *>( + OString( + "/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"" + osVendor + + "\"]/jf:minVersion").getStr()), + m_xmlPathContextVendorSettings); + if (xmlXPathNodeSetIsEmpty(pathObject->nodesetval)) + { + return {}; + } + + VersionInfo aVersionInfo; //Get minVersion OString sExpression = OString( "/jf:javaSelection/jf:vendorInfos/jf:vendor[@name=\"") + diff --git a/jvmfwk/source/fwkbase.hxx b/jvmfwk/source/fwkbase.hxx deleted file mode 100644 index b3779cda96b6..000000000000 --- a/jvmfwk/source/fwkbase.hxx +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- 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_FWKBASE_HXX -#define INCLUDED_JVMFWK_SOURCE_FWKBASE_HXX - -#include <rtl/ustring.hxx> -#include "libxmlutil.hxx" - -namespace jfw -{ - -class VendorSettings -{ - OUString m_xmlDocVendorSettingsFileUrl; - CXmlDocPtr m_xmlDocVendorSettings; - CXPathContextPtr m_xmlPathContextVendorSettings; - -public: - VendorSettings(); - - VersionInfo getVersionInformation(const OUString & sVendor) const; - - ::std::vector< OUString> getSupportedVendors() 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/source/libxmlutil.cxx b/jvmfwk/source/libxmlutil.cxx index d2fe64e391a5..5f1ec5784eb5 100644 --- a/jvmfwk/source/libxmlutil.cxx +++ b/jvmfwk/source/libxmlutil.cxx @@ -17,7 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "libxmlutil.hxx" +#include <libxmlutil.hxx> namespace jfw { diff --git a/jvmfwk/source/libxmlutil.hxx b/jvmfwk/source/libxmlutil.hxx deleted file mode 100644 index 8a58280b406d..000000000000 --- a/jvmfwk/source/libxmlutil.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- 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_LIBXMLUTIL_HXX -#define INCLUDED_JVMFWK_SOURCE_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(); - /** 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(); - explicit 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(); - explicit 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(); - explicit CXmlCharPtr(xmlChar* aDoc); - explicit CXmlCharPtr(const OUString &); - ~CXmlCharPtr(); - CXmlCharPtr & operator = (xmlChar* pObj); - operator xmlChar* () const { return _object;} - operator OUString (); - operator OString () { return OString(reinterpret_cast<sal_Char*>(_object));} -}; - - -} -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |