[Title] Fixed GBS version parsing error
authordonghyuk.yang <donghyuk.yang@samsung.com>
Wed, 31 Jul 2013 11:30:09 +0000 (20:30 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Wed, 31 Jul 2013 11:30:09 +0000 (20:30 +0900)
org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java

index 545c766..a3af370 100644 (file)
@@ -32,106 +32,119 @@ import java.util.ArrayList;
 import org.tizen.nativeplatform.util.CommandLauncher;
 
 public class GBSOptionManager {
-       private static ArrayList<GBSOption> options = new ArrayList<GBSOption>();
-       private static boolean initialized = false;
-       public static double MIN_GBS_VERSION = 0.12;
-       
-       public static void addOption(GBSOption op) {
-               options.add(op);
-       }
-       
-       public static boolean isInitialized() {
-               return initialized;
-       }
-       
-       @SuppressWarnings("unchecked")
-       public static ArrayList<GBSOption> getOptions() {
-               return (ArrayList<GBSOption>)options.clone();
-       }
-       
-       public static GBSOption getOption(String op) {
-               for (GBSOption o : options) {   
-                       if (o.getOption().startsWith(op)) {
-                               return o;
-                       }
-               }
-               
-               return null;
-       }
-       
-       private static boolean checkGBSTool() {
-               
-               // check GBS command
-               try {
-                       if ( !CommandLauncher.execute("which gbs") ) {
-                               return false;
-                       }
-                       String result = CommandLauncher.executeOutput("gbs --version", null, true, null);
-                       
-                       // result format : gbs [version]
-                       String[] results = result.trim().split(" ");
-                       if (results.length != 2) {
-                               return false;
-                       }
-                       String command = results[0];
-                       double ver = Double.parseDouble(results[1]);            
-                       
-                       if ( !command.equals("gbs") || ver < MIN_GBS_VERSION) {
-                               return false;
-                       }
-                       
-                       return true;
-
-               } catch (InterruptedException e) {
-                       e.printStackTrace();
-                       return false;
-               }
-       }
-       
-       public static void initOptions() {
-               options.clear();
-               if (!checkGBSTool()) {
-                       return;
-               }
-               String command = "gbs build --help";
-               String output = "";
-               try {
-                       output = CommandLauncher.executeOutput(command);
-               } catch (InterruptedException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               boolean startArgs = false;
-               for (String s : output.split("\n")) {
-                       if (startArgs) {
-                               s = s.trim();
-                               String[] values = s.split("  +");
-                               if (values.length > 1) {
-                                       String option = values[0].trim();
-                                       String desc = values[1].trim();                                 
-                                       GBSOption op = new GBSOption(option, desc, false);
-                                       options.add(op);
-                               } else if (values.length == 1 && !values[0].trim().startsWith("-")) {
-                                       GBSOption op = options.get(options.size() - 1);
-                                       String desc = values[0].trim();
-                                       String newDesc = "";
-                                       if (!op.getDesc().isEmpty()) {
-                                               newDesc = op.getDesc() + " " + desc;
-                                       } else {
-                                               newDesc = desc;
-                                       }
-                                       op.setDesc(newDesc);
-                               } else if (values.length == 1 && values[0].trim().startsWith("-")) {
-                                       String option = values[0].trim();
-                                       GBSOption op = new GBSOption(option, "", false);
-                                       options.add(op);
-                               }
-                               //System.out.print(values[1]);
-                       }
-                       if (s.startsWith("optional arguments:")) {
-                               startArgs = true;
-                       }
-               }
-               initialized = true;
-       }
+    private static ArrayList<GBSOption> options = new ArrayList<GBSOption>();
+    private static boolean initialized = false;
+    public static double MIN_GBS_VERSION = 0.16;
+
+    public static void addOption(GBSOption op) {
+        options.add(op);
+    }
+
+    public static boolean isInitialized() {
+        return initialized;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static ArrayList<GBSOption> getOptions() {
+        return (ArrayList<GBSOption>) options.clone();
+    }
+
+    public static GBSOption getOption(String op) {
+        for (GBSOption o : options) {
+            if (o.getOption().startsWith(op)) {
+                return o;
+            }
+        }
+
+        return null;
+    }
+
+    private static boolean checkGBSTool() {
+
+        // check GBS command
+        try {
+            if (!CommandLauncher.execute("which gbs")) {
+                return false;
+            }
+            String result = CommandLauncher.executeOutput("gbs --version", null, true, null);
+
+            // result format : gbs [version]
+            String[] results = result.trim().split(" ");
+            if (results.length != 2) {
+                return false;
+            }
+            String command = results[0];
+            String _version = results[1];
+            int dot_firstIdx = _version.indexOf('.');
+            if (dot_firstIdx < 0) {
+                return false;
+            }
+
+            // split version string after second dot
+            // 0.17.2 -> 0.17
+            int dot_secondIdx = _version.indexOf('.', dot_firstIdx + 1);
+            String version = _version;
+            if (dot_secondIdx > -1) {
+                version = _version.substring(0, dot_secondIdx);
+            }
+            double ver = Double.parseDouble(version);
+
+            if (!command.equals("gbs") || ver < MIN_GBS_VERSION) {
+                return false;
+            }
+
+            return true;
+
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    public static void initOptions() {
+        options.clear();
+        if (!checkGBSTool()) {
+            return;
+        }
+        String command = "gbs build --help";
+        String output = "";
+        try {
+            output = CommandLauncher.executeOutput(command);
+        } catch (InterruptedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        boolean startArgs = false;
+        for (String s : output.split("\n")) {
+            if (startArgs) {
+                s = s.trim();
+                String[] values = s.split("  +");
+                if (values.length > 1) {
+                    String option = values[0].trim();
+                    String desc = values[1].trim();
+                    GBSOption op = new GBSOption(option, desc, false);
+                    options.add(op);
+                } else if (values.length == 1 && !values[0].trim().startsWith("-")) {
+                    GBSOption op = options.get(options.size() - 1);
+                    String desc = values[0].trim();
+                    String newDesc = "";
+                    if (!op.getDesc().isEmpty()) {
+                        newDesc = op.getDesc() + " " + desc;
+                    } else {
+                        newDesc = desc;
+                    }
+                    op.setDesc(newDesc);
+                } else if (values.length == 1 && values[0].trim().startsWith("-")) {
+                    String option = values[0].trim();
+                    GBSOption op = new GBSOption(option, "", false);
+                    options.add(op);
+                }
+                // System.out.print(values[1]);
+            }
+            if (s.startsWith("optional arguments:")) {
+                startArgs = true;
+            }
+        }
+        initialized = true;
+    }
 }