Added diagnostics context
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 18 Nov 2008 16:42:05 +0000
changeset 2001 9350afa1a995
parent 2000 a1003b903757
child 2002 4af84b9bf69b
Added diagnostics context
src-diagnostics/.classpath
src-diagnostics/.project
src-diagnostics/.settings/.jsdtscope
src-diagnostics/.settings/org.eclipse.jdt.core.prefs
src-diagnostics/.settings/org.eclipse.jst.common.project.facet.core.prefs
src-diagnostics/.settings/org.eclipse.wst.common.component
src-diagnostics/.settings/org.eclipse.wst.common.project.facet.core.xml
src-diagnostics/.settings/org.eclipse.wst.jsdt.ui.superType.container
src-diagnostics/.settings/org.eclipse.wst.jsdt.ui.superType.name
src-diagnostics/WebContent/META-INF/MANIFEST.MF
src-diagnostics/WebContent/WEB-INF/web.xml
src-diagnostics/build-create.xml
src-diagnostics/build.xml
src-diagnostics/config/diagnostics.properties
src-diagnostics/src/org/openbravo/check/Check.java
src-diagnostics/src/org/openbravo/task/CheckDB.java
src-diagnostics/src/org/openbravo/task/CheckJVMVersion.java
src-diagnostics/src/org/openbravo/task/CheckMemory.java
src-diagnostics/src/org/openbravo/task/CheckTomcatMemory.java
src-diagnostics/src/org/openbravo/task/CheckTomcatVersion.java
src-diagnostics/src/org/openbravo/task/CompareVersion.java
src-diagnostics/src/org/openbravo/utils/PropertiesManager.java
src-diagnostics/src/org/openbravo/utils/ServerConnection.java
src-diagnostics/src/org/openbravo/utils/Version.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.classpath	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-1.5.0-sun-1.5.0.11"/>
+	<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5"/>
+	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
+	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
+	<classpathentry kind="output" path="build/classes"/>
+</classpath>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.project	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>OpenbravoDiagnostics</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.wst.common.project.facet.core.builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.wst.validation.validationbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+	</natures>
+</projectDescription>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/.jsdtscope	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+		<attributes>
+			<attribute name="hide" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+	<classpathentry kind="output" path=""/>
+</classpath>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.jdt.core.prefs	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,7 @@
+#Mon Nov 17 11:09:39 GMT+01:00 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.jst.common.project.facet.core.prefs	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,4 @@
+#Mon Nov 17 11:09:40 GMT+01:00 2008
+classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType\:\:java-1.5.0-sun-1.5.0.11/owners=jst.java\:5.0
+classpath.helper/org.eclipse.jst.server.core.container\:\:org.eclipse.jst.server.tomcat.runtimeTarget\:\:Apache\ Tomcat\ v5.5/owners=jst.web\:2.4
+eclipse.preferences.version=1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.wst.common.component	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+<wb-module deploy-name="OpenbravoDiagnostics">
+<wb-resource deploy-path="/" source-path="/WebContent"/>
+<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
+<property name="context-root" value="OpenbravoDiagnostics"/>
+<property name="java-output-path"/>
+</wb-module>
+</project-modules>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.wst.common.project.facet.core.xml	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+  <runtime name="Apache Tomcat v5.5"/>
+  <fixed facet="jst.java"/>
+  <fixed facet="jst.web"/>
+  <installed facet="jst.java" version="5.0"/>
+  <installed facet="jst.web" version="2.4"/>
+  <installed facet="wst.jsdt.web" version="1.0"/>
+</faceted-project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.wst.jsdt.ui.superType.container	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/.settings/org.eclipse.wst.jsdt.ui.superType.name	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,1 @@
+Window
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/WebContent/META-INF/MANIFEST.MF	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path: 
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/WebContent/WEB-INF/web.xml	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+	<display-name>
+	OpenbravoDiagnostics</display-name>
+
+	  <servlet>
+      <servlet-name>
+        Check
+      </servlet-name>
+      <servlet-class>
+        org.openbravo.check.Check
+      </servlet-class>
+      
+      
+    </servlet>
+	
+	<servlet-mapping>
+      <servlet-name>
+        Check
+      </servlet-name>
+      <url-pattern>
+        /Check.html
+    </url-pattern>
+  </servlet-mapping>
+  
+
+  
+    
+</web-app>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/build-create.xml	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+*************************************************************************
+* 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) 2008 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************
+-->
+<project name="openbravo-diagnostics-build" basedir="." default="check.all">
+
+  <path id="diagnostic.class.path">
+    <fileset dir="WebContent/WEB-INF/lib">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+  
+  <target name="build" depends="clean">
+    <copy todir="WebContent/WEB-INF/lib" >
+      <fileset dir="../lib/runtime">
+        <include name="**/*.jar"/>
+       </fileset>
+    </copy>
+    <javac srcdir="src" destdir="build/classes" encoding="UTF-8" debug="true" debuglevel="lines,vars,source" deprecation="on">
+      <classpath refid="diagnostic.class.path"/>
+    </javac>  
+  </target>
+  
+  <target name="clean">
+    <delete>
+      <fileset dir="WebContent/WEB-INF/lib"/>
+      <fileset dir="build/classes"/>
+    </delete>
+    <mkdir dir="WebContent/WEB-INF/lib"/>
+    <mkdir dir="build/classes"/>
+    <copy file="../config/Openbravo.properties" todir="config"/>
+    <copy todir="WebContent/WEB-INF">
+      <fileset dir="config"/>
+    </copy>
+  </target>
+  
+  <target name="war">
+    <delete failonerror="false" file="lib/OpenbravoDiagnostics.war" />
+    <war compress="true" destfile="OpenbravoDiagnostics.war" encoding="UTF-8" webxml="WebContent/WEB-INF/web.xml">
+      <zipfileset dir="WebContent">
+        <exclude name="**/WEB-INF/web.xml" />
+        <exclude name="**/WEB-INF/lib/servlet-api.jar" />
+      </zipfileset>
+      <classes dir="build/classes"/>
+    </war>
+  </target>
+</project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/build.xml	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,150 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+*************************************************************************
+* 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) 2008 Openbravo SL
+* All Rights Reserved.
+* Contributor(s):  ______________________________________.
+************************************************************************
+-->
+<project name="openbravo-diagnostics" basedir="." default="check.all">
+
+	<property file="config/diagnostics.properties"/>
+	<property file="config/Openbravo.properties"/>
+	<property environment="env"/>
+	
+  <condition property="context.running">
+     <http url="${tomcat.manager.url}/../OpenbravoDiagnostics/Check.html"/>
+   </condition>
+
+	
+	<path id="diagnostic.class.path">
+	  <pathelement path="build/classes"/>
+    <fileset dir="WebContent/WEB-INF/lib">
+      <include name="**/*.jar"/>
+    </fileset>
+	</path>
+	
+	 <path id="tomcat.classpath">
+	    <fileset file="${env.CATALINA_HOME}/server/lib/catalina-ant.jar"/>
+	 </path>
+	
+	 <taskdef name="compareVersion"
+	          classname="org.openbravo.task.CompareVersion">
+	   <classpath refid="diagnostic.class.path"/>
+	 </taskdef>
+
+	<target name="check.all">
+		<ant antfile="build-create.xml" target="build"/>
+		<antcall target="check.db"/>
+		<antcall target="check.ant"/>
+		<antcall target="check.tomcat"/>
+	</target>
+	
+	
+	
+	<target name="check.ant">
+		<antcall target="check.ant.version"/>
+		<antcall target="check.ant.jvm.size"/>
+		<antcall target="check.ant.jvm.version"/>
+	</target>
+	
+	<target name="check.tomcat">
+		<antcall target="deploy.context"/>
+
+		<antcall target="check.tomcat.version"/>
+		<antcall target="check.tomcat.jvm.size"/>
+		<antcall target="check.tomcat.jvm.version"/>	
+	</target>
+	
+	<target name="check.db">
+		<taskdef name="checkDB"
+		                 classname="org.openbravo.task.CheckDB">
+		          <classpath refid="diagnostic.class.path"/>
+		</taskdef>
+		<checkDB/>
+	</target>
+	
+  <target name="check.ant.version">
+  	<echo message="Checking ant version..."/>
+  	<echo message="Minimun ${ant.min.version}, current ${ant.version}"/>
+    <condition property="antversion">
+        <antversion atleast="${ant.min.version}"/>
+    </condition>
+  	<fail unless="antversion" message="Minimum ant version: ${ant.min.version}, current version ${ant.version}"/>
+  	<echo message="Version OK"/>
+  </target>
+	
+	<target name="check.ant.jvm.version">
+	     <echo message="Checking ant's JVM version..."/>
+	     <compareVersion v1="${ant.java.version}"
+	                     v2="${jvm-version}"/>
+	  </target>
+	
+	<target name="check.ant.jvm.size">
+		<taskdef name="checkAntMem"
+		             classname="org.openbravo.task.CheckMemory">
+		      <classpath refid="diagnostic.class.path"/>
+		    </taskdef>
+		    <checkAntMem/>
+	</target>
+	
+	
+	
+	<target name="check.tomcat.version">
+	    <taskdef name="checkTomcatVersion"
+	             classname="org.openbravo.task.CheckTomcatVersion">
+	      <classpath refid="diagnostic.class.path"/>
+	    </taskdef>
+	    <checkTomcatVersion/>
+	  </target>
+	
+	<target name="check.tomcat.jvm.size">
+    <taskdef name="checkMem"
+             classname="org.openbravo.task.CheckTomcatMemory">
+    	<classpath refid="diagnostic.class.path"/>
+    </taskdef>
+		<checkMem/>
+  </target>
+	
+	<target name="check.tomcat.jvm.version">
+	    <taskdef name="checkJVMversion"
+	             classname="org.openbravo.task.CheckJVMVersion">
+	      <classpath refid="diagnostic.class.path"/>
+	    </taskdef>
+	    <checkJVMversion/>
+	  </target>
+  
+	<target name="deploy.context" unless="context.running">
+		<ant antfile="build-create.xml" target="war"/>
+		<taskdef name="deploy.war" classname="org.apache.catalina.ant.DeployTask">
+		  <classpath refid="tomcat.classpath"/>
+		</taskdef>
+		<taskdef name="start"    classname="org.apache.catalina.ant.StartTask">
+		      <classpath refid="tomcat.classpath"/>
+		</taskdef>
+	
+		<deploy.war url="${tomcat.manager.url}" 
+			          username="${tomcat.manager.username}" 
+			          password="${tomcat.manager.password}"
+		            path="/OpenbravoDiagnostics" 
+			          war="file:OpenbravoDiagnostics.war"/>
+		
+		<start      url="${tomcat.manager.url}" 
+		            username="${tomcat.manager.username}" 
+			          password="${tomcat.manager.password}"
+		            path="/OpenbravoDiagnostics"/>
+		
+
+	</target>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/config/diagnostics.properties	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,29 @@
+
+# *************************************************************************
+# * 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) 2008 Openbravo SL 
+# * All Rights Reserved. 
+# * Contributor(s):  ______________________________________.
+# ************************************************************************
+
+ant.min.version=1.7.0
+max.memory=512
+jvm-version=1.6
+
+db.ora.version=10
+db.ora.opencursors=3000
+
+db.pg.version=8.3.3
+db.pg.windows.version=8.3.5
+
+tomcat.version=5.5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/check/Check.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,60 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.check;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class Check extends HttpServlet {
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+        final String command = req.getParameter("Command")==null?"":req.getParameter("Command");
+       
+        final PrintWriter out = resp.getWriter();
+        
+        if (command.equals("memory")){
+          final Runtime runtime = Runtime.getRuntime();
+          final long maxMemory = runtime.maxMemory()/(1024*1024); //Memory in MB
+          
+          out.println(maxMemory);
+        } else if (command.equals("jvm-version")) {
+          out.println(System.getProperty("java.runtime.version"));
+        } else if (command.equals("server")) {
+            out.println(req.getSession().getServletContext().getServerInfo());
+        } else {
+            out.println("Non-recognized command: "+command);
+        }
+        out.close();
+    }
+  
+   @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException {
+     doPost(req, resp);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CheckDB.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,197 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.task;
+
+import java.io.FileInputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.data.UtilSql;
+import org.openbravo.utils.PropertiesManager;
+import org.openbravo.utils.Version;
+
+public class CheckDB extends Task{
+    static Logger log4j = Logger.getLogger(CheckDB.class);
+    
+    @Override
+    public void execute() throws BuildException {
+        
+            log4j.info("Checking database...");
+            final Properties properties = new Properties();
+            try {
+                properties.load(new FileInputStream("../config/Openbravo.properties"));
+            } catch (final Exception e) {
+                throw new BuildException(e);
+            }
+            
+            final String rdbms = properties.getProperty("bbdd.rdbms");
+            final String dbDriver = properties.getProperty("bbdd.driver");
+            String dbServer = properties.getProperty("bbdd.url");
+            
+            final String user = properties.getProperty("bbdd.user");
+            final String userPassword = properties.getProperty("bbdd.password");
+            
+            final String systemUser = properties.getProperty("bbdd.systemUser");
+            final String systemUserPassword = properties.getProperty("bbdd.systemPassword");
+            
+            if (rdbms.equalsIgnoreCase("POSTGRE"))
+                dbServer += "/" + properties.getProperty("bbdd.sid");
+            
+            try {
+                Class.forName(dbDriver);
+            } catch (final Exception e) { 
+                throw new BuildException(e.getMessage()); 
+            }  
+
+             
+            log4j.info("Trying to connect to db server as standard user."); 
+            try {
+                final Connection connUser = DriverManager.getConnection(dbServer, user, userPassword);
+                connUser.close();
+            } catch (final Exception e) { 
+                throw new BuildException(e.getMessage()); 
+            }  
+            log4j.info("Connection OK");
+            
+            log4j.info("Trying to connect to db server as system user.");
+            Connection connSystem = null;
+            try {
+                connSystem = DriverManager.getConnection(dbServer, systemUser, systemUserPassword);
+            } catch (final Exception e) { 
+                throw new BuildException(e.getMessage()); 
+            }  
+            log4j.info("Connection OK");
+            
+            PreparedStatement st;  
+            ResultSet result;
+            
+            if (rdbms.equalsIgnoreCase("ORACLE")){
+                //Check version
+                String versionString = "";
+                log4j.info("Checking Oracle version...");
+                try {
+                    st = connSystem.prepareStatement("select * from v$version where banner like '%Oracle%'");
+                
+                    result = st.executeQuery();
+                    
+                    while (result.next()){
+                        versionString = UtilSql.getValue(result, 1);
+                    }
+                    result.close();
+                    st.close();
+                } catch (final Exception e) { 
+                    throw new BuildException(e.getMessage()); 
+                }  
+                
+                if (versionString.contains("Express Edition")) throw new BuildException("Express Edition not suported");
+                
+                final String version = Version.getVersion(versionString);
+                final String minVersion = new PropertiesManager().getProperty("db.ora.version");
+                String msg = "Minimum required version: "+minVersion+", current version "+version;
+                if (Version.compareVersion(version, minVersion)<0)
+                    throw new BuildException(msg);
+                else {
+                    log4j.info(msg);
+                    log4j.info("Oracle version OK");
+                }
+                
+                //check open_cursors
+                log4j.info("Checking Oracle open cursors...");
+                long openCursors=0;
+                try {
+                    st = connSystem.prepareStatement("SELECT value FROM v$parameter WHERE name ='open_cursors'");
+                    result = st.executeQuery();
+                    while (result.next()){
+                        openCursors = new Long(UtilSql.getValue(result, 1));
+                    }
+                    result.close();
+                    st.close();
+                } catch (final Exception e) { 
+                    throw new BuildException(e.getMessage()); 
+                }
+                final long minOpenCursors = new Long(new PropertiesManager().getProperty("db.ora.opencursors"));
+                msg = "Minimum open cursors required: "+minOpenCursors+", current open cursors "+openCursors;
+                if (openCursors<minOpenCursors) 
+                    throw new BuildException(msg);
+                else {
+                    log4j.info(msg);
+                    log4j.info("Open cursors OK");
+                }
+                
+            } else { //PostgreSQL
+              //Check version
+                log4j.info("Checking PostgreSQL version...");
+                String version = "";
+                try {
+                    st = connSystem.prepareStatement("SELECT setting FROM pg_settings WHERE name = 'server_version'");
+                
+                    result = st.executeQuery();
+                    
+                    while (result.next()){
+                        version = UtilSql.getValue(result, 1);
+                    }
+                    result.close();
+                    st.close();
+                } catch (final Exception e) { 
+                    throw new BuildException(e.getMessage()); 
+                }  
+                
+                
+                String minVersion = new PropertiesManager().getProperty("db.pg.version");
+                if (System.getProperty("os.name").equalsIgnoreCase("Windows")) minVersion = new PropertiesManager().getProperty("db.pg.windows.version");
+                else minVersion = new PropertiesManager().getProperty("db.pg.version");
+                
+                final String msg = "Minimum required version: "+minVersion+", current version "+version;
+                if (Version.compareVersion(version, minVersion)<0)
+                    throw new BuildException(msg);
+                else {
+                    log4j.info(msg);
+                    log4j.info("PostgreSQL version OK");
+                }
+                
+              //Check contrib
+                log4j.info("Checking PostgreSQL contrib package installed...");
+                try {
+                    st = connSystem.prepareStatement("SELECT uuid_generate_v1()");
+                    result = st.executeQuery();
+                    result.close();
+                    st.close();
+                } catch (final Exception e) { 
+                    throw new BuildException("PostgreSQL contrib package seems not to be installed"); 
+                }
+                log4j.info("Contrib package OK");
+                
+            }
+            try {
+              connSystem.close();
+            } catch (final Exception e) { 
+                throw new BuildException(e.getMessage()); 
+            }
+    }
+    
+
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CheckJVMVersion.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,54 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.task;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.utils.PropertiesManager;
+import org.openbravo.utils.ServerConnection;
+import org.openbravo.utils.Version;
+
+public class CheckJVMVersion extends Task {
+    static Logger log4j = Logger.getLogger(CheckJVMVersion.class);
+    
+    @Override
+    public void execute() throws BuildException {
+        log4j.info("Checking Tomcat's JVM version...");
+        
+        final String jvmVersion = new ServerConnection().getCheck("jvm-version");
+        final String minJvmVersion = new PropertiesManager().getProperty("jvm-version");
+        
+        final String msg = "Current Tomcat's JVM version: "+jvmVersion+" minimun required version: "+minJvmVersion;
+        
+        if (Version.compareVersion(jvmVersion, minJvmVersion)<0)
+            throw new BuildException(msg);
+        else {
+            log4j.info(msg);
+            log4j.info("Tomcat's JVM version OK");
+        }
+    }
+
+    public static void main(String[] args) {
+        final CheckJVMVersion c = new CheckJVMVersion();
+        c.execute();
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CheckMemory.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,47 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.task;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.utils.PropertiesManager;
+
+public class CheckMemory extends Task {
+    static Logger log4j = Logger.getLogger(CheckMemory.class);
+    
+    @Override
+    public void execute() throws BuildException {
+        log4j.info("Checking ant's memory...");
+        final Runtime runtime = Runtime.getRuntime();
+        final long maxCurrentMemory = runtime.maxMemory()/(1024*1024); //Memory in MB
+        
+        
+        final long maxMemory = new Long(new PropertiesManager().getProperty("max.memory"));
+        final String msg = "Current max ant's memory:"+maxCurrentMemory+"M, minimun required:"+maxMemory+"M";
+        //check max memory +- 5%, because it is not accurate
+        if (maxMemory>maxCurrentMemory*1.05) throw new BuildException(msg);
+        else {
+            log4j.info(msg);
+            log4j.info("Ant's memory OK ");
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CheckTomcatMemory.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,47 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.task;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.utils.PropertiesManager;
+import org.openbravo.utils.ServerConnection;
+
+
+public class CheckTomcatMemory extends Task{
+    static Logger log4j = Logger.getLogger(CheckTomcatMemory.class);
+    
+  @Override
+  public void execute() throws BuildException {
+      log4j.info("Checking tomcat's memory...");
+      final long maxCurrentMemory = new Long(new ServerConnection().getCheck("memory"));
+      final long MaxMemory = new Long(new PropertiesManager().getProperty("max.memory"));
+      final String msg = "Current max memory in server:"+maxCurrentMemory+"M, minimun required:"+MaxMemory+"M";
+        
+     //check max memory +- 5%, because it is not accurate
+      if (MaxMemory>maxCurrentMemory*1.05) throw new BuildException(msg);
+      else {
+          log4j.info(msg);
+          log4j.info("Tomcat's memory OK ");
+      }
+
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CheckTomcatVersion.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,29 @@
+package org.openbravo.task;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.utils.PropertiesManager;
+import org.openbravo.utils.ServerConnection;
+import org.openbravo.utils.Version;
+
+public class CheckTomcatVersion extends Task{
+    
+    static Logger log4j = Logger.getLogger(CheckTomcatVersion.class);
+    
+    @Override
+    public void execute() throws BuildException {
+        log4j.info("Checking tomcat version...");
+        final String versionString = new ServerConnection().getCheck("server");
+        if (!versionString.contains("Tomcat")) throw new BuildException("Server seems not to be Tomcat");
+        final String version = Version.getVersion(versionString);
+        final String minVersion = new PropertiesManager().getProperty("tomcat.version");
+        final String msg = "Minimun Tomcat version: "+minVersion+", current version: "+version;
+        if (Version.compareVersion(version, minVersion)<0)
+            throw new BuildException(msg);
+        else {
+            log4j.info(msg);
+            log4j.info("Tomcat version OK");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/task/CompareVersion.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,47 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.task;
+
+import org.apache.log4j.Logger;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.openbravo.utils.Version;
+
+public class CompareVersion extends Task {
+    private String v1;
+    private String v2;
+    static Logger log4j = Logger.getLogger(CompareVersion.class);
+    
+    @Override
+    public void execute() throws BuildException {
+      final String msg = "Minimun version "+v2+" current version "+v1;
+      if (Version.compareVersion(v1, v2)<0) 
+          throw new BuildException(msg);
+      log4j.info(msg);
+    }
+
+    public void setV1(String v1) {
+        this.v1 = v1;
+    }
+
+    public void setV2(String v2) {
+        this.v2 = v2;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/utils/PropertiesManager.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,47 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.utils;
+
+import java.io.FileInputStream;
+import java.util.Properties;
+
+public class PropertiesManager {
+    
+    
+    Properties obProperties;
+    
+    public PropertiesManager(String propertiesFile){
+        try{
+            obProperties = new Properties();
+            obProperties.load(new FileInputStream(propertiesFile));
+        } catch (final Exception e) {
+            //do nothing
+        }
+    }
+    
+    public PropertiesManager() {
+        this("config/diagnostics.properties");
+    }
+        
+    
+    public String getProperty(String name){
+        return obProperties.getProperty(name);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/utils/ServerConnection.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,64 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.utils;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class ServerConnection {
+  
+
+  private URL getUrl(String action) throws MalformedURLException {
+      return new URL(new PropertiesManager("config/Openbravo.properties").getProperty("tomcat.manager.url").replace("/manager","")+"/OpenbravoDiagnostics/Check.html?Command="+action);
+  }
+  
+  public String getCheck(String action){
+      BufferedReader br = null;
+      BufferedWriter bw = null;
+      try {
+        final HttpURLConnection conn = (HttpURLConnection) getUrl(action).openConnection();
+        
+        conn.setDoOutput(true);
+        
+        bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
+        bw.flush();
+        bw.close();
+        
+        String s = null;
+        final StringBuilder sb = new StringBuilder();
+        br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+        while ((s = br.readLine()) != null) {
+          sb.append(s);
+        }
+        br.close();
+        return sb.toString();
+      } catch (final IOException e) {
+        //log4j.error(e.getMessage(), e);
+        //throw e;
+      }
+      return "";
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-diagnostics/src/org/openbravo/utils/Version.java	Tue Nov 18 16:42:05 2008 +0000
@@ -0,0 +1,49 @@
+/*
+ *************************************************************************
+ * 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) 2008 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Version {
+    public static int compareVersion(String v1, String v2) {
+        if (v1.equals(v2)) return 0;
+        final String[] version1 = v1.split("\\.");
+        final String[] version2 = v2.split("\\.");
+        final int minorVers = version1.length>version2.length?version2.length:version1.length;
+        for (int i=0;i<minorVers;i++){
+           if (version1[i].equals(version2[i])) continue;
+           return new Integer(version1[i]).compareTo(new Integer(version2[i]));  
+        }
+        return 0;
+    }
+
+    public static String getVersion(String str) {
+        String version = "";
+        if (str == null)
+          return "";
+        final Pattern pattern = Pattern.compile("((\\d+\\.)+)\\d+");
+        final Matcher matcher = pattern.matcher(str);
+        if (matcher.find()) {
+          version = matcher.group();
+        }
+        return version;
+      }
+}