Author: liuzhe
Date: Thu Oct 11 12:18:31 2012
New Revision: 1397012

URL: http://svn.apache.org/viewvc?rev=1397012&view=rev
Log:
Fix: Can't find the correct the soffice.bin if there is another one OpenOffice 
installed in /Applications

Modified:
    
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
    
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/Installer.java

Modified: 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java?rev=1397012&r1=1397011&r2=1397012&view=diff
==============================================================================
--- 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
 (original)
+++ 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/FileUtil.java
 Thu Oct 11 12:18:31 2012
@@ -304,8 +304,18 @@ public class FileUtil {
                return strBuffer.toString();
        }
        
-       
-       
+
+       public static boolean isSymbolicLink(File file) {
+               try {
+                       File parent = file.getParentFile();
+                       String name = file.getName() ;
+                       File toTest = parent != null ? new 
File(parent.getCanonicalPath(), name) : new File(name);
+                       return 
!toTest.getAbsolutePath().equals(toTest.getCanonicalPath());
+               } catch (Exception e) {
+                       return false;
+               }
+       }
+
        /**
         * Find the first file matching the given name.
         * @param dir The directory to search in
@@ -329,6 +339,23 @@ public class FileUtil {
                return null;
        }
        
+       public static File findFile(File dir, String name, boolean 
followSymbolicLink) {
+               if (!dir.isDirectory())
+                       return null;
+               File[] files = dir.listFiles();
+               for (int i = 0; i < files.length; i++) {
+                       if (files[i].isDirectory() && (followSymbolicLink || 
!isSymbolicLink(files[i]))) {
+                               File ret = findFile(files[i], name);
+                               if (ret != null)
+                                       return ret;
+                       } else if (files[i].getName().matches(name)) {
+                               return files[i];
+                       }
+               }
+               
+               return null;
+       }
+       
        /**
         * Find the last file matching the given name.
         * @param dir The directory to search in

Modified: 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/Installer.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/Installer.java?rev=1397012&r1=1397011&r2=1397012&view=diff
==============================================================================
--- 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/Installer.java
 (original)
+++ 
incubator/ooo/trunk/test/testcommon/source/org/openoffice/test/common/Installer.java
 Thu Oct 11 12:18:31 2012
@@ -91,7 +91,7 @@ public class Installer implements Runnab
                                if (files != null && files.length == 1 && 
files[0].isDirectory()) {
                                        files[0].renameTo(installDir);
                                }
-                               File sofficeBin = FileUtil.findFile(installDir, 
"soffice.bin");
+                               File sofficeBin = FileUtil.findFile(installDir, 
"soffice.bin", false);
                                if (sofficeBin == null) 
                                        throw new 
RuntimeException(MessageFormat.format("{0} is not a valid openoffice 
installation package!" , packFile));
                                try {


Reply via email to