# HG changeset patch
# User Rafa Alonso <ral@openbravo.com>
# Date 1463088453 -7200
#      Thu May 12 23:27:33 2016 +0200
# Node ID f448556da1dcd73b825cb3113f3f524f06c243ed
# Parent  27592b2005c6d0a88a9ebf8b769e9e7460b602b8
Added automation capabilities to ant setup:

The problem was that the ant setup ccommand could not be automated

Changed: if the actions option value is provided, the task is executed following those actions
So, if we execute:
   ant setup -Dactions="2 11 somedbname 0 1"
it will setup the context with the default options but setting the database sid to 'somedbname'

diff -r 27592b2005c6 -r f448556da1dc build.xml
--- a/build.xml	Thu May 12 17:14:39 2016 +0200
+++ b/build.xml	Thu May 12 23:27:33 2016 +0200
@@ -1022,12 +1022,12 @@
     </javac>
   </target>
 
-  <target name="setup" depends="init, setup.compile">
+  <target name="setup" depends="init, setup.compile" description="Sets up the Openbravo context">
     <echo message="Launching configuration application..."/>
     <taskdef name="configurationApp" classname="org.openbravo.configuration.ConfigurationApp">
       <classpath refid="project.class.path" />
     </taskdef>
-    <configurationApp/>
+    <configurationApp actions="${actions}"/>
     </target>
   
   <target name="package.core" depends="init, set.version.number">
diff -r 27592b2005c6 -r f448556da1dc src/org/openbravo/configuration/ConfigurationApp.java
--- a/src/org/openbravo/configuration/ConfigurationApp.java	Thu May 12 17:14:39 2016 +0200
+++ b/src/org/openbravo/configuration/ConfigurationApp.java	Thu May 12 23:27:33 2016 +0200
@@ -27,8 +27,10 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Queue;
 import java.util.Scanner;
 
 import org.apache.commons.io.FileUtils;
@@ -138,12 +140,35 @@
   private Scanner agreementLicense = new Scanner(System.in);
   private Scanner infoCollected = new Scanner(System.in);
 
+  private Queue<String> incomming = new LinkedList<String>();
+
+  private String getInfoCollected() {
+    if (incomming.isEmpty()) {
+      return infoCollected.nextLine();
+    }
+    return incomming.poll();
+  }
+
+  // The setter for the "script" argument
+  public void setActions(String actions) {
+    if (actions.equals("${actions}")) {
+      return;
+    }
+    for (String action : actions.split(" ")) {
+      incomming.add(action);
+    }
+    getProject().log(String.format("Scripted mode running \"%s\"", actions));
+  }
+
   /**
    * This is the main method that is invoke by ant setup task.
    * 
    */
   public void execute() {
     Project p = getProject();
+    if (!incomming.isEmpty()) {
+      mainFlowOption = MAIN_MENU;
+    }
     while (mainFlowOption != EXIT_APP) {
       switch (mainFlowOption) {
       case WELCOME:
@@ -245,7 +270,7 @@
         optionToCange.getOptions(p);
         boolean numberOk = false;
         do {
-          String optionS = infoCollected.nextLine();
+          String optionS = getInfoCollected();
           try {
             int option = Integer.parseInt(optionS);
             if (option >= 0 && option < optionToCange.getMax()) {
@@ -266,7 +291,7 @@
       } else if (optionToCange.getType() == ConfigureOption.TYPE_OPT_STRING) {
         p.log("\nPlease introduce " + optionToCange.getAskInfo());
         optionToCange.getOptions(p);
-        String optionString = infoCollected.nextLine();
+        String optionString = getInfoCollected();
         if (!optionString.equals("")) {
           optionToCange.setChosenString(optionString);
         }
@@ -337,7 +362,7 @@
         optionToChange.getOptions(p);
         boolean numberOk = false;
         do {
-          optionS = infoCollected.nextLine();
+          optionS = getInfoCollected();
           try {
             option = Integer.parseInt(optionS);
             if (option >= 0 && option < optionToChange.getMax()) {
@@ -358,7 +383,7 @@
       } else if (optionToChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
         p.log("\nPlease introduce " + optionToChange.getAskInfo());
         optionToChange.getOptions(p);
-        optionString = infoCollected.nextLine();
+        optionString = getInfoCollected();
         if (!optionString.equals("")) {
           optionToChange.setChosenString(optionString);
         }
@@ -373,7 +398,7 @@
         optionToChange.getOptions(p);
         boolean numberOk = false;
         do {
-          optionS = infoCollected.nextLine();
+          optionS = getInfoCollected();
           try {
             option = Integer.parseInt(optionS);
             if (option >= 0 && option < optionToChange.getMax()) {
@@ -394,7 +419,7 @@
       } else if (optionToChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
         p.log("\nPlease introduce " + optionToChange.getAskInfo());
         optionToChange.getOptions(p);
-        optionString = infoCollected.nextLine();
+        optionString = getInfoCollected();
         if (!optionString.equals("")) {
           optionToChange.setChosenString(optionString);
         }
@@ -418,7 +443,7 @@
     boolean menuOptionOk = false;
     int optionConfigure = 0;
     do {
-      String menuOptionS = infoCollected.nextLine();
+      String menuOptionS = getInfoCollected();
       try {
         optionConfigure = Integer.parseInt(menuOptionS);
         menuOptionOk = true;
@@ -454,7 +479,7 @@
       optionToChange.getOptions(p);
       boolean numberOk = false;
       do {
-        String optionS = infoCollected.nextLine();
+        String optionS = getInfoCollected();
         try {
           int option = Integer.parseInt(optionS);
           if (option >= 0 && option < optionToChange.getMax()) {
@@ -475,7 +500,7 @@
     } else if (optionToChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
       p.log("\nPlease introduce " + optionToChange.getAskInfo());
       optionToChange.getOptions(p);
-      String optionString = infoCollected.nextLine();
+      String optionString = getInfoCollected();
       if (!optionString.equals("")) {
         optionToChange.setChosenString(optionString);
       }
@@ -516,7 +541,7 @@
     p.log("Choose [0] for continue with configuration or a number option for modify: ");
     boolean menuOptionOk = false;
     do {
-      String menuOptionS = infoCollected.nextLine();
+      String menuOptionS = getInfoCollected();
       try {
         optionForModify = Integer.parseInt(menuOptionS);
         if (optionForModify >= 0
@@ -581,7 +606,7 @@
         optionOneByOne.getOptions(p);
         boolean numberOk = false;
         do {
-          String optionS = infoCollected.nextLine();
+          String optionS = getInfoCollected();
           try {
             int option = Integer.parseInt(optionS);
             if (option >= 0 && option < optionOneByOne.getMax()) {
@@ -601,7 +626,7 @@
       } else if (optionOneByOne.getType() == ConfigureOption.TYPE_OPT_STRING) {
         p.log("\nPlease introduce " + optionOneByOne.getAskInfo());
         optionOneByOne.getOptions(p);
-        String optionString = infoCollected.nextLine();
+        String optionString = getInfoCollected();
         if (!optionString.equals("")) {
           optionOneByOne.setChosenString(optionString);
         }
@@ -642,7 +667,7 @@
     boolean menuOptionOk = false;
     int menuOption = 3;
     do {
-      String menuOptionS = infoCollected.nextLine();
+      String menuOptionS = getInfoCollected();
       try {
         menuOption = Integer.parseInt(menuOptionS);
         menuOptionOk = true;
