CLI: Add Uninstall CLI 86/13386/2
authorhyunsik.noh <hyunsik.noh@samsung.com>
Wed, 4 Dec 2013 11:46:09 +0000 (20:46 +0900)
committerHyunsik Noh <hyunsik.noh@samsung.com>
Wed, 4 Dec 2013 11:51:21 +0000 (03:51 -0800)
Add UninstallCLI which remove installed package on target.
Add progresslog.
Add returnExecuteCommand in TargetUtil.

Change-Id: Iaaa743fd00a7a32f6e97cf4ba44755636a3ff9e5
Signed-off-by: hyunsik.noh <hyunsik.noh@samsung.com>
org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/messages/TizenCLIMessages.properties
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListDeviceCLI.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/Main.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Uninstall.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/UninstallCLICommand.java [new file with mode: 0644]
org.tizen.ncli.ide/src/org/tizen/ncli/ide/util/TargetUtil.java

index e5c3293..f638141 100644 (file)
@@ -48,8 +48,15 @@ public class TizenCLIMessages extends NLS {
     public static String INST_NO_PACKAGES;
     public static String INST_MANY_PACKAGES;
     
-    public static String iNST_FAIL_TRANSFER_PACKAGE;
-    public static String iNST_FAIL_INVALID_PACKAGE;
+    public static String INST_FAIL_TRANSFER_PACKAGE;
+    public static String INST_FAIL_INVALID_PACKAGE;
+    
+    //UNINST(UNINSTALL)
+    public static String UNINST_UNREMOVABLE_PACKAGE;
+    public static String UNINST_UNEXIST_PACKAGE;
+    
+    public static String UNINST_FAIL_INVALID_PACKAGE;
+    public static String UNINST_FAIL_NO_PACKAGE_ID;
     
     //LIST
     public static String LIST_NO_DEVICE;
index a37e72e..8581597 100644 (file)
@@ -35,8 +35,13 @@ INST_CANNOT_TRANSFER_PACKAGE = Can not transfer {0} package.
 INST_NO_PACKAGES = There is no package.
 INST_MANY_PACKAGES =There are many packages.
 
-iNST_FAIL_TRANSFER_PACKAGE = [Fail] There is the problem to transfer package.
-iNST_FAIL_INVALID_PACKAGE = [Fail] There is the problem about package.
+INST_FAIL_TRANSFER_PACKAGE = [Fail] Fail install. There is the problem to transfer package.
+INST_FAIL_INVALID_PACKAGE = [Fail Fail install. There is the problem about package.
+
+UNINST_UNREMOVABLE_PACKAGE = The package is unremovable.
+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.
 
 LIST_NO_DEVICE = There is no device.
 LIST_CANNOT_GET_DEVICE_LIST = Can not get the device list.
index 1901e76..5b335fc 100644 (file)
@@ -27,9 +27,11 @@ 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.ListDevice;
 import org.tizen.ncli.ide.subcommands.ListDeviceCLICommand;
 
+@TizenSubCommand(name="target" , usage="Show connected target list")
 public class ListDeviceCLI extends AbstractCLI{
     private Logger log = LoggerFactory.getLogger(getClass());
     
@@ -44,7 +46,6 @@ public class ListDeviceCLI extends AbstractCLI{
         command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);
         command.setDetail(detail);
         ListDevice runCommand = command.runCommand();
-        
     }
 
 }
index 95de6e6..414f5d2 100644 (file)
@@ -45,6 +45,7 @@ public class Main {
             @SubCommand(name = "sign", impl = SignCLI.class),
             @SubCommand(name = "cli-config", impl = ConfigCLI.class),
             @SubCommand(name = "install", impl = InstallCLI.class),
+            @SubCommand(name = "uninstall", impl = UninstallCLI.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/UninstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java
new file mode 100644 (file)
index 0000000..0661307
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.Uninstall;
+import org.tizen.ncli.ide.subcommands.UninstallCLICommand;
+/**
+ * Implemented functions of uninstall CLI options.
+ * 
+ * @author Hyunsik Noh{@literal <hyunsik.noh@samsung.com>} (S-core)
+ */
+@TizenSubCommand(name="uninstall" , usage="Uninstall the package from target")
+public class UninstallCLI extends AbstractCLI{
+    private Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Option(name = "--target", usage = "Target to uninstall the package")
+    private String target;
+    @Option(name = "--pkgid", usage = "Target to uninstall the package")
+    private String pkgId;
+    
+    @Override
+    public void execute() {
+        log.trace("Execute UninstallCLI...");
+        UninstallCLICommand command = new UninstallCLICommand();
+        command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);
+        command.setTarget(target);
+        command.setPkgId(pkgId);
+        Uninstall runCommand = command.runCommand();
+    }
+
+}
index 5168577..ad8bcc0 100644 (file)
  */
 package org.tizen.ncli.ide.subcommands;
 
+import java.io.File;
 import java.io.IOException;
 
 import org.eclipse.osgi.util.NLS;
 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;
 import org.tizen.ncli.ide.util.TargetUtil;
 import org.tizen.sdblib.IDevice;
@@ -47,8 +45,6 @@ import org.tizen.sdblib.service.SyncService;
  */
 public class InstallCLICommand extends AbstractSubCommand<Install> {
 
-    private Configuration config;
-    
     private IDevice target = null;
     private String workDir = null;
     private String dirPKG = null;
@@ -59,7 +55,6 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
     private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND;
     
     public InstallCLICommand() {
-        config = new Configuration();
     }
     
     @Override
@@ -69,28 +64,31 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
         } catch (IOException e) {
             log.error("Fail to get work directory canonical path");
         }
+        progressLog.info("[Start] Install Tizen Package:");
         if(target != null) {
             if(isValidPackage()) {
                 if(tranferPackage(srcPath, dirPKG)) {
                     installPackage(ext, srcPath, dirPKG);
                 } else {
-                    System.out.println(TizenCLIMessages.iNST_FAIL_TRANSFER_PACKAGE);
+                    progressLog.info(TizenCLIMessages.INST_FAIL_TRANSFER_PACKAGE);
                 }
             } else {
-                System.out.println(TizenCLIMessages.iNST_FAIL_INVALID_PACKAGE);
+                progressLog.info(TizenCLIMessages.INST_FAIL_INVALID_PACKAGE);
             }
         } else {
-            System.out.println(TizenCLIMessages.FAIL_TARGET);
+            progressLog.info(TizenCLIMessages.FAIL_TARGET);
         }
+        progressLog.info("[End] Install Tizen Package");
         return null;
     }
     
-    public void setTarget(String targetName) {
-        target = TargetUtil.getTarget(targetName);
+    public void setTarget(String targetSerialId) {
+        target = TargetUtil.getTarget(targetSerialId);
+        log.debug("[target]: " + (target == null ? "null" : targetSerialId));
     }
     
     private boolean isValidPackage() {
-        log.trace("validate package");
+        log.trace("=validate package=");
         boolean result = true;
         
         String[] tpks = getPackages(CLIConstant.NATIVE_PKG_EXT);
@@ -110,14 +108,15 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
                 srcPath = wgts[0];
                 ext = CLIConstant.WEB_PKG_EXT;
             }
-            log.info("ext: " + ext + " package: " + srcPath);
+            log.debug("ext: " + ext);
+            log.debug("package: " + srcPath);
         } else {
             result = false;
             if(pkgCnt == 0) {
-                System.out.println(TizenCLIMessages.INST_NO_PACKAGES);
+                progressLog.info(TizenCLIMessages.INST_NO_PACKAGES);
                 log.error(TizenCLIMessages.INST_NO_PACKAGES);
             } else {
-                System.out.println(TizenCLIMessages.INST_MANY_PACKAGES);
+                progressLog.info(TizenCLIMessages.INST_MANY_PACKAGES);
                 log.error(TizenCLIMessages.INST_MANY_PACKAGES);
             }
         }
@@ -125,8 +124,10 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
     }
     
     private String[] getPackages(String type) {
+        log.trace("=get packages=");
         String[] pkgs = null;
         String getPKGCommand =String.format(searchPkgCommand, workDir, type);
+        log.debug("[Get Packages Command]: " + getPKGCommand);
         String returnPkgs = HostUtil.returnExecute(getPKGCommand);
         if(returnPkgs.length() != 0) {
             pkgs = returnPkgs.split("\n");
@@ -135,21 +136,22 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
     }
     
     private boolean tranferPackage(String srcPath, String dirPKG) {
-        log.trace("transfer package");
+        log.trace("=transfer package=");
         boolean result = false;
         SyncService sync = null;
         SyncResult syncSuccess;
+        
         try {
             sync = target.getSyncService();
-            syncSuccess = sync.push( workDir + "/" + srcPath, target.getFileEntry( dirPKG ) );
+            syncSuccess = sync.push( workDir + File.separatorChar + srcPath, target.getFileEntry( dirPKG ) );
             if(syncSuccess.isOk()) {
                 result = true;
             } else {
-                System.out.println(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), srcPath));
+                progressLog.info(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), srcPath));
                 log.error(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), srcPath));
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("[Fail] Fail to push package.");
         } finally {
             if (sync != null) {
                 IOUtil.tryClose(sync);
@@ -159,15 +161,13 @@ public class InstallCLICommand extends AbstractSubCommand<Install> {
     }
     
     private String installPackage(String ext, String srcPath, String dirPKG) {
-        log.trace("install package");
+        log.trace("=install package=");
         String result = null;
+        
         String installCmd = String.format(installCommand, ext, dirPKG + "/" + srcPath);
-        log.debug("[Install]: " + installCmd);
-        String defaultTimeout = config.getValue(ConfigConstant.DEFAULT_SDB_TIMEOUT);
-        int timeout = (defaultTimeout == null ? 60000 : Integer.parseInt(defaultTimeout));
-        SdbCommand sdbCommand = new SdbCommand(target, null, null, timeout);
-        result = sdbCommand.returnExecuteCommand(installCmd);
-        System.out.println(result);
+        log.debug("[Install Command]: " + installCmd);
+        result = TargetUtil.returnExecuteCommand(target, installCmd);
+        progressLog.info(result);
         return result;
     }
 }
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Uninstall.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/Uninstall.java
new file mode 100644 (file)
index 0000000..a22176a
--- /dev/null
@@ -0,0 +1,5 @@
+package org.tizen.ncli.ide.subcommands;
+
+public class Uninstall {
+
+}
\ No newline at end of file
diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/UninstallCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/UninstallCLICommand.java
new file mode 100644 (file)
index 0000000..e05b059
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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.ncli.ide.messages.TizenCLIMessages;
+import org.tizen.ncli.ide.util.TargetUtil;
+import org.tizen.sdblib.IDevice;
+
+
+public class UninstallCLICommand extends AbstractSubCommand<Uninstall> {
+    private IDevice target = null;
+    private String pkgId = null;
+    
+    private String uninstallCommand = TizenPlatformConstants.PKG_TOOL + " -q -u -n %s";
+    private String removableCommand = TizenPlatformConstants.PKG_TOOL_ROAPP_CHECK_COMMAND;
+    private String isRemovable = TizenPlatformConstants.RWAPP_RESULT;
+    private String isUnremovable = TizenPlatformConstants.ROAPP_RESULT;
+    
+    public UninstallCLICommand() {
+    }
+    
+    @Override
+    protected Uninstall call() {
+        progressLog.info("[Start] Uninstall Tizen Package:");
+        if(target != null) {
+            if(pkgId != null) {
+                if(isRemovablePackage()) {
+                    //uninstall
+                    uninstallPackage();
+                } else {
+                    progressLog.info(TizenCLIMessages.UNINST_FAIL_INVALID_PACKAGE);
+                }
+            } else {
+                progressLog.info(TizenCLIMessages.UNINST_FAIL_NO_PACKAGE_ID);
+            }
+        } else {
+            progressLog.info(TizenCLIMessages.FAIL_TARGET);
+        }
+        progressLog.info("[End] Uninstall Tizen Package");
+        return null;
+    }
+    
+    public void setTarget(String targetSerialId) {
+        target = TargetUtil.getTarget(targetSerialId);
+        log.debug("[target]: " + (target == null ? "null" : targetSerialId));
+    }
+
+    public void setPkgId(String pkgId) {
+        this.pkgId = pkgId;
+        log.debug("[pkgId]: " + (pkgId == null ? "null" : pkgId));
+    }
+    
+    private boolean isRemovablePackage() {
+        log.trace("=check removable package=");
+        boolean result = false;
+        String returnResult = null;
+        
+        String removableCmd = String.format(removableCommand, pkgId);
+        log.debug("[check removable command]: " + removableCmd);
+        returnResult = TargetUtil.returnExecuteCommand(target, removableCmd);
+        
+        if(isRemovable.equals(returnResult)) {
+            result = true;
+        } else if(isUnremovable.equals(returnResult)) {
+            progressLog.info(TizenCLIMessages.UNINST_UNREMOVABLE_PACKAGE);
+        } else {
+            progressLog.info(TizenCLIMessages.UNINST_UNEXIST_PACKAGE);
+        }
+        return result;
+    }
+
+    private String uninstallPackage() {
+        log.trace("=uninstall package=");
+        String result = null;
+        
+        String uninstallCmd = String.format(uninstallCommand, pkgId);
+        log.debug("[Uninstall Command]]: " + uninstallCmd);
+        result = TargetUtil.returnExecuteCommand(target, uninstallCmd);
+        progressLog.info(result);
+        return result;
+    }
+}
\ No newline at end of file
index b4e6e27..98a651f 100644 (file)
@@ -28,7 +28,10 @@ import org.eclipse.osgi.util.NLS;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.sdb.command.SdbCommand;
 import org.tizen.common.util.HostUtil;
+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;
 import org.tizen.sdblib.SmartDevelopmentBridge;
@@ -40,8 +43,10 @@ import org.tizen.sdblib.SmartDevelopmentBridge;
  */
 public class TargetUtil {
     private static final Logger log = LoggerFactory.getLogger(TargetUtil.class);
+    private static Configuration config;
     static {
         initSdb();
+        config = new Configuration();
     }
     
     public static void initSdb() {
@@ -107,5 +112,11 @@ public class TargetUtil {
         }
         return target;
     }
-
+    
+    public static String returnExecuteCommand(IDevice target, String command) {
+        String defaultTimeout = config.getValue(ConfigConstant.DEFAULT_SDB_TIMEOUT);
+        int timeout = (defaultTimeout == null ? 60000 : Integer.parseInt(defaultTimeout));
+        SdbCommand sdbCommand = new SdbCommand(target, null, null, timeout);
+        return sdbCommand.returnExecuteCommand(command);
+    }
 }