From e2656a59981379852fbdc3e3de7bcca4b9c4f492 Mon Sep 17 00:00:00 2001 From: "donghyuk.yang" Date: Wed, 31 Jul 2013 20:30:09 +0900 Subject: [PATCH] [Title] Fixed GBS version parsing error --- .../tizen/nativeplatform/gbs/GBSOptionManager.java | 217 +++++++++++---------- 1 file changed, 115 insertions(+), 102 deletions(-) diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java index 545c766..a3af370 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java @@ -32,106 +32,119 @@ import java.util.ArrayList; import org.tizen.nativeplatform.util.CommandLauncher; public class GBSOptionManager { - private static ArrayList options = new ArrayList(); - 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 getOptions() { - return (ArrayList)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 options = new ArrayList(); + 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 getOptions() { + return (ArrayList) 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; + } } -- 2.7.4