From 4e16e82218237086bc91ada6b9ae277b2e90b10d Mon Sep 17 00:00:00 2001 From: Gun Kim Date: Thu, 15 Nov 2012 14:13:09 +0900 Subject: [PATCH] [Title] RdsDeployer is move from nativecommon-eplugin to common-eplugin. [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: If91e46d3f09d66a4abbd4eb5b32b6f7d914fe89d --- .../src/org/tizen/common/rds/RdsDeployer.java | 201 +++++++++++++++++++++ .../src/org/tizen/common/rds/RdsMessages.java | 42 +++++ .../org/tizen/common/rds/RdsMessages.properties | 5 + .../org/tizen/common/util/ISdbCommandHelper.java | 48 +++++ 4 files changed, 296 insertions(+) create mode 100644 org.tizen.common/src/org/tizen/common/rds/RdsDeployer.java create mode 100644 org.tizen.common/src/org/tizen/common/rds/RdsMessages.java create mode 100644 org.tizen.common/src/org/tizen/common/rds/RdsMessages.properties create mode 100644 org.tizen.common/src/org/tizen/common/util/ISdbCommandHelper.java diff --git a/org.tizen.common/src/org/tizen/common/rds/RdsDeployer.java b/org.tizen.common/src/org/tizen/common/rds/RdsDeployer.java new file mode 100644 index 0000000..2ad3d07 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/RdsDeployer.java @@ -0,0 +1,201 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* 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.common.rds; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; +import org.tizen.common.CommonPlugin; +import org.tizen.common.TizenPlatformConstants; +import org.tizen.common.ui.view.console.ConsoleManager; +import org.tizen.common.util.ISdbCommandHelper; +import org.tizen.common.util.log.Logger; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.SyncService; +import org.tizen.sdblib.SyncService.SyncResult; + +/** + * This class deploys delta resource of project to target. + * + * @author Gun Kim + */ +public abstract class RdsDeployer { + protected IProgressMonitor monitor; + protected ConsoleManager console; + protected String pkgType; + protected String strAppInstallPath; + protected IProject project; + protected IDevice device; + protected RdsDeltaDetector deltaDetector; + protected ISdbCommandHelper tizenCommand; + protected List interestList = new ArrayList(); + + /** + * Prints progress information. + * + * @param message + */ + protected abstract void printInfo( String message ); + /** + * Gets package name excluded path which is installed on target + * + * @return String + */ + protected abstract String getAppInstallPath(); + /** + * Deploys using RDS. + * + * @return boolean + */ + public abstract boolean deploy() throws CoreException; + + public RdsDeployer( IProject project, IDevice device, ISdbCommandHelper tizenCommand, ConsoleManager console, String pkgType, IProgressMonitor monitor) { + this.project = project; + this.device = device; + this.tizenCommand = tizenCommand; + this.monitor = monitor; + this.console = console; + this.pkgType = pkgType; + this.strAppInstallPath = getAppInstallPath(); + deltaDetector = new RdsDeltaDetector(device, project, strAppInstallPath); + } + + public void setInterestList( List list) { + interestList = list; + } + + protected void partialInstall( List deltaInfoList ) throws CoreException { + boolean isNeededInstall = false; + String strProjectPath = project.getLocation().toString(); + String strRemotePath = null; + String command = null; + boolean isInteresting = false; + for ( DeltaResourceInfo node : deltaInfoList ) { + isInteresting = false; + for ( DeltaResourceInfo interest : interestList ) { + if ( node.getFullPath().startsWith(strProjectPath + interest.getFullPath()) ) { + isInteresting = true; + if ( interest.getRemotePath() == null ) { + strRemotePath = strAppInstallPath + node.getFullPath().replaceFirst(strProjectPath, ""); + } + else { + strRemotePath = strAppInstallPath + node.getFullPath().replaceFirst(strProjectPath + interest.getFullPath(), interest.getRemotePath()); + } + if ( DeltaResourceInfo.TYPE_INSTALL.equals(interest.getType()) ) { + isNeededInstall = true; + } + break; + } + } + if ( !isInteresting ) { + continue; + } + if ( DeltaResourceInfo.TYPE_MODIFY.equals(node.getType()) ) { + try { + command = NLS.bind(RdsMessages.RDS_PUSH_LOG, node.getFullPath(), strRemotePath); + SyncResult result = device.getSyncService().pushFile(node.getFullPath(), strRemotePath, SyncService.getNullProgressMonitor()); + if ( result.getCode() == SyncService.RESULT_NO_LOCAL_FILE || result.getCode() == SyncService.RESULT_LOCAL_IS_DIRECTORY) { + throw new IOException(command); + } + printInfo( command ); + } catch (IOException e) { + newCoreException(RdsMessages.RDS_PUSH_ERROR, e); + } + } + else if ( DeltaResourceInfo.TYPE_DELETE.equals(node.getType()) ) { + try { + command = "rm -rf " + addQuotes(strRemotePath) + TizenPlatformConstants.CMD_SUFFIX; + tizenCommand.runCommand(command, true, null); + } catch (Exception e) { + newCoreException(RdsMessages.RDS_DELETE_ERROR, e); + } + } + } + + if ( isNeededInstall ) { + postInstall(); + } + } + + protected List getDelta() { + return deltaDetector.getDelta(null, null); + } + + protected void postInstall() throws CoreException { + String installCommand = String.format(TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND, pkgType.toLowerCase(), strAppInstallPath) + TizenPlatformConstants.CMD_SUFFIX; + + try { + tizenCommand.runCommand(installCommand, true, null); + } catch (Exception e) { + newCoreException(RdsMessages.CANNOT_INSTALL, e); + } + } + + protected boolean hasOldResourceInfo() { + deltaDetector.readOldTree(); + if ( !deltaDetector.hasOldTree() ) { + return false; + } + return true; + } + + public void pushResInfoFile() { + String appInstallPath = getAppInstallPath(); + + String strResInfoFile = deltaDetector.makeDeltaFile(null,null); + String strRemotePath = appInstallPath + RdsDeltaDetector.STR_TREE_DIRECTORY + RdsDeltaDetector.STR_TREE_FILE; + + try { + device.getSyncService().pushFile(strResInfoFile, strRemotePath, SyncService.getNullProgressMonitor()); + } catch (IOException e) { + Logger.error(RdsMessages.RDS_RES_INFO_PUSH_ERROR, e); + } + } + + private String addQuotes(String orig) { + return "\"" + orig + "\""; + } + + /** + * Creates a new exception. + * + * @param message a human-readable message, localized to the + * current locale + * @param exception a low-level exception, or null if not + * applicable + */ + public void newCoreException(String message, Throwable exception) throws CoreException { + Status status = new Status(Status.ERROR, CommonPlugin.PLUGIN_ID, message, exception); + throw new CoreException(status); + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/RdsMessages.java b/org.tizen.common/src/org/tizen/common/rds/RdsMessages.java new file mode 100644 index 0000000..e6d5bf4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/RdsMessages.java @@ -0,0 +1,42 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* 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.common.rds; + +import org.eclipse.osgi.util.NLS; + +public class RdsMessages { + static { + NLS.initializeMessages(RdsMessages.class.getName(), RdsMessages.class); + } + + public static String RDS_PUSH_LOG; + public static String RDS_PUSH_ERROR; + public static String RDS_DELETE_ERROR; + public static String CANNOT_INSTALL; + public static String RDS_RES_INFO_PUSH_ERROR; + +} diff --git a/org.tizen.common/src/org/tizen/common/rds/RdsMessages.properties b/org.tizen.common/src/org/tizen/common/rds/RdsMessages.properties new file mode 100644 index 0000000..d6d1a4e --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/RdsMessages.properties @@ -0,0 +1,5 @@ +RDS_PUSH_LOG=[RDS] Pushing file "{0}" to "{1}" in target. +RDS_PUSH_ERROR=[RDS] Failed to push file(s). +RDS_DELETE_ERROR=[RDS] Failed to delete file in target. +CANNOT_INSTALL = Cannot install application. +RDS_RES_INFO_PUSH_ERROR=[RDS] Failed to upload resource information for RDS. \ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/util/ISdbCommandHelper.java b/org.tizen.common/src/org/tizen/common/util/ISdbCommandHelper.java new file mode 100644 index 0000000..1f08ac6 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/ISdbCommandHelper.java @@ -0,0 +1,48 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* 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.common.util; + +/** + * Interface for execute a remote shell command. + */ +public interface ISdbCommandHelper { + /** + * Run the command on the Tizen device + * + * @param command + * @param rCode + * @param expectedResult + * @throws Exception + */ + public void runCommand(String command, boolean rCode, String expectedResult) throws Exception; + /** + * get command's result all line array + * + * @return all result line + */ + public String[] getResultLineStrings(); +} -- 2.7.4