--- /dev/null
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@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.
+* 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<gune.kim@samsung.com>
+ */
+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<DeltaResourceInfo> interestList = new ArrayList<DeltaResourceInfo>();
+
+ /**
+ * 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<DeltaResourceInfo> list) {
+ interestList = list;
+ }
+
+ protected void partialInstall( List<DeltaResourceInfo> 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<DeltaResourceInfo> 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 <code>null</code> 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);
+ }
+}