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 } };
{ "-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"),
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;
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;
return duplicatedOption;
}
- private static String makeInputSuggestion(optionSuggestion optionFortSuggestion) throws SBIException {
+ private static String makeInputSuggestion(OptionSuggestion optionFortSuggestion) throws SBIException {
String suggestion = "";
switch (optionFortSuggestion) {
//LIST
public static String LIST_NO_DEVICE;
- public static String LIST_CANNOT_GET_DEVICE_LIST;
}
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
@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)
})
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;
-public class ListDevice {
+public class ListTarget {
}
*/
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;
}
public void setDetail(boolean detail) {
this.detail = detail;
}
-
}
}
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));
}
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
*/
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);
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);
}
}