diff options
author | Joachim Lingner <jl@openoffice.org> | 2004-05-17 12:55:32 +0000 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2004-05-17 12:55:32 +0000 |
commit | a917e5f73090323c80a5cd0670ea1d2dd69edadb (patch) | |
tree | 2e5f2d0b5c7fe4e98023a7238c9d9edcfbf126e2 | |
parent | 4078f3b82ff4035f17257e965ed56178ffcff983 (diff) |
#i20052#
-rw-r--r-- | jvmfwk/source/framework.cxx | 177 | ||||
-rw-r--r-- | jvmfwk/source/fwkutil.cxx | 119 | ||||
-rw-r--r-- | jvmfwk/source/fwkutil.hxx | 48 |
3 files changed, 236 insertions, 108 deletions
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index 7c6e9b51d5fa..a4ab231a3fe8 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -2,9 +2,9 @@ * * $RCSfile: framework.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: jl $ $Date: 2004-05-13 11:15:02 $ + * last change: $Author: jl $ $Date: 2004-05-17 13:55:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -63,6 +63,7 @@ #include "rtl/ustrbuf.hxx" #include "osl/thread.hxx" #include "osl/module.hxx" +#include "osl/process.h" #include "sal/config.h" #include "jvmfwk/framework.h" #include "jvmfwk/vendorplugin.h" @@ -299,74 +300,94 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti return JFW_E_RUNNING_JVM; if (ppVM == NULL) return JFW_E_INVALID_ARG; -#ifdef WNT - //Because on Windows there is no system setting that we can use to determine - //if Assistive Technology Tool support is needed, we ship a .reg file that the - //user can use to create a registry setting. When the user forgets to set - //the key before he starts the office then a JRE may be selected without access bridge. - //When he later sets the key then we select a JRE with accessibility support but - //only if the user has not manually changed the selected JRE in the options dialog. - if (jfw::isAccessibilitySupportDesired()) + + jfw::CNodeJava javaSettings; + jfw::CJavaInfo aInfo; + jfw::JFW_MODE mode = jfw::getMode(); + + if (mode == jfw::JFW_MODE_OFFICE) { - jfw::CJavaInfo info = NULL; - javaFrameworkError err = JFW_E_NONE; - if ((err = jfw_getSelectedJRE( & info)) != JFW_E_NONE) - return err; - // If no JRE has been selected then we do no select one. This function shall then - //return JFW_E_NO_SELECT - if (info != NULL && - (info->nFeatures & JFW_FEATURE_ACCESSBRIDGE) == 0) +#ifdef WNT + //Because on Windows there is no system setting that we can use to determine + //if Assistive Technology Tool support is needed, we ship a .reg file that the + //user can use to create a registry setting. When the user forgets to set + //the key before he starts the office then a JRE may be selected without access bridge. + //When he later sets the key then we select a JRE with accessibility support but + //only if the user has not manually changed the selected JRE in the options dialog. + if (jfw::isAccessibilitySupportDesired()) { - //has the user manually selected a JRE? - jfw::CNodeJava settings; - if ((errcode = settings.loadFromSettings()) != JFW_E_NONE) - return errcode; - if (settings.getJavaInfoAttrAutoSelect() == true) + jfw::CJavaInfo info = NULL; + javaFrameworkError err = JFW_E_NONE; + if ((err = jfw_getSelectedJRE( & info)) != JFW_E_NONE) + return err; + // If no JRE has been selected then we do no select one. This function shall then + //return JFW_E_NO_SELECT + if (info != NULL && + (info->nFeatures & JFW_FEATURE_ACCESSBRIDGE) == 0) { - //The currently selected JRE has no access bridge - if ((err = jfw_findAndSelectJRE(NULL)) != JFW_E_NONE) - return err; + //has the user manually selected a JRE? + jfw::CNodeJava settings; + if ((errcode = settings.loadFromSettings()) != JFW_E_NONE) + return errcode; + if (settings.getJavaInfoAttrAutoSelect() == true) + { + //The currently selected JRE has no access bridge + if ((err = jfw_findAndSelectJRE(NULL)) != JFW_E_NONE) + return err; + } } } - } #endif - jfw::CNodeJava javaSettings; - if ((errcode = javaSettings.loadFromSettings()) != JFW_E_NONE) - return errcode; + if ((errcode = javaSettings.loadFromSettings()) != JFW_E_NONE) + return errcode; - //get the current java setting (javaInfo) - jfw::CJavaInfo aInfo(javaSettings.getJavaInfo()); - //check if a Java has ever been selected - if (aInfo == NULL) - return JFW_E_NO_SELECT; - //check if the javavendors.xml has changed after a Java was selected - rtl::OString sVendorUpdate; - if ((errcode = jfw::getElementUpdated(sVendorUpdate)) - != JFW_E_NONE) - return errcode; - if (sVendorUpdate != javaSettings.getJavaInfoAttrVendorUpdate()) - return JFW_E_INVALID_SETTINGS; - - //check if JAVA is disabled - //If Java is enabled, but it was disabled when this process was started - // then no preparational work, such as setting the LD_LIBRARY_PATH, was - //done. Therefore if a JRE needs it it must not be started. - if (javaSettings.getEnabled() == sal_False) - return JFW_E_JAVA_DISABLED; - else if (g_bEnabledSwitchedOn && - (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)) - return JFW_E_NEED_RESTART; - - //Check if the selected Java was set in this process. If so it - //must not have the requirments flag JFW_REQUIRE_NEEDRESTART - if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART) - && - (jfw::wasJavaSelectedInSameProcess() == true)) - return JFW_E_NEED_RESTART; + //get the current java setting (javaInfo) + aInfo = javaSettings.getJavaInfo(); + //check if a Java has ever been selected + if (aInfo == NULL) + return JFW_E_NO_SELECT; + //check if the javavendors.xml has changed after a Java was selected + rtl::OString sVendorUpdate; + if ((errcode = jfw::getElementUpdated(sVendorUpdate)) + != JFW_E_NONE) + return errcode; + if (sVendorUpdate != javaSettings.getJavaInfoAttrVendorUpdate()) + return JFW_E_INVALID_SETTINGS; + //check if JAVA is disabled + //If Java is enabled, but it was disabled when this process was started + // then no preparational work, such as setting the LD_LIBRARY_PATH, was + //done. Therefore if a JRE needs it it must not be started. + if (javaSettings.getEnabled() == sal_False) + return JFW_E_JAVA_DISABLED; + else if (g_bEnabledSwitchedOn && + (aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART)) + return JFW_E_NEED_RESTART; + + //Check if the selected Java was set in this process. If so it + //must not have the requirments flag JFW_REQUIRE_NEEDRESTART + if ((aInfo->nRequirements & JFW_REQUIRE_NEEDRESTART) + && + (jfw::wasJavaSelectedInSameProcess() == true)) + return JFW_E_NEED_RESTART; + } // end mode FWK_MODE_OFFICE + else if (mode == jfw::JFW_MODE_ENV_SIMPLE) + { + rtl::OUString sOO_USE_JRE(RTL_CONSTASCII_USTRINGPARAM(ENVIRONMENT_VAR_JRE_PATH)); + + rtl_uString * psOO_USE_JRE = 0; + if (osl_getEnvironment(sOO_USE_JRE.pData, & psOO_USE_JRE) != osl_Process_E_None) + return JFW_E_ERROR; + + rtl::OUString sOO_USE_JRE_VALUE(psOO_USE_JRE, SAL_NO_ACQUIRE); + + if ((errcode = jfw_getJavaInfoByPath(sOO_USE_JRE_VALUE.pData, & aInfo)) + != JFW_E_NONE) + return errcode; + } //get the function jfw_plugin_startJavaVirtualMachine rtl::OUString sLibPath; - if ((errcode = jfw::getPluginLibrary(sLibPath)) != JFW_E_NONE) + if ((errcode = jfw::getPluginLibrary(aInfo.getVendor(), sLibPath)) != JFW_E_NONE) return errcode; osl::Module modulePlugin(sLibPath); if ( ! modulePlugin) @@ -380,38 +401,6 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti if (pFunc == NULL) return JFW_E_ERROR; - //Compose the class path - rtl::OUStringBuffer sBufCP(4096); - //build the class path from the classes directory - rtl::OUString sClassPath; - errcode = jfw::buildClassPathFromDirectory( - javaSettings.m_sClassesDirectory, sClassPath); - if (errcode != JFW_E_NONE) - return JFW_E_ERROR; - sBufCP.append(sClassPath); - // append all user selected jars to the classpath - if (javaSettings.getUserClassPath().getLength() != 0) - { - char szSep[] = {SAL_PATHSEPARATOR,0}; - sBufCP.appendAscii(szSep); - sBufCP.append(javaSettings.getUserClassPath()); - } - //add the path of the UNO components - rtl::OUString sComponents = - jfw::retrieveClassPath( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "${$PKG_SharedUnoFile:UNO_JAVA_CLASSPATH}"))); - sBufCP.append(sComponents); - sComponents = jfw::retrieveClassPath( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "${$PKG_UserUnoFile:UNO_JAVA_CLASSPATH}"))); - - sBufCP.append(sComponents); - rtl::OString sOptionClassPath("-Djava.class.path="); - sOptionClassPath += rtl::OUStringToOString( - sBufCP.makeStringAndClear(), osl_getThreadTextEncoding()); - - // create JavaVMOptions array that is passed to the plugin // it contains the classpath and all options set in the //options dialog @@ -424,6 +413,10 @@ javaFrameworkError SAL_CALL jfw_startVM(JavaVMOption *arOptions, sal_Int32 cOpti return JFW_E_ERROR; //The first argument is the classpath + rtl::OString sOptionClassPath; + if ((errcode = jfw::makeClassPathOption( + mode, javaSettings, sOptionClassPath)) != JFW_E_NONE) + return errcode; arOpt[0].optionString= (char*) sOptionClassPath.getStr(); arOpt[0].extraInfo = NULL; // Set a flag that this JVM has been created via the JNI Invocation API diff --git a/jvmfwk/source/fwkutil.cxx b/jvmfwk/source/fwkutil.cxx index a9ab78218fc7..b14910bf766b 100644 --- a/jvmfwk/source/fwkutil.cxx +++ b/jvmfwk/source/fwkutil.cxx @@ -2,9 +2,9 @@ * * $RCSfile: fwkutil.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: jl $ $Date: 2004-05-14 14:44:09 $ + * last change: $Author: jl $ $Date: 2004-05-17 13:55:31 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -219,19 +219,11 @@ rtl::OUString getPlatform() return buf.makeStringAndClear(); } -javaFrameworkError getPluginLibrary(rtl::OUString & sLibUrl) +javaFrameworkError getPluginLibrary( + const rtl::OUString& sVendor, rtl::OUString & sLibUrl) { javaFrameworkError errcode = JFW_E_NONE; - CNodeJava javaNode; - if ((errcode = javaNode.loadFromSettings()) != JFW_E_NONE) - return errcode; - CJavaInfo aInfo(javaNode.getJavaInfo()); - if (aInfo == NULL) - return JFW_E_NO_SELECT; - - //With the vendor name we can get the associated plugin library - //from the javavendors.xml rtl::OString sVendorsPath = getVendorSettingsPath(); CXmlDocPtr docVendor; CXPathContextPtr contextVendor; @@ -246,7 +238,7 @@ javaFrameworkError getPluginLibrary(rtl::OUString & sLibUrl) rtl::OUStringBuffer usBuffer(256); usBuffer.appendAscii("/jf:javaSelection/jf:plugins/jf:library[@vendor=\""); - usBuffer.append(aInfo.getVendor()); + usBuffer.append(sVendor); usBuffer.appendAscii("\"]/text()"); rtl::OUString ouExpr = usBuffer.makeStringAndClear(); rtl::OString sExpression = @@ -791,4 +783,105 @@ rtl::OUString getDirFromFile(const rtl::OUString& usFilePath) return rtl::OUString(usFilePath.getStr(), index); } +//todo !!! +rtl::OUString getJavaSettingsDirectory() +{ + //test if we are running within an office + return rtl::OUString(); +} + +JFW_MODE getMode() +{ + //Determine if we run in an office process: + rtl_uString* sExe = NULL; + if (osl_getExecutableFile( & sExe) != osl_Process_E_None) + return JFW_MODE_INDETERMINED; + rtl::OUString ouExe(sExe, SAL_NO_ACQUIRE); + + //create the name of the executable + rtl::OUStringBuffer buff(128); + buff.appendAscii("soffice"); + buff.appendAscii(SAL_PRGEXTENSION); + rtl::OUString sOffice = buff.makeStringAndClear(); + + sal_Int32 index = 0; + if ((index = ouExe.lastIndexOf(sOffice)) != 1 + && index + sOffice.getLength() == ouExe.getLength()) + return JFW_MODE_OFFICE; + + + //FWK_MODE_ENV_SIMPLE ? + rtl::OUString sOO_USE_JRE(RTL_CONSTASCII_USTRINGPARAM(ENVIRONMENT_VAR_JRE_PATH)); + + rtl_uString * psOO_USE_JRE = 0; + if (osl_getEnvironment(sOO_USE_JRE.pData, & psOO_USE_JRE) != osl_Process_E_None) + return JFW_MODE_INDETERMINED; + + rtl::OUString sOO_USE_JRE_VALUE(psOO_USE_JRE, SAL_NO_ACQUIRE); + if (sOO_USE_JRE_VALUE.getLength() > 0) + return JFW_MODE_ENV_SIMPLE; + + return JFW_MODE_INDETERMINED; + + +} + +javaFrameworkError makeClassPathOption( + JFW_MODE mode, CNodeJava & javaSettings, rtl::OString & sOption) +{ + //Compose the class path + rtl::OUStringBuffer sBufCP(4096); + char szSep[] = {SAL_PATHSEPARATOR,0}; + if (mode == JFW_MODE_OFFICE) + { + //build the class path from the classes directory + rtl::OUString sClassPath; + javaFrameworkError errcode = jfw::buildClassPathFromDirectory( + javaSettings.m_sClassesDirectory, sClassPath); + if (errcode != JFW_E_NONE) + return JFW_E_ERROR; + sBufCP.append(sClassPath); + // append all user selected jars to the classpath + if (javaSettings.getUserClassPath().getLength() != 0) + { + sBufCP.appendAscii(szSep); + sBufCP.append(javaSettings.getUserClassPath()); + } + } + else if (mode == JFW_MODE_ENV_SIMPLE) + { + //We use the CLASSPATH environment variable + rtl::OUString sCP( + RTL_CONSTASCII_USTRINGPARAM("CLASSPATH")); + + rtl_uString * psCPVal = 0; + if (osl_getEnvironment(sCP.pData, & psCPVal) != osl_Process_E_None) + return JFW_E_ERROR; + + rtl::OUString sCPVal(psCPVal, SAL_NO_ACQUIRE); + sBufCP.append(sCPVal); + } + else + OSL_ASSERT(0); + + //add the path of the UNO components + rtl::OUString sComponents = + jfw::retrieveClassPath( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "${$PKG_SharedUnoFile:UNO_JAVA_CLASSPATH}"))); + sBufCP.append(sComponents); + sComponents = jfw::retrieveClassPath( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "${$PKG_UserUnoFile:UNO_JAVA_CLASSPATH}"))); + + sBufCP.append(sComponents); + rtl::OString sOptionClassPath("-Djava.class.path="); + sOptionClassPath += rtl::OUStringToOString( + sBufCP.makeStringAndClear(), osl_getThreadTextEncoding()); + + sOption = sOptionClassPath; + return JFW_E_NONE; +} + + } diff --git a/jvmfwk/source/fwkutil.hxx b/jvmfwk/source/fwkutil.hxx index 05106fcfa764..777e305eec69 100644 --- a/jvmfwk/source/fwkutil.hxx +++ b/jvmfwk/source/fwkutil.hxx @@ -2,9 +2,9 @@ * * $RCSfile: fwkutil.hxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: jl $ $Date: 2004-05-14 14:44:09 $ + * last change: $Author: jl $ $Date: 2004-05-17 13:55:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,6 +67,8 @@ #include "libxml/parser.h" #include "libxml/xpath.h" +#define ENVIRONMENT_VAR_JRE_PATH "OO_USE_JRE" + namespace jfw { osl::Mutex * getFwkMutex(); @@ -75,6 +77,37 @@ rtl::ByteSequence encodeBase16(const rtl::ByteSequence& rawData); rtl::ByteSequence decodeBase16(const rtl::ByteSequence& data); rtl::OUString getPlatform(); +/** //Todo + Gets the directory where the user data is written + Can have these values: + - ~/.StarOffice/user/config (used in office) + - arbitrary directory determined by environment variable + - tmp directory (running out of office, e.g. regcomp) + + @return + File URL of the directory + */ +rtl::OUString getJavaSettingsDirectory(); + + +enum JFW_MODE +{ + /** The mode is unknown. + */ + JFW_MODE_INDETERMINED, + /** This library is loaded in an office process. + */ + JFW_MODE_OFFICE, + /** We are NOT in an office process. The javavendors.xml is located next to + the jvmfwk.dll, the javasettings.xml is NEIHER created, NOR read or written. + As class path the environment variable CLASSPATH is used. The JRE, which + is to be used is determined by the environment variable OO_USE_JRE. It must + contain a file URL to the JRE. + */ + JFW_MODE_ENV_SIMPLE +}; + +JFW_MODE getMode(); /** Get the file URL to the javasettings.xml */ rtl::OUString getUserSettingsURL(); @@ -99,6 +132,14 @@ rtl::OString getVendorSettingsPath(); rtl::OUString getDirFromFile(const rtl::OUString& usFilePath); +class CNodeJava; +/** creates the -Djava.class.path option with the complete classpath. + If param mode is JFW_MODE_ENV_SIMPLE then the param javaSettings is ignored. + */ +javaFrameworkError makeClassPathOption( + JFW_MODE mode, CNodeJava & javaSettings, /*out*/rtl::OString & sOption); + + struct PluginLibrary; class VersionInfo; class CJavaInfo; @@ -118,7 +159,8 @@ javaFrameworkError getVersionInformation( /** Gets the file URL to the plubin library for the currently selected Java. */ -javaFrameworkError getPluginLibrary(rtl::OUString & sLibPathe); +javaFrameworkError getPluginLibrary( + const rtl::OUString & sVendor, rtl::OUString & sLibPathe); /** 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 |