details:   https://code.openbravo.com/erp/devel/pi/rev/607dccd3524a
changeset: 15432:607dccd3524a
user:      Stefan Hühner <stefan.huehner <at> openbravo.com>
date:      Thu Feb 09 14:55:01 2012 +0100
summary:   Fixed 19078: Reduce number of files compiled for apply.module a lot
- Split out parts of Utility.java into new file BasicUtility.java
- Split out parts of ModuleUtilltiy.java into new file ModuleUtility.java
- Remove error translation code from apply.module call to verify languages
- Reduce list of xsql files being processed in compile.apply.module

diffstat:

 src/build.xml                                                |    2 +-
 src/org/openbravo/erpCommon/ad_forms/TranslationManager.java |   14 +-
 src/org/openbravo/erpCommon/modules/ApplyModule.java         |   54 ++-
 src/org/openbravo/erpCommon/modules/ModuleUtility.java       |  175 ++++++++++
 src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java       |   97 +-----
 src/org/openbravo/erpCommon/utility/BasicUtility.java        |  181 +++++++++++
 src/org/openbravo/erpCommon/utility/OBError.java             |    4 +-
 src/org/openbravo/erpCommon/utility/Utility.java             |   84 +----
 8 files changed, 416 insertions(+), 195 deletions(-)

diffs (truncated from 846 to 300 lines):

diff -r 9794bd1516c7 -r 607dccd3524a src/build.xml
--- a/src/build.xml     Fri Feb 10 18:05:01 2012 +0100
+++ b/src/build.xml     Thu Feb 09 14:55:01 2012 +0100
@@ -166,7 +166,7 @@
     <mkdir dir="${build.apply.module}" />
     <java classname="org.openbravo.data.Sqlc" fork="yes" 
jvm="${env.JAVA_HOME}/bin/java" maxmemory="${build.maxmemory}" 
failonerror="true">
       <arg line="'${base.config}'/Openbravo.properties .xsql . 
'${build.sqlc}'/src" />
-      <jvmarg 
value="-Dsqlc.listOfFiles=PInstanceProcess_data.xsql,ApplyModule_data.xsql,TableSQLQuery_data.xsql,DateTime_data.xsql,ComboTableQuery_data.xsql,PrintJR_data.xsql,DocumentNo_data.xsql,WindowAccess_data.xsql,Tab_data.xsql,WindowTree_data.xsql,ErrorTextParser_data.xsql,Utility_data.xsql,MessageBD_data.xsql,Translation_data.xsql,Buscador_data.xsql,Pinstance_data.xsql,ProcessRequest_data.xsql,Trigger_data.xsql,ProcessRun_data.xsql,Process_data.xsql,OrgTree_data.xsql,VersionUtility_data.xsql,ImportModule_data.xsql,SystemInfo_data.xsql,Heartbeat_data.xsql,Alert_data.xsql,Registration_data.xsql"/>
+      <jvmarg 
value="-Dsqlc.listOfFiles=ApplyModule_data.xsql,PInstanceProcess_data.xsql,Translation_data.xsql,MessageBD_data.xsql"/>
       <classpath refid="project.class.path" />
       <syspropertyset>
          <propertyref name="java.security.egd" />
diff -r 9794bd1516c7 -r 607dccd3524a 
src/org/openbravo/erpCommon/ad_forms/TranslationManager.java
--- a/src/org/openbravo/erpCommon/ad_forms/TranslationManager.java      Fri Feb 
10 18:05:01 2012 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/TranslationManager.java      Thu Feb 
09 14:55:01 2012 +0100
@@ -40,8 +40,8 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.ad_process.buildStructure.Build;
 import org.openbravo.erpCommon.ad_process.buildStructure.BuildTranslation;
+import org.openbravo.erpCommon.utility.BasicUtility;
 import org.openbravo.erpCommon.utility.OBError;
-import org.openbravo.erpCommon.utility.Utility;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.InputSource;
@@ -125,7 +125,7 @@
     } else {
       log4j.error("Can't write on directory: " + strFTPDirectory);
       myMessage.setType("Error");
-      myMessage.setMessage(Utility.messageBD(conn, "CannotWriteDirectory", 
uiLanguage) + " "
+      myMessage.setMessage(BasicUtility.messageBD(conn, 
"CannotWriteDirectory", uiLanguage) + " "
           + strFTPDirectory);
       return myMessage;
     }
@@ -154,11 +154,11 @@
     } catch (final Exception e) {
       log4j.error(e);
       myMessage.setType("Error");
-      myMessage.setMessage(Utility.messageBD(conn, "Error", uiLanguage));
+      myMessage.setMessage(BasicUtility.messageBD(conn, "Error", uiLanguage));
       return myMessage;
     }
     myMessage.setType("Success");
