You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ms...@apache.org on 2019/08/24 19:25:18 UTC

[openoffice] 02/05: Improve Java detection on *nix, by also checking the immediate subdirectories of /usr and /usr/local, where at least FreeBSD puts Java (eg. /usr/local/openjdk8, /usr/local/openjdk7-jre). Also simplify that search code a bit, and eliminate an unnecessary stat() for a directory on which it has already been called earlier.

This is an automated email from the ASF dual-hosted git repository.

mseidel pushed a commit to branch AOO417
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit f031179e3bcf3ce499ef5512ce51dd23c2a77129
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Sun Apr 15 09:46:56 2018 +0000

    Improve Java detection on *nix, by also checking the immediate
    subdirectories of /usr and /usr/local, where at least FreeBSD puts Java
    (eg. /usr/local/openjdk8, /usr/local/openjdk7-jre). Also simplify that
    search code a bit, and eliminate an unnecessary stat() for a directory on
    which it has already been called earlier.
    
    Patch by: me
    
    git-svn-id: https://svn.apache.org/repos/asf/openoffice/trunk@1829200 13f79535-47bb-0310-9956-ffa450edef68
    (cherry picked from commit 58368a3fb4ba73f514fcac5672d8424ed9e2740f)
---
 main/jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 87 +++++++++++++------------
 1 file changed, 45 insertions(+), 42 deletions(-)

diff --git a/main/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/main/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
index c311cb6..b204897 100644
--- a/main/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
+++ b/main/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
@@ -91,25 +91,30 @@ char const *g_arCollectDirs[] = {
     "jvm/"
 };
 
+struct JavaSearchPathEntry {
+    int searchImmediateContents; // More thorough, too slow for /usr/bin and /usr/lib
+    char const *path;
+};
+
 /* These are directories in which a java installation is
    looked for.
 */
-char const *g_arSearchPaths[] = {
+struct JavaSearchPathEntry g_arSearchPaths[] = {
 #ifdef MACOSX
-    "",
-    "Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin",
-    "System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/"
+    { 0, "" },
+    { 0, "Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin" },
+    { 0, "System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/" },
 #else
-    "",
-    "usr/",
-    "usr/local/",
-    "usr/local/IBMJava2-ppc-142",
-    "usr/local/j2sdk1.3.1",
+    { 0, "" },
+    { 1, "usr/" },
+    { 1, "usr/local/" },
+    { 0, "usr/local/IBMJava2-ppc-142" },
+    { 0, "usr/local/j2sdk1.3.1" },
 #ifdef X86_64
-    "usr/lib64/",
+    { 0, "usr/lib64/" },
 #endif
-    "usr/lib/",
-    "usr/bin/"
+    { 0, "usr/lib/" },
+    { 0, "usr/bin/" }
 #endif
 };
 }
@@ -1148,11 +1153,11 @@ void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
         arNames[i] = OUString(g_arJavaNames[i], strlen(g_arJavaNames[i]),
                               RTL_TEXTENCODING_UTF8);
 
-    int cSearchPaths= sizeof(g_arSearchPaths) / sizeof(char*);
+    int cSearchPaths= sizeof(g_arSearchPaths) / sizeof(g_arSearchPaths[0]);
     boost::scoped_array<OUString> sarPathNames(new OUString[cSearchPaths]);
     OUString *arPaths = sarPathNames.get();
     for(int c = 0; c < cSearchPaths; c++)
-        arPaths[c] = OUString(g_arSearchPaths[c], strlen(g_arSearchPaths[c]),
+        arPaths[c] = OUString(g_arSearchPaths[c].path, strlen(g_arSearchPaths[c].path),
                                RTL_TEXTENCODING_UTF8);
 
     int cCollectDirs = sizeof(g_arCollectDirs) / sizeof(char*);
@@ -1174,8 +1179,8 @@ void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
             for(int j= 0; j < cCollectDirs; j++)
             {
                 OUString usDir2(usDir1 + arCollectDirs[j]);
-                // prevent that we scan the whole /usr, /usr/lib, etc directories
-                if (arCollectDirs[j] != OUString())
+                // prevent that we scan the whole /usr/bin, /usr/lib, etc directories
+                if (g_arSearchPaths[ii].searchImmediateContents || arCollectDirs[j] != OUString())
                 {
                     //usr/java/xxx
                     //Examin every subdirectory
@@ -1227,33 +1232,31 @@ void createJavaInfoDirScan(vector<rtl::Reference<VendorBase> >& vecInfos)
                                 + usDir2 + OUSTR(". Osl file error: ")
                                 + OUString::valueOf((sal_Int32) openErr));
                 }
-                else
+            }
+            for (int j= 0; j < cJavaNames; j++)
+            {
+                //When we look directly into a dir like /usr/bin, /usr/lib, etc. then we only
+                //look for certain java directories, such as jre, jdk, etc. Whe do not want
+                //to examine the whole directory because of performance reasons.
+
+                //  usFile          arNames[j]
+                // <------>        <->
+                // file:///usr/lib/jvm
+                //         <------>
+                //          arPaths[ii] (usDir1)
+                //
+                OUString usDir3(usDir1 + arNames[j]);
+                
+                DirectoryItem item3;
+                if(DirectoryItem::get(usDir3, item3) == File::E_None)
                 {
-                    //usr/java
-                    //When we look directly into a dir like /usr, /usr/lib, etc. then we only
-                    //look for certain java directories, such as jre, jdk, etc. Whe do not want
-                    //to examine the whole directory because of performance reasons.
-                    DirectoryItem item2;
-                    if(DirectoryItem::get(usDir2, item2) == File::E_None)
-                    {
-                        for( int k= 0; k < cJavaNames; k++)
-                        {
-                            // /usr/java/j2re1.4.0
-                            OUString usDir3(usDir2 + arNames[k]);
-                            
-                            DirectoryItem item3;
-                            if(DirectoryItem::get(usDir3, item) == File::E_None)
-                            {
-                                //remove trailing '/'
-                                sal_Int32 islash = usDir3.lastIndexOf('/');
-                                if (islash == usDir3.getLength() - 1
-                                    && (islash
-                                        > RTL_CONSTASCII_LENGTH("file://")))
-                                    usDir3 = usDir3.copy(0, islash);
-                                getJREInfoByPath(usDir3,vecInfos);
-                            }
-                        }
-                    }
+                    //remove trailing '/'
+                    sal_Int32 islash = usDir3.lastIndexOf('/');
+                    if (islash == usDir3.getLength() - 1
+                        && (islash
+                            > RTL_CONSTASCII_LENGTH("file://")))
+                        usDir3 = usDir3.copy(0, islash);
+                    getJREInfoByPath(usDir3,vecInfos);
                 }
             }
         }