[mod-check] WADValidation executed by ant task, removed from WAD
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 20 Nov 2009 13:15:31 +0100
changeset 5532 24512d0915ee
parent 5531 caf716c0bf68
child 5533 b6b7e478001c
[mod-check] WADValidation executed by ant task, removed from WAD
src-wad/src/org/openbravo/wad/Wad.java
src/build.xml
src/org/openbravo/service/system/WADValidationResult.java
src/org/openbravo/service/system/WADValidator.java
src/org/openbravo/service/system/WADValidatorTask.java
--- a/src-wad/src/org/openbravo/wad/Wad.java	Fri Nov 20 12:36:27 2009 +0100
+++ b/src-wad/src/org/openbravo/wad/Wad.java	Fri Nov 20 13:15:31 2009 +0100
@@ -45,8 +45,6 @@
 import org.openbravo.wad.controls.WADHidden;
 import org.openbravo.wad.controls.WADLabelControl;
 import org.openbravo.wad.controls.WadControlLabelBuilder;
-import org.openbravo.wad.validation.WADValidationResult;
-import org.openbravo.wad.validation.WADValidator;
 import org.openbravo.xmlEngine.XmlDocument;
 import org.openbravo.xmlEngine.XmlEngine;
 import org.xml.sax.helpers.DefaultHandler;
@@ -260,13 +258,6 @@
       else
         quick = argv[16].equals("quick");
 
