Purge the directory before launching the index because the JavaHelp Indexer failed...
Sylvestre Ledru [Tue, 2 Sep 2008 16:38:09 +0000 (16:38 +0000)]
scilab/modules/helptools/src/java/org/scilab/modules/helptools/BuildJavaHelp.java
scilab/modules/helptools/src/java/org/scilab/modules/helptools/Helpers.java

index 2b5b077..07d6296 100644 (file)
@@ -133,11 +133,12 @@ public final class BuildJavaHelp {
         */
        public static boolean buildJavaHelp(String outputDirectory, String language) {
                Indexer indexer = new Indexer();
-
+               String outputJavaHelp = new String (outputDirectory + JAVAHELPSEARCH_DIR);
                try {
+                       Helpers.deleteDirectory(outputJavaHelp); /* Purge the directory before launching the index because the JavaHelp Indexer failed when launched twice on the same directory */
                        String[] args = new String[] {
                                "-db",
-                               outputDirectory + JAVAHELPSEARCH_DIR, /* Where the Java Help Index should be created */
+                               outputJavaHelp, /* Where the Java Help Index should be created */
                                outputDirectory
                        };
                        indexer.compile(args);
index aef2106..0ea8332 100644 (file)
@@ -174,6 +174,40 @@ public final class Helpers {
 
     // -----------------------------------------------------------------------
 
+    /**
+     * Delete a directory and all his content
+     *
+     * @param dir The path to the directory
+        */
+    public static void deleteDirectory(String dir) {
+               deleteDirectory(new File(dir));
+       }
+
+    /**
+     * Delete a directory and all his content
+     *
+     * @param dir The file object of the path to the directory
+        */
+    public static void deleteDirectory(File dir) {
+
+        String files[] = dir.list();
+        if (files == null) {
+            files = new String[0];
+        }
+        for (int i = 0; i < files.length; i++) {
+            File file = new File(dir, files[i]);
+            if (file.isDirectory()) {
+                Helpers.deleteDirectory(file);
+            } else {
+                file.delete();
+            }
+        }
+        dir.delete();
+
+    }
+
+    // -----------------------------------------------------------------------
+
     public static String[] split(String string, char separatorChar) {
         // Count elements ---