fixed issue 22429: Simplify promotion from testing to production environments
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 29 Nov 2012 14:36:33 +0100
changeset 19231 cdc18afeeefd
parent 19230 7df2baff13d2
child 19232 9b99a04c51e9
child 19329 799006d26440
fixed issue 22429: Simplify promotion from testing to production environments
build.xml
src/org/openbravo/erpCommon/modules/ExtractModule.java
src/org/openbravo/erpCommon/modules/ExtractModuleTask.java
src/org/openbravo/erpCommon/modules/ExtractModule_data.xsql
src/org/openbravo/erpCommon/modules/ImportModule.java
src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java
--- a/build.xml	Mon Dec 17 13:22:07 2012 +0100
+++ b/build.xml	Thu Nov 29 14:36:33 2012 +0100
@@ -89,6 +89,8 @@
   <property name="obx.export.RD" value="false" />
   <property name="obx.export.DB" value="false" />
   <property name="obx.export.CS" value="false" />
+  <property name="obx.export.validate" value="true" />
+  <property name="obx.export.allDeps" value="false" />
   <property name="chekPerms" value="false" />
   <property name="force" value="false" />
   <property name="strict.template.application" value="false" />
@@ -153,6 +155,13 @@
       <equals arg1="true" arg2="${obx.export.CS}" />
     </or>
   </condition>
+  
+  <condition property="obx.exp.validate">
+    <or>
+      <equals arg1="yes" arg2="${obx.export.validate}" />
+      <equals arg1="true" arg2="${obx.export.validate}" />
+    </or>
+  </condition>
 
   <condition property="timestamp">
     <or>
@@ -927,31 +936,39 @@
     <antcall target="export.config.script" />
   </target>
 
-  <target name="package.module">
-    <taskdef name="extractModule" classname="org.openbravo.erpCommon.modules.ExtractModuleTask">
+  <target name="obx.export.validateModules" if="obx.exp.validate">
+    <taskdef name="validateModules" classname="org.openbravo.service.system.SystemValidationTask">
       <classpath refid="project.class.path" />
     </taskdef>
 
-    <taskdef name="validateModules" classname="org.openbravo.service.system.SystemValidationTask">
-      <classpath refid="project.class.path" />
-    </taskdef>
-    
     <taskdef name="WADValidation" classname="org.openbravo.wad.validation.WADValidatorTask">
       <classpath refid="project.class.path" />
     </taskdef>
-            
+
     <echo message="Validating Module..." />
-    
+
     <WADValidation propertiesFile="${base.config}/Openbravo.properties"
                    modules="${module}"
                    stoponerror="true"/>
 
     <validateModules moduleJavaPackage="${module}" failOnError="true" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="module" />
-
+  </target>
+  
+  <target name="package.module">
+    <taskdef name="extractModule" classname="org.openbravo.erpCommon.modules.ExtractModuleTask">
+      <classpath refid="project.class.path" />
+    </taskdef>
+    
+    <antcall target="obx.export.validateModules" />
     <antcall target="obx.export.database" />
     <antcall target="obx.export.config.script" />
 
-    <extractModule moduleName="${module}" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" exportRD="${obx.export.RD}" />
+    <extractModule moduleName="${module}" 
+                   userId="0" 
+                   adminMode="true" 
+                   propertiesFile="${base.config}/Openbravo.properties" 
+                   exportRD="${obx.export.RD}" 
+                   addAllDependencies="${obx.export.allDeps}"/>
   </target>
 
   <target name="diagnostic">
--- a/src/org/openbravo/erpCommon/modules/ExtractModule.java	Mon Dec 17 13:22:07 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ExtractModule.java	Thu Nov 29 14:36:33 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,6 +24,7 @@
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.OutputStreamWriter;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.zip.ZipEntry;
@@ -49,6 +50,8 @@
   private String modulesBaseDir;
   private String destDir;
   private boolean exportReferenceData;
