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>
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;
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.
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());
command.setWorkingDir(workingDir == null ? currentWorkspacePath : workingDir);
command.setDetail(detail);
ListDevice runCommand = command.runCommand();
-
}
}
@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;
--- /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.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();
+ }
+
+}
*/
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;
*/
public class InstallCLICommand extends AbstractSubCommand<Install> {
- private Configuration config;
-
private IDevice target = null;
private String workDir = null;
private String dirPKG = null;
private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND;
public InstallCLICommand() {
- config = new Configuration();
}
@Override
} 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);
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);
}
}
}
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");
}
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);
}
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;
}
}
--- /dev/null
+package org.tizen.ncli.ide.subcommands;
+
+public class Uninstall {
+
+}
\ No newline at end of file
--- /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.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
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;
*/
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() {
}
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);
+ }
}