fixed bug 16146: Do not include same module more than once
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 07 Mar 2011 09:45:38 +0100
changeset 9260 10cbb435abf2
parent 9259 82fac282feaf
child 9261 3c02be0f1ebf
fixed bug 16146: Do not include same module more than once

When packaging module in obx file, it is checked the same module is not included
more than once.
build.xml
src/org/openbravo/service/system/ModuleValidator.java
src/org/openbravo/service/system/SystemValidationResult.java
src/org/openbravo/service/system/SystemValidationTask.java
--- a/build.xml	Mon Mar 07 09:12:39 2011 +0100
+++ b/build.xml	Mon Mar 07 09:45:38 2011 +0100
@@ -915,7 +915,7 @@
                    modules="${module}"
                    stoponerror="true"/>
 
-    <validateModules moduleJavaPackage="${module}" failOnError="false" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="module" />
+    <validateModules moduleJavaPackage="${module}" failOnError="true" userId="0" adminMode="true" propertiesFile="${base.config}/Openbravo.properties" type="module" />
 
     <antcall target="obx.export.database" />
     <antcall target="obx.export.config.script" />
--- a/src/org/openbravo/service/system/ModuleValidator.java	Mon Mar 07 09:12:39 2011 +0100
+++ b/src/org/openbravo/service/system/ModuleValidator.java	Mon Mar 07 09:45:38 2011 +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) 2009-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -20,6 +20,7 @@
 package org.openbravo.service.system;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.hibernate.criterion.Expression;
@@ -95,6 +96,8 @@
     // check dependency on core
     checkDepencyOnCore(module, result);
 
+    checkDuplicatedInclusions(module, result, new ArrayList<String>());
+
     checkDependencyVersion(module, result);
 
     checkJavaPath(module, moduleDir, module.getJavaPackage(), result);
@@ -293,7 +296,24 @@
       result.addWarning(SystemValidationType.MODULE_ERROR, "Module " + module.getName()
           + " or any of its ancestors " + "does not depend on the Core module.");
     }
+  }
 
+  /**
+   * Checks module inclusions are not defined more than once.
+   */
+  private void checkDuplicatedInclusions(Module module, SystemValidationResult result,
+      List<String> verifiedInclusions) {
+    for (ModuleDependency md : module.getModuleDependencyList()) {
+      if (md.isIncluded()) {
+        if (verifiedInclusions.contains(md.getDependentModule().getId())) {
+          result.addError(SystemValidationType.DUPLICATED_INCLUSION, "Module "
+              + md.getDependentModule().getName()
+              + " is included several times in the dependency tree.");
+        }
+        verifiedInclusions.add(md.getDependentModule().getId());
+        checkDuplicatedInclusions(md.getDependentModule(), result, verifiedInclusions);
+      }
+    }
   }
 
   private void checkTableName(Module module, SystemValidationResult result) {
--- a/src/org/openbravo/service/system/SystemValidationResult.java	Mon Mar 07 09:12:39 2011 +0100
+++ b/src/org/openbravo/service/system/SystemValidationResult.java	Mon Mar 07 09:45:38 2011 +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) 2009-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -32,7 +32,7 @@
 public class SystemValidationResult {
 
   public enum SystemValidationType {
-    NAME_TOO_LONG, MODULE_ERROR, CUSTOMIZATION_ID, INCORRECT_DEFAULT_VALUE, WRONG_NAME, WRONG_LENGTH, NO_PRIMARY_KEY_COLUMNS, NOT_NULL_IN_DB_NOT_MANDATORY_IN_AD, MANDATORY_IN_AD_NULLABLE_IN_DB, NOT_EXIST_IN_AD, NOT_EXIST_IN_DB, NOT_PART_OF_FOREIGN_KEY, WRONG_TYPE, INCORRECT_CLIENT_ORG_PROPERTY_NAME, UNEQUAL_DEFAULTVALUE, INCORRECT_PK_NAME, INCORRECT_FK_NAME, INCORRECT_CHECK_NAME, INCORRECT_UNIQUE_NAME, INCORRECT_INDEX_NAME, INCORRECT_NAME_LENGTH, INCORRECT_DATASET_NAME, DEPENDENCY_PROBLEM, HAS_PROPERTY_CONFIGURATION;
+    NAME_TOO_LONG, MODULE_ERROR, CUSTOMIZATION_ID, INCORRECT_DEFAULT_VALUE, WRONG_NAME, WRONG_LENGTH, NO_PRIMARY_KEY_COLUMNS, NOT_NULL_IN_DB_NOT_MANDATORY_IN_AD, MANDATORY_IN_AD_NULLABLE_IN_DB, NOT_EXIST_IN_AD, NOT_EXIST_IN_DB, NOT_PART_OF_FOREIGN_KEY, WRONG_TYPE, INCORRECT_CLIENT_ORG_PROPERTY_NAME, UNEQUAL_DEFAULTVALUE, INCORRECT_PK_NAME, INCORRECT_FK_NAME, INCORRECT_CHECK_NAME, INCORRECT_UNIQUE_NAME, INCORRECT_INDEX_NAME, INCORRECT_NAME_LENGTH, INCORRECT_DATASET_NAME, DEPENDENCY_PROBLEM, HAS_PROPERTY_CONFIGURATION, DUPLICATED_INCLUSION;
 
     public String getName() {
       return this.getClass().getSimpleName();
--- a/src/org/openbravo/service/system/SystemValidationTask.java	Mon Mar 07 09:12:39 2011 +0100
+++ b/src/org/openbravo/service/system/SystemValidationTask.java	Mon Mar 07 09:45:38 2011 +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) 2009 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -102,7 +102,7 @@
         log.warn("Validation successfull no warnings or errors");
       } else {
         final String errors = SystemService.getInstance().logValidationResult(log, result);
-        if (failOnError) {
+        if (!result.getErrors().isEmpty() && failOnError) {
           throw new OBException(errors);
         }
       }