[Libreoffice-commits] core.git: include/jvmfwk jvmfwk/source stoc/source

Stephan Bergmann sbergman at redhat.com
Thu Apr 13 05:49:00 UTC 2017


 include/jvmfwk/framework.hxx  |    6 ++----
 jvmfwk/source/framework.cxx   |   14 ++++++++------
 stoc/source/javavm/javavm.cxx |   30 ++++--------------------------
 3 files changed, 14 insertions(+), 36 deletions(-)

New commits:
commit 1a2afa01c98b6edefaaf18590d6e55c3a9731920
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 12 23:10:11 2017 +0200

    Simplify passing options to jfw_startVM
    
    Change-Id: Idac31e282fe4df69449298a03d491473e460c742
    Reviewed-on: https://gerrit.libreoffice.org/36495
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/jvmfwk/framework.hxx b/include/jvmfwk/framework.hxx
index d6059bb640af..afab60eef427 100644
--- a/include/jvmfwk/framework.hxx
+++ b/include/jvmfwk/framework.hxx
@@ -454,9 +454,7 @@ JVMFWK_DLLPUBLIC javaFrameworkError jfw_getJavaInfoByPath(
     @param pInfo
     [in] optional pointer to a specific JRE; must be caller-freed if not NULL
     @param arOptions
-    [in] the array containing additional start arguments or NULL.
-    @param nSize
-    [in] the size of the array <code>arOptions</code>.
+    [in] the vector containing additional start arguments.
     @param ppVM
     [out] the <code>JavaVM</code> pointer.
     @param ppEnv
@@ -484,7 +482,7 @@ JVMFWK_DLLPUBLIC javaFrameworkError jfw_getJavaInfoByPath(
     <code>JAVA_HOME</code>does not meet the version requirements.
  */
 JVMFWK_DLLPUBLIC javaFrameworkError jfw_startVM(
-    JavaInfo const * pInfo, JavaVMOption * arOptions, sal_Int32 nSize,
+    JavaInfo const * pInfo, std::vector<OUString> const & arOptions,
     JavaVM ** ppVM, JNIEnv ** ppEnv);
 
 /** determines the JRE that is to be used.
diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx
index 0165fcf9efd9..42d99557fc0b 100644
--- a/jvmfwk/source/framework.cxx
+++ b/jvmfwk/source/framework.cxx
@@ -187,10 +187,9 @@ javaFrameworkError jfw_findAllJREs(std::vector<std::unique_ptr<JavaInfo>> *pparI
 }
 
 javaFrameworkError jfw_startVM(
-    JavaInfo const * pInfo, JavaVMOption * arOptions, sal_Int32 cOptions,
+    JavaInfo const * pInfo, std::vector<OUString> const & arOptions,
     JavaVM ** ppVM, JNIEnv ** ppEnv)
 {
-    assert(cOptions == 0 || arOptions != nullptr);
     assert(ppVM != nullptr);
     javaFrameworkError errcode = JFW_E_NONE;
 
@@ -289,7 +288,7 @@ javaFrameworkError jfw_startVM(
         // it contains the classpath and all options set in the
         //options dialog
         std::unique_ptr<JavaVMOption[]> sarJOptions(
-            new JavaVMOption[cOptions + 2 + vmParams.size()]);
+            new JavaVMOption[arOptions.size() + 2 + vmParams.size()]);
         JavaVMOption * arOpt = sarJOptions.get();
         if (! arOpt)
             return JFW_E_ERROR;
@@ -313,10 +312,13 @@ javaFrameworkError jfw_startVM(
             index ++;
         }
         //add all options of the arOptions argument
-        for (int ii = 0; ii < cOptions; ii++)
+        std::vector<OString> convertedOptions;
+        for (auto const & ii: arOptions)
         {
-            arOpt[index].optionString = arOptions[ii].optionString;
-            arOpt[index].extraInfo = arOptions[ii].extraInfo;
+            OString conv = OUStringToOString(ii, osl_getThreadTextEncoding());
+            convertedOptions.push_back(conv);
+            arOpt[index].optionString = const_cast<char *>(conv.getStr());
+            arOpt[index].extraInfo = nullptr;
             index++;
         }
 
diff --git a/stoc/source/javavm/javavm.cxx b/stoc/source/javavm/javavm.cxx
index 18ab9084c78e..a4e9efe66e59 100644
--- a/stoc/source/javavm/javavm.cxx
+++ b/stoc/source/javavm/javavm.cxx
@@ -706,33 +706,11 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
         stoc_javavm::JVM aJvm;
         initVMConfiguration(&aJvm, m_xContext->getServiceManager(),
                             m_xContext);
-        //Create the JavaVMOption array
         const std::vector<OUString> & props = aJvm.getProperties();
-        std::unique_ptr<JavaVMOption[]> sarOptions(
-            new JavaVMOption[props.size()]);
-        JavaVMOption * arOptions = sarOptions.get();
-        //Create an array that contains the strings which are passed
-        //into the options
-        std::unique_ptr<OString[]> sarPropStrings(
-             new OString[props.size()]);
-        OString * arPropStrings = sarPropStrings.get();
-
-        OString sJavaOption("-");
-        typedef std::vector<OUString>::const_iterator cit;
-        int index = 0;
-        for (cit i = props.begin(); i != props.end(); ++i)
+        std::vector<OUString> options;
+        for (auto const & i: props)
         {
-            OString sOption = OUStringToOString(
-                *i, osl_getThreadTextEncoding());
-
-            if (!sOption.matchIgnoreAsciiCase(sJavaOption))
-                arPropStrings[index]= OString("-D") + sOption;
-            else
-                arPropStrings[index] = sOption;
-
-            arOptions[index].optionString = const_cast<sal_Char*>(arPropStrings[index].getStr());
-            arOptions[index].extraInfo = nullptr;
-            index ++;
+            options.push_back(i.startsWith("-") ? i : "-D" + i);
         }
 
         JNIEnv * pMainThreadEnv = nullptr;
@@ -741,7 +719,7 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
         if (getenv("STOC_FORCE_NO_JRE"))
             errcode = JFW_E_NO_SELECT;
         else
-            errcode = jfw_startVM(info.get(), arOptions, index, & m_pJavaVm,
+            errcode = jfw_startVM(info.get(), options, & m_pJavaVm,
                                   & pMainThreadEnv);
 
         bool bStarted = false;


More information about the Libreoffice-commits mailing list