[newupgrade] Additional changes.
authorAntonio Moreno <antonio.moreno@openbravo.com>
Mon, 30 Nov 2009 12:16:23 +0100
changeset 5615 c5482c710ef5
parent 5614 35de562d9634
child 5616 6f463dfe9faf
[newupgrade] Additional changes.
config/log4j.lcf.template
src-core/src/org/openbravo/utils/OBLogAppender.java
src-db/database/sourcedata/AD_MESSAGE.xml
src/log4j.lcf
src/org/openbravo/erpCommon/ad_process/ApplyModules.java
src/org/openbravo/erpCommon/utility/AntExecutor.java
src/org/openbravo/erpCommon/utility/OBPrintStream.java
--- a/config/log4j.lcf.template	Thu Nov 26 18:01:31 2009 +0100
+++ b/config/log4j.lcf.template	Mon Nov 30 12:16:23 2009 +0100
@@ -16,17 +16,12 @@
 # ************************************************************************
 
 # to enable logging in i.e. eclipse console add ", C" to the line below
-log4j.rootCategory=INFO, R, O1
+log4j.rootCategory=INFO, R
 
 # Set our global levels
 log4j.category.org=WARN
 log4j.category.org.openbravo=INFO
 
-# Additional Appender used for apply modules or other cases
-log4j.appender.O1=org.openbravo.utils.OBLogAppender
-log4j.appender.O1.layout=org.apache.log4j.PatternLayout
-log4j.appender.O1.layout.ConversionPattern=%-4r [%t] %-5p %c - %m%n
-
 log4j.appender.R=org.apache.log4j.RollingFileAppender
 log4j.appender.R.File=${catalina.base}/logs/openbravo.log
 log4j.appender.R.MaxFileSize=10000KB
--- a/src-core/src/org/openbravo/utils/OBLogAppender.java	Thu Nov 26 18:01:31 2009 +0100
+++ b/src-core/src/org/openbravo/utils/OBLogAppender.java	Mon Nov 30 12:16:23 2009 +0100
@@ -35,6 +35,7 @@
  * 
  * @author mtaal
  */
