Related to issue 30286: Modulescript ERP Version Update Expose Project
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 21 Jul 2015 08:59:53 +0200
changeset 27142 538992966e33
parent 27141 f6885205cc8d
child 27143 dcf8b6e81b7b
Related to issue 30286: Modulescript ERP Version Update Expose Project
src-core/src/org/openbravo/modulescript/ModuleScript.java
src-core/src/org/openbravo/modulescript/ModuleScriptExecutionLimits.java
src-core/src/org/openbravo/modulescript/ModuleScriptHandler.java
src-core/src/org/openbravo/modulescript/OpenbravoVersion.java
src-db/database/lib/dbsourcemanager.jar
src-test/src/org/openbravo/test/AllAntTaskTests.java
src-test/src/org/openbravo/test/modularity/ModuleScriptsVersions.java
src-util/modulescript/src/org/openbravo/modulescript/OpenbravoVersion.java
--- a/src-core/src/org/openbravo/modulescript/ModuleScript.java	Fri Jul 17 15:04:27 2015 +0200
+++ b/src-core/src/org/openbravo/modulescript/ModuleScript.java	Tue Jul 21 08:59:53 2015 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2010 Openbravo S.L.U.
+ * Copyright (C) 2010-2015 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -12,6 +12,7 @@
 package org.openbravo.modulescript;
 
 import java.io.File;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.apache.tools.ant.BuildException;
