From e9be1570ceea6c5d53d39e7630a5e29fc27f9a5c Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Wed, 4 Dec 2013 18:45:56 +0900 Subject: [PATCH] CLI: Add ListAppCLI Add ListAppCLI which shows installed app list on target. Add native and web package extension variable in CLIConstant. Change-Id: I6f5ab7258a32e317ad3a52cf8c4101fb8e490b32 Signed-off-by: hyunsik.noh --- .../src/org/tizen/ncli/ide/CLIConstant.java | 5 ++ .../ncli/ide/autocomplete/TizenAutoComplete.java | 2 +- .../src/org/tizen/ncli/ide/shell/ListAppCLI.java | 54 ++++++++++++++ .../src/org/tizen/ncli/ide/shell/ListCLI.java | 8 +- .../src/org/tizen/ncli/ide/shell/Main.java | 7 -- .../ncli/ide/subcommands/InstallCLICommand.java | 12 ++- .../org/tizen/ncli/ide/subcommands/ListApp.java | 29 ++++++++ .../ncli/ide/subcommands/ListAppCLICommand.java | 87 ++++++++++++++++++++++ 8 files changed, 185 insertions(+), 19 deletions(-) create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListApp.java create mode 100644 org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java index dd32ddf..c541d2e 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java @@ -24,6 +24,8 @@ */ package org.tizen.ncli.ide; +import org.tizen.common.TizenPlatformConstants; + /** * @author Harry Hyeongseok Heo{@leteral } (S-core) * @@ -34,5 +36,8 @@ public class CLIConstant { public static final String TIZEN_CLI_LOCAL_KEY = "TIZEN.CLI.LOCAL";//Preference key public static final String CLI_HOME = System.getenv("CLI_HOME"); + + public static String NATIVE_PKG_EXT = TizenPlatformConstants.PKGTYPE_TPK.toLowerCase(); + public static String WEB_PKG_EXT = TizenPlatformConstants.PKGTYPE_WGT.toLowerCase(); } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java index 2f048f9..b67fc0f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java @@ -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" }, + { "list", "device", "app" }, { "create", "web-project nativ-project security-profile security-profile-item certificate" }, { "help", commands } }; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java new file mode 100644 index 0000000..f92abcc --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.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.Option; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.ncli.core.TizenSubCommand; +import org.tizen.ncli.ide.subcommands.ListApp; +import org.tizen.ncli.ide.subcommands.ListAppCLICommand; +/** + * Implemented functions of list app CLI options. + * + * @author Hyunsik Noh{@literal } (S-core) + */ +@TizenSubCommand(name="app" , usage="Show installed app list") +public class ListAppCLI extends AbstractCLI{ + private Logger log = LoggerFactory.getLogger(getClass()); + + @Option(name = "--target", metaVar="target name" , usage = "Show installed app list on target") + private String target; + + @Override + public void execute() { + log.trace("Execute ListAppCLI..."); + ListAppCLICommand command = new ListAppCLICommand(); + command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setTarget(target); + ListApp runCommand = command.runCommand(); + } + +} \ 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 index f11671d..dbf9598 100644 --- 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 @@ -26,19 +26,20 @@ 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; +import org.tizen.ncli.core.TizenSubCommandHandler; @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!") + @Argument(index = 0, required = true, handler = TizenSubCommandHandler.class, usage = "Command is needed!") @SubCommands({ - @SubCommand(name = "device", impl = ListDeviceCLI.class) + @SubCommand(name = "device", impl = ListDeviceCLI.class), + @SubCommand(name = "app", impl = ListAppCLI.class) }) private AbstractCLI tizenCLI; @@ -49,7 +50,6 @@ public class ListCLI extends AbstractCLI{ if( null != this.tizenCLI) { this.tizenCLI.execute(); } - } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java index 6309793..95de6e6 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java @@ -5,19 +5,13 @@ package org.tizen.ncli.ide.shell; import java.io.PrintWriter; import java.text.MessageFormat; -import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Set; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; -import org.kohsuke.args4j.OptionHandlerFilter; -import org.kohsuke.args4j.spi.OptionHandler; 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; @@ -25,7 +19,6 @@ import org.tizen.common.util.IOUtil; import org.tizen.ncli.core.CommandInfo; import org.tizen.ncli.core.CommandLineParser; import org.tizen.ncli.core.SubCommandData; -import org.tizen.ncli.core.TizenSubCommand; import org.tizen.ncli.core.TizenSubCommandHandler; import org.tizen.ncli.core.collection.TreeNode; import org.tizen.ncli.ide.messages.TizenCLIMessages; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java index 09ac5b8..5168577 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java @@ -31,6 +31,7 @@ import org.tizen.common.TizenPlatformConstants; import org.tizen.common.sdb.command.SdbCommand; import org.tizen.common.util.HostUtil; import org.tizen.common.util.IOUtil; +import org.tizen.ncli.ide.CLIConstant; import org.tizen.ncli.ide.config.ConfigConstant; import org.tizen.ncli.ide.config.Configuration; import org.tizen.ncli.ide.messages.TizenCLIMessages; @@ -54,9 +55,6 @@ public class InstallCLICommand extends AbstractSubCommand { private String srcPath = null; private String ext = null; - public static String nativePkgExt = TizenPlatformConstants.PKGTYPE_TPK.toLowerCase(); - public static String webPkgExt = TizenPlatformConstants.PKGTYPE_WGT.toLowerCase(); - private String searchPkgCommand = "ls %s | grep .%s"; private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND; @@ -95,10 +93,10 @@ public class InstallCLICommand extends AbstractSubCommand { log.trace("validate package"); boolean result = true; - String[] tpks = getPackages(nativePkgExt); + String[] tpks = getPackages(CLIConstant.NATIVE_PKG_EXT); int tpkCnt = (tpks != null ? tpks.length : 0); - String[] wgts = getPackages(webPkgExt); + String[] wgts = getPackages(CLIConstant.WEB_PKG_EXT); int wgtCnt = (wgts != null ? wgts.length : 0); int pkgCnt = tpkCnt + wgtCnt; if(pkgCnt == 1 ) { @@ -106,11 +104,11 @@ public class InstallCLICommand extends AbstractSubCommand { if(tpkCnt == 1) { //native install srcPath = tpks[0]; - ext = nativePkgExt; + ext = CLIConstant.NATIVE_PKG_EXT; } else { //web install srcPath = wgts[0]; - ext = webPkgExt; + ext = CLIConstant.WEB_PKG_EXT; } log.info("ext: " + ext + " package: " + srcPath); } else { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListApp.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListApp.java new file mode 100644 index 0000000..c05b7dd --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListApp.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 ListApp { + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java new file mode 100644 index 0000000..3bdd146 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java @@ -0,0 +1,87 @@ +/* + * 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.TizenPlatformConstants; +import org.tizen.common.sdb.command.SdbCommand; +import org.tizen.ncli.ide.CLIConstant; +import org.tizen.ncli.ide.util.TargetUtil; +import org.tizen.ncli.ide.config.ConfigConstant; +import org.tizen.ncli.ide.config.Configuration; +import org.tizen.ncli.ide.messages.TizenCLIMessages; +import org.tizen.sdblib.IDevice; + +/** + * This class provides required functions to installed app list on target. + * + * @author Hyunsik Noh{@literal } (S-core) + */ +public class ListAppCLICommand extends AbstractSubCommand { + private Configuration config; + private IDevice target = null; + private String listAppCommand = TizenPlatformConstants.PKG_TOOL + " -l -t %s"; + + private final String PKG_TYPE = "pkg_type"; + + public ListAppCLICommand() { + config = new Configuration(); + } + + @Override + protected ListApp call() { + if(target != null) { + getAppList(CLIConstant.NATIVE_PKG_EXT); + getAppList(CLIConstant.WEB_PKG_EXT); + } else { + System.out.println(TizenCLIMessages.FAIL_TARGET); + } + return null; + } + + public void setTarget(String targetName) { + target = TargetUtil.getTarget(targetName); + } + + private void getAppList(String pkgtype) { + log.trace("get app list"); + String result = null; + String listAppCmd = String.format(listAppCommand, pkgtype); + String defaultTimeout = config.getValue(ConfigConstant.DEFAULT_SDB_TIMEOUT); + int timeout = (defaultTimeout == null ? 60000 : Integer.parseInt(defaultTimeout)); + log.debug("[List App]: " + listAppCmd); + SdbCommand sdbCommand = new SdbCommand(target, null, null, timeout); + result = sdbCommand.returnExecuteCommand(listAppCmd); + setAppList(result); + } + + private void setAppList(String returnExecute) { + String[] lines = returnExecute.split("\n"); + for(String line: lines) { + if(line.startsWith(PKG_TYPE)) { + System.out.println(line); + } + } + } +} -- 2.7.4