--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyunsik Noh <hyunsik.noh@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ *
+ * 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 <hyunsik.noh@samsung.com>} (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();
+ }
+
+}
--- /dev/null
+/*
+ * IDE
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hyunsik Noh <hyunsik.noh@samsung.com>
+ * Hyeongseok Heo <hyeongseok.heo@samsung.com>
+ *
+ * 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<Run> {
+ 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