-    myMessage.setMessage(Utility.messageBD(conn, "Success", uiLanguage));
+    myMessage.setMessage(BasicUtility.messageBD(conn, "Success", uiLanguage));
     return myMessage;
   }
 
@@ -235,7 +235,7 @@
     } else {
       log4j.error("Can't read on directory: " + directory);
       myMessage.setType("Error");
-      myMessage.setMessage(Utility.messageBD(cp, "CannotReadDirectory", 
UILanguage) + " "
+      myMessage.setMessage(BasicUtility.messageBD(cp, "CannotReadDirectory", 
UILanguage) + " "
           + directory);
       return myMessage;
     }
@@ -249,7 +249,7 @@
     } catch (final Exception e) {
       log4j.error(e.toString());
       myMessage.setType("Error");
-      myMessage.setMessage(Utility.messageBD(cp, "Error", UILanguage));
+      myMessage.setMessage(BasicUtility.messageBD(cp, "Error", UILanguage));
       return myMessage;
     }
 
@@ -265,7 +265,7 @@
     }
 
     myMessage.setType("Success");
-    myMessage.setMessage(Utility.messageBD(cp, "Success", UILanguage));
+    myMessage.setMessage(BasicUtility.messageBD(cp, "Success", UILanguage));
     return myMessage;
   }
 
diff -r 9794bd1516c7 -r 607dccd3524a 
src/org/openbravo/erpCommon/modules/ApplyModule.java
--- a/src/org/openbravo/erpCommon/modules/ApplyModule.java      Fri Feb 10 
18:05:01 2012 +0100
+++ b/src/org/openbravo/erpCommon/modules/ApplyModule.java      Thu Feb 09 
14:55:01 2012 +0100
@@ -30,15 +30,14 @@
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 import org.openbravo.base.exception.OBException;
-import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.CPStandAlone;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.ad_forms.TranslationManager;
 import org.openbravo.erpCommon.reference.PInstanceProcessData;
+import org.openbravo.erpCommon.utility.BasicUtility;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.SequenceIdData;
-import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.module.Module;
 import org.openbravo.model.ad.system.Client;
 import org.openbravo.model.common.enterprise.Organization;
@@ -102,18 +101,15 @@
           final String pinstance = SequenceIdData.getUUID();
           PInstanceProcessData.insertPInstance(pool, pinstance, "179", "0", 
"N", "0", "0", "0");
 
-          final VariablesSecureApp vars = new VariablesSecureApp("0", "0", 
"0");
-
           ApplyModuleData.process179(pool, pinstance);
 
-          final PInstanceProcessData[] pinstanceData = 
PInstanceProcessData.select(pool, pinstance);
-          final OBError myMessage = Utility.getProcessInstanceMessage(pool, 
vars, pinstanceData);
+          final OBError myMessage = getProcessInstanceMessageSimple(pool, 
pinstance);
           if (myMessage.getType().equals("Error"))
             log4j.error(myMessage.getMessage());
           else
             log4j.info(myMessage.getMessage());
         } catch (final ServletException ex) {
-          ex.printStackTrace();
+          log4j.error("Error running verify language process", ex);
         }
 
         // Import language modules
@@ -130,7 +126,7 @@
       final ApplyModuleData[] ds = 