@@ -19,7 +20,7 @@
 import org.openbravo.database.ConnectionProvider;
 
 /**
- * Clases extending ModuleScript can be included in Openbravo Core or a module and will be
+ * Classes extending ModuleScript can be included in Openbravo Core or a module and will be
  * automatically executed when the system is rebuilt (technically in: update.database and
  * update.database.mod)
  * 
@@ -38,6 +39,84 @@
   public abstract void execute();
 
   /**
+   * This method prints some log information before calling the execute() method
+   */
+  private void doExecute() {
+    log4j.info("Executing moduleScript: " + this.getClass().getName());
+    execute();
+  }
+
+  /**
+   * This method checks whether the ModuleScript can be executed before invoke the doExecute()
+   * method
+   * 
+   * @param modulesVersionMap
+   *          A data structure that contains module versions mapped by module id
+   */
+  public final void preExecute(Map<String, OpenbravoVersion> modulesVersionMap) {
+    ModuleScriptExecutionLimits executionLimits = getModuleScriptExecutionLimits();
+    if (executionLimits == null || executionLimits.getModuleId() == null
+        || modulesVersionMap == null || modulesVersionMap.size() == 0) {
+      doExecute();
+      return;
+    }
+    if (!executionLimits.areCorrect()) {
+      log4j.error("ModuleScript " + this.getClass().getName()
+          + " not executed because its execution limits are incorrect. "
+          + "Last version should be greater or equal than first version.");
+      return;
+    }
+    OpenbravoVersion currentVersion = modulesVersionMap.get(executionLimits.getModuleId());
+    OpenbravoVersion firstVersion = executionLimits.getFirstVersion();
+    OpenbravoVersion lastVersion = executionLimits.getLastVersion();
+    String additionalInfo = "";
+    if (currentVersion == null) {
+      // Dependent module is being installed
+      if (executeOnInstall()) {
+        doExecute();
+        return;
+      }
+      additionalInfo = this.getClass().getName()
+          + " is configured to not execute it during dependent module installation.";
+    } else {
+      // Dependent module is already installed
+      if ((firstVersion == null || firstVersion.compareTo(currentVersion) < 0)
+          && (lastVersion == null || lastVersion.compareTo(currentVersion) > 0)) {
+        doExecute();
+        return;
+      }
+      additionalInfo = "Dependent module current version (" + currentVersion
+          + ") is not between moduleScript execution limits: first version = " + firstVersion
+          + ", last version = " + lastVersion;
+
+    }
+    log4j.debug("Not necessary to execute moduleScript: " + this.getClass().getName());
+    log4j.debug(additionalInfo);
+  }
+
+  /**
+   * This method can be overridden by the ModuleScript subclasses, to specify the module and the
+   * limit versions to define whether the ModuleScript should be executed or not.
+   * 
+   * @return a ModuleScriptExecutionLimits object which contains the dependent module id and the
+   *         first and last versions of the module that define the execution logic.
+   */
+  protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() {
+    return null;
+  }
+
+  /**
+   * This method can be overridden by the ModuleScript subclasses, to specify if the ModuleScript
+   * should be executed when installing the dependent module.
+   * 
+   * @return a boolean that indicates if the ModuleScript should be executed when installing the
+   *         dependent module.
+   */
+  protected boolean executeOnInstall() {
+    return true;
+  }
+
+  /**
    * This method returns a connection provider, which can be used to execute statements in the
    * database
    * 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-core/src/org/openbravo/modulescript/ModuleScriptExecutionLimits.java	Tue Jul 21 08:59:53 2015 +0200
@@ -0,0 +1,88 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2015 Openbravo S.L.U.
+ * Licensed under the Apache Software License version 2.0
+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to  in writing,  software  distributed
+ * under the License is distributed  on  an  "AS IS"  BASIS,  WITHOUT  WARRANTIES  OR
+ * CONDITIONS OF ANY KIND, either  express  or  implied.  See  the  License  for  the
+ * specific language governing permissions and limitations under the License.
+ ************************************************************************************
+ */
+package org.openbravo.modulescript;
+
+/**
+ * This class is used by ModuleScript objects to store the limits that define if they should be
+ * executed or not. This class holds a String with a module version id, together with the first and
+ * last module versions that establish under which versions a ModuleScript must be executed.
+ */
+public class ModuleScriptExecutionLimits {
+  private String moduleId;
+  private OpenbravoVersion firstVersion;
+  private OpenbravoVersion lastVersion;
+  private boolean correct;
+
+  /**
+   * Basic ModuleScriptExecutionLimits constructor. Used to define a dependency between a
+   * ModuleScript and a module. When upgrading the module whose id is moduleId, the ModuleScript
+   * will be executed only if its version before upgrading is higher than firstVersion and lower
+   * than lastVersion. Otherwise it will not be executed.
+   * 
+   * @param moduleId
+   *          A String with the module id
+   * @param firstVersion
+   *          An OpenbravoVersion which defines the first version of the module with id = moduleId
+   *          since the ModuleScript can be executed
+   * @param lastVersion
+   *          An OpenbravoVersion with the last version of the module with id = moduleId which
+   *          allows the ModuleScript execution
+   */
+  public ModuleScriptExecutionLimits(String moduleId, OpenbravoVersion firstVersion,
+      OpenbravoVersion lastVersion) {
+    this.moduleId = moduleId;
+    this.firstVersion = firstVersion;
+    this.lastVersion = lastVersion;
+    if (firstVersion != null && lastVersion != null && firstVersion.compareTo(lastVersion) > 0) {
+      correct = false;
+    } else {
+      correct = true;
+    }
+  }
+
+  /**
+   * Returns the ModuleScript dependent module id
+   * 
+   * @return a String with the module id
+   */
+  public String getModuleId() {
+    return moduleId;
+  }
+
+  /**
+   * Returns the first version of the dependent module for which the ModuleScript should be
+   * executed.
+   * 
+   * @return a OpenbravoVersion with the first execution version of the dependent module
+   */
+  public OpenbravoVersion getFirstVersion() {
+    return firstVersion;
+  }
+
+  /**
+   * Returns the last version of the dependent module for which the ModuleScript should be executed.
+   * 
+   * @return a OpenbravoVersion with the last execution version of the dependent module
+   */
+  public OpenbravoVersion getLastVersion() {
+    return lastVersion;
+  }
+
+  /**
+   * This method returns true when the last version and first version values are correctly defined.
+   * 
+   * @return false in case first version is higher than last version. Otherwise, it returns true.
+   */
+  public boolean areCorrect() {
+    return correct;
+  }
+}
--- a/src-core/src/org/openbravo/modulescript/ModuleScriptHandler.java	Fri Jul 17 15:04:27 2015 +0200
+++ b/src-core/src/org/openbravo/modulescript/ModuleScriptHandler.java	Tue Jul 21 08:59:53 2015 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2010-2014 Openbravo S.L.U.
+ * Copyright (C) 2010-2015 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -15,7 +15,9 @@
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.log4j.Logger;
 import org.apache.tools.ant.BuildException;
@@ -27,6 +29,7 @@
 
   private File basedir;
   private String moduleJavaPackage;
+  private Map<String, OpenbravoVersion> modulesVersionMap;
 
   @Override
   public void execute() {
@@ -60,12 +63,11 @@
         if (myClass.getGenericSuperclass().equals(
             Class.forName("org.openbravo.modulescript.ModuleScript"))) {
           Object instance = myClass.newInstance();
-          log4j.info("Executing moduleScript: " + s);
           callExecute(myClass, instance);
         }
       } catch (Exception e) {
         log4j.error("Error executing moduleScript: " + s, e);
-        throw new BuildException("Execution of moduleScript " + s + "failed.");
+        throw new BuildException("Execution of moduleScript " + s + " failed.");
       }
     }
   }
