diff --git a/officecfg/registry/schema/org/openoffice/Office/Java.xcs b/officecfg/registry/schema/org/openoffice/Office/Java.xcs index e224edc1b251..1be106081b35 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Java.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Java.xcs @@ -19,6 +19,19 @@ + + + + Contains the Java instrumentation agents archives loaded at JVM startup. + + + + An extension can load its own Java instrumentation agent with the value: %origin%/lib/myagent.jar. + + + + + @@ -63,6 +76,12 @@ false + + + Specifies the Java archives from which the instrumentation agents will be loaded at JVM startup. + + + diff --git a/stoc/source/javavm/javavm.cxx b/stoc/source/javavm/javavm.cxx index 3aeb7c33ff3f..e86c98c9f22b 100644 --- a/stoc/source/javavm/javavm.cxx +++ b/stoc/source/javavm/javavm.cxx @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -321,34 +323,81 @@ void getDefaultLocaleFromConfig( } /// @throws css::uno::Exception -void getJavaPropsFromSafetySettings( +void getJavaPropsFromJavaSettings( stoc_javavm::JVM * pjvm, - const css::uno::Reference & xSMgr, const css::uno::Reference &xCtx) { - css::uno::Reference xConfRegistry = - xSMgr->createInstanceWithContext( - u"com.sun.star.configuration.ConfigurationRegistry"_ustr, - xCtx); - if(!xConfRegistry.is()) + css::uno::Reference xConfigProvider( + xCtx->getValueByName( + u"/singletons/com.sun.star.configuration.theDefaultProvider"_ustr), + css::uno::UNO_QUERY); + + if (!xConfigProvider.is()) throw css::uno::RuntimeException( - u"javavm.cxx: couldn't get ConfigurationRegistry"_ustr, nullptr); + u"javavm.cxx: couldn't get ConfigurationProvider"_ustr, nullptr); - css::uno::Reference xConfRegistry_simple( - xConfRegistry, css::uno::UNO_QUERY_THROW); - xConfRegistry_simple->open( - u"org.openoffice.Office.Java"_ustr, - true, false); - css::uno::Reference xRegistryRootKey = - xConfRegistry_simple->getRootKey(); + css::beans::NamedValue aPath(u"nodepath"_ustr, css::uno::Any(u"org.openoffice.Office.Java/VirtualMachine"_ustr)); + css::uno::Sequence aArguments{ css::uno::Any(aPath) }; - if (xRegistryRootKey.is()) + css::uno::Reference xConfigAccess(xConfigProvider->createInstanceWithArguments( + u"com.sun.star.configuration.ConfigurationAccess"_ustr, + aArguments), + css::uno::UNO_QUERY); + + if (!xConfigAccess.is()) + throw css::uno::RuntimeException( + u"javavm.cxx: couldn't get ConfigurationAccess"_ustr, nullptr); + + if (xConfigAccess->hasByName(u"InstrumentationAgents"_ustr)) { - css::uno::Reference key_NetAccess= xRegistryRootKey->openKey(u"VirtualMachine/NetAccess"_ustr); - if (key_NetAccess.is() - && key_NetAccess->getValueType() != css::registry::RegistryValueType_NOT_DEFINED) + css::uno::Reference xAgentAccess; + xConfigAccess->getByName(u"InstrumentationAgents"_ustr) >>= xAgentAccess; + if (xAgentAccess.is() && xAgentAccess->hasElements()) + { + OUString sScheme(u"vnd.sun.star.expand:"_ustr); + css::uno::Reference exp = css::util::theMacroExpander::get(xCtx); + css::uno::Sequence aAgents = xAgentAccess->getElementNames(); + for (auto const & sAgent : aAgents) + { + css::uno::Reference xAgent; + xAgentAccess->getByName(sAgent) >>= xAgent; + if (!xAgent->hasByName(u"URL"_ustr)) + { + SAL_WARN("stoc.java", "Cant retrieve URL property from InstrumentationAgent: " << sAgent); + continue; + } + OUString sUrl; + xAgent->getByName(u"URL"_ustr) >>= sUrl; + if (sUrl.isEmpty()) + { + SAL_WARN("stoc.java", "Cant use empty URL property from InstrumentationAgent: " << sAgent); + continue; + } + if (sUrl.startsWithIgnoreAsciiCase(sScheme)) + { + try { + sUrl = exp->expandMacros(sUrl.copy(sScheme.getLength())); + } catch (css::lang::IllegalArgumentException & exception) { + SAL_WARN("stoc.java", exception.Message); + continue; + } + } + OUString sPath = sUrl; + osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL(sUrl, sPath); + if (nError != osl::FileBase::E_None) + { + SAL_WARN("stoc.java", "Cant convert url to system path: " << sUrl); + continue; + } + pjvm->pushProp("-javaagent:" + sPath); + } + } + } + if (xConfigAccess->hasByName(u"NetAccess"_ustr)) + { + sal_Int32 val = 0; + if (xConfigAccess->getByName(u"NetAccess"_ustr) >>= val) { - sal_Int32 val= key_NetAccess->getLongValue(); OUString sVal; switch( val) { @@ -362,20 +411,18 @@ void getJavaPropsFromSafetySettings( OUString sProperty = "appletviewer.security.mode=" + sVal; pjvm->pushProp(sProperty); } - css::uno::Reference key_CheckSecurity= xRegistryRootKey->openKey( - u"VirtualMachine/Security"_ustr); - if( key_CheckSecurity.is()) - { - bool val = static_cast(key_CheckSecurity->getLongValue()); - OUString sProperty(u"stardiv.security.disableSecurity="_ustr); - if( val) - sProperty += "false"; - else - sProperty += "true"; - pjvm->pushProp( sProperty); - } } - xConfRegistry_simple->close(); + if (xConfigAccess->hasByName(u"Security"_ustr)) + { + bool val = true; + xConfigAccess->getByName(u"Security"_ustr) >>= val; + OUString sProperty(u"stardiv.security.disableSecurity="_ustr); + if( val) + sProperty += "false"; + else + sProperty += "true"; + pjvm->pushProp(sProperty); + } } void setTimeZone(stoc_javavm::JVM * pjvm) noexcept { @@ -426,10 +473,10 @@ void initVMConfiguration( try { - getJavaPropsFromSafetySettings(&jvm, xSMgr, xCtx); + getJavaPropsFromJavaSettings(&jvm, xCtx); } catch(const css::uno::Exception & exception) { - SAL_INFO("stoc", "couldn't get safety settings because of " << exception); + SAL_INFO("stoc", "couldn't get Java settings because of " << exception); } *pjvm = std::move(jvm);