import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.osgi.util.NLS;
import org.tizen.common.TizenPlatformConstants;
+import org.tizen.common.launch.LaunchMessages;
+import org.tizen.common.util.FileUtil;
import org.tizen.common.util.HostUtil;
import org.tizen.common.util.IOUtil;
import org.tizen.ncli.ide.CLIConstant;
private String srcPath = null;
private String ext = null;
- private String searchPkgCommand = "ls %s | grep .%s";
+ private String searchPkgCommand = "ls %s";
private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND;
public InstallCLICommand() {
} 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);
+ if(installPackage(ext, srcPath, dirPKG)) {
+ progressLog.info(TizenCLIMessages.INST_SUCCESS_PACKAGE);
+ } else {
+ progressLog.info(TizenCLIMessages.INST_FAIL_PACKAGE);
+ }
} else {
progressLog.info(TizenCLIMessages.INST_FAIL_TRANSFER_PACKAGE);
}
} else {
progressLog.info(TizenCLIMessages.FAIL_TARGET);
}
- progressLog.info("[End] Install Tizen Package");
return null;
}
log.trace("=validate package=");
boolean result = true;
- String[] tpks = getPackages(CLIConstant.NATIVE_PKG_EXT);
- int tpkCnt = (tpks != null ? tpks.length : 0);
+ List<String> tpks = new ArrayList<String>();
+ List<String> wgts = new ArrayList<String>();
+ getPackages(tpks, wgts);
- String[] wgts = getPackages(CLIConstant.WEB_PKG_EXT);
- int wgtCnt = (wgts != null ? wgts.length : 0);
+ int tpkCnt = tpks.size();
+ int wgtCnt = wgts.size();
int pkgCnt = tpkCnt + wgtCnt;
+
if(pkgCnt == 1 ) {
dirPKG = TizenPlatformConstants.getAppTmpDirectory(target);
if(tpkCnt == 1) {
//native install
- srcPath = tpks[0];
+ srcPath = tpks.get(0);
ext = CLIConstant.NATIVE_PKG_EXT;
} else {
//web install
- srcPath = wgts[0];
+ srcPath = wgts.get(0);
ext = CLIConstant.WEB_PKG_EXT;
}
log.debug("ext: " + ext);
} else {
result = false;
if(pkgCnt == 0) {
- progressLog.info(TizenCLIMessages.INST_NO_PACKAGES);
- log.error(TizenCLIMessages.INST_NO_PACKAGES);
+ 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);
return result;
}
- private String[] getPackages(String type) {
+ private void getPackages(List<String>tpks, List<String> wgts) {
log.trace("=get packages=");
- String[] pkgs = null;
- String getPKGCommand =String.format(searchPkgCommand, workDir, type);
+
+ String tpk = CLIConstant.NATIVE_PKG_EXT;
+ String wgt = CLIConstant.WEB_PKG_EXT;
+ String ext = null;
+
+ String getPKGCommand =String.format(searchPkgCommand, workDir);
log.debug("[Get Packages Command]: " + getPKGCommand);
String returnPkgs = HostUtil.returnExecute(getPKGCommand);
if(returnPkgs.length() != 0) {
- pkgs = returnPkgs.split("\n");
+ String[] items = returnPkgs.split("\n");
+ for(String item : items) {
+ ext = FileUtil.getFileExtension(item);
+ if(ext != null) {
+ if(tpk.equals(ext)) {
+ tpks.add(item);
+ } else if(wgt.equals(ext)) {
+ wgts.add(item);
+ }
+ }
+ }
}
- return pkgs;
}
private boolean tranferPackage(String srcPath, String dirPKG) {
log.trace("=transfer package=");
+ progressLog.info(LaunchMessages.TRANSFER_PACKAGE);
boolean result = false;
SyncService sync = null;
SyncResult syncSuccess;
try {
sync = target.getSyncService();
- syncSuccess = sync.push( workDir + File.separatorChar + srcPath, target.getFileEntry( dirPKG ) );
+ String srcFilePath = workDir + File.separatorChar + srcPath;
+ 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));
return result;
}
- private String installPackage(String ext, String srcPath, String dirPKG) {
+ private boolean installPackage(String ext, String srcPath, String dirPKG) {
log.trace("=install package=");
- String result = null;
-
+ progressLog.info(LaunchMessages.INSTALL_PACKAGE);
+ boolean result = false;
String installCmd = String.format(installCommand, ext, dirPKG + "/" + srcPath);
log.debug("[Install Command]: " + installCmd);
- result = TargetUtil.getDefault().returnExecuteCommand(target, installCmd);
- progressLog.info(result);
+
+ 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;
+ }
+ }
return result;
}
}