CLI: Change ListDevice to ListTarget 99/13399/3
authorhyunsik.noh <hyunsik.noh@samsung.com>
Thu, 5 Dec 2013 03:06:55 +0000 (12:06 +0900)
committerhyunsik.noh <hyunsik.noh@samsung.com>
Thu, 5 Dec 2013 06:00:10 +0000 (15:00 +0900)
Signed-off-by: hyunsik.noh <hyunsik.noh@samsung.com>
Change-Id: I2343c0e8b0840e349c8364d76b6ee974f878a36b
Signed-off-by: hyunsik.noh <hyunsik.noh@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java [moved from org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java with 79% similarity]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTarget.java [moved from org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDevice.java with 96% similarity]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTargetCLICommand.java [moved from org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDeviceCLICommand.java with 51% similarity]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/TargetUtil.java

index b67fc0f..3366c03 100644 (file)
@@ -35,7 +35,7 @@ public class TizenAutoComplete {
     public static String commands = "build-native build-web cli-config create debug help install list package run sign uninstall";
 
     public static String[][] subCommands = {
-        { "list", "device", "app" },
+        { "list", "target", "app" },
         { "create", "web-project nativ-project security-profile security-profile-item certificate" },
         { "help", commands } };
     
@@ -72,7 +72,7 @@ public class TizenAutoComplete {
         { "-ref", "--ref-project" }
         };
 
-    public enum optionSuggestion {
+    public enum OptionSuggestion {
         architecture(options[1][0], "--arch", "x86 arm"),
         compiler(options[1][0], "--compiler", "llvm gcc"),
         configuration(options[1][0], "--configuration", "Debug Release DA"),
@@ -82,11 +82,11 @@ public class TizenAutoComplete {
         private String option;
         private String suggestion;
 
-        private optionSuggestion(String option) {
+        private OptionSuggestion(String option) {
             this.option = option;
         }
 
-        private optionSuggestion(String mainCmd, String option, String suggestion) {
+        private OptionSuggestion(String mainCmd, String option, String suggestion) {
             this.mainCmd = mainCmd;
             this.option = option;
             this.suggestion = suggestion;
@@ -110,8 +110,8 @@ public class TizenAutoComplete {
         int count = inputs.length;
         if (count > 2) {
             boolean needSuggestion = false;
-            optionSuggestion input = null;
-            for (optionSuggestion optionFortSuggestion : optionSuggestion.values()) {
+            OptionSuggestion input = null;
+            for (OptionSuggestion optionFortSuggestion : OptionSuggestion.values()) {
                 if (optionFortSuggestion.getOption().equals(inputs[count - 1])) {
                     needSuggestion = true;
                     input = optionFortSuggestion;
@@ -274,7 +274,7 @@ public class TizenAutoComplete {
         return duplicatedOption;
     }
 
-    private static String makeInputSuggestion(optionSuggestion optionFortSuggestion) throws SBIException {
+    private static String makeInputSuggestion(OptionSuggestion optionFortSuggestion) throws SBIException {
         String suggestion = "";
 
         switch (optionFortSuggestion) {
index f638141..ad6b7af 100644 (file)
@@ -60,5 +60,4 @@ public class TizenCLIMessages extends NLS {
     
     //LIST
     public static String LIST_NO_DEVICE;
-    public static String LIST_CANNOT_GET_DEVICE_LIST;
 }
index 8581597..14a26a7 100644 (file)
@@ -43,5 +43,4 @@ UNINST_UNEXIST_PACKAGE = The package is not exist.
 UNINST_FAIL_INVALID_PACKAGE = [Fail] Fail uninstall. There is the problem about package.
 UNINST_FAIL_NO_PACKAGE_ID = [Fail] Fail uninstall. There is no package id.
 
-LIST_NO_DEVICE = There is no device.
-LIST_CANNOT_GET_DEVICE_LIST = Can not get the device list.
+LIST_NO_DEVICE = There is no device.
\ No newline at end of file
index dbf9598..8a64cbd 100644 (file)
@@ -38,7 +38,7 @@ public class ListCLI extends AbstractCLI{
     
     @Argument(index = 0, required = true, handler = TizenSubCommandHandler.class, usage = "Command is needed!")
     @SubCommands({ 
-            @SubCommand(name = "device", impl = ListDeviceCLI.class),
+            @SubCommand(name = "target", impl = ListTargetCLI.class),
             @SubCommand(name = "app", impl = ListAppCLI.class)
     })
     
@@ -28,24 +28,24 @@ import org.kohsuke.args4j.Option;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.ncli.core.TizenSubCommand;
-import org.tizen.ncli.ide.subcommands.ListDevice;
-import org.tizen.ncli.ide.subcommands.ListDeviceCLICommand;
+import org.tizen.ncli.ide.subcommands.ListTarget;
+import org.tizen.ncli.ide.subcommands.ListTargetCLICommand;
 
 @TizenSubCommand(name="target" , usage="Show connected target list")
-public class ListDeviceCLI extends AbstractCLI{
+public class ListTargetCLI extends AbstractCLI{
     private Logger log = LoggerFactory.getLogger(getClass());
     
-    @Option(name = "--detail", usage = "Details for device(Device Id/Type/Name)")
+    @Option(name = "--detail", usage = "Details for target(Target Id/Type/Name)")
     private boolean detail;
 
     @Override
     public void execute() {
         log.trace("Execute ListDeviceCLI...");
 
-        ListDeviceCLICommand command = new ListDeviceCLICommand();
+        ListTargetCLICommand command = new ListTargetCLICommand();
         command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);
         command.setDetail(detail);
-        ListDevice runCommand = command.runCommand();
+        ListTarget runCommand = command.runCommand();
     }
 
 }
  */
 package org.tizen.ncli.ide.subcommands;
 
-import org.tizen.common.core.application.InstallPathConfig;
-import org.tizen.common.util.HostUtil;
 import org.tizen.ncli.ide.messages.TizenCLIMessages;
+import org.tizen.ncli.ide.util.TargetUtil;
+import org.tizen.sdblib.IDevice;
 
-public class ListDeviceCLICommand extends AbstractSubCommand<ListDevice> {
-    private final String firstLine = "List of devices attached";
+public class ListTargetCLICommand extends AbstractSubCommand<ListTarget> {
     
     private boolean detail = false;
+    private final String EMULATOR = "Emulator";
+    private final String DEVICE = "Device";
+    private String detailFormat = "[ID] %s\t[TYPE] %s\t[NAME] %s";
+    private String defaultFormat = "[ID] %s";
 
     @Override
-    protected ListDevice call() {
-        String sdb = InstallPathConfig.getSDBPath();
-        String deviceCommand = sdb + " " + "devices";
-        String[] result = HostUtil.returnExecute(deviceCommand).split("\n");
-        if(firstLine.equals(result[0].trim())) {
-            int length = result.length;
-            if(length > 1) {
-                String device = null;
-                for(int i = 1; i < length; i++ ) {
-                    if(detail) {
-                        device = result[i];
-                    } else {
-                        device = result[i].split("\t")[0];
-                    }
-                    System.out.println(device);
+    protected ListTarget call() {
+        IDevice[] targets = TargetUtil.getTargets();
+        int length = targets.length;
+        if(length > 0) {
+            String targetInfo = null;
+            if(detail) {
+                for(IDevice target: targets) {
+                    targetInfo = String.format(detailFormat, target.getSerialNumber() , (target.isEmulator() ? EMULATOR : DEVICE) , target.getDeviceName());
+                    progressLog.info(targetInfo);
                 }
             } else {
-                System.out.println(TizenCLIMessages.LIST_NO_DEVICE);
+                for(IDevice target: targets) {
+                    targetInfo = String.format(defaultFormat, target.getSerialNumber());
+                    progressLog.info(targetInfo);
+                }
             }
         } else {
-            System.out.println(TizenCLIMessages.LIST_CANNOT_GET_DEVICE_LIST);
+            progressLog.error(TizenCLIMessages.LIST_NO_DEVICE);
         }
         return null;
     }
@@ -62,5 +62,4 @@ public class ListDeviceCLICommand extends AbstractSubCommand<ListDevice> {
     public void setDetail(boolean detail) {
         this.detail = detail;
     }
-
 }
index 98a651f..1744e85 100644 (file)
@@ -50,7 +50,7 @@ public class TargetUtil {
     }
     
     public static void initSdb() {
-        log.trace("initialize sdb");
+        log.info("initialize sdb");
         String sdbPath = InstallPathConfig.getSDBPath();
         if (!HostUtil.exists(sdbPath)) {
             log.error(String.format("There is no %s.", sdbPath));
@@ -69,10 +69,15 @@ public class TargetUtil {
     }
     
     public static void finalizeSmartDeviceBridge() {
-        log.trace("finalize sdb");
+        log.info("finalize sdb");
         SmartDevelopmentBridge.disconnectBridge();
     }
     
+    
+    public static IDevice[] getTargets() {
+        return SmartDevelopmentBridge.getBridge().getDevices();
+    }
+    
     /**
      * Returns IDevice object from connected targets.
      * @param targetName
@@ -80,8 +85,8 @@ public class TargetUtil {
      */
     public static IDevice getTarget(String targetName) {
         IDevice target = null;
-        log.trace("set target");
-        IDevice[] targets = SmartDevelopmentBridge.getBridge().getDevices();
+        log.info("set target");
+        IDevice[] targets = getTargets();
         if(targets.length == 0) {
             System.out.println(TizenCLIMessages.NO_CONNECTED_TARGETS);
             log.error(TizenCLIMessages.NO_CONNECTED_TARGETS);
@@ -117,6 +122,7 @@ public class TargetUtil {
         String defaultTimeout = config.getValue(ConfigConstant.DEFAULT_SDB_TIMEOUT);
         int timeout = (defaultTimeout == null ? 60000 : Integer.parseInt(defaultTimeout));
         SdbCommand sdbCommand = new SdbCommand(target, null, null, timeout);
+        log.info("Execute " + command + "via Sdb");
         return sdbCommand.returnExecuteCommand(command);
     }
 }