+@Deprecated
 public class OBLogAppender extends AppenderSkeleton {
 
   private static final ThreadLocal<OutputStream> outputStreamHolder = new ThreadLocal<OutputStream>();
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Nov 26 18:01:31 2009 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Nov 30 12:16:23 2009 +0100
@@ -63673,7 +63673,7 @@
 <!--2C9BE7698E31458E966E9CFBF91A35BF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--2C9BE7698E31458E966E9CFBF91A35BF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--2C9BE7698E31458E966E9CFBF91A35BF-->  <VALUE><![CDATA[BuildError]]></VALUE>
-<!--2C9BE7698E31458E966E9CFBF91A35BF-->  <MSGTEXT><![CDATA[An error has occurred in the build. For a list of actions to take, go to <a href=\"http://wiki.openbravo.com/wiki/Projects/Improved_Upgrade_Process\" target=\"_blank\">this link</a>.]]></MSGTEXT>
+<!--2C9BE7698E31458E966E9CFBF91A35BF-->  <MSGTEXT><![CDATA[An error has occurred in the build. For a list of actions to take, go to ]]></MSGTEXT>
 <!--2C9BE7698E31458E966E9CFBF91A35BF-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
 <!--2C9BE7698E31458E966E9CFBF91A35BF-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--2C9BE7698E31458E966E9CFBF91A35BF--></AD_MESSAGE>
@@ -63799,6 +63799,17 @@
 <!--34EFA62A7253493EB68EF2729587AF47-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--34EFA62A7253493EB68EF2729587AF47--></AD_MESSAGE>
 
+<!--36291177ACFC462B9C745DB27CAF52D4--><AD_MESSAGE>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <AD_MESSAGE_ID><![CDATA[36291177ACFC462B9C745DB27CAF52D4]]></AD_MESSAGE_ID>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <VALUE><![CDATA[BuildWarning2]]></VALUE>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <MSGTEXT><![CDATA[ for more information. <b>You must now restart the application container</b> to see the changes.]]></MSGTEXT>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--36291177ACFC462B9C745DB27CAF52D4-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--36291177ACFC462B9C745DB27CAF52D4--></AD_MESSAGE>
+
 <!--362978666B7D40CBB234EDEB09057CBB--><AD_MESSAGE>
 <!--362978666B7D40CBB234EDEB09057CBB-->  <AD_MESSAGE_ID><![CDATA[362978666B7D40CBB234EDEB09057CBB]]></AD_MESSAGE_ID>
 <!--362978666B7D40CBB234EDEB09057CBB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -63921,6 +63932,17 @@
 <!--3D3CCBA5FE3643C8BF38071DD57C6261-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--3D3CCBA5FE3643C8BF38071DD57C6261--></AD_MESSAGE>
 
+<!--3E6367A072B843E2BB2409FE6382E8C1--><AD_MESSAGE>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <AD_MESSAGE_ID><![CDATA[3E6367A072B843E2BB2409FE6382E8C1]]></AD_MESSAGE_ID>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <VALUE><![CDATA[ThisLink]]></VALUE>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <MSGTEXT><![CDATA[this link]]></MSGTEXT>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--3E6367A072B843E2BB2409FE6382E8C1-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--3E6367A072B843E2BB2409FE6382E8C1--></AD_MESSAGE>
+
 <!--3F6B20FBC89E4B758183842119CC290A--><AD_MESSAGE>
 <!--3F6B20FBC89E4B758183842119CC290A-->  <AD_MESSAGE_ID><![CDATA[3F6B20FBC89E4B758183842119CC290A]]></AD_MESSAGE_ID>
 <!--3F6B20FBC89E4B758183842119CC290A-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -64645,7 +64667,7 @@
 <!--8DB007EDD43F487790B3E304D41C39E6-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--8DB007EDD43F487790B3E304D41C39E6-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--8DB007EDD43F487790B3E304D41C39E6-->  <VALUE><![CDATA[BuildWarning]]></VALUE>
-<!--8DB007EDD43F487790B3E304D41C39E6-->  <MSGTEXT><![CDATA[There were warnings on the build. The application will run, but you should check them to see if there were important. Go to <a href=\"http://wiki.openbravo.com/wiki/Projects/Improved_Upgrade_Process\" target=\"_blank\">this link</a> for more information. <b>You must now restart the application container</b> to see the changes.]]></MSGTEXT>
+<!--8DB007EDD43F487790B3E304D41C39E6-->  <MSGTEXT><![CDATA[There were warnings on the build. The application will run, but you should check them to see if there were important. Go to ]]></MSGTEXT>
 <!--8DB007EDD43F487790B3E304D41C39E6-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
 <!--8DB007EDD43F487790B3E304D41C39E6-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--8DB007EDD43F487790B3E304D41C39E6--></AD_MESSAGE>
--- a/src/log4j.lcf	Thu Nov 26 18:01:31 2009 +0100
+++ b/src/log4j.lcf	Mon Nov 30 12:16:23 2009 +0100
@@ -17,12 +17,7 @@
 
 # File is used by ApplyModule and other ant tasks
 
-log4j.rootCategory=INFO, A1, O1, O2
-
-# Additional Appender used for apply modules or other cases
-log4j.appender.O1=org.openbravo.utils.OBLogAppender
-log4j.appender.O1.layout=org.apache.log4j.PatternLayout
-log4j.appender.O1.layout.ConversionPattern=%-4r [%t] %-5p %c - %m%n
+log4j.rootCategory=INFO, A1, O2
 
 # Additional Appender used for Improved Upgrade Process
 log4j.appender.O2=org.openbravo.utils.OBRebuildAppender
--- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Thu Nov 26 18:01:31 2009 +0100
+++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java	Mon Nov 30 12:16:23 2009 +0100
@@ -78,8 +78,6 @@
       update(response, vars);
     } else if (vars.commandIn("REQUESTERRORSTATE")) {
       requesterrorstate(response, vars);
-    } else if (vars.commandIn("UPDATELOG")) {
-      updateLog(response, vars);
     } else if (vars.commandIn("GETERR")) {
       getError(response, vars);
     } else if (vars.commandIn("RESTART")) {
@@ -95,11 +93,6 @@
    * Prints the default page for the process, showing the process description and a OK and Cancel
    * buttons. First it checks whether the server has write permissions to be able to execute the
    * process.
-   * 
-   * @param response
-   * @param vars
-   * @throws IOException
-   * @throws ServletException
    */
   private void printPage(HttpServletRequest request, HttpServletResponse response,
       VariablesSecureApp vars) throws IOException, ServletException {
@@ -210,6 +203,13 @@
     RestartTomcat.restart();
   }
 
+  /**
+   * This method returns an ApplyModulesResponse object, that later is transformed into a JSON
+   * object and resend to the rebuild window.
+   * 
+   * @param state
+   * @return
+   */
   private ApplyModulesResponse fillResponse(String state) {
     ApplyModulesResponse resp = new ApplyModulesResponse();
     resp.setState(Integer.parseInt(state.replace("RB", "")));
@@ -258,6 +258,10 @@
     return resp;
   }
 
+  /**
+   * This method is called via AJAX through a timer in the rebuild window. It returns the current
+   * status of the system (and warnings/errors that happened in the current state)
+   */
   private void update(HttpServletResponse response, VariablesSecureApp vars) {
     PreparedStatement ps = null;
     try {
@@ -288,11 +292,17 @@
         try {
           releasePreparedStatement(ps);
         } catch (SQLException e) {
-          log4j.error(e);
+          log4j.error(
+              "Error while trying to close prepared statement when updating the rebuild window", e);
         }
     }
   }
 
+  /**
+   * This method is called via AJAX, and returns the status and warnings/errors for a particular
+   * state. This method will be called when the Rebuild Window notices that one or more steps were
+   * not updated and the build process already finished them
+   */
   private void requesterrorstate(HttpServletResponse response, VariablesSecureApp vars) {
     String state = vars.getStringParameter("reqStatus");
     ApplyModulesResponse pet = fillResponse(state);
@@ -319,11 +329,6 @@
   /**
    * Method to be called via AJAX. Creates a new AntExecutor object, saves it in session and
    * executes the apply modules task on it.
-   * 
-   * @param response
-   * @param vars
-   * @throws IOException
-   * @throws ServletException
    */
   private void startApply(HttpServletResponse response, VariablesSecureApp vars)
       throws IOException, ServletException {
@@ -353,8 +358,6 @@
 
       ant.setLogFile(vars.getStringParameter("logfile"));
 
-      vars.setSessionObject("ApplyModules|Log", ant);
-
       // do not execute tranlsation process (all entries should be already in the module)
       ant.setProperty("tr", "no");
 
@@ -403,7 +406,7 @@
       }
       out.close();
     } catch (final Exception e) {
-      e.printStackTrace();
+      log4j.error("Error while updating the system status in the rebuild window.", e);
       // rolback the old transaction and start a new one
       // to store the build log
       OBDal.getInstance().rollbackAndClose();
@@ -420,7 +423,7 @@
         releasePreparedStatement(ps3);
         releasePreparedStatement(updateSession);
       } catch (SQLException e) {
-        log4j.error(e);
+        log4j.error("Error while updating the system status in the rebuild window.", e);
       }
       OBContext.getOBContext().setInAdministratorMode(admin);
     }
@@ -455,33 +458,8 @@
   }
 
   /**
-   * Method to be called via AJAX. It is intended to be called periodically to show the log
-   * generated after the las call
-   * 
-   * @param response
-   * @param vars
-   * @throws IOException
-   * @throws ServletException
-   */
-  private void updateLog(HttpServletResponse response, VariablesSecureApp vars) throws IOException,
-      ServletException {
-    try {
-      final AntExecutor ant = (AntExecutor) vars.getSessionObject("ApplyModules|Log");
-      if (ant != null)
-        ant.setPrintWriter(response.getWriter());
-    } catch (final Exception e) {
-      e.printStackTrace();
-    }
-  }
-
-  /**
    * Method to be called via AJAX. It returns a XML structure with the error messages (if any) or a
    * Success one
-   * 
-   * @param response
-   * @param vars
-   * @throws IOException
-   * @throws ServletException
    */
   private void getError(HttpServletResponse response, VariablesSecureApp vars) throws IOException,
       ServletException {
@@ -495,9 +473,9 @@
       if (rs.next()) {
         error.setType("Error");
         error.setTitle(Utility.messageBD(myPool, "Error", vars.getLanguage()));
-        error
-            .setMessage(Utility.messageBD(myPool, "BuildError", vars.getLanguage())
-                + "<a href=\"http://wiki.openbravo.com/wiki/UpgradeTips\" target=\"_blank\">this link</a>.");
+        error.setMessage(Utility.messageBD(myPool, "BuildError", vars.getLanguage())
+            + "<a href=\"http://wiki.openbravo.com/wiki/UpgradeTips\" target=\"_blank\">"
+            + Utility.messageBD(myPool, "ThisLink", vars.getLanguage()) + "</a>.");
 
       } else {
         ps2 = getPreparedStatement("SELECT MESSAGE FROM AD_ERROR_LOG WHERE ERROR_LEVEL='WARN'");
@@ -506,10 +484,10 @@
         if (rs2.next()) {
           error.setType("Warning");
           error.setTitle(Utility.messageBD(myPool, "Warning", vars.getLanguage()));
-          error
-              .setMessage(Utility.messageBD(myPool, "BuildWarning", vars.getLanguage())
-                  + "<a href=\"http://wiki.openbravo.com/wiki/UpgradeTips\" target=\"_blank\">this link</a>."
-                  + Utility.messageBD(myPool, "BuildWarning2", vars.getLanguage()));
+          error.setMessage(Utility.messageBD(myPool, "BuildWarning", vars.getLanguage())
+              + "<a href=\"http://wiki.openbravo.com/wiki/UpgradeTips\" target=\"_blank\">"
+              + Utility.messageBD(myPool, "ThisLink", vars.getLanguage()) + "</a>."
+              + Utility.messageBD(myPool, "BuildWarning2", vars.getLanguage()));
 
         } else {
           error.setType("Success");
--- a/src/org/openbravo/erpCommon/utility/AntExecutor.java	Thu Nov 26 18:01:31 2009 +0100
+++ b/src/org/openbravo/erpCommon/utility/AntExecutor.java	Mon Nov 30 12:16:23 2009 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SL 
- * All portions are Copyright (C) 2008 Openbravo SL 
+ * All portions are Copyright (C) 2008-2009 Openbravo SL 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -24,7 +24,6 @@
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
@@ -33,7 +32,6 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
 import org.apache.tools.ant.listener.Log4jListener;
-import org.openbravo.utils.OBLogAppender;
 
 /**
  * The AntExecutor class allows to execute ant tasks in a given build.xml file.
@@ -45,8 +43,8 @@
 
   private Project project;
   private String baseDir;
-  private OBPrintStream log;
-  private OBPrintStream err;
+  private PrintStream log;
+  private PrintStream err;
   private String returnMessage;
   private PrintWriter out;
 
@@ -88,6 +86,7 @@
     this(buildDir + "/build.xml", buildDir);
   }
 
+  @Deprecated
   public void setPrintWriter(PrintWriter p) {
     out = p;
   }
@@ -102,6 +101,7 @@
    * @return - The complete file name (including directory)
    * @throws Exception
    */
+  @Deprecated
   public String setLogFile(String directory, String logFileName) throws Exception {
     // DefaultLogger logger = new DefaultLogger();
     final FileOutputStream logFile = new FileOutputStream(directory + "/" + logFileName);
@@ -129,9 +129,10 @@
   // return null;
   // return setLogFile(baseDir + "/log", name);
   // }
+  @Deprecated
   public void setLogFileInOBPrintStream(File f) {
-    log.setLogFile(f);
-    err.setLogFile(f);
+    ((OBPrintStream) log).setLogFile(f);
+    ((OBPrintStream) err).setLogFile(f);
   }
 
   public void setLogFile(String filename) {
@@ -158,6 +159,7 @@
    * 
    * @see OBPrintStream
    */
+  @Deprecated
   public void setOBPrintStreamLog(PrintWriter p) {
     setPrintWriter(p);
     final DefaultLogger logger1 = new DefaultLogger();
@@ -171,6 +173,7 @@
     log = ps1;
   }
 
+  @Deprecated
   public void setOBPrintStreamLog(PrintStream p) {
     final DefaultLogger logger1 = new DefaultLogger();
     final OBPrintStream ps1 = new OBPrintStream(p);
@@ -184,7 +187,7 @@
 
     // force log4j to also print to this response
     // OBLogAppender.setOutputStream(ps1);
-    OBLogAppender.setProject(project);
+    org.openbravo.utils.OBLogAppender.setProject(project);
   }
 
   /**
@@ -216,19 +219,9 @@
       project.executeTarget(task);
     } catch (final BuildException e) {
       logger.error(e.getMessage(), e);
-      logger.error(throwableToString(e));
-      err.print(e.toString());
     }
   }
 
-  // log stack trace
-  private String throwableToString(Throwable t) {
-    final StringWriter sw = new StringWriter();
-    final PrintWriter pw = new PrintWriter(sw);
-    t.printStackTrace(pw);
-    return sw.toString();
-  }
-
   /**
    * Executes a set of ant tasks
    * 
@@ -244,8 +237,6 @@
       project.executeTargets(tasks);
     } catch (final BuildException e) {
       logger.error(e.getMessage(), e);
-      err.print(e.toString());
-      logger.error(throwableToString(e));
     }
   }
 
@@ -257,8 +248,9 @@
    * @param v
    *          - boolean value to set
    */
+  @Deprecated
   public void setFinished(boolean v) {
-    log.setFinished(v);
+    ((OBPrintStream) log).setFinished(v);
     if (out != null)
       out.close();
   }
@@ -278,6 +270,7 @@
    * 
    * @return - error String
    */
+  @Deprecated
   public String getErr() {
     // note returnMessage has to be stored in a member because calling
     // err.getLog(...) twice will always result in an empty string
@@ -285,7 +278,7 @@
     if (returnMessage != null) {
       return returnMessage;
     }
-    returnMessage = err.getLog(OBPrintStream.TEXT_PLAIN);
+    returnMessage = ((OBPrintStream) err).getLog(OBPrintStream.TEXT_PLAIN);
     if (returnMessage == null || returnMessage.equals("")) {
       final String mode = project.getProperty("deploy.mode");
       returnMessage = "SuccessRebuild." + mode;
@@ -293,6 +286,7 @@
     return returnMessage;
   }
 
+  @Deprecated
   public boolean hasErrorOccured() {
     return !getErr().startsWith("SuccessRebuild");
   }
--- a/src/org/openbravo/erpCommon/utility/OBPrintStream.java	Thu Nov 26 18:01:31 2009 +0100
+++ b/src/org/openbravo/erpCommon/utility/OBPrintStream.java	Mon Nov 30 12:16:23 2009 +0100
@@ -32,6 +32,7 @@
  * @see AntExecutor
  * 
  */
+@Deprecated
 class OBPrintStream extends PrintStream {
   private StringBuffer log;
   private boolean finished;
@@ -78,7 +79,8 @@
   }
 
   /**
-   * Writes a byte array to the internal PrintStream, replaces line breaks with the <br/> html tag.
+   * Writes a byte array to the internal PrintStream, replaces line breaks with the <br/>
+   * html tag.
    */
   @Override
   public void write(byte[] buf) {