From e61aa88e3dffcff717e7683cf18727701fcbb360 Mon Sep 17 00:00:00 2001 From: Joachim Lingner Date: Wed, 21 Apr 2004 08:30:36 +0000 Subject: #i20052# --- jvmfwk/inc/jvmfwk/framework.h | 48 ++++++-- jvmfwk/inc/jvmfwk/vendorplugin.h | 22 +++- jvmfwk/source/elements.cxx | 254 ++++++++++++++++++++++++++++++--------- jvmfwk/source/elements.hxx | 43 +++++-- jvmfwk/source/framework.cxx | 236 +++++++++++++++++++++++++++++++++++- jvmfwk/source/framework.map | 4 + jvmfwk/source/javasettings.xsd | 7 ++ 7 files changed, 532 insertions(+), 82 deletions(-) (limited to 'jvmfwk') diff --git a/jvmfwk/inc/jvmfwk/framework.h b/jvmfwk/inc/jvmfwk/framework.h index 46db70224a6d..4255cc12b0ba 100644 --- a/jvmfwk/inc/jvmfwk/framework.h +++ b/jvmfwk/inc/jvmfwk/framework.h @@ -2,9 +2,9 @@ * * $RCSfile: framework.h,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2004-04-19 14:09:00 $ + * last change: $Author: jl $ $Date: 2004-04-21 09:30:34 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -168,7 +168,8 @@ javaFrameworkError SAL_CALL jfw_findAndSelectJava(JavaInfo **pInfo); pparInfo. If the path for some reason is no JRE then the path will be removed from an internal list.

*/ -javaFrameworkError SAL_CALL jfw_findAllJavas(JavaInfo ***pparInfo, sal_Int32 size); +javaFrameworkError SAL_CALL jfw_findAllJREs( + JavaInfo ***pparInfo, sal_Int32 *pSize); /** determines if a path belongs to a Java installation.

@@ -327,13 +328,13 @@ javaFrameworkError SAL_CALL jfw_getEnabled(sal_Bool *pbEnabled); /** sets options, such as debug options. - arOptions can be null if nLen is also 0. + arOptions can be null if nSize is also 0. @return - JFW_E_INVALIDARG arOptions is NULL and nLen is not 0 + JFW_E_INVALIDARG arOptions is NULL and nSize is not 0 */ javaFrameworkError SAL_CALL jfw_setVMParameters( - rtl_uString ** arParameters, sal_Int32 nLen); + rtl_uString ** arParameters, sal_Int32 nSize); /** Caller needs to free the returned array with rtl_freeMemory. The containes rtl_uStrings must be released with rtl_uString_release. @@ -344,11 +345,11 @@ javaFrameworkError SAL_CALL jfw_setVMParameters( JFW_E_CONFIG_READWRITE Error during access of internal data store.
JFW_E_FORMAT_STORE The structure of the internal data store is not as expected.
- JFW_E_INVALIDARG parOptions or pLen are NULL
+ JFW_E_INVALIDARG parOptions or pSize are NULL
*/ javaFrameworkError SAL_CALL jfw_getVMParameters( rtl_uString *** parParameters, - sal_Int32 * pLen); + sal_Int32 * pSize); /** The argument pC must be a valid string. If the value is NULL then @@ -362,23 +363,44 @@ javaFrameworkError SAL_CALL jfw_getUserClassPath(rtl_uString ** ppCP); /** saves the location of a JRE.

- When jfw_findAllJavas is called then the paths added by this + When jfw_findAllJREs is called then the paths added by this function are evaluated. If the location still represents a JRE then a JavaInfo object is created which is returned along with - all other JavaInfo objects by jfw_findAllJavas. If the location - cannot be recognized then the location string is deleted from - an internal list. The next time jfw_findAllJavas is called the - location is not taken into account anymore. + all other JavaInfo objects by jfw_findAllJREs. If the location + cannot be recognized then the location string is ignored.

A validation if sLocation points to a JRE is not performed. To do that one has to use jfw_getJavaInfoByPath.

+

+ Adding a path that is already stored causes no error. @param sLocation File URL to an directory which contains a JRE. */ javaFrameworkError SAL_CALL jfw_addJRELocation(rtl_uString * sLocation); +/** stores an array containing paths to JRE installations. +

+ The function does not verify if the paths points to JRE. However, + it makes sure that every path is unique. That is, if the array + contains string which are the same then only one is stored.

+

+ If arLocations is NULL or arLocations has the length null + then all previously stored paths are deleted. Otherwise, + the old values are overwritten.

+ */ +javaFrameworkError SAL_CALL jfw_setJRELocations( + rtl_uString ** arLocations, sal_Int32 nSize); +/** obtains an array containing paths to JRE installations. +

+ It is not guaranteed that the returned paths represent + a valid JRE. One can use jfw_getJavaInfoByPath to check this. +

+ */ +javaFrameworkError SAL_CALL jfw_getJRELocations( + rtl_uString *** parLocations, sal_Int32 * pSize); + void SAL_CALL jfw_lock(); diff --git a/jvmfwk/inc/jvmfwk/vendorplugin.h b/jvmfwk/inc/jvmfwk/vendorplugin.h index 9935ec0f7e08..bf2b4e33b7ee 100644 --- a/jvmfwk/inc/jvmfwk/vendorplugin.h +++ b/jvmfwk/inc/jvmfwk/vendorplugin.h @@ -2,9 +2,9 @@ * * $RCSfile: vendorplugin.h,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2004-04-19 15:01:15 $ + * last change: $Author: jl $ $Date: 2004-04-21 09:30:35 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -94,6 +94,11 @@ typedef enum In case an error occurred parJavaInfo does not to be freed.

