From: hyunsik.noh Date: Thu, 5 Dec 2013 09:05:53 +0000 (+0900) Subject: CLI: Add Run CLI. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9612145b7c84f78787d7aab31d68ed0a03c0b7a1;p=sdk%2Ftools%2Fcli.git CLI: Add Run CLI. Change-Id: I593ff7fdb5b517b76320069ef90063c5a2baa981 Signed-off-by: hyunsik.noh --- 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 496fb81..ea0e322 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 @@ -42,13 +42,13 @@ public class TizenAutoComplete { public static String[][] options = { { "cli-config", "--list --global" }, - { "build-native", "--predefine-option --arch --compiler --configuration" }, + { "build-native", "--arch --compiler --configuration" }, { "build-web", "--output -opt --optimize -euf --exclude-uifw -efum --exclude-uifw-min" }, { "sign", "--profile" }, { "package", "-t --type --sign -ref --ref-project" }, { "install", "--target" }, - { "uninstall", "--target" }, - { "run", "--target" }, + { "uninstall", "--target --pkgid" }, + { "run", "--target --appId"}, { "debug", "--target" } }; 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 ad6b7af..229c21d 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 @@ -58,6 +58,9 @@ public class TizenCLIMessages extends NLS { public static String UNINST_FAIL_INVALID_PACKAGE; public static String UNINST_FAIL_NO_PACKAGE_ID; + //RUN(RUN) + public static String RUN_FAIL_CANNOT_FIND_APP_NAME; + //LIST public static String LIST_NO_DEVICE; } 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 14a26a7..64caa82 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 @@ -43,4 +43,6 @@ 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. +RUN_CANNOT_FIND_APP_NAME = [Fail]Can not find app name. + LIST_NO_DEVICE = There is no device. \ No newline at end of file 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 414f5d2..b0ef3bd 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 @@ -46,6 +46,7 @@ public class Main { @SubCommand(name = "cli-config", impl = ConfigCLI.class), @SubCommand(name = "install", impl = InstallCLI.class), @SubCommand(name = "uninstall", impl = UninstallCLI.class), + @SubCommand(name = "run", impl = RunCLI.class), @SubCommand(name = "list", impl = ListCLI.class), @SubCommand(name = "help", impl = HelpCLI.class) }) private AbstractCLI tizenCLI; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java new file mode 100644 index 0000000..acf73f7 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java @@ -0,0 +1,59 @@ +/* + * 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.Install; +import org.tizen.ncli.ide.subcommands.InstallCLICommand; +import org.tizen.ncli.ide.subcommands.Run; +import org.tizen.ncli.ide.subcommands.RunCLICommand; +/** + * Implemented functions of run CLI options. + * + * @author Hyunsik Noh{@literal } (S-core) + */ +@TizenSubCommand(name="run" , usage="Run the app to target") +public class RunCLI extends AbstractCLI{ + private Logger log = LoggerFactory.getLogger(getClass()); + + @Option(name = "--target", usage = "Target to run the app") + private String target; + @Option(name = "--appid", usage = "App Id to run") + private String appId; + + @Override + public void execute() { + log.trace("Execute RunCLI..."); + RunCLICommand command = new RunCLICommand(); + command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir); + command.setTarget(target); + command.setAppId(appId); + Run runCommand = command.runCommand(); + } + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java index 0661307..4932ba7 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java @@ -28,8 +28,6 @@ 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.Install; -import org.tizen.ncli.ide.subcommands.InstallCLICommand; import org.tizen.ncli.ide.subcommands.Uninstall; import org.tizen.ncli.ide.subcommands.UninstallCLICommand; /** @@ -43,7 +41,7 @@ public class UninstallCLI extends AbstractCLI{ @Option(name = "--target", usage = "Target to uninstall the package") private String target; - @Option(name = "--pkgid", usage = "Target to uninstall the package") + @Option(name = "--pkgid", usage = "Package Id to uninstall") private String pkgId; @Override diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Run.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Run.java new file mode 100644 index 0000000..f92ec1f --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Run.java @@ -0,0 +1,5 @@ +package org.tizen.ncli.ide.subcommands; + +public class Run { + +} diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java new file mode 100644 index 0000000..0e73859 --- /dev/null +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java @@ -0,0 +1,132 @@ +/* + * 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.ncli.ide.CLIConstant; +import org.tizen.ncli.ide.messages.TizenCLIMessages; +import org.tizen.ncli.ide.util.TargetUtil; +import org.tizen.sdblib.IDevice; + + +public class RunCLICommand extends AbstractSubCommand { + private IDevice target = null; + private String appId = null; + private String appName = null; + private String appType = null; + + private String appNameCommand = "/usr/bin/pkginfo --pkg %s | grep -i Label"; + private String appTypeCommand = "/usr/bin/pkginfo --pkg %s | grep -i Type"; + private String runNativeAppCommand = "launch_app %s.%s"; + private String runWebAppCommand = "/usr/bin/wrt-launcher --s %s.%s --t 60000"; + + public RunCLICommand() { + } + + @Override + protected Run call() { + progressLog.info("[Start] Run Tizen App"); + if(target != null) { + appName = getAppName(); + appType = getAppType(); + if(appName != null && appType != null ) { + //run + runApp(); + } else { + progressLog.info(TizenCLIMessages.RUN_FAIL_CANNOT_FIND_APP_NAME); + } + } else { + progressLog.info(TizenCLIMessages.FAIL_TARGET); + } + progressLog.info("[End] Run Tizen App"); + return null; + } + + public void setTarget(String targetSerialId) { + target = TargetUtil.getTarget(targetSerialId); + log.debug("[target]: " + (target == null ? "null" : targetSerialId)); + } + + public void setAppId(String appId) { + this.appId = appId; + log.debug("[appId]: " + (appId == null ? "null" : appId)); + } + + private String getAppName() { + log.trace("=get app name="); + String appName = null; + String returnStr = null; + + String appNameCmd = String.format(appNameCommand, appId); + log.debug("[get app name command]: " + appNameCmd); + returnStr = TargetUtil.returnExecuteCommand(target, appNameCmd); + if(returnStr.length() > 0) { + String[] returnStrs = returnStr.split(" "); + appName = returnStrs[returnStrs.length -1]; + progressLog.info("[Name]: " + appName); + } else { + log.error("Can not get app type"); + } + return appName; + } + + private String getAppType() { + log.trace("=get app type="); + String appType = null; + String returnStr = null; + + String appTypeCmd = String.format(appTypeCommand, appId); + log.debug("[get app type command]: " + appTypeCmd); + returnStr = TargetUtil.returnExecuteCommand(target, appTypeCmd); + if(returnStr.length() > 0) { + String[] returnStrs = returnStr.split(" "); + appType = returnStrs[returnStrs.length -1]; + if(!CLIConstant.NATIVE_PKG_EXT.equals(appType) && !CLIConstant.WEB_PKG_EXT.equals(appType)) { + appType = null; + //not supported app type. + } else { + progressLog.info("[Type]: " + appType); + } + } else { + log.error("Can not get app type"); + } + return appType; + } + + private String runApp() { + log.info("=run app="); + String result = null; + String runCommand = null; + if(CLIConstant.NATIVE_PKG_EXT.equals(appType)) { + runCommand = String.format(runNativeAppCommand, appId, appName); + } else { + //TODO + runCommand = String.format(runWebAppCommand, appId, appName); + } + log.debug("[Run Command]]: " + runCommand); + result = TargetUtil.returnExecuteCommand(target, runCommand); + progressLog.info(result); + return result; + } +} \ No newline at end of file