From 871ad12065a35445840db5784274db877bed400a Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Mon, 25 Nov 2013 18:58:14 +0900 Subject: [PATCH] CLI: Add basic ListCLI. Add ListCLI(only for device list) Change-Id: I2c80aa1ec87807beec928df205e91b9801f207b1 Signed-off-by: hyunsik.noh --- .../tizen/ncli/ide/messages/TizenCLIMessages.java | 4 ++ .../ncli/ide/messages/TizenCLIMessages.properties | 5 +- .../src/org/tizen/ncli/ide/shell/ListCLI.java | 54 ++++++++++++++++++ .../org/tizen/ncli/ide/shell/ListDeviceCLI.java | 50 ++++++++++++++++ .../org/tizen/ncli/ide/subcommands/ListDevice.java | 29 ++++++++++ .../ncli/ide/subcommands/ListDeviceCLICommand.java | 66 ++++++++++++++++++++++ 6 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDevice.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDeviceCLICommand.java diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java index 0073369..629c90d 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java @@ -36,4 +36,8 @@ public class TizenCLIMessages extends NLS { public static String SIGN_NO_PROFILES; public static String SIGN_NO_SIGNING_PROFILE; public static String SIGN_NO_CONFIG_PROFILES; + + //LIST + public static String LIST_NO_DEVICE; + public static String LIST_CANNOT_GET_DEVICE_LIST; } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties index 9dd602d..294aa2f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties @@ -23,4 +23,7 @@ BN_SUCCESS_SET_TARGET_INFO = Success to write the build target information SIGN_NO_PROFILES = There is no {0}. SIGN_NO_SIGNING_PROFILE = No Signing profile {0} item in {1}. -SIGN_NO_CONFIG_PROFILES = There is no default profiles value in config file. \ No newline at end of file +SIGN_NO_CONFIG_PROFILES = There is no default profiles value in config file. + +LIST_NO_DEVICE = There is no device. +LIST_CANNOT_GET_DEVICE_LIST = Can not get the device list. \ No newline at end of file diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java new file mode 100644 index 0000000..2590f6b --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java @@ -0,0 +1,54 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.ncli.ide.shell; + +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.spi.SubCommand; +import org.kohsuke.args4j.spi.SubCommandHandler; +import org.kohsuke.args4j.spi.SubCommands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.ncli.core.TizenSubCommand; + +@TizenSubCommand(name="list" , usage="Show the list") +public class ListCLI extends AbstractCLI{ + private Logger log = LoggerFactory.getLogger(getClass()); + + @Argument(index = 0, required = true, handler = SubCommandHandler.class, usage = "Command is needed!") + @SubCommands({ + @SubCommand(name = "device", impl = ListDeviceCLI.class) + }) + + private AbstractCLI tizenCLI; + + @Override + public void execute() { + if( null != this.tizenCLI) { + this.tizenCLI.execute(); + } + + } + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java new file mode 100644 index 0000000..1901e76 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java @@ -0,0 +1,50 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.ncli.ide.shell; + +import org.kohsuke.args4j.Option; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.ncli.ide.subcommands.ListDevice; +import org.tizen.ncli.ide.subcommands.ListDeviceCLICommand; + +public class ListDeviceCLI extends AbstractCLI{ + private Logger log = LoggerFactory.getLogger(getClass()); + + @Option(name = "--detail", usage = "Details for device(Device Id/Type/Name)") + private boolean detail; + + @Override + public void execute() { + log.trace("Execute ListDeviceCLI..."); + + ListDeviceCLICommand command = new ListDeviceCLICommand(); + command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setDetail(detail); + ListDevice runCommand = command.runCommand(); + + } + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDevice.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDevice.java new file mode 100644 index 0000000..b76c25d --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDevice.java @@ -0,0 +1,29 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +package org.tizen.ncli.ide.subcommands; + +public class ListDevice { + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDeviceCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDeviceCLICommand.java new file mode 100644 index 0000000..60a2419 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListDeviceCLICommand.java @@ -0,0 +1,66 @@ +/* + * IDE + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Hyunsik Noh + * Hyeongseok Heo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ +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; + +public class ListDeviceCLICommand extends AbstractSubCommand { + private final String firstLine = "List of devices attached"; + + private boolean detail = false; + + @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); + } + } else { + System.out.println(TizenCLIMessages.LIST_NO_DEVICE); + } + } else { + System.out.println(TizenCLIMessages.LIST_CANNOT_GET_DEVICE_LIST); + } + return null; + } + + public void setDetail(boolean detail) { + this.detail = detail; + } + +} -- 2.7.4