The array parJavaInfo must be freed by the caller with rtl_freeMemory. + @return + JFW_PLUGIN_E_NONE, + JFW_PLUGIN_E_ERROR, + JFW_PLUGIN_E_INVALID_ARG, + JFW_PLUGIN_E_WRONG_VERSION_FORMAT */ javaPluginError getAllJavaInfos( rtl_uString *sMinVersion, @@ -103,6 +108,15 @@ javaPluginError getAllJavaInfos( JavaInfo*** parJavaInfo, sal_Int32 *nLenInfoList); +/** + @return + JFW_PLUGIN_E_NONE + JFW_PLUGIN_E_ERROR + JFW_PLUGIN_E_INVALID_ARG + JFW_PLUGIN_E_WRONG_VERSION_FORMAT + JFW_PLUGIN_E_FAILED_REQUIREMENTS + JFW_PLUGIN_E_NO_JRE + */ javaPluginError getJavaInfoByPath( rtl_uString *path, rtl_uString *sMinVersion, @@ -115,6 +129,10 @@ javaPluginError getJavaInfoByPath(

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

+ @param + JFW_PLUGIN_E_NONE, + JFW_PLUGIN_E_ERROR, + JFW_PLUGIN_E_INVALID_ARG, */ javaPluginError startJavaVirtualMachine( diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx index 3f67908f186b..7f19697ff7c8 100644 --- a/jvmfwk/source/elements.cxx +++ b/jvmfwk/source/elements.cxx @@ -2,9 +2,9 @@ * * $RCSfile: elements.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2004-04-19 15:54:55 $ + * last change: $Author: jl $ $Date: 2004-04-21 09:30:35 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -63,6 +63,7 @@ #include "fwkutil.hxx" #include "libxmlutil.hxx" #include "osl/thread.hxx" +#include #include "libxml/parser.h" #include "libxml/xpath.h" #include "libxml/xpathinternals.h" @@ -113,32 +114,10 @@ sal_Int32 VersionInfo::getExcludeVersionSize() CNodeJava::CNodeJava(): m_bEnabled(sal_True), m_bEnabledModified(false), m_bUserClassPathModified(false), m_bJavaInfoModified(false), - m_bVmParametersModified(false) + m_bVmParametersModified(false), m_bJRELocationsModified(false) { } -void CNodeJava::getVmParametersArray(rtl_uString *** parParams, sal_Int32 * size) -{ - osl::MutexGuard guard(getFwkMutex()); - OSL_ASSERT(parParams != NULL && size != NULL); - - *parParams = (rtl_uString **) - rtl_allocateMemory(sizeof(rtl_uString*) * m_arVmParameters.size()); - if (*parParams == NULL) - return; - - int j=0; - typedef std::vector::const_iterator it; - for (it i = m_arVmParameters.begin(); i != m_arVmParameters.end(); - i++, j++) - { - rtl::OUString sParam = - rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); - (*parParams)[j] = sParam.pData; - rtl_uString_acquire(sParam.pData); - } - *size = m_arVmParameters.size(); -} javaFrameworkError CNodeJava::loadFromSettings() { @@ -255,6 +234,33 @@ javaFrameworkError CNodeJava::loadUserSettings() } } } + else if (xmlStrcmp(cur->name, (xmlChar*) "jreLocations") == 0) + { + CXmlCharPtr sNil = xmlGetNsProp( + cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE); + if (sNil == NULL) + { + OSL_ASSERT(0); + return JFW_E_FORMAT_STORE; + } + if (xmlStrcmp(sNil, (xmlChar*) "false") == 0) + { + //throw away share settings + m_arJRELocations.clear(); + xmlNode * pLoc = cur->children; + while (pLoc != NULL) + { + if (xmlStrcmp(pLoc->name, (xmlChar*) "location") == 0) + { + CXmlCharPtr sLoc = xmlNodeListGetString( + docUser, pLoc->children, 1); + m_arJRELocations.push_back(sLoc); + } + pLoc = pLoc->next; + } + } + } + cur = cur->next; } return errcode; @@ -265,7 +271,7 @@ javaFrameworkError CNodeJava::loadShareSettings() javaFrameworkError errcode = JFW_E_NONE; CXmlDocPtr docShare; - //Read the share elements, do not head the nil attributes + //Read the share elements, do not heed the nil attributes rtl::OString sSettingsPath = jfw::getSharedSettingsPath(); //There must not be a share settings file docShare = xmlParseFile(sSettingsPath.getStr()); @@ -312,26 +318,30 @@ javaFrameworkError CNodeJava::loadShareSettings() } else if (xmlStrcmp(cur->name, (xmlChar*) "vmParameters") == 0) { - CXmlCharPtr sNil = xmlGetNsProp( - cur, (xmlChar*) "nil", (xmlChar*) NS_SCHEMA_INSTANCE); - if (sNil == NULL) + xmlNode * pOpt = cur->children; + while (pOpt != NULL) { - OSL_ASSERT(0); - return JFW_E_FORMAT_STORE; + if (xmlStrcmp(pOpt->name, (xmlChar*) "param") == 0) + { + CXmlCharPtr sOpt = xmlNodeListGetString( + docShare, pOpt->children, 1); + m_arVmParameters.push_back(sOpt); + } + pOpt = pOpt->next; } - if (xmlStrcmp(sNil, (xmlChar*) "false") == 0) + } + else if (xmlStrcmp(cur->name, (xmlChar*) "jreLocations") == 0) + { + xmlNode * pLoc = cur->children; + while (pLoc != NULL) { - xmlNode * pOpt = cur->children; - while (pOpt != NULL) + if (xmlStrcmp(pLoc->name, (xmlChar*) "location") == 0) { - if (xmlStrcmp(pOpt->name, (xmlChar*) "param") == 0) - { - CXmlCharPtr sOpt = xmlNodeListGetString( - docShare, pOpt->children, 1); - m_arVmParameters.push_back(sOpt); - } - pOpt = pOpt->next; + CXmlCharPtr sLoc = xmlNodeListGetString( + docShare, pLoc->children, 1); + m_arJRELocations.push_back(sLoc); } + pLoc = pLoc->next; } } @@ -454,7 +464,7 @@ javaFrameworkError CNodeJava::writeSettings() const typedef std::vector::const_iterator cit; for (cit i = m_arVmParameters.begin(); i != m_arVmParameters.end(); i++) { - xmlNewTextChild(vmParameters, NULL, (xmlChar*) "option", + xmlNewTextChild(vmParameters, NULL, (xmlChar*) "param", (xmlChar*) i->getStr()); //add a new line xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n"); @@ -462,8 +472,47 @@ javaFrameworkError CNodeJava::writeSettings() const } } + //set element + if (m_bJRELocationsModified) + { + rtl::OString sExpression= rtl::OString( + "/jf:java/jf:jreLocations"); + pathObj = xmlXPathEvalExpression((xmlChar*) sExpression.getStr(), + contextUser); + if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval)) + return JFW_E_FORMAT_STORE; + xmlNode* jreLocationsNode = pathObj->nodesetval->nodeTab[0]; + //set xsi:nil = false; + xmlSetNsProp(jreLocationsNode, nsXsi,(xmlChar*) "nil", + (xmlChar*) "false"); + + //remove option elements + xmlNode* cur = jreLocationsNode->children; + while (cur != NULL) + { + xmlNode* lastNode = cur; + cur = cur->next; + xmlUnlinkNode(lastNode); + xmlFreeNode(lastNode); + } + //add a new line after + if (m_arJRELocations.size() > 0) + { + xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n"); + xmlAddChild(jreLocationsNode, nodeCrLf); + } + + typedef std::vector::const_iterator cit; + for (cit i = m_arJRELocations.begin(); i != m_arJRELocations.end(); i++) + { + xmlNewTextChild(jreLocationsNode, NULL, (xmlChar*) "location", + (xmlChar*) i->getStr()); + //add a new line + xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n"); + xmlAddChild(jreLocationsNode, nodeCrLf); + } + } - //set , element must exist // sExpression = if (xmlSaveFormatFile(sSettingsPath.getStr(), docUser, 1) == -1) return JFW_E_CONFIG_READWRITE; @@ -533,7 +582,7 @@ rtl::OUString const & CNodeJava::getJavaInfoAttrVendorUpdate() const return m_aInfo.sAttrVendorUpdate; } -const std::vector & CNodeJava::getVmParameters() +const std::vector & CNodeJava::getVmParameters() const { return m_arVmParameters; } @@ -555,6 +604,99 @@ void CNodeJava::setVmParameters(rtl_uString * * arOptions, sal_Int32 size) m_bVmParametersModified = true; } +void CNodeJava::getVmParametersArray( + rtl_uString *** parParams, sal_Int32 * size) const +{ + osl::MutexGuard guard(getFwkMutex()); + OSL_ASSERT(parParams != NULL && size != NULL); + + *parParams = (rtl_uString **) + rtl_allocateMemory(sizeof(rtl_uString*) * m_arVmParameters.size()); + if (*parParams == NULL) + return; + + int j=0; + typedef std::vector::const_iterator it; + for (it i = m_arVmParameters.begin(); i != m_arVmParameters.end(); + i++, j++) + { + rtl::OUString sParam = + rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); + (*parParams)[j] = sParam.pData; + rtl_uString_acquire(sParam.pData); + } + *size = m_arVmParameters.size(); +} + + +void CNodeJava::setJRELocations(rtl_uString * * arLocations, sal_Int32 size) +{ + OSL_ASSERT( !(arLocations == 0 && size != 0)); + m_arJRELocations.clear(); + if (arLocations != NULL) + { + for (int i = 0; i < size; i++) + { + const rtl::OUString & usLocation = (rtl_uString*) arLocations[i]; + rtl::OString osLocation = rtl::OUStringToOString( + usLocation, RTL_TEXTENCODING_UTF8); + //only add the path if not already present + std::vector::const_iterator it = + std::find(m_arJRELocations.begin(), m_arJRELocations.end(), + osLocation); + if (it == m_arJRELocations.end()) + m_arJRELocations.push_back(osLocation); + } + } + m_bJRELocationsModified = true; +} + +void CNodeJava::addJRELocation(rtl_uString * sLocation) +{ + OSL_ASSERT( sLocation); + + const rtl::OUString & usLocation = sLocation; + rtl::OString osLocation = rtl::OUStringToOString( + usLocation, RTL_TEXTENCODING_UTF8); + //only add the path if not already present + std::vector::const_iterator it = + std::find(m_arJRELocations.begin(), m_arJRELocations.end(), + osLocation); + if (it == m_arJRELocations.end()) + m_arJRELocations.push_back(osLocation); + + m_bJRELocationsModified = true; +} + +const std::vector & CNodeJava::getJRELocations() const +{ + return m_arJRELocations; +} + +void CNodeJava::getJRELocations( + rtl_uString *** parLocations, sal_Int32 * size) const +{ + osl::MutexGuard guard(getFwkMutex()); + OSL_ASSERT(parLocations != NULL && size != NULL); + + *parLocations = (rtl_uString **) + rtl_allocateMemory(sizeof(rtl_uString*) * m_arJRELocations.size()); + if (*parLocations == NULL) + return; + + int j=0; + typedef std::vector::const_iterator it; + for (it i = m_arJRELocations.begin(); i != m_arJRELocations.end(); + i++, j++) + { + rtl::OUString sLocation = + rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); + (*parLocations)[j] = sLocation.pData; + rtl_uString_acquire(sLocation.pData); + } + *size = m_arJRELocations.size(); +} + //===================================================================== CNodeJavaInfo::CNodeJavaInfo() : nFeatures(0), nRequirements(0), bNil(true), m_bEmptyNode(false) @@ -687,21 +829,21 @@ javaFrameworkError CNodeJavaInfo::writeToNode(xmlDoc* pDoc, (xmlChar*) "nil", (xmlChar*) "false"); - //Check if the JavaInfo was set with an empty value, then all - //children are deleted - if (m_bEmptyNode && pJavaInfoNode->children != NULL) + //Delete the children of JavaInfo + xmlNode* cur = pJavaInfoNode->children; + while (cur != NULL) { - xmlNode* cur = pJavaInfoNode->children; - while (cur != NULL) - { - xmlNode* lastNode = cur; - cur = cur->next; - xmlUnlinkNode(lastNode); - xmlFreeNode(lastNode); - } - return errcode; + xmlNode* lastNode = cur; + cur = cur->next; + xmlUnlinkNode(lastNode); + xmlFreeNode(lastNode); } + //If the JavaInfo was set with an empty value, + //then we are done. + if (m_bEmptyNode) + return errcode; + //add a new line after xmlNode * nodeCrLf = xmlNewText((xmlChar*) "\n"); xmlAddChild(pJavaInfoNode, nodeCrLf); diff --git a/jvmfwk/source/elements.hxx b/jvmfwk/source/elements.hxx index 4413f1964c31..f452510935fc 100644 --- a/jvmfwk/source/elements.hxx +++ b/jvmfwk/source/elements.hxx @@ -2,9 +2,9 @@ * * $RCSfile: elements.hxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2004-04-19 15:55:35 $ + * last change: $Author: jl $ $Date: 2004-04-21 09:30:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -168,6 +168,16 @@ class CNodeJava */ std::vector m_arVmParameters; bool m_bVmParametersModified; + + /** User configurable option. /java/jreLocations + The value is valid after loadFromSettings has been called successfully. + The value is that of the user setting. If it is nil + (/java/jreLocations[@xsi:nil = true]) then it represents the share setting. + If there are no share settings then array is empty. + */ + std::vector m_arJRELocations; + bool m_bJRELocationsModified; + public: @@ -214,7 +224,30 @@ public: void setVmParameters(rtl_uString * * arParameters, sal_Int32 size); /** returns the parameters from the element /java/vmParameters/param. */ - const std::vector & getVmParameters(); + const std::vector & getVmParameters() const; + + /** returns an array. + Caller must free the strings and the array. + */ + void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size) const; + + /** sets the /java/jreLocations/location elements. + The values are kept in a vector m_arJRELocations. When this method is + called then the vector is cleared and the new values are inserted. + The xsi:nil attribute of vmParameters will be set to true; + */ + void setJRELocations(rtl_uString * * arParameters, sal_Int32 size); + + void addJRELocation(rtl_uString * sLocation); + /** returns the parameters from the element /java/jreLocations/location. + */ + const std::vector & getJRELocations() const; + + + /** returns an array. + Caller must free the strings and the array. + */ + void getJRELocations(rtl_uString *** parLocations, sal_Int32 * size) const; /** reads user and share settings. user data supersede @@ -228,10 +261,6 @@ public: */ javaFrameworkError writeSettings() const; - /** returns an array. - Caller must free the strings and the array. - */ - void getVmParametersArray(rtl_uString *** parParameters, sal_Int32 * size); }; diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index d16eb5307ebb..89af27dc4d67 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -2,9 +2,9 @@ * * $RCSfile: framework.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: jl $ $Date: 2004-04-19 15:55:05 $ + * last change: $Author: jl $ $Date: 2004-04-21 09:30:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,7 @@ #include "libxml/xpath.h" #include "libxml/xpathinternals.h" #include +#include #include "jni.h" #include "framework.hxx" @@ -90,6 +91,181 @@ namespace { JavaVM * g_pJavaVM = NULL; } +javaFrameworkError SAL_CALL jfw_findAllJREs(JavaInfo ***pparInfo, sal_Int32 *pSize) +{ + osl::MutexGuard guard(jfw::getFwkMutex()); + javaFrameworkError errcode = JFW_E_NONE; + if (pparInfo == NULL || pSize == NULL) + return JFW_E_INVALID_ARG; + + //Prepare the xml document and context + rtl::OString sSettingsPath = jfw::getVendorSettingsPath(); + jfw::CXmlDocPtr doc = xmlParseFile(sSettingsPath.getStr()); + if (doc == NULL) + { + OSL_ASSERT(0); + return JFW_E_ERROR; + } + jfw::CXPathContextPtr context = xmlXPathNewContext(doc); + int reg = xmlXPathRegisterNs(context, (xmlChar*) "jf", + (xmlChar*) NS_JAVA_FRAMEWORK); + if (reg == -1) + return JFW_E_ERROR; + + //Get a list of plugins which provide Java information + std::vector vecPlugins; + errcode = jfw::getVendorPluginURLs(doc, context, & vecPlugins); + if (errcode != JFW_E_NONE) + return errcode; + + + //Add the JavaInfos found by getAllJavaInfos to the vector + //Make sure that the contents are destroyed if this + //function returns with an error + std::vector vecInfo; + //Add the JavaInfos found by getJavaInfoByPath to this vector + //Make sure that the contents are destroyed if this + //function returns with an error + std::vector vecInfoManual; + typedef std::vector::iterator it_info; + //get the list of paths to jre locations which have been + //added manually + jfw::CNodeJava node; + errcode = node.loadFromSettings(); + if (errcode != JFW_E_NONE) + return errcode; + + const std::vector vecJRELocations = + node.getJRELocations(); + //Use every plug-in library to get Java installations. + typedef std::vector::const_iterator ci_pl; + for (ci_pl i = vecPlugins.begin(); i != vecPlugins.end(); i++) + { + const jfw::PluginLibrary & library = *i; + jfw::VersionInfo versionInfo; + errcode = jfw::getVersionInformation(doc, context, library.sVendor, + & versionInfo); + if (errcode != JFW_E_NONE) + { //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_CONFIG_READWRITE; + } + osl::Module pluginLib(library.sPath); + if (pluginLib.is() == sal_False) + { + //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_NO_PLUGIN; + } + getAllJavaInfos_ptr getAllJavaFunc = + (getAllJavaInfos_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getAllJavaInfos"))); + + OSL_ASSERT(getAllJavaFunc); + if (getAllJavaFunc == NULL) + { + //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_ERROR; + } + //get all installations of one vendor according to minVersion, + //maxVersion and excludeVersions + sal_Int32 cInfos = 0; + JavaInfo** arInfos = NULL; + javaPluginError plerr = (*getAllJavaFunc)( + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & arInfos, + & cInfos); + + if (plerr != JFW_PLUGIN_E_NONE) + { //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_ERROR; + } + for (int i = 0; i < cInfos; i++) + vecInfo.push_back(arInfos[i]); + rtl_freeMemory(arInfos); + + //Check if the current plugin can detect JREs at the location + // of the paths added by jfw_setJRELocations or jfw_addJRELocation + //get the function from the plugin + getJavaInfoByPath_ptr getJavaInfoByPathFunc = + (getJavaInfoByPath_ptr) pluginLib.getSymbol( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getJavaInfoByPath"))); + + OSL_ASSERT(getJavaInfoByPathFunc); + if (getJavaInfoByPathFunc == NULL) + { //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_ERROR; + } + typedef std::vector::const_iterator citLoc; + for (citLoc i = vecJRELocations.begin(); + i != vecJRELocations.end(); i++) + { + rtl::OUString sLocation = + rtl::OStringToOUString(*i, RTL_TEXTENCODING_UTF8); + JavaInfo* pInfo = NULL; + plerr = (*getJavaInfoByPathFunc)( + sLocation.pData, + versionInfo.sMinVersion.pData, + versionInfo.sMaxVersion.pData, + versionInfo.getExcludeVersions(), + versionInfo.getExcludeVersionSize(), + & pInfo); + if (plerr == JFW_PLUGIN_E_NO_JRE) + continue; + if (plerr == JFW_PLUGIN_E_FAILED_REQUIREMENTS) + continue; + else if (plerr !=JFW_PLUGIN_E_NONE) + { //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), + jfw_freeJavaInfo); + return JFW_E_ERROR; + } + if (pInfo) + vecInfoManual.push_back(pInfo); + } + } + //create an fill the array of JavaInfo* + sal_Int32 nSize = vecInfo.size() + vecInfoManual.size(); + *pparInfo = (JavaInfo**) rtl_allocateMemory( + nSize * sizeof(JavaInfo*)); + if (*pparInfo == NULL) + { //delete JavaInfo objects + std::for_each(vecInfo.begin(), vecInfo.end(), jfw_freeJavaInfo); + std::for_each(vecInfoManual.begin(), vecInfoManual.end(), jfw_freeJavaInfo); + return JFW_E_ERROR; + } + typedef std::vector::iterator it; + int index = 0; + //Add the automatically detected JREs + for (it i = vecInfo.begin(); i != vecInfo.end(); i++) + (*pparInfo)[index++] = *i; + //Add the manually detected JREs + //ToDo compare if the javainfo is already contained + //new function jfw_isEqualJavaInfo + for (it i = vecInfoManual.begin();i != vecInfoManual.end(); i++) + (*pparInfo)[index++] = *i; + + *pSize = nSize; + return errcode; +} + javaFrameworkError SAL_CALL jfw_startJava(JavaVMOption *arOptions, sal_Int32 cOptions, JavaVM **ppVM, JNIEnv **ppEnv) { @@ -421,8 +597,8 @@ javaFrameworkError SAL_CALL jfw_getJavaInfoByPath( if (pPath == NULL || ppInfo == NULL) return JFW_E_INVALID_ARG; javaFrameworkError errcode = JFW_E_NONE; - sal_Int64 nFeatureFlags = 0L; - jfw::CJavaInfo aCurrentInfo; +// sal_Int64 nFeatureFlags = 0L; +// jfw::CJavaInfo aCurrentInfo; //Prepare the xml document and context rtl::OString sSettingsPath = jfw::getVendorSettingsPath(); jfw::CXmlDocPtr doc = xmlParseFile(sSettingsPath.getStr()); @@ -600,6 +776,58 @@ javaFrameworkError SAL_CALL jfw_getUserClassPath(rtl_uString ** ppCP) return errcode; } +javaFrameworkError SAL_CALL jfw_addJRELocation(rtl_uString * sLocation) +{ + osl::MutexGuard guard(jfw::getFwkMutex()); + javaFrameworkError errcode = JFW_E_NONE; + jfw::CNodeJava node; + + if (sLocation == NULL) + return JFW_E_INVALID_ARG; + errcode = node.loadFromSettings(); + if (errcode != JFW_E_NONE) + return errcode; + node.addJRELocation(sLocation); + errcode = node.writeSettings(); + if (errcode != JFW_E_NONE) + return errcode; + return errcode; + +} + +javaFrameworkError SAL_CALL jfw_setJRELocations( + rtl_uString ** arLocations, sal_Int32 nLen) +{ + osl::MutexGuard guard(jfw::getFwkMutex()); + javaFrameworkError errcode = JFW_E_NONE; + jfw::CNodeJava node; + + if (arLocations == NULL && nLen != 0) + return JFW_E_INVALID_ARG; + node.setJRELocations(arLocations, nLen); + errcode = node.writeSettings(); + if (errcode != JFW_E_NONE) + return errcode; + return errcode; + +} + +javaFrameworkError SAL_CALL jfw_getJRELocations( + rtl_uString *** parLocations, sal_Int32 *pLen) +{ + osl::MutexGuard guard(jfw::getFwkMutex()); + javaFrameworkError errcode = JFW_E_NONE; + if (parLocations == NULL || pLen == NULL) + return JFW_E_INVALID_ARG; + jfw::CNodeJava node; + errcode = node.loadFromSettings(); + if (errcode == JFW_E_NONE) + { + node.getJRELocations(parLocations, pLen); + } + return errcode; +} + void SAL_CALL jfw_lock() { osl::Mutex * mutex = jfw::getFwkMutex(); diff --git a/jvmfwk/source/framework.map b/jvmfwk/source/framework.map index d311ed7110a7..b94ddafc55bb 100644 --- a/jvmfwk/source/framework.map +++ b/jvmfwk/source/framework.map @@ -2,6 +2,7 @@ UDK_3_0_0 { global: # jvmfwk/framework.h: jfw_freeJavaInfo; + jfw_findAllJREs; jfw_findAndSelectJava; jfw_startJava; jfw_isJavaRunning; @@ -14,6 +15,9 @@ UDK_3_0_0 { jfw_getVMParameters; jfw_setUserClassPath; jfw_getUserClassPath; + jfw_setJRELocations; + jfw_getJRELocations; + jfw_addJRELocation; jfw_lock; jfw_unlock; local: diff --git a/jvmfwk/source/javasettings.xsd b/jvmfwk/source/javasettings.xsd index 03b3bf407c37..75107181edf6 100644 --- a/jvmfwk/source/javasettings.xsd +++ b/jvmfwk/source/javasettings.xsd @@ -21,6 +21,7 @@ + @@ -45,4 +46,10 @@ + + + + + + -- cgit