CLI: Add ListAppCLI 80/13380/2
authorhyunsik.noh <hyunsik.noh@samsung.com>
Wed, 4 Dec 2013 09:45:56 +0000 (18:45 +0900)
committerhyunsik.noh <hyunsik.noh@samsung.com>
Wed, 4 Dec 2013 10:07:10 +0000 (19:07 +0900)
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 <hyunsik.noh@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/CLIConstant.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListApp.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java [new file with mode: 0644]

index dd32ddf..c541d2e 100644 (file)
@@ -24,6 +24,8 @@
  */\r
 package org.tizen.ncli.ide;\r
 \r
+import org.tizen.common.TizenPlatformConstants;\r
+\r
 /**\r
  * @author Harry Hyeongseok Heo{@leteral <hyeongseok.heo@samsung.com>} (S-core)\r
  *\r
@@ -34,5 +36,8 @@ public class CLIConstant {
        public static final String TIZEN_CLI_LOCAL_KEY = "TIZEN.CLI.LOCAL";//Preference key\r
        \r
        public static final String CLI_HOME = System.getenv("CLI_HOME");\r
+       \r
+    public static String NATIVE_PKG_EXT = TizenPlatformConstants.PKGTYPE_TPK.toLowerCase();\r
+    public static String WEB_PKG_EXT = TizenPlatformConstants.PKGTYPE_WGT.toLowerCase();\r
 \r
 }\r
index 2f048f9..b67fc0f 100644 (file)
@@ -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 (file)
index 0000000..f92abcc
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.ListApp;
+import org.tizen.ncli.ide.subcommands.ListAppCLICommand;
+/**
+ * Implemented functions of list app CLI options.
+ * 
+ * @author Hyunsik Noh{@literal <hyunsik.noh@samsung.com>} (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
index f11671d..dbf9598 100644 (file)
@@ -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();
         }
-        
     }
 
 }
index 6309793..95de6e6 100644 (file)
@@ -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;
index 09ac5b8..5168577 100644 (file)
@@ -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<Install> {
     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<Install> {
         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<Install> {
             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 (file)
index 0000000..c05b7dd
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+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 (file)
index 0000000..3bdd146
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.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 <hyunsik.noh@samsung.com>} (S-core)
+ */
+public class ListAppCLICommand extends AbstractSubCommand<ListApp> {
+    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);
+            }
+        }
+    }
+}