-      boolean failOnErrorVerification;
-      if (argv.length <= 17 || argv[17].equals("true")) {
-        failOnErrorVerification = true;
-      } else {
-        failOnErrorVerification = false;
-      }
-
       if (quick) {
         module = "%";
         strWindowName = "xx";
@@ -290,7 +281,6 @@
       log4j.info("Web path: " + webPath);
       log4j.info("Src path: " + strBaseSrc);
       log4j.info("Quick mode: " + quick);
-      log4j.info("Stop on failed verification:" + failOnErrorVerification);
 
       final File fileFin = new File(dirFin);
       if (!fileFin.exists()) {
@@ -375,14 +365,6 @@
       TabsData[] tabsData = td.toArray(new TabsData[0]);
       log4j.info(tabsData.length + " tabs to compile.");
 
-      log4j.info("Verifing tabs...");
-      WADValidator validator = new WADValidator(wad.pool, tabsData);
-      WADValidationResult validationResult = validator.validate();
-      validationResult.printLog();
-      if (validationResult.hasErrors() && failOnErrorVerification) {
-        throw new Exception("Tabs verification has errors");
-      }
-
       // Call to update the table identifiers
       log4j.info("Updating table identifiers");
       WadData.updateIdentifiers(wad.pool, quick ? "Y" : "N");
--- a/src/build.xml	Fri Nov 20 12:36:27 2009 +0100
+++ b/src/build.xml	Fri Nov 20 13:15:31 2009 +0100
@@ -345,17 +345,27 @@
     </copy>
   </target>
 
-  <target name="wad" depends="init">
+  <target name="wadvalidation">
+    <taskdef name="WADValidation" classname="org.openbravo.service.system.WADValidatorTask">
+            <classpath refid="project.class.path" />
+          </taskdef>
+        
+        <WADValidation propertiesFile="${base.config}/Openbravo.properties"
+                       modules="${module}"
+                       stoponerror="${stopOnWadError}"/>
+  </target>
+  
+  <target name="wad" depends="init, wadvalidation">
     <java classname="org.openbravo.wad.Wad" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}" failonerror="true">
-      <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'noquick' '${stopOnWadError}'" />
+      <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'noquick'" />
       <classpath refid="project.class.path" />
     </java>
     <antcall target="postwad" inheritall="true" inheritrefs="true" />
   </target>
 
-  <target name="wad.quick" depends="init">
+  <target name="wad.quick" depends="init, wadvalidation">
     <java classname="org.openbravo.wad.Wad" jvm="${env.JAVA_HOME}/bin/java" fork="yes" maxmemory="${build.maxmemory}">
-      <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'quick' '${stopOnWadError}'" />
+      <arg line="'${base.config}' '${tab}' '${build.AD}/org/openbravo/erpWindows' '${build.AD}/org/openbravo/erpCommon' '${build.sqlc}/src' '${webTab}' '${build.AD}/org/openbravo/erpCommon/ad_actionButton' '${base.design}' '${base.translate.structure}' '${client.web.xml}' '..' '${attach.path}' '${web.url}' '${base.src}' '${complete}' '${module}' 'quick'" />
       <classpath refid="project.class.path" />
     </java>
     <antcall target="postwad" inheritall="true" inheritrefs="true" />
--- a/src/org/openbravo/service/system/WADValidationResult.java	Fri Nov 20 12:36:27 2009 +0100
+++ b/src/org/openbravo/service/system/WADValidationResult.java	Fri Nov 20 13:15:31 2009 +0100
@@ -106,7 +106,7 @@
   /**
    * Prints the result in the log
    */
-  public void printLog() {
+  public void printLog(boolean stopOnError) {
     for (WADValidationType type : warnings.keySet()) {
       log.warn("+++++++++++++++++++++++++++++++++++++++++++++++++++");
       log.warn("Warnings for Validation type: " + type.getDescription());
@@ -116,7 +116,7 @@
       }
     }
 
-    if (errors.size() > 0) {
+    if (!stopOnError && errors.size() > 0) {
       log.error("The following errors during validation do not stop the");
       log.error("compilation process to allow backwards compatibility for");
       log.error("modules, but they MUST be fixed because in future core ");
--- a/src/org/openbravo/service/system/WADValidator.java	Fri Nov 20 12:36:27 2009 +0100
+++ b/src/org/openbravo/service/system/WADValidator.java	Fri Nov 20 13:15:31 2009 +0100
@@ -28,7 +28,7 @@
  * 
  */
 public class WADValidator {
-  private String moduleId;
+  private String modules;
   private ConnectionProvider conn;
   private String checkAll;
 
@@ -40,9 +40,9 @@
    * @param moduleId
    *          Module to check
    */
-  public WADValidator(ConnectionProvider conn, String moduleId) {
-    checkAll = (moduleId == null || moduleId.equals("%") || moduleId.equals("")) ? "Y" : "N";
-    this.moduleId = checkAll.equals("Y") ? "" : moduleId;
+  public WADValidator(ConnectionProvider conn, String modules) {
+    checkAll = (modules == null || modules.equals("%") || modules.equals("")) ? "Y" : "N";
+    this.modules = checkAll.equals("Y") ? "" : modules;
     this.conn = conn;
   }
 
@@ -60,7 +60,7 @@
 
   private void validateIdentifier(WADValidationResult result) {
     try {
-      WADValidatorData data[] = WADValidatorData.checkIdentifier(conn, moduleId, checkAll);
+      WADValidatorData data[] = WADValidatorData.checkIdentifier(conn, modules, checkAll);
       for (WADValidatorData issue : data) {
         result.addError(WADValidationType.MISSING_IDENTIFIER, "Table " + issue.tablename
             + " has not identifier.");
@@ -73,7 +73,7 @@
 
   private void validateKey(WADValidationResult result) {
     try {
-      WADValidatorData data[] = WADValidatorData.checkKey(conn, moduleId, checkAll);
+      WADValidatorData data[] = WADValidatorData.checkKey(conn, modules, checkAll);
       for (WADValidatorData issue : data) {
         result.addError(WADValidationType.MISSING_KEY, "Table " + issue.tablename
             + " has not primary key.");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/openbravo/service/system/WADValidatorTask.java	Fri Nov 20 13:15:31 2009 +0100
@@ -0,0 +1,66 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 SL 
+ * All portions are Copyright (C) 2009 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.service.system;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.database.CPStandAlone;
+
+public class WADValidatorTask extends Task {
+  private String propertiesFile;
+  private String modules;
+  private boolean stoponerror;
+
+  @Override
+  public void execute() throws BuildException {
+    System.out.println("stop on error:" + stoponerror);
+    CPStandAlone conn = new CPStandAlone(propertiesFile);
+    WADValidator val = new WADValidator(conn, modules);
+    WADValidationResult result = val.validate();
+    result.printLog(stoponerror);
+    if (result.hasErrors() && stoponerror) {
+      throw new BuildException("WAD verification has errors");
+    }
+  }
+
+  public String getPropertiesFile() {
+    return propertiesFile;
+  }
+
+  public void setPropertiesFile(String propertiesFile) {
+    this.propertiesFile = propertiesFile;
+  }
+
+  public String getModules() {
+    return modules;
+  }
+
+  public void setModules(String modules) {
+    this.modules = modules;
+  }
+
+  public boolean isStoponerror() {
+    return stoponerror;
+  }
+
+  public void setStoponerror(boolean failonerror) {
+    this.stoponerror = failonerror;
+  }
+
+}