ApplyModuleData.selectClientReferenceModules(pool);
 
       if (ds != null && ds.length > 0) {
-        ModuleUtiltiy.orderModuleByDependency(ds);
+        ModuleUtility.orderModuleByDependency(ds);
         // build list of reference data modules which have files to import
         List<ApplyModuleData> dsToImport = new ArrayList<ApplyModuleData>();
         for (ApplyModuleData amd : ds) {
@@ -149,10 +145,10 @@
 
           File datasetFile = new File(strImportFile);
           log4j.info("Importing data from " + amd.name + " module. Dataset: "
-              + Utility.wikifiedName(amd.dsName) + ".xml");
+              + BasicUtility.wikifiedName(amd.dsName) + ".xml");
 
           // Import data from the xml file
-          final String strXml = Utility.fileToString(datasetFile.getPath());
+          final String strXml = 
BasicUtility.fileToString(datasetFile.getPath());
           final DataImportService importService = 
DataImportService.getInstance();
           final ImportResult result = importService.importDataFromXML(
               OBDal.getInstance().get(Client.class, "0"),
@@ -187,6 +183,42 @@
   }
 
   /**
+   * Gets untranslated result of the 'ad_language_create' pl-function call.
+   * 
+   * This is a very much simplified version of the 
'Utility.getProcesInstanceMessage' function
+   * suitable for the simple usecase as needed inside ApplyModule.
+   * 
+   * @param conn
+   *          Handler for the database connection.
+   * @param pinstance
+   *          ad_pinstance_id to look at
+   * @return Object with the message.
+   * @throws ServletException
+   */
+  private static OBError getProcessInstanceMessageSimple(ConnectionProvider 
conn, String pinstance)
+      throws ServletException {
+    PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(pool, 
pinstance);
+
+    OBError myMessage = new OBError();
+    if (pinstanceData != null && pinstanceData.length > 0) {
+      String message = pinstanceData[0].errormsg;
+
+      String type = "Error";
+      if (pinstanceData[0].result.equals("1")) {
+        type = "Success";
+      }
+
+      int errorPos = message.indexOf("@ERROR=");
+      if (errorPos != -1) {
+        // skip the @ERROR= marker in output
+        myMessage.setMessage(message.substring(errorPos + 7));
+      }
+      myMessage.setType(type);
+    }
+    return myMessage;
+  }
+
+  /**
    * Helper function to construct the data-file name for a dataset.
    */
   private String dataSet2ImportFilename(ApplyModuleData ds) throws 
FileNotFoundException {
@@ -196,7 +228,7 @@
     else
       strPath = obDir + "/modules/" + ds.javapackage + 
"/referencedata/standard";
 
-    strPath = strPath + "/" + Utility.wikifiedName(ds.dsName) + ".xml";
+    strPath = strPath + "/" + BasicUtility.wikifiedName(ds.dsName) + ".xml";
     return strPath;
   }
 
diff -r 9794bd1516c7 -r 607dccd3524a 
src/org/openbravo/erpCommon/modules/ModuleUtility.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/erpCommon/modules/ModuleUtility.java    Thu Feb 09 
14:55:01 2012 +0100
@@ -0,0 +1,175 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * 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-2012 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.erpCommon.modules;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.data.FieldProvider;
+import org.openbravo.model.ad.module.Module;
+import org.openbravo.model.ad.module.ModuleDependency;
+
+/**
+ * Module related utilities needed by the 'ApplyModule' module class.
+ * 
+ * Before the 'ant apply.module' target is run a mini compilation is done to 
compile all classes
+ * needed by that code (and not more). This ModuleUtility class was split out 
of the main 'ModuleUtiltiy'
+ * class to not pull in the big chain of transitive compile-time dependencies 
into ApplyModule.
+ * 
+ * Nothing should be added here without reviewing the list of files compiled 
by the 'ant
+ * compile.apply.module' target to check that it did not grow.
+ * 
+ */
+
+/**
+ * This class implements different utilities related to modules
+ * 
+ * 
+ */
+class ModuleUtility {
+  protected static Logger log4j = Logger.getLogger(ModuleUtility.class);
+
+  /**
+   * It receives an ArrayList<String> with modules IDs and returns the same 
list ordered taking into
+   * account the module dependency tree.
+   * <p/>
+   * Note that the module list must be a complete list of modules, no 
dependencies will be checked
+   * for more than one level of deep, this means that passing an incomplete 
list might not be
+   * ordered correctly.
+   * 
+   * @param modules
+   *          List of module to order
+   * @return modules list ordered
+   * @throws Exception
+   */
+  public static List<String> orderByDependency(List<String> modules) throws 
Exception {
+
+    Map<String, List<String>> modsWithDeps = getModsDeps(modules);
+    List<String> rt = orderDependencies(modsWithDeps);
+    return rt;
+  }
+
+  /**
+   * Modifies the passed modules {@link FieldProvider} parameter ordering it 
taking into account
+   * dependencies.
+   * <p/>
+   * 
+   * @param modules
+   *          {@link FieldProvider} that will be sorted. It must contain at 
least a field named
+   *          <i>adModuleId</i>
+   * @throws Exception
+   */
+  public static void orderModuleByDependency(FieldProvider[] modules) throws 
Exception {
+    OBContext.setAdminMode();
+    try {
+      List<Module> allModules = 
OBDal.getInstance().createCriteria(Module.class).list();
+      ArrayList<String> allMdoulesId = new ArrayList<String>();
+      for (Module mod : allModules) {
+        allMdoulesId.add(mod.getId());
+      }
+      List<String> modulesOrder = orderByDependency(allMdoulesId);
+
+      FieldProvider[] fpModulesOrder = new FieldProvider[modules.length];
+      int i = 0;
+      for (String modId : modulesOrder) {
+        for (int j = 0; j < modules.length; j++) {
+          if (modules[j].getField("adModuleId").equals(modId)) {
+            fpModulesOrder[i] = modules[j];
+            i++;
+          }
+        }
+      }
+
+      for (int j = 0; j < modules.length; j++) {
+        modules[j] = fpModulesOrder[j];

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to