* Contact:
* Hoon Kang <h245.kang@samsung.com>
* YoonKi Park <yoonki.park@samsung.com>
+ * Gun Kim <gune.kim@samsung.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
}
-class ThreadOnDemandInstall extends Thread {
- private final DebugTool tool;
- private final IDevice device;
-
- ThreadOnDemandInstall(final DebugTool tool, final IDevice device, String name) {
- super(name);
- this.tool = tool;
- this.device = device;
- }
-
- @Override
- public void run() {
- try {
- if ( DebugTool.RPM_PACKAGE_TYPE.equals(tool.getPackagetype()) ) {
- installRPMPackage(tool);
- }
- else {
- installTarPackage(tool);
- }
- } catch (CoreException e) {
- Logger.error("Error to install tools", e);
- }
- }
-
- private boolean copyPackage(String source, String destination) {
- boolean pushResult = false;
- try {
- SyncService syncService = device.getSyncService();
- SyncResult pushSyncResult = syncService.pushFile(source, destination,
- SyncService.getNullProgressMonitor());
- if (SyncService.RESULT_OK == pushSyncResult.getCode()) {
- pushResult = true;
- }
- } catch (TimeoutException e) {
- return false;
- } catch (SdbCommandRejectedException e) {
- return false;
- } catch (IOException e) {
- return false;
- }
- return pushResult;
- }
-
- private final void installTarPackage(DebugTool tool) throws CoreException {
- String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
- String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
-
- // delete old version
- try {
- device.executeShellCommand(
- "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
- } catch (IOException e) {
- return;
- }
-
- boolean isCopied = copyPackage(local, remote);
- if (isCopied) {
- try {
- //make one string command for sequential executing
- device.executeShellCommand(
- "rm -rf " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getPackagename() + " && "
- + "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && tar -xzf " + tool.getBinaryname() + " && "
- + "echo 'version:" + tool.getVersion() + "' >" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/" +
- tool.getControlFile() + " && "
- + "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && rm " + tool.getBinaryname() );
-
- } catch (IOException e) {
- Logger.error("Error after copied " + tool.getPackagename() , e);
- }
- }
- else if (!isCopied) {
- Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
- }
- }
-
- private final void installRPMPackage(DebugTool tool) throws CoreException {
- boolean isInstalled = false;
- String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
- String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
-
- String packagename;
-
- BufferedReader br = null;
- SdbShellProcess sdbShell = null;
- try {
- sdbShell = device.executeShellCommand(String.format( DebugTool.RPM_QUERY_COMMAND, "\"%{NAME}\\n\"", tool.getPackagename()));
- br = new BufferedReader(new InputStreamReader(sdbShell.getInputStream()));
-
- while (null != (packagename = br.readLine())) {
- if ( tool.getPackagename().equals(packagename)){
- isInstalled = true;
- break;
- }
- }
- } catch (IOException e1) {
- } finally {
- IOUtil.tryClose(br);
- if ( sdbShell != null ) {
- sdbShell.destroy();
- }
- }
-
- boolean isCopied = copyPackage(local, remote);
- if (isCopied) {
- String command = null;
- if ( isInstalled ) {
- command = String.format(DebugTool.RPM_UPGRADE_COMMAND, remote);
- }
- else {
- command = String.format(DebugTool.RPM_INSTALL_COMMAND, remote);
- }
- try {
- command = command + String.format("&& rm -f %s", remote);
- device.executeShellCommand(command);
- } catch (IOException e) {
- Logger.error("Error occurred while executing rpm command " + command , e);
- }
- }
- else if (!isCopied) {
- Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
- }
- }
-}
-
class InstallProgress implements IRunnableWithProgress {
private static final String CMD_RESULT_CHECK = "; echo $?";
+ private static final String CMD_TAR_INSTALL =
+ "rm -rf " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s && " + // remove old version package
+ "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && " + // move to directory for on-demand
+ "tar -xzf %s && " + // install new version package
+ "echo 'version:%s'>" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s && " + // create control file
+ "rm -f " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s"; // remove package.tar
+
private IDevice device = null;
continue;
}
- threadName = "on-demandThread-" + dt.getPackagename();
- Thread thread = new ThreadOnDemandInstall(dt, device, threadName);
- thread.start();
+ threadName = "OnDemandInstallThread-" + dt.getPackagename();
+ Runnable r = new OnDemandInstall(dt);
+ Thread t = new Thread(r, threadName);
+ t.start();
}
pMonitor.done();
}
public void setDevice(IDevice pDevice) {
device = pDevice;
}
+
+ private boolean copyPackage(String source, String destination) {
+ boolean pushResult = false;
+ try {
+ SyncService syncService = device.getSyncService();
+ SyncResult pushSyncResult = syncService.pushFile(source, destination,
+ SyncService.getNullProgressMonitor());
+ if (SyncService.RESULT_OK == pushSyncResult.getCode()) {
+ pushResult = true;
+ }
+ } catch (TimeoutException e) {
+ return false;
+ } catch (SdbCommandRejectedException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ }
+ return pushResult;
+ }
+
+ private final void installTarPackage(DebugTool tool) throws CoreException {
+ String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
+ String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
+
+ // delete old version
+ try {
+ device.executeShellCommand(
+ "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
+ } catch (IOException e) {
+ Logger.error("Failed delete old version ( " + tool.getPackagename() + " )");
+ return;
+ }
+
+ boolean isCopied = copyPackage(local, remote);
+ if (isCopied) {
+ try {
+ //make one string command for sequential executing
+ String installCommand = String.format(CMD_TAR_INSTALL, tool.getPackagename(),
+ tool.getBinaryname(),
+ tool.getVersion(), tool.getControlFile(),
+ tool.getBinaryname());
+ device.executeShellCommand(installCommand);
+
+ } catch (IOException e) {
+ Logger.error("Error after copied " + tool.getPackagename() , e);
+ }
+ }
+ else if (!isCopied) {
+ Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
+ }
+ }
+
+ private final void installRPMPackage(DebugTool tool) throws CoreException {
+ boolean isInstalled = false;
+ String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
+ String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
+
+ String packagename;
+
+ BufferedReader br = null;
+ SdbShellProcess sdbShell = null;
+ try {
+ sdbShell = device.executeShellCommand(String.format( DebugTool.RPM_QUERY_COMMAND, "\"%{NAME}\\n\"", tool.getPackagename()));
+ br = new BufferedReader(new InputStreamReader(sdbShell.getInputStream()));
+
+ while (null != (packagename = br.readLine())) {
+ if ( tool.getPackagename().equals(packagename)){
+ isInstalled = true;
+ break;
+ }
+ }
+ } catch (IOException e1) {
+ } finally {
+ IOUtil.tryClose(br);
+ if ( sdbShell != null ) {
+ sdbShell.destroy();
+ }
+ }
+
+ boolean isCopied = copyPackage(local, remote);
+ if (isCopied) {
+ String command = null;
+ if ( isInstalled ) {
+ command = String.format(DebugTool.RPM_UPGRADE_COMMAND, remote);
+ }
+ else {
+ command = String.format(DebugTool.RPM_INSTALL_COMMAND, remote);
+ }
+ try {
+ command = command + String.format("; rm -f %s", remote);
+ device.executeShellCommand(command);
+ } catch (IOException e) {
+ Logger.error("Error occurred while executing rpm command " + command , e);
+ }
+ }
+ else if (!isCopied) {
+ Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
+ }
+ }
private void installCoreException(String message, Throwable exception) throws CoreException {
Status status = new Status(Status.ERROR, ConnectionPlugin.PLUGIN_ID, message, exception);
throw new CoreException(status);
}
+
+ class OnDemandInstall implements Runnable {
+ private final DebugTool tool;
+
+ OnDemandInstall(final DebugTool tool) {
+ this.tool = tool;
+ }
+
+ @Override
+ public void run() {
+ try {
+ if ( DebugTool.RPM_PACKAGE_TYPE.equals(tool.getPackagetype()) ) {
+ installRPMPackage(tool);
+ }
+ else {
+ installTarPackage(tool);
+ }
+ } catch (CoreException e) {
+ Logger.error("Error to install tools", e);
+ }
+ }
+ }
}
public class ToolsInstall {
}
}
});
-
}
}