+  private List<String> processedModules;
+  private boolean addAllDependencies = false;
 
   /**
    * Initializes a ExtractModule instance for Stand Alone conection
@@ -61,6 +64,7 @@
   public ExtractModule(String xmlPoolFile, String modulesDir) {
     pool = new CPStandAlone(xmlPoolFile);
     modulesBaseDir = modulesDir;
+    processedModules = new ArrayList<String>();
   }
 
   /**
@@ -84,13 +88,13 @@
                 + " for module does not exist.\nYou may have not exported database before packaging this module");
       }
 
-      relativeDir = modulesBaseDir + File.separator + "modules" + File.separator;
       final FileOutputStream file = new FileOutputStream(destDir + "/" + module.javapackage + "-"
           + module.version + ".obx");
       final ZipOutputStream obx = new ZipOutputStream(file);
       extractModule(moduleID, moduleDirectory, obx);
-      if (module.type.equals("P") || module.type.equals("T")) {
-        log4j.info(module.javapackage + " is a package/template looking for inner modules...");
+      log4j.info("addAllDependencies: " + addAllDependencies);
+      if (addAllDependencies || module.type.equals("P") || module.type.equals("T")) {
+        log4j.info(module.javapackage + " looking for inner modules...");
         extractPackage(moduleID, obx);
       }
       obx.close();
@@ -162,7 +166,14 @@
     if (exportReferenceData && ExtractModuleData.hasReferenceData(pool, moduleID)) {
       extractReferenceData(moduleID, moduleDirectory);
     }
-    createOBX(new File(moduleDirectory), obx);
+    if ("0".equals(moduleID)) {
+      log4j.info("obx for core...");
+      relativeDir = modulesBaseDir + File.separator;
+      createOBX(ModuleUtiltiy.getCore(modulesBaseDir), obx);
+    } else {
+      relativeDir = modulesBaseDir + File.separator + "modules" + File.separator;
+      createOBX(new File(moduleDirectory), obx);
+    }
   }
 
   /**
@@ -173,22 +184,26 @@
    * @throws Exception
    */
   private void extractPackage(String moduleID, ZipOutputStream obx) throws Exception {
-    final ExtractModuleData modules[] = ExtractModuleData.selectContainedModules(pool, moduleID);
+    final ExtractModuleData modules[] = ExtractModuleData.selectContainedModules(pool, moduleID,
+        addAllDependencies ? "Y" : "N");
     for (int i = 0; i < modules.length; i++) {
-      if (modules[i].adModuleId.equals("0")) {
+      if (processedModules.contains(modules[i].adModuleId)) {
+        log4j.info("Skipping already processed module:" + modules[i].javapackage);
+        continue;
+      }
+      processedModules.add(modules[i].adModuleId);
+      if (!addAllDependencies && modules[i].adModuleId.equals("0")) {
         log4j.warn("Core is included! It is not going to be packaged...");
       } else {
         obx.putNextEntry(new ZipEntry(modules[i].javapackage + "-" + modules[i].version + ".obx"));
         final ByteArrayOutputStream ba = new ByteArrayOutputStream();
         final ZipOutputStream moduleObx = new ZipOutputStream(ba);
         final String moduleDirectory = modulesBaseDir + "/modules/" + modules[i].javapackage;
-        relativeDir = modulesBaseDir + File.separator + "modules" + File.separator;
         log4j.info("Extracting module: " + modules[i].javapackage);
         extractModule(modules[i].adModuleId, moduleDirectory, moduleObx);
-        if (modules[i].type.equals("P") || modules[i].type.equals("T")) {
+        if (addAllDependencies || modules[i].type.equals("P") || modules[i].type.equals("T")) {
           // If it is Package or Template it can contain other modules
-          log4j
-              .info(modules[i].javapackage + " is a package/template looking for inner modules...");
+          log4j.info(modules[i].javapackage + " looking for inner modules...");
           extractPackage(modules[i].adModuleId, moduleObx);
         }
         moduleObx.close();
@@ -209,11 +224,16 @@
    * @throws Exception
    */
   private void createOBX(File file, ZipOutputStream obx) throws Exception {
-    final File[] list = file.listFiles(new FilenameFilter() {
-      public boolean accept(File f, String s) {
-        return !(s.equals(".svn") || s.equals(".hg"));
-      }
-    });
+    File[] list;
+    if (file.isDirectory()) {
+      list = file.listFiles(new FilenameFilter() {
+        public boolean accept(File f, String s) {
+          return !(s.equals(".svn") || s.equals(".hg"));
+        }
+      });
+    } else {
+      list = new File[] { file };
+    }
     String fileSeparator = File.separator;
     for (int i = 0; list != null && i < list.length; i++) {
       if (list[i].isDirectory()) {
@@ -239,6 +259,12 @@
     }
   }
 
+  private void createOBX(List<File> files, ZipOutputStream obx) throws Exception {
+    for (File f : files) {
+      createOBX(f, obx);
+    }
+  }
+
   public void setDestDir(String d) {
     destDir = d;
   }
@@ -246,4 +272,8 @@
   public void setExportReferenceData(boolean export) {
     exportReferenceData = export;
   }
+
+  public void setAddAllDependencies(boolean addAllDependencies) {
+    this.addAllDependencies = addAllDependencies;
+  }
 }
--- a/src/org/openbravo/erpCommon/modules/ExtractModuleTask.java	Mon Dec 17 13:22:07 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ExtractModuleTask.java	Thu Nov 29 14:36:33 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,10 +29,10 @@
   private String moduleName;
   private String moduleID;
 
-  private String propertiesFile;
   private String destDir;
   private String obDir;
   private boolean exportRD = false;
+  private boolean addAllDependencies = false;
 
   /**
    * Initialize DAL only in case RD exportation is active
@@ -57,6 +57,7 @@
       ExtractModule em = new ExtractModule(propertiesFile, obDir);
       em.setDestDir(destDir);
       em.setExportReferenceData(exportRD);
+      em.setAddAllDependencies(addAllDependencies);
 
       if (moduleID != null && !moduleID.equals(""))
         em.extract(moduleID);
@@ -67,16 +68,6 @@
     }
   }
 
-  @Override
-  public String getPropertiesFile() {
-    return propertiesFile;
-  }
-
-  @Override
-  public void setPropertiesFile(String propertiesFile) {
-    this.propertiesFile = propertiesFile;
-  }
-
   public void setDestDir(String destFile) {
     this.destDir = destFile;
   }
@@ -96,4 +87,8 @@
   public void setExportRD(boolean exportRD) {
     this.exportRD = exportRD;
   }
+
+  public void setAddAllDependencies(boolean addAllDependencies) {
+    this.addAllDependencies = addAllDependencies;
+  }
 }
--- a/src/org/openbravo/erpCommon/modules/ExtractModule_data.xsql	Mon Dec 17 13:22:07 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ExtractModule_data.xsql	Thu Nov 29 14:36:33 2012 +0100
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -39,9 +39,10 @@
         FROM AD_MODULE_DEPENDENCY D, AD_MODULE M
        WHERE D.AD_MODULE_ID = ?
          AND M.AD_MODULE_ID = D.AD_DEPENDENT_MODULE_ID
-         AND D.ISINCLUDED = 'Y'
+         AND (D.ISINCLUDED = 'Y' or ? = 'Y')
     ]]></Sql>
     <Parameter name="moduleID"/>
+    <Parameter name="includeDependencies"/>
   </SqlMethod>
   
   <SqlMethod name="hasReferenceData" type="preparedStatement" return="boolean">
--- a/src/org/openbravo/erpCommon/modules/ImportModule.java	Mon Dec 17 13:22:07 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ImportModule.java	Thu Nov 29 14:36:33 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -1902,19 +1902,7 @@
    * 
    */
   private File[] getCore() {
-    ArrayList<File> core = new ArrayList<File>();
-    core.add(new File(obDir + "/build.xml"));
-    core.add(new File(obDir + "/legal"));
-    core.add(new File(obDir + "/lib"));
-    core.add(new File(obDir + "/src-core"));
-    core.add(new File(obDir + "/src-db"));
-    core.add(new File(obDir + "/src-gen"));
-    core.add(new File(obDir + "/src-trl"));
-    core.add(new File(obDir + "/src-wad"));
-    core.add(new File(obDir + "/src"));
-    core.add(new File(obDir + "/web"));
-    core.add(new File(obDir + "/src-test"));
-    core.add(new File(obDir + "/src-util"));
+    List<File> core = ModuleUtiltiy.getCore(obDir);
     File[] module = new File[core.size()];
     return core.toArray(module);
   }
--- a/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java	Mon Dec 17 13:22:07 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java	Thu Nov 29 14:36:33 2012 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2012 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,6 +19,7 @@
 
 package org.openbravo.erpCommon.modules;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -152,4 +153,26 @@
       OBContext.restorePreviousMode();
     }
   }
+
+  /**
+   * Returns all directories and files that are part of core
+   * 
+   * @return
+   */
+  static List<File> getCore(String obDir) {
+    List<File> core = new ArrayList<File>();
+    core.add(new File(obDir + "/build.xml"));
+    core.add(new File(obDir + "/legal"));
+    core.add(new File(obDir + "/lib"));
+    core.add(new File(obDir + "/src-core"));
+    core.add(new File(obDir + "/src-db"));
+    core.add(new File(obDir + "/src-gen"));
+    core.add(new File(obDir + "/src-trl"));
+    core.add(new File(obDir + "/src-wad"));
+    core.add(new File(obDir + "/src"));
+    core.add(new File(obDir + "/web"));
+    core.add(new File(obDir + "/src-test"));
+    core.add(new File(obDir + "/src-util"));
+    return core;
+  }
 }