import org.tizen.common.util.FileUtil;
import org.tizen.common.util.HostUtil;
import org.tizen.common.util.IOUtil;
+import org.tizen.common.util.StringUtil;
import org.tizen.ncli.ide.CLIConstant;
import org.tizen.ncli.ide.messages.TizenCLIMessages;
import org.tizen.ncli.ide.util.TargetUtil;
public class InstallCLICommand extends AbstractSubCommand<Install> {
private IDevice target = null;
+ private String name = null;
+
private String workDir = null;
private String dirPKG = null;
- private String srcPath = null;
+ private String pkgName = null;
private String ext = null;
private String searchPkgCommand = "ls %s";
private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND;
+ private final String SUCCESS= "ok";
+ private final String PKGID = "pkgid[";
public InstallCLICommand() {
}
log.error("Fail to get work directory canonical path");
}
if(target != null) {
- if(isValidPackage()) {
- if(tranferPackage(srcPath, dirPKG)) {
- if(installPackage(ext, srcPath, dirPKG)) {
+ if(getPackage()) {
+ if(tranferPackage(pkgName, dirPKG)) {
+ if(installPackage(ext, pkgName, dirPKG)) {
progressLog.info(TizenCLIMessages.INST_SUCCESS_PACKAGE);
} else {
progressLog.info(TizenCLIMessages.INST_FAIL_PACKAGE);
this.name = name;
log.debug("[name]: " + name);
}
-
- private boolean isValidPackage() {
- log.trace("=validate package=");
- boolean result = true;
-
- List<String> tpks = new ArrayList<String>();
- List<String> wgts = new ArrayList<String>();
- getPackages(tpks, wgts);
-
- int tpkCnt = tpks.size();
- int wgtCnt = wgts.size();
- int pkgCnt = tpkCnt + wgtCnt;
+
+ private boolean getPackage() {
+ log.trace("=get package=");
+ boolean result = false;
+ dirPKG = TizenPlatformConstants.getAppTmpDirectory(target);
- if(pkgCnt == 1 ) {
- dirPKG = TizenPlatformConstants.getAppTmpDirectory(target);
- if(tpkCnt == 1) {
- //native install
- srcPath = tpks.get(0);
- ext = CLIConstant.NATIVE_PKG_EXT;
+ if(name == null) {
+ List<String> tpks = new ArrayList<String>();
+ List<String> wgts = new ArrayList<String>();
+ getPackages(tpks, wgts);
+
+ int tpkCnt = tpks.size();
+ int wgtCnt = wgts.size();
+ int pkgCnt = tpkCnt + wgtCnt;
+
+ if(pkgCnt == 1 ) {
+ result = true;
+ if(tpkCnt == 1) {
+ //native install
+ pkgName = tpks.get(0);
+ ext = CLIConstant.NATIVE_PKG_EXT;
+ } else {
+ //web install
+ pkgName = wgts.get(0);
+ ext = CLIConstant.WEB_PKG_EXT;
+ }
+ log.debug("ext: " + ext);
+ log.debug("package: " + pkgName);
} else {
- //web install
- srcPath = wgts.get(0);
- ext = CLIConstant.WEB_PKG_EXT;
+ if(pkgCnt == 0) {
+ progressLog.info(TizenCLIMessages.INST_NO_PACKAGE);
+ log.error(TizenCLIMessages.INST_NO_PACKAGE);
+ } else {
+ progressLog.info(TizenCLIMessages.INST_MANY_PACKAGES);
+ log.error(TizenCLIMessages.INST_MANY_PACKAGES);
+ }
}
- log.debug("ext: " + ext);
- log.debug("package: " + srcPath);
} else {
- result = false;
- if(pkgCnt == 0) {
- progressLog.info(TizenCLIMessages.INST_NO_PACKAGE);
- log.error(TizenCLIMessages.INST_NO_PACKAGE);
+ String srcFilePath = workDir + File.separatorChar + name;
+ String getPKGCommand =String.format(searchPkgCommand, srcFilePath);
+ String returnPkg = HostUtil.returnExecute(getPKGCommand);
+ if(srcFilePath.equals(returnPkg)) {
+ result = true;
+ pkgName = name;
+ ext = FileUtil.getFileExtension(pkgName);
+
+ log.debug("ext: " + ext);
+ log.debug("package: " + pkgName);
} else {
- progressLog.info(TizenCLIMessages.INST_MANY_PACKAGES);
- log.error(TizenCLIMessages.INST_MANY_PACKAGES);
+ progressLog.info(NLS.bind(TizenCLIMessages.INST_NO_NAMED_PACKAGE, name));
}
}
return result;
}
}
- private boolean tranferPackage(String srcPath, String dirPKG) {
+ private boolean tranferPackage(String pkgName, String dirPKG) {
log.trace("=transfer package=");
progressLog.info(LaunchMessages.TRANSFER_PACKAGE);
boolean result = false;
try {
sync = target.getSyncService();
- String srcFilePath = workDir + File.separatorChar + srcPath;
+ String srcFilePath = workDir + File.separatorChar + pkgName;
syncSuccess = sync.push( srcFilePath, target.getFileEntry( dirPKG ) );
if(syncSuccess.isOk()) {
result = true;
progressLog.info(NLS.bind(LaunchMessages.TRANSFERRED_PACKAGE, srcFilePath, dirPKG));
} else {
- progressLog.info(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), srcPath));
- log.error(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), srcPath));
+ progressLog.info(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), pkgName));
+ log.error(NLS.bind((TizenCLIMessages.INST_CANNOT_TRANSFER_PACKAGE), pkgName));
}
} catch (IOException e) {
log.error("[Fail] Fail to push package.");
String returnResult = TargetUtil.getDefault().returnExecuteCommand(target, installCmd);
log.debug(returnResult);
- String[] tokens = returnResult.split("\\s+");
- for(String token : tokens) {
- if("val[ok]".equals(token)) {
- result = true;
- break;
+ String[] lines = returnResult.split("\n");
+ for(String line : lines) {
+ int lastIndex = line.lastIndexOf('[');
+ if(lastIndex != -1) {
+ String returnStatus = line.substring(lastIndex + 1, lastIndex+3);
+ if((SUCCESS.equals(returnStatus))) {
+ result = true;
+ String pkgId = getPkgId(line);
+ if(pkgId != null) {
+ progressLog.info(NLS.bind(TizenCLIMessages.INST_INSTALLED, pkgId));
+ }
+ break;
+ }
}
}
return result;
}
+
+ private String getPkgId(String line) {
+ int startIndex = line.indexOf(PKGID);
+ int endIndex = line.indexOf(']', startIndex);
+
+ String pkgId = line.substring(startIndex + PKGID.length(), endIndex);
+ return pkgId;
+ }
}