Fixes issue 25108: export.config.script takes into account templates dependency 3.0PR14Q2 3.0PR14Q2.1
authorAugusto Mauch <augusto.mauch@openbravo.com>
Fri, 21 Mar 2014 08:55:19 +0100
changeset 467 3f0764688bff
parent 466 c21df20ed7b1
child 468 721a2855f050
Fixes issue 25108: export.config.script takes into account templates dependency

The ExportConfigScript class now orders the templates according to its dependencies.
src/org/openbravo/ddlutils/task/ExportConfigScript.java
--- a/src/org/openbravo/ddlutils/task/ExportConfigScript.java	Tue Sep 10 11:33:22 2013 +0200
+++ b/src/org/openbravo/ddlutils/task/ExportConfigScript.java	Fri Mar 21 08:55:19 2014 +0100
@@ -13,6 +13,7 @@
 package org.openbravo.ddlutils.task;
 
 import java.io.File;
+import java.util.List;
 import java.util.Vector;
 
 import org.apache.commons.beanutils.DynaBean;
@@ -111,7 +112,6 @@
 
       final Vector<File> dataFiles = DBSMOBUtil.loadFilesFromFolder(getCoreData());
 
-      Vector<File> configScripts = new Vector<File>();
       for (int j = 0; j < util.getModuleCount(); j++) {
         if (!util.getModule(j).name.equalsIgnoreCase("CORE")) {
           final File dirF = new File(moduledir, util.getModule(j).dir
@@ -119,11 +119,6 @@
           if (dirF.exists()) {
             dataFiles.addAll(DBSMOBUtil.loadFilesFromFolder(dirF.getAbsolutePath()));
           }
-          File configScript = new File(moduledir, util.getModule(j).dir
-              + "/src-db/database/configScript.xml");
-          if (!util.getModule(j).dir.equals(industryTemplate) && configScript.exists()
-              && DBSMOBUtil.isApplied(platform, util.getModule(j).dir))
-            configScripts.add(configScript);
         }
       }
 
@@ -145,20 +140,6 @@
         }
       }
 
-      getLog().info("Loading and applying configuration scripts");
-      DatabaseIO dbIOs = new DatabaseIO();
-      for (File f : configScripts) {
-        getLog().info("Loading configuration script: " + f.getAbsolutePath());
-        Vector<Change> changes = dbIOs.readChanges(f);
-        for (Change change : changes) {
-          if (change instanceof ModelChange)
-            ((ModelChange) change).apply(xmlModel, platform.isDelimitedIdentifierModeOn());
-          else if (change instanceof DataChange)
-            ((DataChange) change).apply(databaseOrgData, platform.isDelimitedIdentifierModeOn());
-          getLog().debug(change);
-        }
-      }
-
       getLog().info("Loading complete model from current database");
       final Database currentdb = platform.loadModelFromDatabase(excludeFilter);
 
@@ -186,6 +167,27 @@
         }
       }
 
+      List<String> configScripts = DBSMOBUtil.getInstance().getSortedTemplates(databaseOrgData);
+      getLog().info("Loading and applying configuration scripts");
+      DatabaseIO dbIOs = new DatabaseIO();
+      for (String configScript : configScripts) {
+        File f = new File(moduledir, configScript + "/src-db/database/configScript.xml");
+        if (configScript.equals(industryTemplate) || !f.exists()
+            || !DBSMOBUtil.isApplied(platform, configScript)) {
+          continue;
+        }
+
+        getLog().info("Loading configuration script: " + f.getAbsolutePath());
+        Vector<Change> changes = dbIOs.readChanges(f);
+        for (Change change : changes) {
+          if (change instanceof ModelChange)
+            ((ModelChange) change).apply(xmlModel, platform.isDelimitedIdentifierModeOn());
+          else if (change instanceof DataChange)
+            ((DataChange) change).apply(databaseOrgData, platform.isDelimitedIdentifierModeOn());
+          getLog().debug(change);
+        }
+      }
+
       getLog().info("Comparing models...");
       final Vector<String> modIds = new Vector<String>();
       for (int i = 0; i < util.getModuleCount(); i++) {
@@ -276,8 +278,8 @@
   }
 
   /**
-   * Functionality for deleting data during create.database was removed.
-   * Function is kept to not require lock-step update of dbsm.jar & build-create.xml
+   * Functionality for deleting data during create.database was removed. Function is kept to not
+   * require lock-step update of dbsm.jar & build-create.xml
    */
   @Deprecated
   public void setFilter(String filter) {