@@ -73,24 +75,72 @@
   @SuppressWarnings("unchecked")
   private ArrayList<String> callExecute(Class<?> myClass, Object instance)
       throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
-    return (ArrayList<String>) myClass.getMethod("execute", new Class[0]).invoke(instance,
-        new Object[0]);
+    return (ArrayList<String>) myClass.getMethod("preExecute", new Class[] { Map.class }).invoke(
+        instance, new Object[] { getModulesVersionMap() });
   }
 
+  /**
+   * Returns a File with the base directory
+   * 
+   * @return a File with the base directory
+   */
   public File getBasedir() {
     return basedir;
   }
 
+  /**
+   * Sets the base directory
+   * 
+   * @param basedir
+   *          File used to set the base directory
+   */
   public void setBasedir(File basedir) {
     this.basedir = basedir;
   }
 
+  /**
+   * Returns the java package
+   * 
+   * @return a String with the module java package
+   */
   public String getModuleJavaPackage() {
     return moduleJavaPackage;
   }
 
+  /**
+   * Sets the java package
+   * 
+   * @param moduleJavaPackage
+   *          String to set the java package
+   */
   public void setModuleJavaPackage(String moduleJavaPackage) {
     this.moduleJavaPackage = moduleJavaPackage;
   }
 
+  /**
+   * Creates the OpenbravoVersion map from a map of version strings
+   * 
+   * @param currentVersionsMap
+   *          A data structure that contains Strings with module versions mapped by module id
+   */
+  public void setModulesVersionMap(Map<String, String> currentVersionsMap) {
+    modulesVersionMap = new HashMap<String, OpenbravoVersion>();
+    for (Map.Entry<String, String> entry : currentVersionsMap.entrySet()) {
+      try {
+        modulesVersionMap.put(entry.getKey(), new OpenbravoVersion(entry.getValue()));
+      } catch (Exception ex) {
+        log4j.error(
+            "Not possible to recover the current version of module with id: " + entry.getKey(), ex);
+      }
+    }
+  }
+
+  /**
+   * Returns a map with the current module versions
+   * 
+   * @return A data structure that contains module versions mapped by module id
+   */
+  public Map<String, OpenbravoVersion> getModulesVersionMap() {
+    return this.modulesVersionMap;
+  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-core/src/org/openbravo/modulescript/OpenbravoVersion.java	Tue Jul 21 08:59:53 2015 +0200
@@ -0,0 +1,112 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (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 SLU
+ * All portions are Copyright (C) 2010 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.modulescript;
+
+/**
+ * This class represents an Openbravo ERP version number. It is designed to compare Openbravo ERP
+ * version numbers
+ * 
+ * @author adrian
+ */
+public class OpenbravoVersion implements Comparable<OpenbravoVersion> {
+
+  private int major1;
+  private int major2;
+  private int minor;
+
+  /**
+   * Creates a new Openbravo version object based on its three version numbers.
+   * 
+   * @param major1
+   *          the major1 version number
+   * @param major2
+   *          the major2 version number
+   * @param minor
+   *          the minor version number
+   */
+  public OpenbravoVersion(int major1, int major2, int minor) {
+    this.major1 = major1;
+    this.major2 = major2;
+    this.minor = minor;
+  }
+
+  /**
+   * Creates a new Openbravo version object based on its <code>String</code> representation.
+   * 
+   * @param version
+   *          the version representation
+   */
+  public OpenbravoVersion(String version) {
+
+    String[] numbers = version.split("\\.");
+
+    if (numbers.length != 3) {
+      throw new IllegalArgumentException("Version must consist in three numbers separated by .");
+    }
+    this.major1 = Integer.valueOf(numbers[0]);
+    this.major2 = Integer.valueOf(numbers[1]);
+    this.minor = Integer.valueOf(numbers[2]);
+  }
+
+  /**
+   * Gets the Major1 version number
+   * 
+   * @return The Major1 version number
+   */
+  public int getMajor1() {
+    return major1;
+  }
+
+  /**
+   * Returns the Major1 version number
+   * 
+   * @return The Major2 version number
+   */
+  public int getMajor2() {
+    return major2;
+  }
+
+  /**
+   * Returns the Minor version number
+   * 
+   * @return The Minor version number
+   */
+  public int getMinor() {
+    return minor;
+  }
+
+  public int compareTo(OpenbravoVersion o) {
+    if (major1 == o.major1) {
+      if (major2 == o.major2) {
+        return (minor < o.minor ? -1 : (minor == o.minor ? 0 : 1));
+      } else {
+        return major2 < o.major2 ? -1 : 1;
+      }
+    } else {
+      return major1 < o.major1 ? -1 : 1;
+    }
+  }
+
+  @Override
+  public String toString() {
+    return Integer.toString(major1) + "." + Integer.toString(major2) + "."
+        + Integer.toString(minor);
+  }
+}
Binary file src-db/database/lib/dbsourcemanager.jar has changed
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java	Fri Jul 17 15:04:27 2015 +0200
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java	Tue Jul 21 08:59:53 2015 +0200
@@ -66,6 +66,7 @@
 import org.openbravo.test.modularity.DBPrefixTest;
 import org.openbravo.test.modularity.DatasetServiceTest;
 import org.openbravo.test.modularity.MergePropertiesTest;
+import org.openbravo.test.modularity.ModuleScriptsVersions;
 import org.openbravo.test.modularity.TableNameTest;
 import org.openbravo.test.preference.PreferenceTest;
 import org.openbravo.test.scheduling.ProcessSchedulingTest;
@@ -193,7 +194,10 @@
     // client kernel
     FreemarkerTemplateProcessorTest.class, //
     GenerateComponentTest.class, //
-    LabelTest.class
+    LabelTest.class, //
+
+    // moduleScripts
+    ModuleScriptsVersions.class
 
 })
 public class AllAntTaskTests {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/modularity/ModuleScriptsVersions.java	Tue Jul 21 08:59:53 2015 +0200
@@ -0,0 +1,145 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (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 SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.modularity;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openbravo.modulescript.ModuleScript;
+import org.openbravo.modulescript.ModuleScriptExecutionLimits;
+import org.openbravo.modulescript.OpenbravoVersion;
+
+/**
+ * Test cases covering module script executions when updating database regarding the original
+ * version the module is being updated from.
+ * 
+ * @author alostale
+ * 
+ */
+@RunWith(Parameterized.class)
+public class ModuleScriptsVersions {
+
+  /** current module version we are updating from */
+  final static Map<String, OpenbravoVersion> modulesVersionMap;
+  static {
+    String currentCoreVersion = "3.0.10000";
+
+    modulesVersionMap = new HashMap<String, OpenbravoVersion>();
+    modulesVersionMap.put("0", new OpenbravoVersion(currentCoreVersion));
+  }
+
+  private String moduleId;
+  private String fromVersion;
+  private String toVersion;
+  private boolean onInstall;
+  private boolean shouldExecute;
+
+  /**
+   * @param moduleId
+   *          UUID of the module to establish the dependency with
+   * @param fromVersion
+   *          defines the first module version of the execution dependency
+   * @param toVersion
+   *          defines the last module version of the execution dependency
+   * @param onInstall
+   *          flag to indicate if the moduleScript should be executed on install
+   * @param shouldExecute
+   *          flag to indicate the final result, i.e., if the moduleScript should be executed or not
+   * @param description
+   *          description for the test case
+   */
+  public ModuleScriptsVersions(String moduleId, String fromVersion, String toVersion,
+      boolean onInstall, boolean shouldExecute, String description) {
+    this.moduleId = moduleId;
+    this.fromVersion = fromVersion;
+    this.toVersion = toVersion;
+    this.onInstall = onInstall;
+    this.shouldExecute = shouldExecute;
+  }
+
+  @Parameters(name = "{index}: ''{5}'' -- moduleId: {0} - version limits: [{1}-{2}] - on install: {3} - should execute: {4}")
+  public static Collection<Object[]> data() {
+    return Arrays
+        .asList(new Object[][] {
+            { "AAA", null, null, true, true, "New module should be executed on install" },
+            { "AAA", null, null, false, false, "New module should not be executed on install" },
+
+            // fromVersion defined without toVersion
+            { "0", "3.0.9000", null, true, true,
+                "Minimum version does not affect, is lower than current one, should execute" },
+            { "0", "3.0.20000", null, true, false,
+                "Minimum version is higher than current one, should not execute (issue does not exist yet)" },
+
+            // toVersion defined without fromVersion
+            { "0", null, "3.0.9000", true, false,
+                "Updating from newer, should not execute (issue was already fixed)" },
+            { "0", null, "3.0.20000", true, true,
+                "Updating from older, should execute (issue was not yet fixed)" },
+
+            // both boundaries defined
+            { "0", "3.0.20000", "3.0.9000", true, false, "Incorrect definition" },
+            { "0", "3.0.8000", "3.0.20000", true, true, "---" },
+            { "0", "3.0.8000", "3.0.9000", true, false, "---" },
+            { "0", "3.0.15000", "3.0.20000", true, false, "---" } });
+  }
+
+  /** Executes the module script with current version boundaries */
+  @Test
+  public void moduleScriptIsExecutedBasedOnVersionLimits() {
+    FakeModuleScript ms = new FakeModuleScript();
+    ms.preExecute(modulesVersionMap);
+    assertThat("Script was executed", ms.wasExecuted, is(shouldExecute));
+  }
+
+  /** Fake module script with version limits, it simply flags when it is executed */
+  public class FakeModuleScript extends ModuleScript {
+    /** flag set when the script has been executed */
+    boolean wasExecuted = false;
+
+    @Override
+    public void execute() {
+      wasExecuted = true;
+    }
+
+    @Override
+    public ModuleScriptExecutionLimits getModuleScriptExecutionLimits() {
+      if (moduleId == null) {
+        return null;
+      }
+      return new ModuleScriptExecutionLimits(moduleId, //
+          fromVersion == null ? null : new OpenbravoVersion(fromVersion),//
+          toVersion == null ? null : new OpenbravoVersion(toVersion));
+    }
+
+    @Override
+    public boolean executeOnInstall() {
+      return onInstall;
+    }
+  }
+}
--- a/src-util/modulescript/src/org/openbravo/modulescript/OpenbravoVersion.java	Fri Jul 17 15:04:27 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- *************************************************************************
- * The contents of this file are subject to the Openbravo  Public  License
- * Version  1.1  (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 SLU
- * All portions are Copyright (C) 2010 Openbravo SLU
- * All Rights Reserved.
- * Contributor(s):  ______________________________________.
- ************************************************************************
- */
-
-package org.openbravo.modulescript;
-
-/**
- * This class represents an Openbravo ERP version number. It is designed to compare Openbravo ERP
- * version numbers
- * 
- * @author adrian
- */
-public class OpenbravoVersion implements Comparable<OpenbravoVersion> {
-
-  private int major1;
-  private int major2;
-  private int minor;
-
-  /**
-   * Creates a new Openbravo version object based on its three version numbers.
-   * 
-   * @param major1
-   *          the major1 version number
-   * @param major2
-   *          the major2 version number
-   * @param minor
-   *          the minor version number
-   */
-  public OpenbravoVersion(int major1, int major2, int minor) {
-    this.major1 = major1;
-    this.major2 = major2;
-    this.minor = minor;
-  }
-
-  /**
-   * Creates a new Openbravo version object based on its <code>String</code> representation.
-   * 
-   * @param version
-   *          the version representation
-   */
-  public OpenbravoVersion(String version) {
-
-    String[] numbers = version.split("\\.");
-
-    if (numbers.length != 3) {
-      throw new IllegalArgumentException("Version must consist in three numbers separated by .");
-    }
-    this.major1 = Integer.valueOf(numbers[0]);
-    this.major2 = Integer.valueOf(numbers[1]);
-    this.minor = Integer.valueOf(numbers[2]);
-  }
-
-  /**
-   * Gets the Major1 version number
-   * 
-   * @return The Major1 version number
-   */
-  public int getMajor1() {
-    return major1;
-  }
-
-  /**
-   * Returns the Major1 version number
-   * 
-   * @return The Major2 version number
-   */
-  public int getMajor2() {
-    return major2;
-  }
-
-  /**
-   * Returns the Minor version number
-   * 
-   * @return The Minor version number
-   */
-  public int getMinor() {
-    return minor;
-  }
-
-  public int compareTo(OpenbravoVersion o) {
-    if (major1 == o.major1) {
-      if (major2 == o.major2) {
-        return (minor < o.minor ? -1 : (minor == o.minor ? 0 : 1));
-      } else {
-        return major2 < o.major2 ? -1 : 1;
-      }
-    } else {
-      return major1 < o.major1 ? -1 : 1;
-    }
-  }
-
-  @Override
-  public String toString() {
-    return Integer.toString(major1) + "." + Integer.toString(major2) + "."
-        + Integer.toString(minor);
-  }
-}