details:   /erp/devel/pi/rev/02584b440762
changeset: 9761:02584b440762
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Jan 13 09:00:16 2011 +0100
summary:   Removed constants which are not used

details:   /erp/devel/pi/rev/ce728a2f1e39
changeset: 9762:ce728a2f1e39
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Jan 13 09:00:51 2011 +0100
summary:   Enabled compression of generated static resource when no module in 
dev, improved handling of cycle in mod deps

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
             |  77 +++++++++-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
 |   9 +-
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
 |   9 +-
 3 files changed, 80 insertions(+), 15 deletions(-)

diffs (158 lines):

diff -r 8b12f1ed85be -r ce728a2f1e39 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
      Thu Jan 13 08:58:39 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelUtils.java
      Thu Jan 13 09:00:51 2011 +0100
@@ -27,6 +27,7 @@
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.FetchMode;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
@@ -50,6 +51,13 @@
 
   private static KernelUtils instance = new KernelUtils();
 
+  // the static dependency list is used when a cycle is detected
+  // in the modules
+  private static String[] STATICDEPENDENCYLIST = new String[] { 
"org.openbravo",
+      "org.openbravo.base.weld", "org.openbravo.service.json", 
"org.openbravo.client.kernel",
+      "org.openbravo.userinterface.smartclient", 
"org.openbravo.service.datasource",
+      "org.openbravo.client.application", 
"org.openbravo.userinterface.selector" };
+
   public static synchronized KernelUtils getInstance() {
     if (instance == null) {
       instance = new KernelUtils();
@@ -62,6 +70,7 @@
   }
 
   private List<Module> sortedModules = null;
+  private Boolean isAnyModuleInDevelopment = null;
 
   public Property getPropertyFromColumn(Column column) {
     final Entity entity = 
ModelProvider.getInstance().getEntity(column.getTable().getName());
@@ -159,13 +168,47 @@
 
     final List<ModuleWithLowLevelCode> moduleLowLevelCodes = new 
ArrayList<ModuleWithLowLevelCode>();
     OBContext.setAdminMode();
+
     try {
+      // note, because of the left join fetch on module dependencies
+      // a module is returned for each module dependency, take care of this in
+      // the for-loop below
       final OBCriteria<Module> modules = 
OBDal.getInstance().createCriteria(Module.class);
-      for (Module module : modules.list()) {
-        final ModuleWithLowLevelCode moduleLowLevelCode = new 
ModuleWithLowLevelCode();
-        moduleLowLevelCode.setModule(module);
-        moduleLowLevelCode.setLowLevelCode(computeLowLevelCode(module, new 
ArrayList<Module>()));
-        moduleLowLevelCodes.add(moduleLowLevelCode);
+      modules.setFetchMode(Module.PROPERTY_MODULEDEPENDENCYLIST, 
FetchMode.JOIN);
+      final List<Module> handledModules = new ArrayList<Module>();
+      try {
+        for (Module module : modules.list()) {
+          if (handledModules.contains(module)) {
+            continue;
+          }
+          handledModules.add(module);
+          final ModuleWithLowLevelCode moduleLowLevelCode = new 
ModuleWithLowLevelCode();
+          moduleLowLevelCode.setModule(module);
+          moduleLowLevelCode.setLowLevelCode(computeLowLevelCode(module, new 
ArrayList<Module>()));
+          moduleLowLevelCodes.add(moduleLowLevelCode);
+        }
+      } catch (ModuleDependencyCycleException e) {
+        // use static list...
+        moduleLowLevelCodes.clear();
+        handledModules.clear();
+        for (Module module : modules.list()) {
+          if (handledModules.contains(module)) {
+            continue;
+          }
+          handledModules.add(module);
+          final ModuleWithLowLevelCode moduleLowLevelCode = new 
ModuleWithLowLevelCode();
+          moduleLowLevelCode.setModule(module);
+          int index = 0;
+          for (String pkg : STATICDEPENDENCYLIST) {
+            if (pkg.equals(module.getJavaPackage())) {
+              break;
+            }
+
+            index++;
+          }
+          moduleLowLevelCode.setLowLevelCode(index);
+          moduleLowLevelCodes.add(moduleLowLevelCode);
+        }
       }
       Collections.sort(moduleLowLevelCodes);
       final List<Module> result = new ArrayList<Module>();
@@ -190,7 +233,8 @@
       for (Module moduleCycle : modules) {
         log.error(moduleCycle.getName());
       }
-      throw new OBException("Cycle detected in module dependencies");
+      throw new ModuleDependencyCycleException("Cycle detected in module 
dependencies with module "
+          + module + " check the error log for the cycle");
     }
     modules.add(module);
     int currentLevel = 0;
@@ -294,4 +338,25 @@
     }
     return targetTab;
   }
+
+  public Boolean isAnyModuleInDevelopment() {
+    if (isAnyModuleInDevelopment == null) {
+      isAnyModuleInDevelopment = false;
+      final List<Module> modules = getModulesOrderedByDependency();
+      for (Module module : modules) {
+        isAnyModuleInDevelopment |= module.isInDevelopment();
+      }
+    }
+    return isAnyModuleInDevelopment;
+  }
+
+  private class ModuleDependencyCycleException extends OBException {
+
+    private static final long serialVersionUID = 1L;
+
+    public ModuleDependencyCycleException(String message) {
+      super(message);
+    }
+
+  }
 }
diff -r 8b12f1ed85be -r ce728a2f1e39 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
  Thu Jan 13 08:58:39 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/StaticResourceComponent.java
  Thu Jan 13 09:00:51 2011 +0100
@@ -223,7 +223,14 @@
       sb.append("}\n});");
     }
 
-    final String output = sb.toString();
+    // note compress, note that modules are cached in memory
+    // when changing development status, system needs to be restarted.
+    final String output;
+    if (KernelUtils.getInstance().isAnyModuleInDevelopment()) {
+      output = JSCompressor.getInstance().compress(sb.toString());
+    } else {
+      output = sb.toString();
+    }
     final String md5 = DigestUtils.md5Hex(output);
     final File dir = new File(context.getRealPath(GEN_TARGET_LOCATION));
     if (!dir.exists()) {
diff -r 8b12f1ed85be -r ce728a2f1e39 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
  Thu Jan 13 08:58:39 2011 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/templates/application-js.ftl
  Thu Jan 13 09:00:51 2011 +0100
@@ -71,11 +71,4 @@
     },
     
     I18N: {}
-};
-
-OB.Application.moduleVersionParameters = {
-<#list data.moduleVersionParameters as moduleVersionParameter>
-'${moduleVersionParameter.id?js_string}' : 
'${moduleVersionParameter.value?js_string}'<#if 
moduleVersionParameter_has_next>,</#if>
-</#list>};
-
-OB.Constants.VERSION_QUERYSTRING = "_version=" + OB.Application.systemVersion 
+ "&_language=" + OB.Application.language;
+};
\ No newline at end of file

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to