View: Rootstrap: Added connection module
authordonghyuk.yang <donghyuk.yang@samsung.com>
Wed, 16 Apr 2014 05:08:48 +0000 (14:08 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Wed, 16 Apr 2014 05:08:48 +0000 (14:08 +0900)
Added connection module to rootstrap view. User can connect remote host
throurgh rootstrap view and create rootstrap to remote host.

Change-Id: I88fec12c9b14c48a20b5995a10c444542b95d50c
Signed-off-by: donghyuk.yang <donghyuk.yang@samsung.com>
39 files changed:
org.tizen.nativeplatform/META-INF/MANIFEST.MF
org.tizen.nativeplatform/icons/rootstrap/connect.gif [new file with mode: 0644]
org.tizen.nativeplatform/icons/rootstrap/disconnect.gif [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/Activator.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/CommandUtil.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/DeviceCommandLauncher.java [moved from org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncherOnDevice.java with 97% similarity]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/HostCommandLauncher.java [moved from org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncher.java with 92% similarity]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteCommandUtil.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteHostCommandLauncher.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteRootstrapCommandLauncher.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteScriptProvider.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RootstrapCommandLauncher.java [moved from org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncherOnRootstrap.java with 93% similarity]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/ScriptProvider.java [moved from org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CommandLauncherUtil.java with 75% similarity]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/coredump/CoredumpSelectionHandler.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/gbs/GBSOptionManager.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/git/GitCommander.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/PlatformMIProcessAdapter.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/password/PasswordInputWizard.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/deb/DebCommanderHost.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderDevice.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteHost.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteRootstrap.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRootstrap.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rds/CachePackageChecksum.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rds/RpmRapidDeployer.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteConnectionManager.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteTools.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/repo/commander/LocalRepoMounter.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/BaseFileSystemGenerator.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RemoteRootstrapManager.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RootstrapManager.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/XMLPluginGenerator.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/PlatformFileUtil.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/RootstrapUtil.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RemoteConnectionDialog.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapUIMessages.properties
org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RootstrapView.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/wizards/TizenPlatformMainWizardPage.java

index e4d9b9e..2f554c9 100644 (file)
@@ -36,6 +36,7 @@ Import-Package: org.eclipse.cdt.debug.core,
  org.eclipse.cdt.launch.internal.ui,
  org.eclipse.cdt.launch.ui,
  org.eclipse.core.expressions,
+ org.eclipse.core.filesystem,
  org.eclipse.core.net.proxy,
  org.eclipse.debug.core,
  org.eclipse.debug.core.model,
@@ -49,6 +50,28 @@ Import-Package: org.eclipse.cdt.debug.core,
  org.eclipse.jgit.storage.file;version="0.12.1",
  org.eclipse.jgit.transport;version="0.12.1",
  org.eclipse.jgit.util;version="0.12.1",
+ org.eclipse.ptp.rdt.core.serviceproviders,
+ org.eclipse.ptp.rdt.core.services,
+ org.eclipse.ptp.remote.core,
+ org.eclipse.ptp.remote.core.exception,
+ org.eclipse.ptp.remote.remotetools.core,
+ org.eclipse.ptp.remote.rse.core,
+ org.eclipse.ptp.remotetools.core,
+ org.eclipse.ptp.remotetools.environment.launcher.core,
+ org.eclipse.ptp.remotetools.exception,
+ org.eclipse.ptp.services.core,
+ org.eclipse.ptp.utils.file.core,
+ org.eclipse.rse.core.model,
+ org.eclipse.rse.core.subsystems,
+ org.eclipse.rse.services.clientserver.messages,
+ org.eclipse.rse.services.files,
+ org.eclipse.rse.services.shells,
+ org.eclipse.rse.shells.ui,
+ org.eclipse.rse.subsystems.files.core.model,
+ org.eclipse.rse.subsystems.files.core.servicesubsystem,
+ org.eclipse.rse.subsystems.files.core.subsystems,
+ org.eclipse.rse.subsystems.shells.core.subsystems,
+ org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem,
  org.eclipse.ui,
  org.eclipse.ui.dialogs,
  org.eclipse.ui.wizards.datatransfer,
diff --git a/org.tizen.nativeplatform/icons/rootstrap/connect.gif b/org.tizen.nativeplatform/icons/rootstrap/connect.gif
new file mode 100644 (file)
index 0000000..6fc8305
Binary files /dev/null and b/org.tizen.nativeplatform/icons/rootstrap/connect.gif differ
diff --git a/org.tizen.nativeplatform/icons/rootstrap/disconnect.gif b/org.tizen.nativeplatform/icons/rootstrap/disconnect.gif
new file mode 100644 (file)
index 0000000..dc47edf
Binary files /dev/null and b/org.tizen.nativeplatform/icons/rootstrap/disconnect.gif differ
index f0682ef..247bab1 100644 (file)
@@ -34,8 +34,8 @@ import org.tizen.nativecommon.build.ProjectTypeManager;
 import org.tizen.nativeplatform.build.PlatformConfigurationManager;
 import org.tizen.nativeplatform.build.PlatformProjectDependentBuilder;
 import org.tizen.nativeplatform.build.PlatformProjectDependentPackager;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
 import org.tizen.nativeplatform.preferences.PreferencesManager;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
 
 /**
  * The activator class controls the plug-in life cycle
@@ -68,7 +68,7 @@ public class Activator extends AbstractUIPlugin {
                 PlatformProjectDependentBuilder.getInstance(),
                 PlatformProjectDependentPackager.getInstance(), true);
         PreferencesManager.setDefaultValues();
-        CommandLauncherUtil.clearPlatformTempDir();
+        CommandUtil.clearPlatformTempDir();
     }
 
     /*
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/CommandUtil.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/CommandUtil.java
new file mode 100644 (file)
index 0000000..576da5a
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.command.launcher;
+
+import static org.tizen.common.util.IOUtil.tryClose;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jgit.util.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.util.FileUtil;
+import org.tizen.common.util.HostUtil;
+import org.tizen.nativeplatform.password.SudoPasswdManager;
+import org.tizen.nativeplatform.util.PlatformFileUtil;
+
+public class CommandUtil {
+
+    public static String DEFAULT_PLATFORM_COMMAND_DIR = "platform_command";
+    public static String DEFAULT_PLATFORM_CACHING_DIR = "platform_cache";
+    public static String DEFAULT_PLATFORM_COREDUMP_DIR = "platform_coredump";
+
+
+    public static int LIMIT_COMMAND_LENGTH = 800;
+    public static final Logger logger = LoggerFactory.getLogger(CommandUtil.class);
+
+    public static String[] splitCommandArgs(String args) {
+        List<String> argList = new ArrayList<String>();
+        if (args.length() > LIMIT_COMMAND_LENGTH) {
+            String[] splited = args.split(" ");
+            String newArgs = "";
+            for (String arg : splited) {
+                if (newArgs.length() < LIMIT_COMMAND_LENGTH) {
+                    newArgs += arg + " ";
+                } else {
+                    newArgs += arg + " ";
+                    argList.add(newArgs.trim());
+                    newArgs = "";
+                }
+            }
+            argList.add(newArgs.trim());
+        } else {
+            argList.add(args);
+        }
+        return argList.toArray(new String[0]);
+    }
+
+    public static Process createProcess(String command, String workingDir, boolean includeStdErr)
+            throws InterruptedException {
+        // start process
+        return createProcess(command, workingDir, null, includeStdErr);
+    }
+
+    public static synchronized Process createProcess(String command, String workingDir,
+            Map<String, String> newEnv, boolean includeStdErr) throws InterruptedException {
+        // start process
+        String[] fullCommand = HostUtil.getCommand(command);
+        ProcessBuilder pb = new ProcessBuilder();
+        pb.redirectErrorStream(includeStdErr);
+        pb.command(fullCommand);
+        if (newEnv != null) {
+            pb.environment().clear();
+            pb.environment().putAll(newEnv);
+        }
+        if (workingDir != null) {
+            pb.directory(new File(workingDir));
+        }
+        Process proc;
+        try {
+            proc = pb.start();
+        } catch (IOException e) {
+            throw new InterruptedException(String.format("Creating process failed! : %s => %s",
+                    command, e.getMessage()));
+        }
+
+        return proc;
+    }
+    
+    public static String makeTempDirectory() {
+        final File temp;
+
+        try {
+            temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
+            if (!(temp.delete())) {
+                throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
+            }
+
+            if (!(temp.mkdir())) {
+                throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+
+        return temp.getPath();
+    }
+
+    public static boolean clearPlatformTempDir() {
+        return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
+    }
+
+    public static boolean clearCachingDir() {
+        boolean result = FileUtil.recursiveDelete(new File(getCachingDir()));
+        return result;
+    }
+
+    public static boolean clearWorkingDir() {
+        boolean result = FileUtil.recursiveDelete(new File(getWorkingDir()));
+        return result;
+    }
+
+    public static boolean clearCoredumpDir() {
+        boolean result = FileUtil.recursiveDelete(new File(getCoredumpDir()));
+        return result;
+    }
+
+    public static String getCachingDir() {
+        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+                .toOSString();
+    }
+
+    public static String getCachingDir(IProject project) {
+        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+                .append(project.getName()).toOSString();
+    }
+
+    public static String getWorkingDir() {
+        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COMMAND_DIR)
+                .toOSString();
+    }
+
+    public static String getCoredumpDir() {
+        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COREDUMP_DIR)
+                .toOSString();
+    }
+
+
+
+    public static boolean verifySudoPasswd(String passwd) {
+        if (passwd == null || passwd.isEmpty()) {
+            return false;
+        }
+        String scriptFile = ScriptProvider.getSudoAskScript(passwd);
+        if (scriptFile == null) {
+            return false;
+        }
+        boolean result = false;
+        try {
+            String command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k true",
+                    scriptFile);
+            result = HostCommandLauncher.execute(command);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            if (scriptFile != null) {
+                logger.error(String.format("Failed to execute script file: %s",
+                        scriptFile));
+                ScriptProvider.cleanUpScript(scriptFile);
+            }
+        }
+        return result;
+    }
+
+    public static String getRandomNum() {
+        Random rd = new Random();
+        rd.setSeed(System.currentTimeMillis());
+        int value = rd.nextInt(Integer.MAX_VALUE);
+        return Integer.toString(value);
+    }
+
+
+}
@@ -25,7 +25,7 @@
  *
  */
 
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -42,7 +42,7 @@ import org.tizen.sdblib.exception.SdbCommandRejectedException;
 import org.tizen.sdblib.exception.ShellCommandUnresponsiveException;
 import org.tizen.sdblib.exception.TimeoutException;
 
-public class CommandLauncherOnDevice {
+public class DeviceCommandLauncher {
 
     public static synchronized ICommandStatus execute(IDevice device, String command,
             PackageManagerOutputReceiver rec) {
@@ -25,7 +25,7 @@
  *
  */
 
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
 
 import static org.tizen.common.util.IOUtil.tryClose;
 
@@ -39,7 +39,7 @@ import java.util.Map;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.tizen.common.ui.view.console.ConsoleManager;
 
-public class CommandLauncher {
+public class HostCommandLauncher {
     public static final String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
 
     public static boolean executeSudo(String command) throws InterruptedException {
@@ -66,7 +66,7 @@ public class CommandLauncher {
             throws InterruptedException {
 
         // generate script
-        String scriptCmd = CommandLauncherUtil.genSudoExecuteExpectScript(command);
+        String scriptCmd = ScriptProvider.genSudoExecuteExpectScript(command);
         if (scriptCmd == null) {
             throw new InterruptedException("Generating execution script failed!");
         }
@@ -76,7 +76,7 @@ public class CommandLauncher {
         } catch (InterruptedException e) {
             throw e;
         } finally {
-            CommandLauncherUtil.cleanUpScript(scriptCmd, true);
+            ScriptProvider.cleanUpScript(scriptCmd, true);
         }
         return result;
     }
@@ -86,7 +86,7 @@ public class CommandLauncher {
             throws InterruptedException {
 
         // generate script
-        String scriptCmd = CommandLauncherUtil.genSudoExecuteScript(command);
+        String scriptCmd = ScriptProvider.genSudoExecuteScript(command);
         if (scriptCmd == null) {
             throw new InterruptedException("Generating execution script failed!");
         }
@@ -96,7 +96,7 @@ public class CommandLauncher {
         } catch (InterruptedException e) {
             throw e;
         } finally {
-            CommandLauncherUtil.cleanUpScript(scriptCmd);
+            ScriptProvider.cleanUpScript(scriptCmd);
         }
         return result;
     }
@@ -115,7 +115,7 @@ public class CommandLauncher {
             throws InterruptedException {
 
         // start process
-        Process proc = CommandLauncherUtil.createProcess(command, workingDir, newEnv, false);
+        Process proc = CommandUtil.createProcess(command, workingDir, newEnv, false);
 
         // handle console
         if (consoleViewName != null) {
@@ -172,7 +172,7 @@ public class CommandLauncher {
             boolean includeStdErr, IProgressMonitor monitor) throws InterruptedException {
 
         // generate script
-        String scriptCmd = CommandLauncherUtil.genSudoExecuteScript(command);
+        String scriptCmd = ScriptProvider.genSudoExecuteScript(command);
         if (scriptCmd == null) {
             throw new InterruptedException("Generating execution script failed!");
         }
@@ -182,7 +182,7 @@ public class CommandLauncher {
         } catch (InterruptedException e) {
             throw e;
         } finally {
-            CommandLauncherUtil.cleanUpScript(scriptCmd);
+            ScriptProvider.cleanUpScript(scriptCmd);
         }
         return result;
     }
@@ -199,7 +199,7 @@ public class CommandLauncher {
         BufferedReader input = null;
         StringBuilder contents = null;
         try {
-            proc = CommandLauncherUtil.createProcess(command, workingDir, includeStdErr);
+            proc = CommandUtil.createProcess(command, workingDir, includeStdErr);
 
             contents = new StringBuilder();
             input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
@@ -240,7 +240,7 @@ public class CommandLauncher {
         BufferedReader input = null;
         List<String> contents = new ArrayList<String>();
         try {
-            proc = CommandLauncherUtil.createProcess(command, workingDir, includeStdErr);
+            proc = CommandUtil.createProcess(command, workingDir, includeStdErr);
 
             input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
             String line = null;
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteCommandUtil.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteCommandUtil.java
new file mode 100644 (file)
index 0000000..3dab6e0
--- /dev/null
@@ -0,0 +1,238 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.command.launcher;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ptp.remotetools.core.IRemoteExecutionTools;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.core.IRemoteScript;
+import org.eclipse.ptp.remotetools.core.RemoteProcess;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteExecutionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
+import org.tizen.nativeplatform.util.PlatformFileUtil;
+
+public class RemoteCommandUtil {
+
+    public static String DEFAULT_PLATFORM_COMMAND_DIR = "platform_command";
+    public static String DEFAULT_PLATFORM_CACHING_DIR = "platform_cache";
+    public static String DEFAULT_PLATFORM_COREDUMP_DIR = "platform_coredump";
+    public static String RUN_SUDO_SHELLNAME = "run-sudo";
+    public static String DEBUGGING_INTERRUPT_SHELLNAME = "interruptProc";
+    public static String EXIT_VALUE_FILENAME = "exit-status";
+    public static String CACHE_CHECKSUM_FILENAME = "cache_checksum";
+    public static String SHELL_EXT = ".sh";
+    public static String EXPECT_EXT = ".exp";
+    public static int LIMIT_COMMAND_LENGTH = 800;
+    public static final Logger logger = LoggerFactory.getLogger(RemoteCommandUtil.class);
+
+    public static String[] splitCommandArgs(String args) {
+        List<String> argList = new ArrayList<String>();
+        if (args.length() > LIMIT_COMMAND_LENGTH) {
+            String[] splited = args.split(" ");
+            String newArgs = "";
+            for (String arg : splited) {
+                if (newArgs.length() < LIMIT_COMMAND_LENGTH) {
+                    newArgs += arg + " ";
+                } else {
+                    newArgs += arg + " ";
+                    argList.add(newArgs.trim());
+                    newArgs = "";
+                }
+            }
+            argList.add(newArgs.trim());
+        } else {
+            argList.add(args);
+        }
+        return argList.toArray(new String[0]);
+    }
+
+    public static Process createProcess(String command, String workingDir, boolean includeStdErr)
+            throws InterruptedException {
+        // start process
+        return createProcess(command, workingDir, null, includeStdErr);
+    }
+
+    public static synchronized Process createProcess(String command, String workingDir,
+            Map<String, String> newEnv, boolean includeStdErr) throws InterruptedException {
+        // start process
+        RemoteProcess proc = null;
+        
+        try {
+            IRemoteExecutionTools exectool = RemoteConnectionManager.getRemoteTools().getExecTool();
+            IRemoteScript script = exectool.createScript();
+            if (workingDir != null && !workingDir.isEmpty()) {
+                String[] commands = {"cd " + workingDir, command};
+                script.setScript(commands);
+            } else {
+                script.setScript(command);
+            }
+            script.setFetchProcessErrorStream(true);
+            script.setFetchProcessInputStream(true);
+            script.setFetchProcessOutputStream(true);
+            proc = exectool.executeProcess(script);
+        } catch (RemoteExecutionException e) {
+            throw new InterruptedException(String.format("Creating process failed! : %s => %s",
+                    command, e.getMessage()));
+        } catch (RemoteConnectionException e) {
+            throw new InterruptedException(String.format("Creating process failed! : %s => %s",
+                    command, e.getMessage()));
+        } catch (CancelException e) {
+            throw new InterruptedException(String.format("Creating process failed! : %s => %s",
+                    command, e.getMessage()));
+        }
+        return proc;
+    }
+    
+    public static String makeTempDirectory() {
+        String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();
+        String tempDir = new Path(userhome).append("tmp").append("temp"+Long.toString(System.nanoTime())).toString();        
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            boolean exists = filetool.hasDirectory(tempDir, new NullProgressMonitor());
+            if (exists) {
+                // TODO: remove tempdir
+            }
+            filetool.assureDirectory(tempDir, new NullProgressMonitor());
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            return null;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            return null;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            return null;
+        }
+        return tempDir;
+    }
+
+    public static boolean clearPlatformTempDir() {
+        return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
+    }
+
+    public static boolean clearCachingDir() {
+        String dir = getCachingDir();
+        return clearDir(dir);    
+    }
+
+    public static boolean clearWorkingDir() {
+        String dir = getWorkingDir();
+        return clearDir(dir);
+    }
+
+    public static boolean clearCoredumpDir() {
+        String dir = getCoredumpDir();
+        return clearDir(dir);
+    }
+    
+    private static boolean clearDir(String dir) {
+        boolean result = true;
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            boolean exists = filetool.hasDirectory(dir, new NullProgressMonitor());
+            if (exists) {
+                filetool.removeDirectory(dir, new NullProgressMonitor());
+                result = !filetool.hasDirectory(dir, new NullProgressMonitor());
+            }
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            return false;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            return false;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            return false;
+        }        
+        return result;
+    }
+
+    public static String getCachingDir() {
+        return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+                .toString();
+    }
+
+    public static String getCachingDir(IProject project) {
+        return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+                .append(project.getName()).toString();
+    }
+
+    public static String getWorkingDir() {
+        return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_COMMAND_DIR)
+                .toString();
+    }
+
+    public static String getCoredumpDir() {
+        return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_COREDUMP_DIR)
+                .toString();
+    }
+
+    public static boolean verifySudoPasswd(String passwd) {
+        if (passwd == null || passwd.isEmpty()) {
+            return false;
+        }
+        String scriptFile = RemoteScriptProvider.getSudoAskScript(passwd);
+        if (scriptFile == null) {
+            return false;
+        }
+        boolean result = false;
+        try {
+            String command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k true",
+                    scriptFile);
+            result = RemoteHostCommandLauncher.execute(command);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            if (scriptFile != null) {
+                logger.error(String.format("Failed to execute script file: %s",
+                        scriptFile));
+                RemoteScriptProvider.cleanUpScript(scriptFile);
+            }
+        }
+        return result;
+    }
+
+    public static String getRandomNum() {
+        Random rd = new Random();
+        rd.setSeed(System.currentTimeMillis());
+        int value = rd.nextInt(Integer.MAX_VALUE);
+        return Integer.toString(value);
+    }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteHostCommandLauncher.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteHostCommandLauncher.java
new file mode 100644 (file)
index 0000000..2ed3640
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.command.launcher;
+
+import static org.tizen.common.util.IOUtil.tryClose;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.tizen.common.ui.view.console.ConsoleManager;
+
+public class RemoteHostCommandLauncher {
+    public static final String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+
+    public static boolean executeSudo(String command) throws InterruptedException {
+        return executeSudo(command, null, null, null);
+    }
+
+    public static boolean executeSudo(String command, String workingDir)
+            throws InterruptedException {
+        return executeSudo(command, workingDir, null, null);
+    }
+
+    public static boolean executeSudo(String command, String workingDir, String consoleViewName,
+            IProgressMonitor monitor) throws InterruptedException {
+
+        return executeSudo(command, workingDir, null, consoleViewName, monitor);
+    }
+
+    public static boolean executeSudoWithExpect(String command) throws InterruptedException {
+        return executeSudoWithExpect(command, null, null, null, null);
+    }
+
+    public static boolean executeSudoWithExpect(String command, String workingDir,
+            Map<String, String> newEnv, String consoleViewName, IProgressMonitor monitor)
+            throws InterruptedException {
+
+        // generate script
+        String scriptCmd = RemoteScriptProvider.genSudoExecuteExpectScript(command);
+        if (scriptCmd == null) {
+            throw new InterruptedException("Generating execution script failed!");
+        }
+        boolean result = false;
+        try {
+            result = execute(scriptCmd, workingDir, newEnv, consoleViewName, monitor);
+        } catch (InterruptedException e) {
+            throw e;
+        } finally {
+            RemoteScriptProvider.cleanUpScript(scriptCmd, true);
+        }
+        return result;
+    }
+
+    public static boolean executeSudo(String command, String workingDir,
+            Map<String, String> newEnv, String consoleViewName, IProgressMonitor monitor)
+            throws InterruptedException {
+
+        // generate script
+        String scriptCmd = RemoteScriptProvider.genSudoExecuteScript(command);
+        if (scriptCmd == null) {
+            throw new InterruptedException("Generating execution script failed!");
+        }
+        boolean result = false;
+        try {
+            result = execute(scriptCmd, workingDir, newEnv, consoleViewName, monitor);
+        } catch (InterruptedException e) {
+            throw e;
+        } finally {
+            RemoteScriptProvider.cleanUpScript(scriptCmd);
+        }
+        return result;
+    }
+
+    public static boolean execute(String command) throws InterruptedException {
+        return execute(command, null, null, null);
+    }
+
+    public static boolean execute(String command, String workingDir, String consoleViewName,
+            IProgressMonitor monitor) throws InterruptedException {
+        return execute(command, workingDir, null, consoleViewName, monitor);
+    }
+
+    public static synchronized boolean execute(String command, String workingDir,
+            Map<String, String> newEnv, String consoleViewName, IProgressMonitor monitor)
+            throws InterruptedException {
+
+        // start process
+        Process proc = RemoteCommandUtil.createProcess(command, workingDir, newEnv, false);
+
+        // handle console
+        if (consoleViewName != null) {
+            ConsoleManager cm = new ConsoleManager(consoleViewName, true);
+            cm.clear();
+            BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+            String line = null;
+            try {
+                while ((line = input.readLine()) != null) {
+                    cm.println(line);
+                    if (monitor != null && monitor.isCanceled()) {
+                        cm.println(String.format("Canceled command: %s", command));
+                        throw new InterruptedException("Command execution is canceled!");
+                    }
+                }
+            } catch (IOException e) {
+                cm.println(e.getMessage());
+                e.printStackTrace();
+            } finally {
+                if (input != null) {
+                    tryClose(input);
+                }
+            }
+        }
+
+        // wait for process finish
+        proc.waitFor();
+
+        // wait for monitor thread finish
+        if (monitor != null) {
+            if (monitor.isCanceled()) {
+                throw new InterruptedException("Command execution is canceled!");
+            }
+        }
+
+        // abnormal termination
+        if (proc.exitValue() != 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public static String executeSudoOutput(String command) throws InterruptedException {
+        return executeSudoOutput(command, null, false, null);
+    }
+
+    public static String executeSudoOutput(String command, String workingDir, boolean includeStdErr)
+            throws InterruptedException {
+        return executeSudoOutput(command, workingDir, includeStdErr, null);
+    }
+
+    public static String executeSudoOutput(String command, String workingDir,
+            boolean includeStdErr, IProgressMonitor monitor) throws InterruptedException {
+
+        // generate script
+        String scriptCmd = RemoteScriptProvider.genSudoExecuteScript(command);
+        if (scriptCmd == null) {
+            throw new InterruptedException("Generating execution script failed!");
+        }
+        String result = "";
+        try {
+            result = executeOutput(scriptCmd, workingDir, includeStdErr, monitor);
+        } catch (InterruptedException e) {
+            throw e;
+        } finally {
+            RemoteScriptProvider.cleanUpScript(scriptCmd);
+        }
+        return result;
+    }
+
+    public static String executeOutput(String command) throws InterruptedException {
+        return executeOutput(command, null, false, null);
+    }
+
+    public static synchronized String executeOutput(String command, String workingDir,
+            boolean includeStdErr, IProgressMonitor monitor) throws InterruptedException {
+
+        // start process
+        Process proc = null;
+        BufferedReader input = null;
+        StringBuilder contents = null;
+        try {
+            proc = RemoteCommandUtil.createProcess(command, workingDir, includeStdErr);
+
+            contents = new StringBuilder();
+            input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+            String line = null;
+            while ((line = input.readLine()) != null) {
+                contents.append(line);
+                contents.append(LINE_SEPARATOR);
+                if (monitor != null && monitor.isCanceled()) {
+                    contents.append(String.format("Canceled command: %s", command));
+                    throw new InterruptedException("Command execution is canceled!");
+                }
+            }
+
+            // wait for process finish
+            proc.waitFor();
+
+            // wait for monitor thread finish
+            if (monitor != null) {
+                if (monitor.isCanceled()) {
+                    throw new InterruptedException("Command execution is canceled!");
+                }
+            }
+        } catch (IOException e) {
+            throw new InterruptedException("Reading process standard output failed!");
+        } finally {
+            if (input != null) {
+                tryClose(input);
+            }
+        }
+
+        return contents.toString().trim();
+    }
+
+    public static synchronized List<String> executeOutput(String command, String workingDir,
+            IProgressMonitor monitor, boolean includeStdErr) throws InterruptedException {
+        // start process
+        Process proc = null;
+        BufferedReader input = null;
+        List<String> contents = new ArrayList<String>();
+        try {
+            proc = RemoteCommandUtil.createProcess(command, workingDir, includeStdErr);
+
+            input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+            String line = null;
+            while ((line = input.readLine()) != null) {
+                contents.add(line.trim());
+                if (monitor != null && monitor.isCanceled()) {
+                    contents.add(String.format("Canceled command: %s", command));
+                    throw new InterruptedException("Command execution is canceled!");
+                }
+            }
+
+            // wait for process finish
+            proc.waitFor();
+
+            // wait for monitor thread finish
+            if (monitor != null) {
+                if (monitor.isCanceled()) {
+                    throw new InterruptedException("Command execution is canceled!");
+                }
+            }
+        } catch (IOException e) {
+            throw new InterruptedException("Reading process standard output failed!");
+        } finally {
+            if (input != null) {
+                tryClose(input);
+            }
+        }
+
+        return contents;
+    }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteRootstrapCommandLauncher.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteRootstrapCommandLauncher.java
new file mode 100644 (file)
index 0000000..0a253d9
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.command.launcher;
+
+import static org.tizen.common.util.IOUtil.tryClose;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.tizen.nativeplatform.pkg.commander.CommandStatus;
+import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
+import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
+
+public class RemoteRootstrapCommandLauncher {
+
+    public static ICommandStatus executeSudo(String command, String workingDir,
+            PackageManagerOutputReceiver rec, IProgressMonitor monitor) {
+        return executeSudo(command, workingDir, null, rec, monitor);
+    }
+
+    public static ICommandStatus executeSudo(String command, String workingDir,
+            Map<String, String> newEnv, PackageManagerOutputReceiver rec, IProgressMonitor monitor) {
+
+        // generate script
+        ICommandStatus status = null;
+        String scriptCmd = RemoteScriptProvider.genSudoExecuteScript(command);
+        if (scriptCmd == null) {
+            status = new CommandStatus(IStatus.ERROR, command,
+                    "Generating execution script failed!", null);
+            return status;
+        }
+        status = execute(scriptCmd, workingDir, newEnv, rec, monitor);
+        RemoteScriptProvider.cleanUpScript(scriptCmd);
+        return status;
+    }
+
+    public static ICommandStatus execute(String command, String workingDir,
+            PackageManagerOutputReceiver rec, IProgressMonitor monitor) {
+        return execute(command, workingDir, null, rec, monitor);
+    }
+
+    public static synchronized ICommandStatus execute(String command, String workingDir,
+            Map<String, String> newEnv, PackageManagerOutputReceiver rec, IProgressMonitor monitor) {
+
+        CommandStatus status = null;
+        Process proc = null;
+        List<String> log = new ArrayList<String>();
+
+        // start process
+        try {
+            proc = RemoteCommandUtil.createProcess(command, workingDir, newEnv, true);
+
+            BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+            String line = null;
+            try {
+                while ((line = input.readLine()) != null) {
+                    log.add(line);
+                    if (rec != null && rec.getMsgConsoleStream() != null) {
+                        rec.processNewLine(line);
+                    }
+                    if (monitor != null && monitor.isCanceled()) {
+                        if (rec != null) {
+                            rec.processNewLine(String.format("Canceled command: %s", command));
+                        }
+                        throw new InterruptedException("Command execution is canceled!");
+                    }
+                }
+            } catch (IOException e) {
+                if (rec != null) {
+                    rec.processNewLine(e.getMessage());
+                }
+                e.printStackTrace();
+                status = new CommandStatus(IStatus.ERROR, command, e.getMessage(), log, e);
+            } finally {
+                if (input != null) {
+                    tryClose(input);
+                }
+            }
+
+            // wait for process finish
+            proc.waitFor();
+
+            // wait for monitor thread finish
+            if (monitor != null) {
+                if (monitor.isCanceled()) {
+                    status = new CommandStatus(IStatus.ERROR, command,
+                            "Command execution is canceled!", log, null);
+                    return status;
+                }
+            }
+        } catch (InterruptedException e) {
+            status = new CommandStatus(IStatus.ERROR, command, e.getMessage(), log, e);
+            return status;
+        }
+
+        status = new CommandStatus(IStatus.OK, proc.exitValue(), command, "Executed command", log,
+                null);
+        return status;
+    }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteScriptProvider.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/command/launcher/RemoteScriptProvider.java
new file mode 100644 (file)
index 0000000..638ec3f
--- /dev/null
@@ -0,0 +1,390 @@
+package org.tizen.nativeplatform.command.launcher;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.core.IRemoteItem;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.nativeplatform.password.SudoPasswdManager;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
+import static org.tizen.common.util.IOUtil.tryClose;
+
+public class RemoteScriptProvider {
+    public static String RUN_SUDO_SHELLNAME = "run-sudo";
+    public static String DEBUGGING_INTERRUPT_SHELLNAME = "interruptProc";
+    public static String EXIT_VALUE_FILENAME = "exit-status";
+    public static String CACHE_CHECKSUM_FILENAME = "cache_checksum";
+    public static String SHELL_EXT = ".sh";
+    public static String EXPECT_EXT = ".exp";
+    
+    public static final Logger logger = LoggerFactory.getLogger(RemoteScriptProvider.class);
+    
+    /**
+     * Generate script to cache checksum information for package files. The
+     * script file role is as following. 1. Extract package file(.rpm) to
+     * "~/tmp/platform_cache" directory 2. Print checksum information for all
+     * extracted files.
+     * 
+     * @param project
+     *            Packages belong to the project.
+     * @param filePaths
+     *            The path of package files. File delimiter is white space(" ").
+     * @return The path of script file.
+     */
+    public static synchronized String genCacheChecksumScript(IProject project, String filePaths) {
+        return null;
+    }
+
+    // return generate expect script and return script path
+    public static String genSudoExecuteExpectScript(String command) {
+        String passwd = SudoPasswdManager.getSudoPassword();
+        String shellScriptPath = null;
+        String expectScriptPath = null;
+        PrintWriter pw = null;
+        String workingDir = RemoteCommandUtil.getWorkingDir();        
+
+        String randomNum = RemoteCommandUtil.getRandomNum();
+        String exitStatusFileName = EXIT_VALUE_FILENAME + "_" + randomNum;
+        String expectScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + EXPECT_EXT;
+        String runScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + SHELL_EXT;
+        String exitStatusScriptPath = (new Path(workingDir).append(exitStatusFileName).toString()); 
+        
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            filetool.assureDirectory(workingDir, new NullProgressMonitor());
+
+            // create expect script file
+            expectScriptPath = new Path(workingDir).append(expectScriptName).toString();
+            filetool.createFile(expectScriptPath, new NullProgressMonitor());         
+            OutputStream out = filetool.getOutputStream(expectScriptPath, IRemoteFileTools.NONE, new NullProgressMonitor());
+            pw = new PrintWriter(out);
+            pw.write("#!/usr/bin/expect --");
+            pw.write('\n');
+            pw.format("spawn sh -c \"%s;echo \\$? > %s\"", command, exitStatusScriptPath);
+            pw.write('\n');
+            pw.write("while (1) {");
+            pw.write('\n');
+            pw.write("  expect {");
+            pw.write('\n');
+            pw.write("    \"password for\" {");
+            pw.write('\n');
+            pw.write(String.format("send \"%s\\r\"", passwd));
+            pw.write('\n');
+            pw.write("    }");
+            pw.write('\n');
+            pw.write("    eof {");
+            pw.write('\n');
+            pw.write("      return");
+            pw.write('\n');
+            pw.write("    }");
+            pw.write('\n');
+            pw.write("  }");
+            pw.write('\n');
+            pw.write("}");
+            pw.write('\n');
+            pw.close();
+            
+            IRemoteItem item = filetool.getFile(expectScriptPath, new NullProgressMonitor());
+            if (item.exists()) {
+                item.setExecutable(true);
+                item.commitAttributes(new NullProgressMonitor());
+            }
+
+            shellScriptPath = new Path(workingDir).append(runScriptName).toString();
+            filetool.createFile(shellScriptPath, new NullProgressMonitor());          
+            out = filetool.getOutputStream(shellScriptPath, IRemoteFileTools.NONE, new NullProgressMonitor());
+            pw = new PrintWriter(out);
+            pw.write("#!/bin/bash -ee");
+            pw.write('\n');
+            pw.write(expectScriptPath);
+            pw.write('\n');
+            pw.format("EXIT_CODE=`cat %s`", exitStatusScriptPath);
+            pw.write('\n');
+            pw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
+            pw.write('\n');
+            pw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
+            pw.write('\n');
+            pw.write(" exit 1");
+            pw.write('\n');
+            pw.write("fi");
+            pw.close();
+            
+            item = filetool.getFile(shellScriptPath, new NullProgressMonitor());
+            if (item.exists()) {
+                item.setExecutable(true);
+                item.commitAttributes(new NullProgressMonitor());
+            }
+
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            if (shellScriptPath != null && !shellScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", shellScriptPath), e);
+                cleanUpScript(shellScriptPath);
+            }
+            if (expectScriptPath != null && !expectScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", expectScriptPath), e);
+                cleanUpScript(expectScriptPath);
+            }
+            return null;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            if (shellScriptPath != null && !shellScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", shellScriptPath), e);
+                cleanUpScript(shellScriptPath);
+            }
+            if (expectScriptPath != null && !expectScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", expectScriptPath), e);
+                cleanUpScript(expectScriptPath);
+            }
+            return null;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            if (shellScriptPath != null && !shellScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", shellScriptPath), e);
+                cleanUpScript(shellScriptPath);
+            }
+            if (expectScriptPath != null && !expectScriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", expectScriptPath), e);
+                cleanUpScript(expectScriptPath);
+            }
+            return null;
+        } finally {
+            tryClose(pw);
+        }
+
+        // execute script
+        //return shellScript.getPath();
+        return shellScriptPath;
+    }
+
+    // return generate shell script and return script path
+    public static String genSudoExecuteScript(String command) {
+        String passwd = SudoPasswdManager.getSudoPassword();
+        PrintWriter pw = null;
+        String workingDir = RemoteCommandUtil.getWorkingDir();
+
+        String scriptFile = getSudoAskScript(passwd);
+        if (scriptFile == null) {
+            return null;
+        }
+        String randomNum = RemoteCommandUtil.getRandomNum();
+        String exitStatusFileName = EXIT_VALUE_FILENAME + "_" + randomNum;
+        String runScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + SHELL_EXT;
+        String exitStatusScriptPath = (new Path(workingDir).append(exitStatusFileName).toString()); 
+        String scriptPath = new Path(workingDir).append(runScriptName).toString();
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            filetool.assureDirectory(workingDir, new NullProgressMonitor());
+            filetool.createFile(scriptPath, new NullProgressMonitor());           
+            OutputStream out = filetool.getOutputStream(scriptPath, IRemoteFileTools.NONE, new NullProgressMonitor());
+            String _command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k %s;echo $? > %s",
+                    scriptFile, command, exitStatusScriptPath);
+            pw = new PrintWriter(out);
+            pw.write("#!/bin/bash -ee");
+            pw.write('\n');
+            pw.write(_command);
+            pw.write('\n');
+            pw.write(String.format("EXIT_CODE=`cat %s`", exitStatusScriptPath));
+            pw.write('\n');
+            pw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
+            pw.write('\n');
+            pw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
+            pw.write('\n');
+            pw.write(" exit 1");
+            pw.write('\n');
+            pw.write("fi");
+            pw.write('\n');
+            
+            IRemoteItem item = filetool.getFile(scriptPath, new NullProgressMonitor());
+            if (item.exists()) {
+                item.setExecutable(true);
+                item.commitAttributes(new NullProgressMonitor());
+            }
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            if (scriptPath != null && !scriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", scriptPath), e);
+                cleanUpScript(scriptPath);
+            }
+            return null;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            if (scriptPath != null && !scriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", scriptPath), e);
+                cleanUpScript(scriptPath);
+            }
+            return null;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            if (scriptPath != null && !scriptPath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", scriptPath), e);
+                cleanUpScript(scriptPath);
+            }
+            return null;
+        } finally {
+            tryClose(pw);
+        }
+
+        // execute script
+        return scriptPath;
+    }
+
+    // generate interrupt script for platform debugging and return script path
+    public static String genDebugginInterruptScript(Process process) {
+        return null;
+    }
+
+    public static String getSudoAskScript(String passwd) {
+        String workingDir = RemoteCommandUtil.getWorkingDir();
+        PrintWriter pw = null;
+        String remoteFilePath = null;
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            filetool.assureDirectory(workingDir, new NullProgressMonitor());
+            remoteFilePath = new Path(workingDir).append("sudo_ask.sh").toString();
+            filetool.createFile(remoteFilePath, new NullProgressMonitor());
+            OutputStream out = filetool.getOutputStream(remoteFilePath, IRemoteFileTools.NONE, new NullProgressMonitor());
+            pw = new PrintWriter(out);
+            pw.write("#!/bin/bash");
+            pw.write('\n');
+            pw.format("echo %s", passwd);
+            pw.close();
+
+            IRemoteItem item = filetool.getFile(remoteFilePath, new NullProgressMonitor());
+            if (item.exists()) {
+                item.setExecutable(true);
+                item.commitAttributes(new NullProgressMonitor());
+            }
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            if (remoteFilePath != null && !remoteFilePath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", remoteFilePath), e);
+                cleanUpScript(remoteFilePath);
+            }
+            return null;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            if (remoteFilePath != null && !remoteFilePath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", remoteFilePath), e);
+                cleanUpScript(remoteFilePath);
+            }
+            return null;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            if (remoteFilePath != null && !remoteFilePath.isEmpty()) {
+                logger.error(String.format("Failed to write file: %s", remoteFilePath), e);
+                cleanUpScript(remoteFilePath);
+            }
+            return null;
+        } finally {
+            tryClose(pw);
+        }
+        return remoteFilePath;
+    }
+    
+    public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
+        if (scriptFile == null || scriptFile.isEmpty()) {
+            return false;
+        }
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            IRemoteItem script = filetool.getFile(scriptFile, new NullProgressMonitor());
+            if (script == null || !script.exists()) {
+                logger.error(String.format("The file does not exist. Failed to remove script file: %s", scriptFile));
+                return false;
+            } else {
+                filetool.removeFile(scriptFile, new NullProgressMonitor());
+            }
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove script file: %s", scriptFile), e);         
+            return false;
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove script file: %s", scriptFile), e);
+            return false;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove script file: %s", scriptFile), e);
+            return false;
+        }
+
+        String scriptFileName = new Path(scriptFile).lastSegment();
+
+        if (removeExpectScript) {
+            String expectScriptFileName = scriptFileName.substring(0,
+                    scriptFileName.lastIndexOf('.'));
+            expectScriptFileName = expectScriptFileName + EXPECT_EXT;
+            String expectScriptFile = new Path(scriptFile).removeLastSegments(1).append(expectScriptFileName).toString();
+            try {
+                IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+                IRemoteItem expectScript = filetool.getFile(expectScriptFile, new NullProgressMonitor());
+                if (expectScript == null || !expectScript.exists()) {
+                    logger.error(String.format("The file does not exist. Failed to remove expect script file: %s", expectScriptFile));
+                    return false;
+                } else {
+                    filetool.removeFile(expectScriptFile, new NullProgressMonitor());
+                }
+            } catch (RemoteConnectionException e) {             
+                e.printStackTrace();
+                logger.error(String.format("Failed to remove expect script file: %s", expectScriptFile), e);
+                return false;
+            } catch (RemoteOperationException e) {
+                e.printStackTrace();
+                logger.error(String.format("Failed to remove expect script file: %s", expectScriptFile), e);
+                return false;
+            } catch (CancelException e) {
+                e.printStackTrace();
+                logger.error(String.format("Failed to remove expect script file: %s", expectScriptFile), e);
+                return false;
+            }
+        }
+
+        String[] strs = scriptFileName.split("_");
+        String num = strs[strs.length - 1];
+        num = num.substring(0, num.lastIndexOf('.'));
+        String exitValuefileName = EXIT_VALUE_FILENAME + "_" + num;
+        String exitStatusFile = new Path(scriptFile).removeLastSegments(1).append(exitValuefileName).toString();
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            IRemoteItem exitFile = filetool.getFile(exitStatusFile, new NullProgressMonitor());
+            if (exitFile == null || !exitFile.exists()) {
+                logger.error(String.format("The file does not exist. Failed to remove exit status file: %s", exitStatusFile));
+                return false;
+            } else {
+                filetool.removeFile(exitStatusFile, new NullProgressMonitor());
+            }
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove exit status file: %s", exitStatusFile), e);
+            return false;
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove exit status file: %s", exitStatusFile), e);
+            return false;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove exit status file: %s", exitStatusFile), e);
+            return false;
+        }
+        return true;
+    }
+
+    public static boolean cleanUpScript(String scriptFile) {
+        return cleanUpScript(scriptFile, false);
+    }
+}
@@ -25,7 +25,7 @@
  *
  */
 
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
 
 import static org.tizen.common.util.IOUtil.tryClose;
 
@@ -42,7 +42,7 @@ import org.tizen.nativeplatform.pkg.commander.CommandStatus;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
 
-public class CommandLauncherOnRootstrap {
+public class RootstrapCommandLauncher {
 
     public static ICommandStatus executeSudo(String command, String workingDir,
             PackageManagerOutputReceiver rec, IProgressMonitor monitor) {
@@ -54,14 +54,14 @@ public class CommandLauncherOnRootstrap {
 
         // generate script
         ICommandStatus status = null;
-        String scriptCmd = CommandLauncherUtil.genSudoExecuteScript(command);
+        String scriptCmd = ScriptProvider.genSudoExecuteScript(command);
         if (scriptCmd == null) {
             status = new CommandStatus(IStatus.ERROR, command,
                     "Generating execution script failed!", null);
             return status;
         }
         status = execute(scriptCmd, workingDir, newEnv, rec, monitor);
-        CommandLauncherUtil.cleanUpScript(scriptCmd);
+        ScriptProvider.cleanUpScript(scriptCmd);
         return status;
     }
 
@@ -79,7 +79,7 @@ public class CommandLauncherOnRootstrap {
 
         // start process
         try {
-            proc = CommandLauncherUtil.createProcess(command, workingDir, newEnv, true);
+            proc = CommandUtil.createProcess(command, workingDir, newEnv, true);
 
             BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
             String line = null;
@@ -1,31 +1,4 @@
-/*
- * Native Platform
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Donghyuk Yang <donghyuk.yang@samsung.com>  
- * DongHee Yang <donghee.yang@samsung.com>
- * Kangho Kim <kh5325.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.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
 
 import static org.tizen.common.util.IOUtil.tryClose;
 
@@ -34,125 +7,25 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jgit.util.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.tizen.common.util.FileUtil;
-import org.tizen.common.util.HostUtil;
 import org.tizen.nativeplatform.password.SudoPasswdManager;
 
-public class CommandLauncherUtil {
-
-    public static String DEFAULT_PLATFORM_COMMAND_DIR = "platform_command";
-    public static String DEFAULT_PLATFORM_CACHING_DIR = "platform_cache";
-    public static String DEFAULT_PLATFORM_COREDUMP_DIR = "platform_coredump";
-    public static String RUN_SUDO_SHELLNAME = "run-sudo";
+public class ScriptProvider {
+    
     public static String DEBUGGING_INTERRUPT_SHELLNAME = "interruptProc";
     public static String EXIT_VALUE_FILENAME = "exit-status";
     public static String CACHE_CHECKSUM_FILENAME = "cache_checksum";
     public static String SHELL_EXT = ".sh";
     public static String EXPECT_EXT = ".exp";
-    public static int LIMIT_COMMAND_LENGTH = 800;
-    public static final Logger logger = LoggerFactory.getLogger(CommandLauncherUtil.class);
-
-    public static String[] splitCommandArgs(String args) {
-        List<String> argList = new ArrayList<String>();
-        if (args.length() > LIMIT_COMMAND_LENGTH) {
-            String[] splited = args.split(" ");
-            String newArgs = "";
-            for (String arg : splited) {
-                if (newArgs.length() < LIMIT_COMMAND_LENGTH) {
-                    newArgs += arg + " ";
-                } else {
-                    newArgs += arg + " ";
-                    argList.add(newArgs.trim());
-                    newArgs = "";
-                }
-            }
-            argList.add(newArgs.trim());
-        } else {
-            argList.add(args);
-        }
-        return argList.toArray(new String[0]);
-    }
-
-    public static Process createProcess(String command, String workingDir, boolean includeStdErr)
-            throws InterruptedException {
-        // start process
-        return createProcess(command, workingDir, null, includeStdErr);
-    }
-
-    public static synchronized Process createProcess(String command, String workingDir,
-            Map<String, String> newEnv, boolean includeStdErr) throws InterruptedException {
-        // start process
-        String[] fullCommand = HostUtil.getCommand(command);
-        ProcessBuilder pb = new ProcessBuilder();
-        pb.redirectErrorStream(includeStdErr);
-        pb.command(fullCommand);
-        if (newEnv != null) {
-            pb.environment().clear();
-            pb.environment().putAll(newEnv);
-        }
-        if (workingDir != null) {
-            pb.directory(new File(workingDir));
-        }
-        Process proc;
-        try {
-            proc = pb.start();
-        } catch (IOException e) {
-            throw new InterruptedException(String.format("Creating process failed! : %s => %s",
-                    command, e.getMessage()));
-        }
-
-        return proc;
-    }
-
-    public static boolean clearPlatformTempDir() {
-        return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
-    }
-
-    public static boolean clearCachingDir() {
-        boolean result = FileUtil.recursiveDelete(new File(getCachingDir()));
-        return result;
-    }
-
-    public static boolean clearWorkingDir() {
-        boolean result = FileUtil.recursiveDelete(new File(getWorkingDir()));
-        return result;
-    }
-
-    public static boolean clearCoredumpDir() {
-        boolean result = FileUtil.recursiveDelete(new File(getCoredumpDir()));
-        return result;
-    }
-
-    public static String getCachingDir() {
-        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
-                .toOSString();
-    }
-
-    public static String getCachingDir(IProject project) {
-        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
-                .append(project.getName()).toOSString();
-    }
-
-    public static String getWorkingDir() {
-        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COMMAND_DIR)
-                .toOSString();
-    }
-
-    public static String getCoredumpDir() {
-        return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COREDUMP_DIR)
-                .toOSString();
-    }
-
+    public static String RUN_SUDO_SHELLNAME = "run-sudo";
+    
+    public static final Logger logger = LoggerFactory.getLogger(ScriptProvider.class);
+    
     /**
      * Generate script to cache checksum information for package files. The
      * script file role is as following. 1. Extract package file(.rpm) to
@@ -168,8 +41,8 @@ public class CommandLauncherUtil {
     public static synchronized String genCacheChecksumScript(IProject project, String filePaths) {
         BufferedWriter bw = null;
         File cacheChecksumScript = null;
-        String cachingDir = getCachingDir(project);
-        String workingDir = getWorkingDir();
+        String cachingDir = CommandUtil.getCachingDir(project);
+        String workingDir = CommandUtil.getWorkingDir();
         try {
             FileUtils.mkdirs(new File(workingDir), true);
         } catch (IOException e1) {
@@ -177,7 +50,7 @@ public class CommandLauncherUtil {
             return null;
         }
         try {
-            String randomNum = getRandomNum();
+            String randomNum = CommandUtil.getRandomNum();
             String fileName = CACHE_CHECKSUM_FILENAME + "_" + randomNum + SHELL_EXT;
             cacheChecksumScript = new File(new Path(workingDir).append(fileName).toOSString());
             if (!cacheChecksumScript.createNewFile()) {
@@ -247,14 +120,14 @@ public class CommandLauncherUtil {
         File expectScript = null;
         File shellScript = null;
         BufferedWriter bw = null;
-        String workingDir = getWorkingDir();
+        String workingDir = CommandUtil.getWorkingDir();
         try {
-            FileUtils.mkdirs(new File(getWorkingDir()), true);
+            FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
         } catch (IOException e1) {
             logger.error(String.format("Failed to make directory: %s", workingDir), e1);
             return null;
         }
-        String randomNum = getRandomNum();
+        String randomNum = CommandUtil.getRandomNum();
         String exitStatusFileName = EXIT_VALUE_FILENAME + "_" + randomNum;
         String expectScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + EXPECT_EXT;
         String runScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + SHELL_EXT;
@@ -358,9 +231,9 @@ public class CommandLauncherUtil {
         String passwd = SudoPasswdManager.getSudoPassword();
         File shellScript = null;
         BufferedWriter bw = null;
-        String workingDir = getWorkingDir();
+        String workingDir = CommandUtil.getWorkingDir();
         try {
-            FileUtils.mkdirs(new File(getWorkingDir()), true);
+            FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
         } catch (IOException e1) {
             logger.error(String.format("Failed to make directory: %s", workingDir), e1);
             return null;
@@ -369,7 +242,7 @@ public class CommandLauncherUtil {
         if (scriptFile == null) {
             return null;
         }
-        String randomNum = getRandomNum();
+        String randomNum = CommandUtil.getRandomNum();
         String exitStatusFileName = EXIT_VALUE_FILENAME + "_" + randomNum;
         String runScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + SHELL_EXT;
         File exitStatusScript = new File(new Path(workingDir).append(exitStatusFileName)
@@ -426,9 +299,9 @@ public class CommandLauncherUtil {
         String passwd = SudoPasswdManager.getSudoPassword();
         File interruptScript = null;
         BufferedWriter bw = null;
-        String workingDir = getWorkingDir();
+        String workingDir = CommandUtil.getWorkingDir();
         try {
-            FileUtils.mkdirs(new File(getWorkingDir()), true);
+            FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
         } catch (IOException e1) {
             logger.error(String.format("Failed to make directory: %s", workingDir), e1);
             e1.printStackTrace();
@@ -440,7 +313,7 @@ public class CommandLauncherUtil {
             String pid = f.get(process).toString();
 
             // create interrupt script file
-            String randomNum = getRandomNum();
+            String randomNum = CommandUtil.getRandomNum();
             String scriptName = DEBUGGING_INTERRUPT_SHELLNAME + "_" + randomNum + SHELL_EXT;
             interruptScript = new File(new Path(workingDir).append(scriptName).toOSString());
             if (!interruptScript.createNewFile()) {
@@ -519,10 +392,10 @@ public class CommandLauncherUtil {
     }
 
     public static String getSudoAskScript(String passwd) {
-        String workingDir = getWorkingDir();
+        String workingDir = CommandUtil.getWorkingDir();
         try {
             if (!new File(workingDir).exists()) {
-                FileUtils.mkdirs(new File(getWorkingDir()), true);
+                FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
             }
         } catch (IOException e1) {
             logger.error(String.format("Failed to make directory: %s", workingDir), e1);
@@ -563,38 +436,7 @@ public class CommandLauncherUtil {
 
         return sudoAskScript.getPath();
     }
-
-    public static boolean verifySudoPasswd(String passwd) {
-        if (passwd == null || passwd.isEmpty()) {
-            return false;
-        }
-        String scriptFile = getSudoAskScript(passwd);
-        if (scriptFile == null) {
-            return false;
-        }
-        boolean result = false;
-        try {
-            String command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k true",
-                    scriptFile);
-            result = CommandLauncher.execute(command);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-            if (scriptFile != null) {
-                logger.error(String.format("Failed to execute script file: %s",
-                        scriptFile));
-                cleanUpScript(scriptFile);
-            }
-        }
-        return result;
-    }
-
-    private static String getRandomNum() {
-        Random rd = new Random();
-        rd.setSeed(System.currentTimeMillis());
-        int value = rd.nextInt(Integer.MAX_VALUE);
-        return Integer.toString(value);
-    }
-
+    
     public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
         if (scriptFile == null || scriptFile.isEmpty()) {
             return false;
index 1a9e36b..2f5116c 100644 (file)
@@ -16,9 +16,9 @@ import org.tizen.common.util.FileUtil;
 import org.tizen.common.util.FilenameUtil;
 import org.tizen.common.util.IOUtil;
 import org.tizen.nativecommon.launch.TizenLaunchCommand;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget;
-import org.tizen.nativeplatform.util.CommandLauncher;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
 import org.tizen.sdblib.service.FileEntry;
 import org.tizen.sdblib.service.SyncResult;
 
@@ -47,7 +47,7 @@ public class CoredumpSelectionHandler {
         monitor.beginTask("", 1);
         monitor.subTask(String.format("Downloading %s file...", ext));
         try {
-            String workingDir = CommandLauncherUtil.getCoredumpDir();
+            String workingDir = CommandUtil.getCoredumpDir();
             FileUtil.createDirectory(workingDir);
             String path = entry.getFullPath();
             String fileName = new Path(path).lastSegment();
@@ -63,7 +63,7 @@ public class CoredumpSelectionHandler {
         monitor.beginTask("", 1);
         monitor.subTask("Downloading coredump archive...");
         try {
-            String workingDir = CommandLauncherUtil.getCoredumpDir();
+            String workingDir = CommandUtil.getCoredumpDir();
             FileUtil.createDirectory(workingDir);
             String coredumpPath = corefileEntry.getFullPath();
             String fileName = new Path(coredumpPath).lastSegment().replace(".tar.gz", "");
@@ -83,16 +83,16 @@ public class CoredumpSelectionHandler {
         monitor.beginTask("", 2);
         monitor.subTask("Extracting coredump archive...");
         try {
-            String workingDir = CommandLauncherUtil.getCoredumpDir();
+            String workingDir = CommandUtil.getCoredumpDir();
             FileUtil.createDirectory(workingDir);
             // extract .coredump file
             String cmd = String.format(TizenPlatformConstants.DEBUG_COREFILE_EXTRACT_COMMAND,
                     coredumpArchive, workingDir, coreExpr);
-            String corefilePath = CommandLauncher.executeOutput(cmd);
+            String corefilePath = HostCommandLauncher.executeOutput(cmd);
             // extract .cs file
             cmd = String.format(TizenPlatformConstants.DEBUG_COREFILE_EXTRACT_COMMAND,
                     coredumpArchive, workingDir, csExpr);
-            String csfilePath = CommandLauncher.executeOutput(cmd);
+            String csfilePath = HostCommandLauncher.executeOutput(cmd);
             monitor.worked(1);
 
             monitor.subTask("Copying coredump and cs file...");
@@ -116,7 +116,7 @@ public class CoredumpSelectionHandler {
                 // clean up
                 File file = new File(coreSrcFilePath);
                 cmd = "rm -r " + file.getParent();
-                CommandLauncher.execute(cmd);
+                HostCommandLauncher.execute(cmd);
 
                 String[] result = { coreDstFilePath, csDstFilePath };
                 monitor.worked(1);
index 609d12a..639d8e6 100644 (file)
@@ -30,7 +30,7 @@ package org.tizen.nativeplatform.gbs;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.tizen.nativeplatform.util.CommandLauncher;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 
 public class GBSOptionManager {
     private static List<GBSOption> options = new ArrayList<GBSOption>();
@@ -63,10 +63,10 @@ public class GBSOptionManager {
 
         // check GBS command
         try {
-            if (!CommandLauncher.execute("which gbs")) {
+            if (!HostCommandLauncher.execute("which gbs")) {
                 return false;
             }
-            String result = CommandLauncher.executeOutput("gbs --version", null, true, null);
+            String result = HostCommandLauncher.executeOutput("gbs --version", null, true, null);
 
             // result format : gbs [version]
             String[] results = result.trim().split(" ");
@@ -109,7 +109,7 @@ public class GBSOptionManager {
         String command = "gbs build --help";
         String output = "";
         try {
-            output = CommandLauncher.executeOutput(command);
+            output = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
index 63bd2fb..883c919 100644 (file)
@@ -67,7 +67,7 @@ import org.eclipse.jgit.transport.URIish;
 import org.eclipse.jgit.util.FS;
 import org.eclipse.ui.PlatformUI;
 import org.osgi.service.prefs.BackingStoreException;
-import org.tizen.nativeplatform.util.CommandLauncher;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.util.PlatformFileUtil;
 
 public class GitCommander {
index 45709ea..33f9181 100644 (file)
@@ -45,8 +45,8 @@ import org.eclipse.core.runtime.OperationCanceledException;
 import org.eclipse.core.runtime.Path;
 import org.tizen.nativecommon.build.CommonProjectDependentBuilder;
 import org.tizen.nativecommon.build.ProjectTypeManager;
-import org.tizen.nativeplatform.util.CommandLauncher;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.ScriptProvider;
 
 public class PlatformMIProcessAdapter extends MIProcessAdapter {
 
@@ -72,10 +72,10 @@ public class PlatformMIProcessAdapter extends MIProcessAdapter {
     @Override
     public void interrupt(MIInferior inferior) {
         if (gdbProcess instanceof Spawner) {
-            String interruptCmd = CommandLauncherUtil.genDebugginInterruptScript(gdbProcess);
+            String interruptCmd = ScriptProvider.genDebugginInterruptScript(gdbProcess);
             Process shellProcess;
             try {
-                shellProcess = CommandLauncherUtil.createProcess(interruptCmd, null, false);
+                shellProcess = CommandUtil.createProcess(interruptCmd, null, false);
                 shellProcess.waitFor();
             } catch (InterruptedException e) {
                 e.printStackTrace();
@@ -85,7 +85,7 @@ public class PlatformMIProcessAdapter extends MIProcessAdapter {
 
             inferior.setSuspended();
             waitForInterrupt(inferior);
-            CommandLauncherUtil.cleanUpScript(interruptCmd);
+            ScriptProvider.cleanUpScript(interruptCmd);
             // super.interrupt(inferior);
         } else {
             BufferedWriter bw;
index e2a3469..588835b 100644 (file)
@@ -9,7 +9,9 @@ import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.wizard.IWizardContainer;
 import org.eclipse.jface.wizard.Wizard;
 import org.tizen.common.util.DialogUtil;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
+import org.tizen.common.util.OSChecker;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.RemoteCommandUtil;
 
 public class PasswordInputWizard extends Wizard {
 
@@ -44,7 +46,12 @@ public class PasswordInputWizard extends Wizard {
                 public void run(IProgressMonitor monitor) throws InvocationTargetException,
                         InterruptedException {
                     monitor.beginTask(resources.getString("Msg.Verify.Passwd"), -1);
-                    boolean result = CommandLauncherUtil.verifySudoPasswd(password);
+                    boolean result = false;
+                    if (OSChecker.isWindows()) {
+                        result = CommandUtil.verifySudoPasswd(password);
+                    } else {
+                        result = RemoteCommandUtil.verifySudoPasswd(password);
+                    }
                     if (!result) {
                         throw new InterruptedException(resources
                                 .getString("Msg.Failed.Verify.Passwd"));
index 17fd36f..7b34464 100644 (file)
@@ -5,6 +5,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.model.PkgInfo;
@@ -14,7 +15,6 @@ import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
 import org.tizen.nativeplatform.repo.model.Repository;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
 import org.tizen.nativeplatform.types.PkgInstallTypes;
-import org.tizen.nativeplatform.util.CommandLauncher;
 
 public class DebCommanderHost implements IPkgCommander {
 
@@ -194,7 +194,7 @@ public class DebCommanderHost implements IPkgCommander {
         String result = "";
         String command = makeCommand(DpkgTool.statusCommand(pkg));
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             e.printStackTrace();
             return false;
index 76b5d52..e33f13a 100644 (file)
@@ -39,6 +39,7 @@ import org.eclipse.ui.console.MessageConsoleStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.common.ui.view.console.ConsoleManager;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.model.Package;
@@ -52,7 +53,6 @@ import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
 import org.tizen.nativeplatform.repo.model.Repository;
 import org.tizen.nativeplatform.types.PkgInstallTypes;
 import org.tizen.nativeplatform.util.CharacterStripper;
-import org.tizen.nativeplatform.util.CommandLauncher;
 
 public abstract class RpmCommanderCommon implements IPkgCommander {
 
@@ -167,7 +167,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         }
         String command = RpmTool.fileArchCommand(filePath);
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
             // result = hostExecute(command);
         } catch (InterruptedException e) {
             logger.error(e.getMessage(), e);
@@ -187,7 +187,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         }
         String command = RpmTool.fileNameCommand(filePath);
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             logger.error(e.getMessage(), e);
         }
@@ -206,7 +206,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         }
         String command = RpmTool.fileFullVerCommand(filePath);
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             logger.error(e.getMessage(), e);
         }
@@ -337,7 +337,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         }
         String command = String.format("file %s", filePath);
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             logger.error(e.getMessage(), e);
         }
@@ -355,7 +355,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander {
         }
         String command = String.format("file %s", filePath);
         try {
-            result = CommandLauncher.executeOutput(command);
+            result = HostCommandLauncher.executeOutput(command);
         } catch (InterruptedException e) {
             logger.error(e.getMessage(), e);
         }
index e3bdb01..38b6e66 100644 (file)
@@ -38,13 +38,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.tizen.common.TizenPlatformConstants;
+import org.tizen.nativeplatform.command.launcher.DeviceCommandLauncher;
 import org.tizen.nativeplatform.pkg.commander.CommandStatus;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.model.PkgStatus;
 import org.tizen.nativeplatform.pkg.tools.PkgcmdTool;
 import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
-import org.tizen.nativeplatform.util.CommandLauncherOnDevice;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.exception.SdbCommandRejectedException;
 import org.tizen.sdblib.exception.TimeoutException;
@@ -91,7 +91,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         if (!syncResult.isOk()) {
             return new CommandStatus(IStatus.ERROR, "", syncResult.getMessage(), null);
         }
-        value.add(pathOnDevice.toOSString());
+        value.add(pathOnDevice.toString());
         printResultLog(String.format("[RDS] Copied file: %s \n " +
                 "-> %s", srcPath, dstPath));
         return new CommandStatus(IStatus.OK, value, null);
@@ -116,7 +116,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
             if (!syncResult.isOk()) {
                 return new CommandStatus(IStatus.ERROR, "", syncResult.getMessage(), null);
             }
-            value.add(pathOnDevice.toOSString());
+            value.add(pathOnDevice.toString());
         }
 
         return new CommandStatus(IStatus.OK, value, null);
@@ -291,7 +291,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         if (printCommand) {
             printCommandLog(command);
         }
-        ICommandStatus status = CommandLauncherOnDevice.execute(device, command, rec);
+        ICommandStatus status = DeviceCommandLauncher.execute(device, command, rec);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
         }
@@ -303,7 +303,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         if (printCommand) {
             printCommandLog(command);
         }
-        ICommandStatus status = CommandLauncherOnDevice.execute(device, command, rec, timeout);
+        ICommandStatus status = DeviceCommandLauncher.execute(device, command, rec, timeout);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
         }
@@ -316,7 +316,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
             printCommandLog(command);
         }
         rec.setPrintConsole(printLog);
-        ICommandStatus status = CommandLauncherOnDevice.execute(device, command, rec);
+        ICommandStatus status = DeviceCommandLauncher.execute(device, command, rec);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
         }
@@ -338,7 +338,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         if (printlog) {
             printCommandLog(command);
         }
-        ICommandStatus status = CommandLauncherOnDevice.execute(device, command, rec);
+        ICommandStatus status = DeviceCommandLauncher.execute(device, command, rec);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
         }
@@ -350,7 +350,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         if (printlog) {
             printCommandLog(command);
         }
-        ICommandStatus status = CommandLauncherOnDevice.execute(device, command, rec, timeout);
+        ICommandStatus status = DeviceCommandLauncher.execute(device, command, rec, timeout);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
         }
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteHost.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteHost.java
new file mode 100644 (file)
index 0000000..e0cc196
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.pkg.commander.rpm;
+
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
+import org.tizen.nativeplatform.pkg.model.PkgStatus;
+import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
+import org.tizen.nativeplatform.types.CmdTargetTypes;
+
+public class RpmCommanderRemoteHost extends RpmCommanderCommon {
+    private final CmdTargetTypes CMD_TYPE = CmdTargetTypes.HOST;
+
+    public RpmCommanderRemoteHost() {
+        super();
+    }
+
+    public RpmCommanderRemoteHost(boolean useConsoleLog) {
+        super(useConsoleLog, null);
+    }
+
+    @Override
+    protected PackageManagerOutputReceiver getNewOuputReceiver() {
+        return null;
+    }
+
+    @Override
+    public Map<String, PkgStatus> getLocalPkgList() {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus copyFilesToTmpDir(String[] fileList) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus makeDir(String path) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus removeFile(String path) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, IProgressMonitor monitor) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, int timeout, IProgressMonitor monitor) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, IProgressMonitor monitor, boolean printlog) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
+            IProgressMonitor monitor) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec, int timeout,
+            IProgressMonitor monitor) {
+        return null;
+    }
+
+    @Override
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
+            IProgressMonitor monitor, boolean printLog) {
+        return null;
+    }
+
+    @Override
+    protected void changeUpdateMode() {
+        return;
+    }
+
+    @Override
+    protected void actionBeforeUsingZypper() {
+        return;
+    }
+
+    @Override
+    public ICommandStatus copyFile(String srcPath, String dstPath) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus getMd5Checksum(String path) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus changeSmack(String path, String a_label, String e_label) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus getSmack(String paths) {
+        return null;
+    }
+
+    @Override
+    public CmdTargetTypes getCommandType() {
+        return CMD_TYPE;
+    }
+
+    @Override
+    public boolean isRunningApp(String appId) {
+        return false;
+    }
+
+    @Override
+    public ICommandStatus killApp(String appId) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus launchApp(String appId) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus executeBinary(String binary) {
+        return null;
+    }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteRootstrap.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRemoteRootstrap.java
new file mode 100644 (file)
index 0000000..ea6309b
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.pkg.commander.rpm;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.tizen.common.util.FileUtil;
+import org.tizen.nativeplatform.command.launcher.RootstrapCommandLauncher;
+import org.tizen.nativeplatform.password.SudoPasswdManager;
+import org.tizen.nativeplatform.pkg.commander.CommandStatus;
+import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
+import org.tizen.nativeplatform.pkg.model.PkgStatus;
+import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
+import org.tizen.nativeplatform.types.CmdTargetTypes;
+
+public class RpmCommanderRemoteRootstrap extends RpmCommanderCommon {
+
+    private static final String CONSOLE_NAME = "Rootstrap Internal";
+    private static final String REMOVE_PKGS = "rpm-x86-arm";
+    private final CmdTargetTypes CMD_TYPE = CmdTargetTypes.ROOTSTRAP;
+
+    private IPath rootPath;
+
+    public RpmCommanderRemoteRootstrap(IPath rootPath) {
+        super(CONSOLE_NAME);
+        this.rootPath = rootPath;
+        actionBeforeUsingZypper();
+    }
+
+    public RpmCommanderRemoteRootstrap(IPath rootPath, boolean useConsoleLog) {
+        super(useConsoleLog, CONSOLE_NAME);
+        this.rootPath = rootPath;
+        actionBeforeUsingZypper();
+    }
+
+    protected void actionBeforeUsingZypper() {
+        /*
+         * (with --nodeps --force) 
+         * Error: Subprocess failed. 
+         * Error: RPM failed:
+         * error: db4 error(-30971) from dbenv->open: DB_VERSION_MISMATCH:
+         * Database environment version mismatch error: cannot open Packages
+         * index using db4 - (-30971) error: cannot open Packages database in
+         * /var/lib/rpm error: db4 error(-30971) from dbenv->open:
+         * DB_VERSION_MISMATCH: Database environment version mismatch error:
+         * cannot open Packages database in /var/lib/rpm
+         */
+        if (checkPkgInstalled(REMOVE_PKGS)) {
+            uninstallPkg(REMOVE_PKGS, null);
+        }
+    }
+
+    public ICommandStatus copyFilesToTmpDir(String[] fileList) {
+        List<String> value = new ArrayList<String>();
+        for (String filePath : fileList) {
+            String filename = new File(filePath).getName();
+            IPath pathOnRootstrap = new Path(TMP_DIR).append(filename);
+            IPath toFilePath = rootPath.append(pathOnRootstrap);
+            try {
+                FileUtil.copyTo(filePath, toFilePath.toOSString());
+            } catch (IOException e) {
+                return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
+            }
+            value.add(pathOnRootstrap.toOSString());
+        }
+        return new CommandStatus(IStatus.OK, value, null);
+    }
+
+    @Override
+    public Map<String, PkgStatus> getLocalPkgList() {
+        String tag = "\\\\<pkg\\\\>%{NAME},%{VERSION}-%{RELEASE},%{ARCH}\\\\<\\\\/pkg\\\\>";
+        return getLocalPkgList(tag);
+    }
+
+    protected ICommandStatus execute(String command, IProgressMonitor monitor) {
+        return execute(command, monitor, true);
+    }
+
+    protected ICommandStatus execute(String command, int timeout, IProgressMonitor monitor) {
+        return execute(command, monitor, true);
+    }
+
+    protected ICommandStatus execute(String command, IProgressMonitor monitor, boolean printCommand) {
+        String chrootedCommand = getChrootedCommand(command);
+        if (printCommand) {
+            printCommandLog(chrootedCommand);
+        }
+        ICommandStatus status = RootstrapCommandLauncher.executeSudo(chrootedCommand, null, rec,
+                monitor);
+        if (!status.isOk()) {
+            logger.error(status.getMessage(), status.getException());
+        }
+        return status;
+    }
+
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
+            IProgressMonitor monitor) {
+        return execute(command, rec, monitor, true);
+    }
+
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec, int timeout,
+            IProgressMonitor monitor) {
+        return execute(command, rec, monitor, true);
+    }
+
+    protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
+            IProgressMonitor monitor, boolean printlog) {
+        String chrootedCommand = getChrootedCommand(command);
+        if (printlog) {
+            printCommandLog(chrootedCommand);
+        }
+        ICommandStatus status = RootstrapCommandLauncher.executeSudo(chrootedCommand, null, rec,
+                monitor);
+        if (!status.isOk()) {
+            logger.error(status.getMessage(), status.getException());
+        }
+        return status;
+    }
+
+    private String getChrootedCommand(String cmd) {
+        return String.format("chroot %s sh -c \"%s\"", rootPath.toOSString(), cmd);
+    }
+
+    protected PackageManagerOutputReceiver getNewOuputReceiver() {
+        return null;
+    }
+
+    @Override
+    protected void changeUpdateMode() {
+        return;
+    }
+
+    @Override
+    public ICommandStatus copyFile(String srcPath, String dstPath) {
+        List<String> value = new ArrayList<String>();
+        IPath pathOnRootstrap = new Path(dstPath);
+        IPath toFilePath = rootPath.append(pathOnRootstrap);
+        String passwd = SudoPasswdManager.getSudoPassword();
+        String command = String.format("echo %s | sudo -S cp %s %s", passwd, srcPath,
+                toFilePath.toOSString());
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
+        if (!status.isOk()) {
+            logger.error(status.getMessage(), status.getException());
+            return status;
+        }
+        printResultLog(String.format("Copied file: %s \n " + "-> %s", srcPath,
+                toFilePath.toOSString()));
+        value.add(pathOnRootstrap.toOSString());
+        return new CommandStatus(IStatus.OK, value, null);
+    }
+
+    @Override
+    public ICommandStatus removeFile(String path) {
+        List<String> value = new ArrayList<String>();
+        IPath pathOnRootstrap = new Path(path);
+        IPath toFilePath = rootPath.append(pathOnRootstrap);
+        String passwd = SudoPasswdManager.getSudoPassword();
+        String command = String.format("echo %s | sudo -S rm -f %s", passwd,
+                toFilePath.toOSString());
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
+        if (!status.isOk()) {
+            logger.error(status.getMessage(), status.getException());
+            return status;
+        }
+        printResultLog(String.format("Removed file: %s", toFilePath.toOSString()));
+        value.add(pathOnRootstrap.toOSString());
+        return new CommandStatus(IStatus.OK, value, null);
+    }
+
+    @Override
+    public ICommandStatus makeDir(String path) {
+        List<String> value = new ArrayList<String>();
+        IPath pathOnRootstrap = new Path(path);
+        IPath toFilePath = rootPath.append(pathOnRootstrap);
+        String passwd = SudoPasswdManager.getSudoPassword();
+        String command = String.format("echo %s | sudo -S mkdir -p %s", passwd,
+                toFilePath.toOSString());
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
+        if (!status.isOk()) {
+            logger.error(status.getMessage(), status.getException());
+            return status;
+        }
+        printResultLog(String.format("Make dir: %s", toFilePath.toOSString()));
+        value.add(pathOnRootstrap.toOSString());
+        return new CommandStatus(IStatus.OK, value, null);
+    }
+
+    @Override
+    public ICommandStatus getMd5Checksum(String path) {
+        String command = String.format("md5sum %s", path);
+        ICommandStatus status;
+        status = RootstrapCommandLauncher.execute(command, rootPath.toOSString(), null, null);
+        if (status.isOk()) {
+            printResultLog(String.format("[RDS] Checked checksum: %s", path));
+        }
+        return status;
+    }
+
+    @Override
+    public ICommandStatus changeSmack(String pathm, String a_label, String e_label) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus getSmack(String paths) {
+        return null;
+    }
+
+    @Override
+    public CmdTargetTypes getCommandType() {
+        return CMD_TYPE;
+    }
+
+    @Override
+    public boolean isRunningApp(String appId) {
+        return false;
+    }
+
+    @Override
+    public ICommandStatus killApp(String appId) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus launchApp(String appId) {
+        return null;
+    }
+
+    @Override
+    public ICommandStatus executeBinary(String binary) {
+        return null;
+    }
+}
index b10f8e2..4d35bbf 100644 (file)
@@ -38,13 +38,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.tizen.common.util.FileUtil;
+import org.tizen.nativeplatform.command.launcher.RootstrapCommandLauncher;
 import org.tizen.nativeplatform.password.SudoPasswdManager;
 import org.tizen.nativeplatform.pkg.commander.CommandStatus;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.model.PkgStatus;
 import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
-import org.tizen.nativeplatform.util.CommandLauncherOnRootstrap;
 
 public class RpmCommanderRootstrap extends RpmCommanderCommon {
 
@@ -118,7 +118,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
         if (printCommand) {
             printCommandLog(chrootedCommand);
         }
-        ICommandStatus status = CommandLauncherOnRootstrap.executeSudo(chrootedCommand, null, rec,
+        ICommandStatus status = RootstrapCommandLauncher.executeSudo(chrootedCommand, null, rec,
                 monitor);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
@@ -142,7 +142,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
         if (printlog) {
             printCommandLog(chrootedCommand);
         }
-        ICommandStatus status = CommandLauncherOnRootstrap.executeSudo(chrootedCommand, null, rec,
+        ICommandStatus status = RootstrapCommandLauncher.executeSudo(chrootedCommand, null, rec,
                 monitor);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
@@ -171,7 +171,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
         String passwd = SudoPasswdManager.getSudoPassword();
         String command = String.format("echo %s | sudo -S cp %s %s", passwd, srcPath,
                 toFilePath.toOSString());
-        ICommandStatus status = CommandLauncherOnRootstrap.execute(command, null, rec, null);
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
             return status;
@@ -190,7 +190,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
         String passwd = SudoPasswdManager.getSudoPassword();
         String command = String.format("echo %s | sudo -S rm -f %s", passwd,
                 toFilePath.toOSString());
-        ICommandStatus status = CommandLauncherOnRootstrap.execute(command, null, rec, null);
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
             return status;
@@ -208,7 +208,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
         String passwd = SudoPasswdManager.getSudoPassword();
         String command = String.format("echo %s | sudo -S mkdir -p %s", passwd,
                 toFilePath.toOSString());
-        ICommandStatus status = CommandLauncherOnRootstrap.execute(command, null, rec, null);
+        ICommandStatus status = RootstrapCommandLauncher.execute(command, null, rec, null);
         if (!status.isOk()) {
             logger.error(status.getMessage(), status.getException());
             return status;
@@ -222,7 +222,7 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
     public ICommandStatus getMd5Checksum(String path) {
         String command = String.format("md5sum %s", path);
         ICommandStatus status;
-        status = CommandLauncherOnRootstrap.execute(command, rootPath.toOSString(), null, null);
+        status = RootstrapCommandLauncher.execute(command, rootPath.toOSString(), null, null);
         if (status.isOk()) {
             printResultLog(String.format("[RDS] Checked checksum: %s", path));
         }
index 434d20f..7dfe656 100644 (file)
@@ -7,9 +7,10 @@ import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.Path;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
+import org.tizen.nativeplatform.command.launcher.ScriptProvider;
 import org.tizen.nativeplatform.pkg.model.IPackage;
-import org.tizen.nativeplatform.util.CommandLauncher;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
 
 public class CachePackageChecksum {
     /* 
@@ -43,13 +44,13 @@ public class CachePackageChecksum {
         if (pkgFileList == null || pkgFileList.isEmpty()) {
             return false;
         }
-        String command = CommandLauncherUtil.genCacheChecksumScript(project, pkgFileList);
+        String command = ScriptProvider.genCacheChecksumScript(project, pkgFileList);
         if (command == null) {
             return false;
         }
         int beforeSize = checksums.size();
-        String output = CommandLauncher.executeOutput(command);
-        CommandLauncherUtil.cleanUpScript(command);
+        String output = HostCommandLauncher.executeOutput(command);
+        ScriptProvider.cleanUpScript(command);
         String key = "";
         /*
          * output format is as following: 
@@ -154,7 +155,7 @@ public class CachePackageChecksum {
         String pkgFile = new Path(pkgPath).lastSegment();
         String command = String.format("md5sum %s | awk '{print $2 \"_\" $1}'", pkgFile);
         // output should be "<package path>_<checksum>" format
-        String output = CommandLauncher.executeOutput(command, workingPath, false, null);
+        String output = HostCommandLauncher.executeOutput(command, workingPath, false, null);
         return output;
     }
 }
index 4bfec33..534015e 100644 (file)
@@ -11,12 +11,12 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
 import org.tizen.nativeplatform.launch.PlatformLaunchMessages;
 import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.model.IPackage;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
-import org.tizen.nativeplatform.util.CommandLauncherUtil;
 
 public class RpmRapidDeployer {
     private IProject project;
@@ -106,7 +106,7 @@ public class RpmRapidDeployer {
     private boolean processCopiedFiles(List<String> fileList) {
         for (final String file : fileList) {
             String targetFilePath = new Path(file).removeFirstSegments(1).toOSString();
-            String srcFilePath = new Path(CommandLauncherUtil.getCachingDir(project)).append(file)
+            String srcFilePath = new Path(CommandUtil.getCachingDir(project)).append(file)
                     .toOSString();
             ICommandStatus status = commander.copyFile(srcFilePath, targetFilePath);
             if (status == null || !status.isOk()) {
@@ -122,7 +122,7 @@ public class RpmRapidDeployer {
             IPath filePath = new Path(file);
             String targetFilePath = filePath.removeFirstSegments(1).toOSString();
             String targetPath = filePath.removeFirstSegments(1).removeLastSegments(1).toOSString();
-            String srcFilePath = new Path(CommandLauncherUtil.getCachingDir(project)).append(file)
+            String srcFilePath = new Path(CommandUtil.getCachingDir(project)).append(file)
                     .toOSString();
             ICommandStatus status = commander.makeDir(targetPath);
             if (status == null || !status.isOk()) {
@@ -184,8 +184,8 @@ public class RpmRapidDeployer {
     private Map<String, String[]> getSmackInfo(String fileList) {
         Map<String, String[]> smackInfo = new HashMap<String, String[]>();
         String[] args;
-        if (fileList.length() > CommandLauncherUtil.LIMIT_COMMAND_LENGTH) {
-            args = CommandLauncherUtil.splitCommandArgs(fileList);
+        if (fileList.length() > CommandUtil.LIMIT_COMMAND_LENGTH) {
+            args = CommandUtil.splitCommandArgs(fileList);
         } else {
             args = new String[1];
             args[0] = fileList;
@@ -278,8 +278,8 @@ public class RpmRapidDeployer {
         Map<String, String> checksumMap = new HashMap<String, String>();
         // if command is too long, split it.
         String[] args;
-        if (fileList.length() > CommandLauncherUtil.LIMIT_COMMAND_LENGTH) {
-            args = CommandLauncherUtil.splitCommandArgs(fileList);
+        if (fileList.length() > CommandUtil.LIMIT_COMMAND_LENGTH) {
+            args = CommandUtil.splitCommandArgs(fileList);
         } else {
             args = new String[1];
             args[0] = fileList;
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteConnectionManager.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteConnectionManager.java
new file mode 100644 (file)
index 0000000..87e6934
--- /dev/null
@@ -0,0 +1,121 @@
+package org.tizen.nativeplatform.remote.connection;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.ptp.remote.core.IRemoteConnection;
+import org.eclipse.ptp.remote.core.IRemoteConnectionManager;
+import org.eclipse.ptp.remote.core.IRemoteServices;
+import org.eclipse.ptp.remote.core.PTPRemoteCorePlugin;
+import org.eclipse.ptp.remote.core.exception.RemoteConnectionException;
+import org.eclipse.ptp.remote.remotetools.core.RemoteToolsConnection;
+import org.eclipse.ptp.remote.remotetools.core.RemoteToolsServices;
+import org.eclipse.ptp.remotetools.core.IRemoteExecutionManager;
+
+@SuppressWarnings("restriction")
+public class RemoteConnectionManager {
+    public static String DEFAULT_CONNECTION_NAME = "remote_connection";
+    private static Map<String, RemoteTools> connectionMap = new HashMap<String, RemoteTools>();
+    
+    public static boolean createConnection(String host, String user, String pass, IProgressMonitor monitor) {
+        return createConnection(host, user, pass, DEFAULT_CONNECTION_NAME, monitor);
+    }
+    
+    public static boolean createConnection(String host, String user, String pass, String connectionName, 
+            IProgressMonitor monitor) {
+        try {
+            IRemoteConnection conn = getConnection(connectionName);
+            if (conn == null) {
+                monitor.beginTask("Creating connection...", 2);
+                IRemoteConnectionManager manager = getConnectionManager();
+                conn = manager.newConnection(connectionName);
+                conn.setAddress(host);
+                conn.setUsername(user);
+                conn.setPassword(pass);
+                conn.open(new SubProgressMonitor(monitor, 1));
+                monitor.subTask("Setting remote tools...");
+                String userhome = conn.getWorkingDirectory();
+                RemoteToolsConnection toolsConn = (RemoteToolsConnection)conn;
+                IRemoteExecutionManager execMgr = toolsConn.createExecutionManager();
+                RemoteTools remoteTools = new RemoteTools(host, user, pass, userhome, execMgr);
+                monitor.worked(1);
+                connectionMap.put(connectionName, remoteTools);
+            }
+        } catch (org.eclipse.ptp.remotetools.exception.RemoteConnectionException e) {
+            e.printStackTrace();
+            return false;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            return false;
+        } finally {
+            monitor.done();
+        }
+        return true;
+    }
+    
+    public static boolean connected() {
+        return connected(DEFAULT_CONNECTION_NAME);
+    }
+    
+    public static boolean connected(String name) {
+        return connectionMap.containsKey(name);
+    }
+    
+    public static void removeConnection() {
+        removeConnection(DEFAULT_CONNECTION_NAME);
+    }
+    
+    public static void removeConnection(String name) {
+        RemoteTools tools = getRemoteTools(name);
+        if (tools != null) {
+            tools.clear();
+        }
+        closeConnection(name);
+        if (connectionMap.containsKey(name)) {
+            connectionMap.remove(name);
+        }
+    }
+    
+    private static void closeConnection(String name) {
+        IRemoteConnection conn = getConnection(name);
+        if (conn != null) {
+            conn.close();
+        }
+        IRemoteConnectionManager manager = getConnectionManager();
+        try {
+            manager.removeConnection(conn);
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    public static RemoteTools getRemoteTools() {
+        return getRemoteTools(DEFAULT_CONNECTION_NAME);
+    }
+    
+    public static RemoteTools getRemoteTools(String name) {
+        return connectionMap.get(name);
+    }
+    
+    private static IRemoteConnectionManager getConnectionManager() {
+        PTPRemoteCorePlugin plugin = new PTPRemoteCorePlugin();
+        IRemoteServices[] services = plugin.getAllRemoteServices();
+        IRemoteConnectionManager manager = null;
+        for (IRemoteServices service : services) {
+            if (service instanceof RemoteToolsServices) {
+                manager = service.getConnectionManager();
+            }
+        }
+        return manager;
+    }
+    
+    public static IRemoteConnection getConnection(String name) {
+        IRemoteConnectionManager manager = getConnectionManager();
+        if (manager != null) {
+            return manager.getConnection(name);
+        }
+        return null;
+    }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteTools.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/remote/connection/RemoteTools.java
new file mode 100644 (file)
index 0000000..b4b507a
--- /dev/null
@@ -0,0 +1,109 @@
+package org.tizen.nativeplatform.remote.connection;
+
+import org.eclipse.ptp.remotetools.core.IRemoteCopyTools;
+import org.eclipse.ptp.remotetools.core.IRemoteExecutionManager;
+import org.eclipse.ptp.remotetools.core.IRemoteExecutionTools;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.core.IRemotePathTools;
+import org.eclipse.ptp.remotetools.core.IRemoteStatusTools;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+
+public class RemoteTools {
+    private String host = "";
+    private String user = "";
+    private String pass = "";
+    private String userhome = "";
+    private IRemoteExecutionManager execMgr = null;
+    
+    public RemoteTools(String host, String user, String pass, String userhome, IRemoteExecutionManager execMgr) {
+        this.host = host;
+        this.user = user;
+        this.pass = pass;
+        this.userhome = userhome;
+        this.execMgr = execMgr;
+    }
+    
+    public void clear() {
+        execMgr = null;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public void setUser(String user) {
+        this.user = user;
+    }
+
+    public String getPass() {
+        return pass;
+    }
+
+    public void setPass(String pass) {
+        this.pass = pass;
+    }
+
+    public String getUserhome() {
+        return userhome;
+    }
+
+    public void setUserhome(String userhome) {
+        this.userhome = userhome;
+    }
+
+    public IRemoteExecutionManager getExecMgr() {
+        return execMgr;
+    }
+
+    public void setExecMgr(IRemoteExecutionManager execMgr) {
+        this.execMgr = execMgr;
+    }
+
+    public IRemoteExecutionTools getExecTool() {
+        try {
+            return execMgr.getExecutionTools();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public IRemoteCopyTools getCopyTool() {
+        try {
+            return execMgr.getRemoteCopyTools();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public IRemoteFileTools getFileTool() {
+        try {
+            return execMgr.getRemoteFileTools();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public IRemotePathTools getPathTool() {
+        return execMgr.getRemotePathTools();
+    }
+
+    public IRemoteStatusTools getStatusTool() {
+        try {
+            return execMgr.getRemoteStatusTools();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}
index 9b4cc2a..58b8c61 100644 (file)
@@ -14,8 +14,8 @@ import org.eclipse.core.runtime.Path;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.repo.model.Repository;
-import org.tizen.nativeplatform.util.CommandLauncher;
 import org.tizen.nativeplatform.views.model.PlatformRootstrap;
 
 public class LocalRepoMounter {
@@ -183,10 +183,10 @@ public class LocalRepoMounter {
         try {
             String mkdirCommand = String.format("sudo -S mkdir -p %s",
                     targetRepofullPath.toOSString());
-            if (CommandLauncher.executeSudo(mkdirCommand, null, null, "Platform Internal", monitor)) {
+            if (HostCommandLauncher.executeSudo(mkdirCommand, null, null, "Platform Internal", monitor)) {
                 String mountCommand = String.format("sudo -S mount --bind %s %s", repoLocalPath,
                         targetRepofullPath.toOSString());
-                if (CommandLauncher.executeSudo(mountCommand, null, null, "Platform Internal",
+                if (HostCommandLauncher.executeSudo(mountCommand, null, null, "Platform Internal",
                         monitor)) {
                     mountMap.put(repoLocalPath, targetRepofullPath.toOSString());
                     increaseMountCount();
@@ -235,7 +235,7 @@ public class LocalRepoMounter {
             IPath repoPath = getMountedRepoPath(repoLocalPath);
             if (repoPath != null) {
                 String umountCommand = String.format("sudo -S umount %s", repoPath.toOSString());
-                if (CommandLauncher.executeSudo(umountCommand, null, null, "Platform Internal",
+                if (HostCommandLauncher.executeSudo(umountCommand, null, null, "Platform Internal",
                         monitor)) {
                     mountMap.remove(repoLocalPath);
                     decreaseMountCount();
index 28f1c7a..85c2941 100644 (file)
@@ -7,11 +7,20 @@ import java.util.Map;
 
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.tizen.common.core.application.InstallPathConfig;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
 import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
+import org.tizen.nativeplatform.command.launcher.RemoteCommandUtil;
+import org.tizen.nativeplatform.command.launcher.RemoteHostCommandLauncher;
 import org.tizen.nativeplatform.preferences.PreferencesManager;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
 import org.tizen.nativeplatform.repo.model.Repository;
-import org.tizen.nativeplatform.util.CommandLauncher;
 import org.tizen.nativeplatform.util.RootstrapUtil;
 import org.tizen.nativeplatform.views.model.PlatformRootstrap;
 
@@ -30,11 +39,11 @@ public class BaseFileSystemGenerator {
         String tempDirPath = null;
         try {
             // make temp directory
-            tempDirPath = RootstrapUtil.makeTempDirectory();
+            tempDirPath = CommandUtil.makeTempDirectory();
             latestTempRootstrap = new PlatformRootstrap(id, id, arch, tempDirPath, null, "", false);
 
             // use rogen
-            String rogen = InstallPathConfig.getSDKPath() + "/tools/rogen/bin/rogen.rb";
+            String rogen = RootstrapUtil.getRogenPath();
             String baseArch = RootstrapUtil.getBaseArchitecture(arch);
             String urlData = "";
             for (String url : reposURLs) {
@@ -64,20 +73,20 @@ public class BaseFileSystemGenerator {
             }
 
             if (rootstrapDir.exists()) {
-                if (!CommandLauncher.executeSudoWithExpect(command, rootstrapDir.getParent(), env,
+                if (!HostCommandLauncher.executeSudoWithExpect(command, rootstrapDir.getParent(), env,
                         "Platform Internal", monitor)) {
                     return false;
                 }
             } else {
-                if (!CommandLauncher.executeSudoWithExpect(command, tempDirPath, env,
+                if (!HostCommandLauncher.executeSudoWithExpect(command, tempDirPath, env,
                         "Platform Internal", monitor)) {
                     return false;
                 }
 
                 // copy
                 String rootstrapBasePath = rootstrapDir.getParent();
-                CommandLauncher.execute(String.format("mkdir -p %s", rootstrapBasePath));
-                CommandLauncher.executeSudo(String.format("sudo -S mv %s/%s %s/", tempDirPath, id,
+                HostCommandLauncher.execute(String.format("mkdir -p %s", rootstrapBasePath));
+                HostCommandLauncher.executeSudo(String.format("sudo -S mv %s/%s %s/", tempDirPath, id,
                         rootstrapBasePath));
             }
         } finally {
@@ -86,7 +95,7 @@ public class BaseFileSystemGenerator {
 
         return true;
     }
-
+    
     public static boolean generate(String rootstrapPath, String arch, List<Repository> reposURLs,
             IPath confFile, IProgressMonitor monitor) throws InterruptedException {
         List<String> repos = new ArrayList<String>();
@@ -95,20 +104,132 @@ public class BaseFileSystemGenerator {
         }
         return generate(rootstrapPath, repos, arch, confFile, monitor);
     }
+    
+    public static boolean remoteGenerate(String rootstrapPath, List<String> reposURLs, String arch,
+            IPath confFile, IProgressMonitor monitor) throws InterruptedException {
+        //File rootstrapDir = new File(rootstrapPath);
+        IPath rootstrapDir = new Path(rootstrapPath);
+        String id = rootstrapDir.lastSegment();
+        String tempDirPath = null;
+        try {
+            // make temp directory
+            tempDirPath = RemoteCommandUtil.makeTempDirectory();
+            latestTempRootstrap = new PlatformRootstrap(id, id, arch, tempDirPath, null, "", false);
+
+            // use rogen
+            String rogen = RootstrapUtil.getRemoteRogenPath();
+            String baseArch = RootstrapUtil.getBaseArchitecture(arch);
+            String urlData = "";
+            for (String url : reposURLs) {
+                urlData += (urlData.isEmpty() ? url : "," + url);
+            }
+
+            String command;
+            SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+            Map<String, String> env = sbi.getEnvMap();
+            if (PreferencesManager.isProxyUsed()) {
+                String[] proxyInfo = PreferencesManager.getProxyParsedURL();
+                if (proxyInfo != null) {
+                    String protocol = proxyInfo[0];
+                    String host = proxyInfo[1];
+                    String port = proxyInfo[2];                    
+                    String envKey = String.format("%s_proxy", protocol);
+                    String envValue = String.format("%s://%s:%s", protocol, host, port);
+                    env.put(envKey, envValue);
+                }
+            }
+
+            command = String.format("%s -n %s -a %s -u %s -p rpm --ctrl GBS -g TizenPlatform",
+                    rogen, id, baseArch, urlData);
+
+            if (confFile != null) {
+                command += String.format(" -d %s", confFile.toOSString());
+            }
+
+            boolean exists = false;
+            try {
+                exists = RemoteConnectionManager.getRemoteTools().getFileTool().hasDirectory(rootstrapDir.toString(), new NullProgressMonitor());
+            } catch (RemoteOperationException e) {
+                e.printStackTrace();
+            } catch (RemoteConnectionException e) {
+                e.printStackTrace();
+            } catch (CancelException e) {
+                e.printStackTrace();
+            }
+            if (exists) {
+                if (!RemoteHostCommandLauncher.executeSudoWithExpect(command, rootstrapDir.removeLastSegments(1).toString(), env,
+                        "Platform Internal", monitor)) {
+                    return false;
+                }
+            } else {
+                if (!RemoteHostCommandLauncher.executeSudoWithExpect(command, tempDirPath, env,
+                        "Platform Internal", monitor)) {
+                    return false;
+                }
+
+                // copy
+                String rootstrapBasePath = rootstrapDir.removeLastSegments(1).toString();
+                RemoteHostCommandLauncher.execute(String.format("mkdir -p %s", rootstrapBasePath));
+                RemoteHostCommandLauncher.executeSudo(String.format("sudo -S mv %s/%s %s/", tempDirPath, id,
+                        rootstrapBasePath));
+            }
+        } finally {
+
+        }
+
+        return true;
+    }
+
+    public static boolean remoteGenerate(String rootstrapPath, String arch, List<Repository> reposURLs,
+            IPath confFile, IProgressMonitor monitor) throws InterruptedException {
+        List<String> repos = new ArrayList<String>();
+        for (Repository repo : reposURLs) {
+            repos.add(repo.getUri());
+        }
+        return remoteGenerate(rootstrapPath, repos, arch, confFile, monitor);
+    }
 
     public static void remove(String id, String arch) throws InterruptedException {
         String path = RootstrapUtil.getUserRootstrapPath(id);
         // check sub-directory
         String checkDir = String.format("%s/local/BUILD-ROOTS/scratch.%s.0/proc", path, arch);
         if (new File(checkDir).exists()) {
-            CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+            HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
         }
         checkDir = String.format("%s/local/BUILD-ROOTS/scratch.%s.0/dev/pts", path, arch);
         if (new File(checkDir).exists()) {
-            CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+            HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
         }
 
-        CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path), null);
+        HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path), null);
+    }
+    
+    public static boolean remoteRemove(String id, String arch) throws InterruptedException {
+        String path = RootstrapUtil.getUserRootstrapPath(id);
+        String checkDir = String.format("%s/local/BUILD-ROOTS/scratch.%s.0/proc", path, arch);
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            boolean exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
+            if (exists) {
+                RemoteHostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+            }
+            checkDir = String.format("%s/local/BUILD-ROOTS/scratch.%s.0/dev/pts", path, arch);
+            exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
+            if (exists) {
+                RemoteHostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+            }
+            RemoteHostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path), null);
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            return false;
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            return false;
+        } catch (CancelException e) {
+            e.printStackTrace();
+            return false;
+        }
+        return true;
     }
 
 }
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RemoteRootstrapManager.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/rootstrap/RemoteRootstrapManager.java
new file mode 100644 (file)
index 0000000..48cac42
--- /dev/null
@@ -0,0 +1,548 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.rootstrap;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.ptp.remotetools.core.IRemoteCopyTools;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.core.IRemoteItem;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.util.FileUtil;
+import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativecommon.build.exception.SBIException;
+import org.tizen.nativecommon.build.model.SBIModel;
+import org.tizen.nativeplatform.build.PlatformConfigurationManager;
+import org.tizen.nativeplatform.command.launcher.RemoteHostCommandLauncher;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
+import org.tizen.nativeplatform.repo.commander.RepoManager;
+import org.tizen.nativeplatform.repo.model.Repository;
+import org.tizen.nativeplatform.util.RootstrapUtil;
+import org.tizen.nativeplatform.views.model.PlatformRootstrap;
+
+public class RemoteRootstrapManager {
+
+    public static final int LIST_INITIALIZED = 1 << 1;
+    public static final int LIST_NON_INITIALIZED = 1 << 2;
+    public static final int LIST_X86 = 1 << 3;
+    public static final int LIST_ARM = 1 << 4;
+
+    private static List<PlatformRootstrap> rootstraps = new ArrayList<PlatformRootstrap>();
+    private static List<PlatformRootstrap> userRootstraps = new ArrayList<PlatformRootstrap>();
+    private static PlatformRootstrap selectedRootstrap;
+    public static Set<IRootstrapChangedListener> changedListener = new HashSet<IRootstrapChangedListener>();
+
+    private static boolean init;
+    private static final String URL_SEP_REGEXP = "[|]";
+
+    protected static final Logger logger = LoggerFactory.getLogger(RemoteRootstrapManager.class);
+
+    private RemoteRootstrapManager() {
+    }
+
+    private synchronized static void initialize(IProgressMonitor monitor) {
+
+        if (!RemoteConnectionManager.connected()) {
+            monitor.done();
+            return;
+        }
+        
+        monitor.beginTask("Synchronizing rootstraps...", 3);
+        try {
+            SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+            String localpluginPath = SmartBuildInterface.getInstance().getPluginPath();
+            String remotepluginPath = RootstrapUtil.getRemoteUserRootstrapPluginPath();
+            List<String> remotelists = new ArrayList<String>();
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+            if (filetool == null || copytool == null) {
+                return;
+            }
+            try {
+                IRemoteItem[] items = filetool.listItems(remotepluginPath, new NullProgressMonitor());
+                for(IRemoteItem item : items) {
+                    String remotepath = item.getPath();
+                    String filename = FileUtil.getFileNameFromPath(remotepath);
+                    String ext = FileUtil.getFileExtension(filename);
+                    if (ext.equals("xml")) {
+                        int index = filename.lastIndexOf(".xml");
+                        String filenameWithoutExt = filename.substring(0, index);
+                        remotelists.add(filenameWithoutExt);
+                    }
+                    String localpath = new Path(localpluginPath).append(filename).toOSString();
+                    copytool.downloadFileToFile(remotepath, localpath);               
+                }
+            } catch (RemoteOperationException e) {
+                e.printStackTrace();
+            } catch (RemoteConnectionException e) {
+                e.printStackTrace();
+            } catch (CancelException e) {
+                e.printStackTrace();
+            }
+            monitor.worked(1);
+            monitor.subTask("Reinitializing rootstraps...");
+            
+            SBIModel.reinitialize();
+            monitor.worked(1);
+            monitor.subTask("Adding rootstraps...");
+            List<String> lists = sbi.getRootstrapList();
+            for (String id : lists) {
+                String type = sbi.getSupportToolchainTypeFromRootstrapID(id);
+                if (!type.equals(PlatformRootstrap.SUPPORTED_TOOLCHAIN_TYPE)) {
+                    continue;
+                }
+                if (!remotelists.contains(id)) {
+                    if (!sbi.getIsDefaultFromRootstrapID(id)) {
+                        continue;
+                    }
+                }
+                String rootName = sbi.getRootstrapNameFromRootstrapID(id);
+                String arch = sbi.getArchitectureFromRootstrapID(id);
+                String path = sbi.getRootstrapPathFromRootstrapID(id);
+                String version = sbi.getRootstrapVersionFromRootstrapID(id);
+                boolean isDefault = sbi.getIsDefaultFromRootstrapID(id);
+                List<Repository> reposURLs = new ArrayList<Repository>();
+                String rootstrapPath = sbi.getRootstrapPropertyValue(id, PlatformRootstrap.PROPERTY_REPO_URLS);
+                String confFile = sbi.getRootstrapPropertyValue(id, PlatformRootstrap.PROPERTY_CONFIGURATION_FILE);
+                if (rootstrapPath != null && rootstrapPath.split(URL_SEP_REGEXP).length >= 1) {
+                    int idx = 0;
+                    for (String url : rootstrapPath.split(URL_SEP_REGEXP)) {
+                        String name = String.format("url%d", idx++);
+                        if (RepoManager.isLocalUrl(url)) {
+                            reposURLs.add(new Repository(name, url, RepoManager.LOCAL_REPO_TYPE));
+                        } else {
+                            reposURLs.add(new Repository(name, url, RepoManager.REMOTE_REPO_TYPE));
+                        }
+                    }
+                }
+                boolean initialized = false;
+                if (!isDefault) {
+                    try {
+                        initialized = filetool.hasDirectory(path, new NullProgressMonitor());
+                    } catch (RemoteOperationException e) {
+                        e.printStackTrace();
+                    } catch (RemoteConnectionException e) {
+                        e.printStackTrace();
+                    } catch (CancelException e) {
+                        e.printStackTrace();
+                    }
+                } 
+                addRootstrap(new PlatformRootstrap(id, rootName, arch, version, path, reposURLs,
+                        confFile, initialized, isDefault));
+            }
+            monitor.worked(1);
+            init = true;
+        } catch (SBIException e) {
+            logger.error("Failed to initialize rootstraps", e);
+            e.printStackTrace();
+        } finally {
+            monitor.done();
+        }
+    }
+
+    public static PlatformRootstrap addRootstrap(PlatformRootstrap rootstrap) {
+        rootstraps.add(rootstrap);
+        if (!rootstrap.isDefault()) {
+            userRootstraps.add(rootstrap);
+        }
+        SBIModel.addRootstrap(rootstrap, true);
+        RootstrapManager.notifyChangedRootstrap();
+        return rootstrap;
+    }
+
+    public static boolean removeRootstrap(String id) {
+        PlatformRootstrap rootstrap = getRootstrap(id);
+        if (rootstrap != null) {
+            try {
+                BaseFileSystemGenerator.remoteRemove(rootstrap.getId(), rootstrap.getArch());
+            } catch (InterruptedException e) {
+                logger.error(String.format("Failed to rootstrap: [%s]", id), e);
+                e.printStackTrace();
+                return false;
+            }
+            rootstraps.remove(rootstrap);
+            if (userRootstraps.contains(rootstrap)) {
+                userRootstraps.remove(rootstrap);
+            }
+            XMLPluginGenerator.remoteRemove(rootstrap.getId());
+            SBIModel.removeRootstrap(rootstrap);
+            RootstrapManager.notifyChangedRootstrap();
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public static boolean exportRootstrap(PlatformRootstrap rootstrap, String exportFilePath,
+            IProgressMonitor monitor) throws InterruptedException {
+        return false;
+    }
+
+    public static PlatformRootstrap importRootstrap(String importFilePath, IProgressMonitor monitor)
+            throws InterruptedException {
+        return null;
+    }
+
+    public static List<PlatformRootstrap> getRootstraps(int listType) {
+        List<PlatformRootstrap> totalList = new ArrayList<PlatformRootstrap>();
+        if ((listType & LIST_INITIALIZED) != 0) {
+            mergeListExceptDuplicated(getInitializedRootstrap(), totalList);
+        }
+        if ((listType & LIST_NON_INITIALIZED) != 0) {
+            mergeListExceptDuplicated(getNonInitializedRootstrap(), totalList);
+        }
+        if ((listType & LIST_X86) != 0) {
+            mergeListExceptDuplicated(getX86Rootstrap(), totalList);
+        }
+        if ((listType & LIST_ARM) != 0) {
+            mergeListExceptDuplicated(getArmRootstrap(), totalList);
+        }
+        return totalList;
+    }
+
+    private static void mergeListExceptDuplicated(List<PlatformRootstrap> source,
+            List<PlatformRootstrap> target) {
+        for (PlatformRootstrap r : source) {
+            if (!target.contains(r)) {
+                target.add(r);
+            }
+        }
+    }
+
+    public static List<PlatformRootstrap> getRootstraps() {
+        checkInit();
+        return rootstraps;
+    }
+
+    public static List<PlatformRootstrap> getUserRootstraps() {
+        checkInit();
+        return userRootstraps;
+    }
+    
+    public static void clearRootstrap() {
+        rootstraps.clear();
+        RootstrapManager.notifyChangedRootstrap();
+    }
+
+    public static List<PlatformRootstrap> getX86Rootstrap() {
+        checkInit();
+        List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
+        for (PlatformRootstrap r : rootstraps) {
+            String arch = r.getArch();
+            if (PlatformConfigurationManager.containValue(
+                    PlatformConfigurationManager.ARCHGROUP_X86, arch)) {
+                list.add(r);
+            }
+        }
+        return list;
+    }
+
+    public static List<PlatformRootstrap> getArmRootstrap() {
+        checkInit();
+        List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
+        for (PlatformRootstrap r : rootstraps) {
+            String arch = r.getArch();
+            if (PlatformConfigurationManager.containValue(
+                    PlatformConfigurationManager.ARCHGROUP_ARM, arch)) {
+                list.add(r);
+            }
+        }
+        return list;
+    }
+
+    public static List<PlatformRootstrap> getInitializedRootstrap() {
+        checkInit();
+        List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.isInitialized()) {
+                list.add(r);
+            }
+        }
+        return list;
+    }
+
+    public static List<PlatformRootstrap> getNonInitializedRootstrap() {
+        checkInit();
+        List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
+        for (PlatformRootstrap r : rootstraps) {
+            if (!r.isInitialized()) {
+                list.add(r);
+            }
+        }
+        return list;
+    }
+
+    public static String getRootstrapId(String name) {
+        checkInit();
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.getName().equals(name)) {
+                return r.getId();
+            }
+        }
+        return "";
+    }
+
+    public static PlatformRootstrap getRootstrap(String id) {
+        checkInit();
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.getId().equals(id)) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    public static PlatformRootstrap getDefaultRootstrap(String arch) {
+        return findDefaultRootstrap(arch);
+    }
+
+    public static PlatformRootstrap findDefaultRootstrap(String arch) {
+        for (PlatformRootstrap r : rootstraps) {
+            String[] archs = PlatformConfigurationManager.ARCHGROUP_X86;
+            if (PlatformConfigurationManager.isArmArch(arch)) {
+                archs = PlatformConfigurationManager.ARCHGROUP_ARM;
+            }
+            if (r.isDefault() && PlatformConfigurationManager.containValue(archs, r.getArch())) {
+                return r;
+            }
+        }
+        return null;
+
+    }
+
+    public static boolean existsRootstrap(String id) {
+        checkInit();
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.getId().equals(id)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static void reinitialize(IProgressMonitor monitor) {
+        init = false;
+        rootstraps.clear();
+        initialize(monitor);
+    }
+
+    public static void updateRootstrap(PlatformRootstrap rootstrap) {
+        if (rootstrap != null) {
+            try {
+                XMLPluginGenerator
+                        .remoteGenerate(rootstrap.getId(), rootstrap.getName(), rootstrap.getArch(),
+                                rootstrap.getVersion(), rootstrap.getPath().toOSString(),
+                                rootstrap.getJustRepoURLs(), rootstrap.getConfFile(),
+                                rootstrap.isDefault());
+                SBIModel.updateRootstrap(rootstrap);
+                RemoteRootstrapManager.notifyChangedRootstrap();
+            } catch (SBIException e) {
+                logger.error(String.format("Failed to update rootstrap: [%s]", rootstrap.getId()),
+                        e);
+                e.printStackTrace();
+            }
+        }
+    }
+
+    public static void setSelectedRootstrap(PlatformRootstrap selected) {
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.isChecked()) {
+                r.setChecked(false);
+            }
+        }
+        selected.setChecked(true);
+        selectedRootstrap = selected;
+    }
+
+    public static void setSelectedRootstrap(String id) {
+        for (PlatformRootstrap r : RemoteRootstrapManager.getRootstraps()) {
+            if (id.equals(r.getId())) {
+                setSelectedRootstrap(r);
+                break;
+            }
+        }
+    }
+
+    public static void resetSelectedRootstrap() {
+        for (PlatformRootstrap r : rootstraps) {
+            if (r.isChecked()) {
+                r.setChecked(false);
+            }
+        }
+    }
+
+    public static boolean isInitialized(String rootId) {
+        PlatformRootstrap root = getRootstrap(rootId);
+        if (root != null) {
+            return root.isInitialized();
+        } else {
+            return false;
+        }
+    }
+
+    public static boolean checkInitialized(String rootId) {
+        PlatformRootstrap root = getRootstrap(rootId);
+        if (root != null) {
+            return root.checkInitialized();
+        } else {
+            return false;
+        }
+    }
+
+    public static PlatformRootstrap getSelectedRootstrap() {
+        return selectedRootstrap;
+    }
+
+    public static synchronized void addListener(IRootstrapChangedListener listener) {
+        changedListener.add(listener);
+    }
+
+    public static synchronized void removeListener(IRootstrapChangedListener listener) {
+        changedListener.remove(listener);
+    }
+
+    public static synchronized void notifyChangedRootstrap() {
+
+        Iterator<IRootstrapChangedListener> ite = changedListener.iterator();
+        while (ite.hasNext()) {
+            IRootstrapChangedListener tl = ite.next();
+            if (tl != null) {
+                tl.rootstrapChanged();
+            }
+        }
+    }
+
+    public static synchronized void notifyChangedSelectionListener(String rootName) {
+
+        Iterator<IRootstrapChangedListener> ite = changedListener.iterator();
+        while (ite.hasNext()) {
+            IRootstrapChangedListener tl = ite.next();
+            if (tl != null) {
+                tl.selectionChanged(rootName);
+            }
+        }
+    }
+
+    private static void checkInit() {
+        if (!init) {
+            initialize(new NullProgressMonitor());
+        }
+    }
+
+    public static void removeLatestTempDirForRootstrap() {
+        PlatformRootstrap tempRootstrap = BaseFileSystemGenerator.getLatestTempRootstrap();
+        if (tempRootstrap == null) {
+            return;
+        }
+        String id = tempRootstrap.getId();
+        String arch = tempRootstrap.getArch();
+        String path = tempRootstrap.getPath().toString();
+        if (id == null || arch == null || path == null ||
+                id.isEmpty() || arch.isEmpty() || path.isEmpty()) {
+            return;
+        }
+        try {
+            if (!path.isEmpty()) {
+                IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+                boolean exists = filetool.hasDirectory(path, new NullProgressMonitor());
+                if (exists) {
+                    String checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/proc",
+                            path, id, arch);
+                    exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
+                    if (exists) {
+                        RemoteHostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+                    }
+                    checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/dev/pts",
+                            path, id, arch);
+                    exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
+                    if (exists) {
+                        RemoteHostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+                    }
+                    checkDir = String.format("%s/%s/", path, id);
+                    exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
+                    if (exists) {
+                        RemoteHostCommandLauncher.execute(String.format("rm -rf %s", checkDir));
+                    }
+                    // remove
+                    RemoteHostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
+                }
+            }
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove temp rootstrap directory: %s", path), e);
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove temp rootstrap directory: %s", path), e);
+        } catch (CancelException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove temp rootstrap directory: %s", path), e);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            logger.error(String.format("Failed to remove temp rootstrap directory: %s", path), e);
+        }
+    }
+
+    public static PlatformRootstrap generate(String name, String arch, String version,
+            List<Repository> reposURLs, boolean immediateGen, IPath confFile,
+            IProgressMonitor monitor) throws InterruptedException {
+
+        boolean initialized = false;
+        String id = name;
+        if (immediateGen) {
+            if (BaseFileSystemGenerator.remoteGenerate(RootstrapUtil.getRemoteUserRootstrapPath(id), arch,
+                    reposURLs, confFile, monitor)) {
+                initialized = true;
+            } else {
+                return null;
+            }
+        }
+
+        // generate SBI plugins
+        if (XMLPluginGenerator.remoteGenerate(id, name, arch, version, null, reposURLs, confFile)) {
+            return new PlatformRootstrap(id, name, arch, RootstrapUtil.getUserRootstrapPath(id),
+                    reposURLs, confFile, initialized, false);
+        } else {
+            if (immediateGen) {
+                BaseFileSystemGenerator.remoteRemove(id, arch);
+            }
+            return null;
+        }
+    }
+}
index 793db56..53ec4a4 100644 (file)
@@ -30,11 +30,9 @@ package org.tizen.nativeplatform.rootstrap;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.eclipse.core.runtime.IPath;
@@ -47,9 +45,10 @@ import org.tizen.nativecommon.build.exception.SBIException;
 import org.tizen.nativecommon.build.model.Rootstrap;
 import org.tizen.nativecommon.build.model.SBIModel;
 import org.tizen.nativeplatform.build.PlatformConfigurationManager;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
 import org.tizen.nativeplatform.repo.commander.RepoManager;
 import org.tizen.nativeplatform.repo.model.Repository;
-import org.tizen.nativeplatform.util.CommandLauncher;
 import org.tizen.nativeplatform.util.RootstrapUtil;
 import org.tizen.nativeplatform.views.model.PlatformRootstrap;
 
@@ -149,7 +148,7 @@ public class RootstrapManager {
             IProgressMonitor monitor) throws InterruptedException {
 
         // make temp directory
-        String tempDirPath = RootstrapUtil.makeTempDirectory();
+        String tempDirPath = CommandUtil.makeTempDirectory();
 
         try {
             // rootstrapPath = /home/sdk/tizen-sdk-data/user-rootstraps/latest
@@ -168,13 +167,13 @@ public class RootstrapManager {
                 return false;
             }
             String rootstrapID = rootstrap.getId();
-            if (!CommandLauncher.execute(String.format(
+            if (!HostCommandLauncher.execute(String.format(
                     "tar cvzf %s/rootstrap1.tar.gz %s --exclude=local/BUILD-ROOTS/%s", tempDirPath,
                     rootstrapID, scratchName), workingPath, "Platform Internal", monitor)) {
                 return false;
             }
 
-            if (!CommandLauncher
+            if (!HostCommandLauncher
                     .executeSudo(
                             String.format(
                                     "sudo -S tar cvzf %s/rootstrap2.tar.gz %s/local/BUILD-ROOTS/%s --exclude=home/abuild --exclude=etc/passwd",
@@ -187,12 +186,12 @@ public class RootstrapManager {
             String pluginFileName = rootstrap.getId() + ".xml";
             String pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
                     pluginFileName).toOSString();
-            if (!CommandLauncher.execute(String.format("cp %s %s/", pluginPath, tempDirPath))) {
+            if (!HostCommandLauncher.execute(String.format("cp %s %s/", pluginPath, tempDirPath))) {
                 return false;
             }
 
             // zip them together
-            if (!CommandLauncher.execute(String.format(
+            if (!HostCommandLauncher.execute(String.format(
                     "tar cvzf %s rootstrap1.tar.gz rootstrap2.tar.gz %s", exportFilePath,
                     pluginFileName), tempDirPath, "Platform Internal", monitor)) {
                 return false;
@@ -201,7 +200,7 @@ public class RootstrapManager {
             return true;
         } finally {
             // remove temporary directory
-            CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath));
+            HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath));
         }
     }
 
@@ -213,11 +212,11 @@ public class RootstrapManager {
         String rootstrapPath = null;
 
         // make temp directory
-        String tempDirPath = RootstrapUtil.makeTempDirectory();
+        String tempDirPath = CommandUtil.makeTempDirectory();
 
         try {
             // extract "tar" archive
-            if (!CommandLauncher.execute(String.format("tar xvf %s", importFilePath), tempDirPath,
+            if (!HostCommandLauncher.execute(String.format("tar xvf %s", importFilePath), tempDirPath,
                     "Platform Internal", monitor)) {
                 cleanUpRootstrap(pluginPath, rootstrapPath);
                 throw new InterruptedException("Extracting rootsrap failed!");
@@ -252,7 +251,7 @@ public class RootstrapManager {
             // copy xml
             pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
                     pluginFileName).toOSString();
-            CommandLauncher.execute(String.format("cp %s %s", pluginFilePath, pluginPath));
+            HostCommandLauncher.execute(String.format("cp %s %s", pluginFilePath, pluginPath));
 
             // reload
             try {
@@ -276,18 +275,18 @@ public class RootstrapManager {
                             baseDirDir.toString()));
                 }
             } else if (new File(rootstrapPath).exists()) {
-                CommandLauncher
+                HostCommandLauncher
                         .executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
             }
 
-            if (!CommandLauncher.execute(
+            if (!HostCommandLauncher.execute(
                     String.format("tar xvf %s/rootstrap1.tar.gz", tempDirPath),
                     baseDirDir.getPath(), "Platform Internal", monitor)) {
                 cleanUpRootstrap(pluginPath, rootstrapPath);
                 throw new InterruptedException("Extracting rootsrap failed!");
             }
 
-            if (!CommandLauncher.executeSudo(
+            if (!HostCommandLauncher.executeSudo(
                     String.format("sudo -S tar xvf %s/rootstrap2.tar.gz", tempDirPath),
                     baseDirDir.getPath(), "Platform Internal", monitor)) {
                 cleanUpRootstrap(pluginPath, rootstrapPath);
@@ -297,14 +296,14 @@ public class RootstrapManager {
             return result;
         } finally {
             // remove temporary directory
-            CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath), null);
+            HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath), null);
         }
     }
 
     private static void cleanUpRootstrap(String pluginPath, String rootstrapPath)
             throws InterruptedException {
         if (pluginPath != null) {
-            CommandLauncher.execute(String.format("rm -rf %s", pluginPath));
+            HostCommandLauncher.execute(String.format("rm -rf %s", pluginPath));
             try {
                 SBIModel.reinitialize();
             } catch (SBIException e1) {
@@ -312,7 +311,7 @@ public class RootstrapManager {
             }
         }
         if (rootstrapPath != null) {
-            CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
+            HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
         }
     }
 
@@ -570,19 +569,19 @@ public class RootstrapManager {
                 String checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/proc",
                         path, id, arch);
                 if (new File(checkDir).exists()) {
-                    CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+                    HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
                 }
                 checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/dev/pts",
                         path, id, arch);
                 if (new File(checkDir).exists()) {
-                    CommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+                    HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
                 }
                 checkDir = String.format("%s/%s/", path, id);
                 if (new File(checkDir).exists()) {
-                    CommandLauncher.execute(String.format("rm -rf %s", checkDir));
+                    HostCommandLauncher.execute(String.format("rm -rf %s", checkDir));
                 }
                 // remove
-                CommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
+                HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
             }
         } catch (InterruptedException e) {
             e.printStackTrace();
index 22689b9..ee6f942 100644 (file)
@@ -18,12 +18,19 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.ptp.remotetools.core.IRemoteCopyTools;
+import org.eclipse.ptp.remotetools.core.IRemoteFileTools;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.nativecommon.build.SmartBuildInterface;
 import org.tizen.nativecommon.build.model.SBIModel;
 import org.tizen.nativecommon.build.model.Target;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
 import org.tizen.nativeplatform.repo.model.Repository;
 import org.tizen.nativeplatform.util.RootstrapUtil;
 import org.tizen.nativeplatform.views.model.PlatformRootstrap;
@@ -197,6 +204,152 @@ public class XMLPluginGenerator {
         return true;
     }
 
+    public static boolean remoteGenerate(String id, String name, String arch, String version,
+            String path, List<String> reposURLs, IPath confFile, boolean isDefault) {
+        IPath pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath());
+        IPath filePath = pluginPath.append(id + ".xml"); 
+        try {
+            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+
+            // root element
+            Document doc = docBuilder.newDocument();
+            Element rootElement = doc.createElement(ELEMENT_EXTENSION);
+            doc.appendChild(rootElement);
+
+            Attr attr = doc.createAttribute(ATTR_POINT);
+            attr.setValue("rootstrapDefinition");
+            rootElement.setAttributeNode(attr);
+
+            Element node1 = doc.createElement(ELEMENT_ROOTSTRAP);
+            rootElement.appendChild(node1);
+
+            Attr attrId = doc.createAttribute(ATTR_ID);
+            attrId.setValue(id);
+            Attr attrName = doc.createAttribute(ATTR_NAME);
+            attrName.setValue(name);
+            Attr attrArch = doc.createAttribute(ATTR_ARCH);
+            attrArch.setValue(arch);
+            Attr attrPath = doc.createAttribute(ATTR_PATH);
+            if (path == null) {
+                attrPath.setValue(RootstrapUtil.getUserRootstrapPathOfXml(name));
+            } else {
+                attrPath.setValue(RootstrapUtil.getRootstrapPathOfXml(path));
+            }
+            Attr attrType = doc.createAttribute(ATTR_TOOLTYPE);
+            attrType.setValue(PlatformRootstrap.SUPPORTED_TOOLCHAIN_TYPE);
+            Attr attrVer = doc.createAttribute(ATTR_VER);
+            attrVer.setValue(version);
+
+            node1.setAttributeNode(attrId);
+            node1.setAttributeNode(attrName);
+            node1.setAttributeNode(attrArch);
+            node1.setAttributeNode(attrPath);
+            node1.setAttributeNode(attrType);
+            node1.setAttributeNode(attrVer);
+
+            //String reposURLString = "";
+            StringBuffer sbReposURL = new StringBuffer();
+            for (String URL : reposURLs) {
+                if (sbReposURL.length() != 0) {
+                    sbReposURL.append(URL_SEP);
+                }
+                sbReposURL.append(URL);
+            }
+
+            Element node2 = doc.createElement(ELEMENT_PROPERTY);
+            node1.appendChild(node2);
+
+            Attr attrKey = doc.createAttribute(ATTR_KEY);
+            attrKey.setValue(PlatformRootstrap.PROPERTY_REPO_URLS);
+            Attr attrValue = doc.createAttribute(ATTR_VALUE);
+            attrValue.setValue(sbReposURL.toString());
+
+            node2.setAttributeNode(attrKey);
+            node2.setAttributeNode(attrValue);
+
+            Element node3 = doc.createElement(ELEMENT_PROPERTY);
+            node1.appendChild(node3);
+
+            attrKey = doc.createAttribute(ATTR_KEY);
+            attrKey.setValue(PlatformRootstrap.PROPERTY_CONFIGURATION_FILE);
+            attrValue = doc.createAttribute(ATTR_VALUE);
+            if (confFile == null) {
+                attrValue.setValue("");
+            } else {
+                attrValue.setValue(confFile.toOSString());
+            }
+
+            node3.setAttributeNode(attrKey);
+            node3.setAttributeNode(attrValue);
+
+            // if it is default rootstrap, set default property.
+            if (isDefault) {
+                Element node6 = doc.createElement(ELEMENT_PROPERTY);
+                node1.appendChild(node6);
+                attrKey = doc.createAttribute(ATTR_KEY);
+                attrKey.setValue(PlatformRootstrap.PROPERTY_DEFAULT);
+                attrValue = doc.createAttribute(ATTR_VALUE);
+                attrValue.setValue("true");
+                node6.setAttributeNode(attrKey);
+                node6.setAttributeNode(attrValue);
+            }
+
+            TransformerFactory transformerFactory = TransformerFactory.newInstance();
+            Transformer transformer = transformerFactory.newTransformer();
+
+            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+            DOMSource source = new DOMSource(doc);
+            StreamResult result = new StreamResult(new FileOutputStream(new File(
+                    filePath.toOSString())));
+
+            transformer.transform(source, result);
+
+        } catch (ParserConfigurationException e) {
+            logger.error(String.format("Failed to generate XML file: [%s]", e), e);
+            e.printStackTrace();
+            return false;
+        } catch (TransformerConfigurationException e) {
+            logger.error(String.format("Failed to generate XML file: [%s]", e), e);
+            e.printStackTrace();
+            return false;
+        } catch (FileNotFoundException e) {
+            logger.error(String.format("Failed to generate XML file: [%s]", e), e);
+            e.printStackTrace();
+            return false;
+        } catch (TransformerException e) {
+            logger.error(String.format("Failed to generate XML file: [%s]", e), e);
+            e.printStackTrace();
+            return false;
+        }
+        IPath remotepluginPath = new Path(RootstrapUtil.getRemoteUserRootstrapPluginPath());
+        IPath remotefilePath = remotepluginPath.append(id + ".xml");
+        
+        try {
+            IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+            copytool.uploadFileToFile(filePath.toOSString(), remotefilePath.toString());
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        } catch (CancelException e) {
+            e.printStackTrace();
+        }
+     
+        return true;
+    }
+    
+    public static boolean remoteGenerate(String id, String name, String arch, String version,
+            String path, List<Repository> reposURLs, IPath confFile) {
+        List<String> repos = new ArrayList<String>();
+        for (Repository repo : reposURLs) {
+            repos.add(repo.getUri());
+        }
+        return remoteGenerate(id, name, arch, version, path, repos, confFile, false);
+    }
+    
     public static void remove(String id) {
         // remove related targets
         List<Target> targetList = SBIModel.getTargetList();
@@ -215,4 +368,18 @@ public class XMLPluginGenerator {
         new File(RootstrapUtil.getPluginXML(id)).delete();
     }
 
+    public static void remoteRemove(String id) {
+        remove(id);
+        String path = RootstrapUtil.getRemotePluginXML(id);
+        try {
+            IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+            filetool.removeFile(path, new NullProgressMonitor());
+        } catch (RemoteOperationException e) {
+            e.printStackTrace();
+        } catch (RemoteConnectionException e) {
+            e.printStackTrace();
+        } catch (CancelException e) {
+            e.printStackTrace();
+        }
+    }
 }
index 8757402..3ac0fba 100644 (file)
@@ -31,6 +31,7 @@ import java.io.File;
 import java.io.FilenameFilter;
 
 import org.eclipse.core.runtime.Path;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
 
 public class PlatformFileUtil {
 
@@ -42,6 +43,15 @@ public class PlatformFileUtil {
         }
         return tmpDir;
     }
+    
+    public static String getRemoteTmpDir() {
+        String tmpDir = "/tmp";
+        String homeDir = RemoteConnectionManager.getRemoteTools().getUserhome();
+        if (homeDir != null) {
+            tmpDir = new Path(homeDir).append("tmp").toString();
+        }
+        return tmpDir;
+    }
 
     public static File findFirstFilebyExtension(File searchPath, String ext) {
         File[] allFiles = searchPath.listFiles(new ExtFilter(ext));
index 9e58c66..12719e4 100644 (file)
@@ -34,31 +34,14 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
 
 public class RootstrapUtil {
 
     private static final String USER_ROOSTRAP_BASE_DIR_NAME = "user-rootstraps";
+    private static final String REMOTE_TIZEN_SDK_DIR_NAME = "tizen-sdk-remote-data";
+    private static final String REMOTE_ROOSTRAP_PLUGINS_DIR_NAME = "user-rootstrap-plugins";
 
-    public static String makeTempDirectory() {
-        final File temp;
-
-        try {
-            temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
-            if (!(temp.delete())) {
-                throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
-            }
-
-            if (!(temp.mkdir())) {
-                throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-            return null;
-        }
-
-        return temp.getPath();
-    }
-    
     public static String getBaseArchitecture(String arch) {
         if (arch.contains("arm")) {
             return "arm";
@@ -67,10 +50,20 @@ public class RootstrapUtil {
         }
     }
     
+    public static String getRemoteUserRootstrapPluginPath() {
+        String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();
+        return new Path(userhome).append(REMOTE_TIZEN_SDK_DIR_NAME).append(REMOTE_ROOSTRAP_PLUGINS_DIR_NAME).toString();
+    }
+    
     public static String getUserRootstrapPath(String id) {
         return new Path(getBaseUserRootstrapPath()).append(id).toOSString();
     }
     
+    public static String getRemoteUserRootstrapPath(String id) {
+        String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();
+        return new Path(userhome).append(REMOTE_TIZEN_SDK_DIR_NAME).append(REMOTE_ROOSTRAP_PLUGINS_DIR_NAME).append(id).toString();
+    }
+    
     public static String getBaseUserRootstrapPath() {
         return new Path(InstallPathConfig.getUserDataPath()).append(USER_ROOSTRAP_BASE_DIR_NAME)
                 .toOSString();
@@ -78,7 +71,6 @@ public class RootstrapUtil {
     
     public static String getUserRootstrapPathOfXml(String id) {
         String rootstrapPath = getUserRootstrapPath(id);
-
         return getRootstrapPathOfXml(rootstrapPath);
     }
     
@@ -99,4 +91,17 @@ public class RootstrapUtil {
         IPath pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath());
         return pluginPath.append(id + ".xml").toOSString();
     }
+
+    public static String getRemotePluginXML(String id) {
+        return new Path(getRemoteUserRootstrapPluginPath()).append(id + ".xml").toString();
+    }
+    
+    public static String getRogenPath() {
+        return new Path(InstallPathConfig.getSDKPath()).append("tools").append("rogen").append("bin").append("rogen.rb").toString();
+    }
+    
+    public static String getRemoteRogenPath() {
+        String userhome = RemoteConnectionManager.getRemoteTools().getUserhome();
+        return new Path(userhome).append(REMOTE_TIZEN_SDK_DIR_NAME).append("tools").append("rogen").append("bin").append("rogen.rb").toString();
+    }
 }
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RemoteConnectionDialog.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/views/ui/RemoteConnectionDialog.java
new file mode 100644 (file)
index 0000000..7291e65
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Native Platform
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Donghyuk Yang <donghyuk.yang@samsung.com>  
+ * DongHee Yang <donghee.yang@samsung.com>
+ * Kangho Kim <kh5325.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.nativeplatform.views.ui;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.common.util.DialogUtil;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
+
+public class RemoteConnectionDialog extends Dialog {
+
+    private Shell shell;
+
+    private Text hostText;
+    private Text userText;
+    private Text passText;
+    private Text sudoText;    
+
+    private int x = 0;
+    private int y = 0;
+    private int width = 300;
+    private int height = 250;
+
+    private final String BUNDLE_NAME = RemoteConnectionDialog.class.getPackage().getName()
+            + ".RootstrapUIMessages";//$NON-NLS-1$
+    private ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_NAME);
+
+    public RemoteConnectionDialog(Shell parentShell) {
+        super(parentShell);
+        this.shell = parentShell;
+        Rectangle bounds = parentShell.getBounds();
+        x = bounds.x + (bounds.width - width) / 2;
+        y = bounds.y + (bounds.height - height) / 2;
+    }
+
+    @Override
+    protected void configureShell(Shell newShell) {
+        super.configureShell(newShell);
+
+        newShell.setText(resources.getString("RemoteConnDlg.Title"));
+        newShell.setLocation(x, y);
+        newShell.setSize(width, height);
+    }
+
+    @Override
+    protected void createButtonsForButtonBar(Composite parent) {
+        super.createButtonsForButtonBar(parent);
+        
+        Button ok = getButton(IDialogConstants.OK_ID);
+        ok.setText("Connect");
+        setButtonLayoutData(ok);
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+
+        Composite composite = new Composite(parent, SWT.NONE);
+        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
+                | GridData.VERTICAL_ALIGN_BEGINNING));
+        composite.setLayout(new GridLayout(1, false));
+
+        createConnectionComposite(composite);
+        return null;
+    }
+    
+    private void createConnectionComposite(Composite parent) {
+        Composite composite = new Composite(parent, SWT.NONE);
+        composite.setLayout(new GridLayout(2, false));
+        GridData gridData = new GridData(GridData.FILL_BOTH);
+        composite.setLayoutData(gridData);
+        
+        gridData = new GridData(GridData.FILL_HORIZONTAL);
+        gridData.minimumHeight = 0;
+        
+        Label hostLabel = new Label(composite, SWT.NONE);
+        hostLabel.setText("Host:");        
+        hostText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+        hostText.setLayoutData(gridData);
+        Label userLabel = new Label(composite, SWT.NONE);
+        userLabel.setText("User ID:");
+        userText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+        userText.setLayoutData(gridData);
+        Label passwordLabel = new Label(composite, SWT.NONE);
+        passwordLabel.setText("Password:");
+        passText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+        passText.setLayoutData(gridData);
+        Label sudoLabel = new Label(composite, SWT.NONE);
+        sudoLabel.setText("Sudo password:");
+        sudoText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+        sudoText.setLayoutData(gridData);
+    }
+
+    @Override
+    protected void okPressed() {
+        final String host = hostText.getText();
+        final String user = userText.getText();
+        final String pass = passText.getText();
+        
+        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
+        try {
+            dialog.run(true, true, new IRunnableWithProgress() {
+                @Override
+                public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                    InterruptedException {
+                     monitor.beginTask(resources.getString("RemoteConnDlg.Progress.Creating"), 1);
+                     try {
+                         if (!RemoteConnectionManager.createConnection(host, user, pass, new SubProgressMonitor(monitor, 1))) {
+                             DialogUtil.openMessageDialog(getShell(), "Failed to connect");
+                         }
+                     } finally {
+                         monitor.done();
+                     }
+                }
+             });
+         } catch (Exception e) {             
+             return;
+         }
+         super.okPressed();
+    }
+}
index 0196b33..8e0b109 100644 (file)
@@ -20,6 +20,9 @@ View.Desc.Status = * Status : %s
 View.Desc.Repos = * Repository URLs
 View.Desc.ConfFile = * Configuration File\n  - %s
 
+RemoteConnDlg.Title = Remote Connection Dialog
+RemoteConnDlg.Progress.Creating = Creating remote connection...
+
 GenRootDlg.Title = Generate Rootstrap Dialog
 GenRootDlg.Desc = Generate rootstrap based on remote repository or local repository.
 GenRootDlg.Label.Rootstrapname = Rootstrap Name :
index bff12cc..2fc0423 100644 (file)
@@ -52,6 +52,7 @@ import org.eclipse.jface.action.IMenuListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ArrayContentProvider;
@@ -93,20 +94,25 @@ import org.tizen.common.TizenHelpContextIds;
 import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.common.util.DialogUtil;
 import org.tizen.common.util.ImageUtil;
+import org.tizen.common.util.OSChecker;
+import org.tizen.common.util.SWTUtil;
 import org.tizen.nativecommon.ProjectUtil;
 import org.tizen.nativecommon.build.SmartBuildInterface;
 import org.tizen.nativecommon.build.exception.SBIException;
 import org.tizen.nativeplatform.Activator;
 import org.tizen.nativeplatform.build.PlatformConfigurationManager;
+import org.tizen.nativeplatform.command.launcher.RemoteCommandUtil;
 import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget;
 import org.tizen.nativeplatform.pkgmgr.PkgMgrInitializer;
 import org.tizen.nativeplatform.pkgmgr.ui.RPMPackageDialog;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
 import org.tizen.nativeplatform.repo.commander.LocalRepoMounter;
 import org.tizen.nativeplatform.repo.commander.RepoManager;
 import org.tizen.nativeplatform.repo.model.Repository;
 import org.tizen.nativeplatform.rootstrap.BaseFileSystemGenerator;
 import org.tizen.nativeplatform.rootstrap.IRootstrapChangedListener;
+import org.tizen.nativeplatform.rootstrap.RemoteRootstrapManager;
 import org.tizen.nativeplatform.rootstrap.RootstrapManager;
 import org.tizen.nativeplatform.types.PkgTypes;
 import org.tizen.nativeplatform.util.GBSArchitectureChecker;
@@ -294,8 +300,42 @@ public class RootstrapView extends ViewPart {
         toolBar = new ToolBar(composite, SWT.NULL);
         GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
         toolBar.setLayoutData(gridData);
-        new ToolItem(toolBar, SWT.SEPARATOR); // Separator
-
+        //new ToolItem(toolBar, SWT.SEPARATOR); // Separator
+        
+        if (OSChecker.isWindows()) {
+            ToolItem connectRemoteHost = new ToolItem(toolBar, SWT.PUSH);
+            Image connectIcon = ImageUtil.getImage(Activator.PLUGIN_ID, "icons/rootstrap/connect.gif");
+            connectRemoteHost.setImage(connectIcon);
+            connectRemoteHost.setToolTipText("Connect remote host");
+    
+            connectRemoteHost.addSelectionListener(new SelectionListener() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    showConnectDialog();
+                }
+    
+                @Override
+                public void widgetDefaultSelected(SelectionEvent e) {
+                }
+            });
+            
+            ToolItem disconnect = new ToolItem(toolBar, SWT.PUSH);
+            Image disconnectIcon = ImageUtil.getImage(Activator.PLUGIN_ID, "icons/rootstrap/disconnect.gif");
+            disconnect.setImage(disconnectIcon);
+            disconnect.setToolTipText("Disconnect remote host");
+    
+            disconnect.addSelectionListener(new SelectionListener() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    disconnectRemotehost();
+                }
+    
+                @Override
+                public void widgetDefaultSelected(SelectionEvent e) {
+                }
+            });
+        }
+        
         ToolItem addRootstrap = new ToolItem(toolBar, SWT.PUSH);
         Image addIcon = ImageUtil.getImage(Activator.PLUGIN_ID, "icons/rootstrap/add.gif");
         addRootstrap.setImage(addIcon);
@@ -309,12 +349,11 @@ public class RootstrapView extends ViewPart {
 
             @Override
             public void widgetDefaultSelected(SelectionEvent e) {
-                // Nothing to do
             }
         });
         addRootstrap.setEnabled(true);
 
-        new ToolItem(toolBar, SWT.SEPARATOR); // Separator
+        //new ToolItem(toolBar, SWT.SEPARATOR); // Separator
 
         ToolItem importRootstrap = new ToolItem(toolBar, SWT.PUSH);
         Image editIcon = ImageUtil.getImage(Activator.PLUGIN_ID, "icons/rootstrap/import.gif");
@@ -329,11 +368,11 @@ public class RootstrapView extends ViewPart {
 
             @Override
             public void widgetDefaultSelected(SelectionEvent e) {
-                // Nothing to do
             }
-
         });
-
+        if (OSChecker.isWindows()) {
+            updateToolbarEnable();
+        }
     }
 
     private void createRootstrapTableComposite(Composite parent) {
@@ -368,7 +407,7 @@ public class RootstrapView extends ViewPart {
 
         tableViewer.setLabelProvider(new TableViewerProvider());
         tableViewer.setContentProvider(new ArrayContentProvider());
-        tableViewer.setInput(RootstrapManager.getRootstraps());
+        tableViewer.setInput(getRootstrapTableInput());
 
         tableViewer.getTable().addSelectionListener(new SelectionListener() {
 
@@ -527,29 +566,118 @@ public class RootstrapView extends ViewPart {
         };
         actionExport.setText(resources.getString("View.Contextmenu.Export"));
     }
-
-    private void showAddDialog() {
-        PkgCommandTarget target = new PkgCommandTarget(PkgTypes.DPKG);
-        IPkgCommander dpkgCommander = target.getHostCommander();
-
-        if (!dpkgCommander.checkPkgInstalled(PREREQUISITE_PKG)) {
-            String msg = String.format(resources.getString("GenRootDlg.Error.Miss.Prerequisite"), 
-                    PREREQUISITE_PKG, PREREQUISITE_PKG);
-            DialogUtil.openErrorDialog(msg);
+    
+    private void updateToolbarEnable() {
+        ToolItem[] items = toolBar.getItems();
+        if (RemoteConnectionManager.connected()) {
+            items[0].setEnabled(false);
+            items[1].setEnabled(true);
+            items[2].setEnabled(true);
+            items[3].setEnabled(false);
         } else {
-            RootstrapGenDialog dlg = new RootstrapGenDialog(shell);
-            if (dlg.open() == RootstrapGenDialog.OK) {
-                String rootstrapName = dlg.getRootstrapName();
-                String arch = GBSArchitectureChecker.changeToSupportedArchitecture(dlg
-                        .getSelectionTab().getArchitecture());
-                List<String> repositoryURLs = dlg.getSelectionTab().getRepositoryURLs();
-                List<Repository> repoURLs = RepoManager.createRepoList(repositoryURLs);
+            items[0].setEnabled(true);
+            items[1].setEnabled(false);
+            items[2].setEnabled(false);
+            items[3].setEnabled(false);
+        }
+    }
+    
+    private void showConnectDialog() {
+
+        RemoteConnectionDialog dlg = new RemoteConnectionDialog(shell);
+        if (dlg.open() == Dialog.OK) {
+             ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
+             try {
+                dialog.run(true, true, new IRunnableWithProgress() {
+                     @Override
+                     public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                             InterruptedException {
+                         monitor.beginTask("Synchronizing...", 2);
+                         try {
+                             monitor.subTask("Synchronizing rootstraps...");
+                             RemoteRootstrapManager.reinitialize(new SubProgressMonitor(monitor, 1));
+                             monitor.subTask("Clear platform temp directory");
+                             RemoteCommandUtil.clearPlatformTempDir();
+                             monitor.worked(1);
+                             SWTUtil.syncExec(new Runnable() {
+                                 public void run() {
+                                     updateToolbarEnable();
+                                 }
+                             });
+                             monitor.worked(1);
+                         } finally {
+                             monitor.done();
+                         }
+                     }
+                 });
+            } catch (Exception e) {
+                logger.error("Failed to synchronize rootstraps", e);
+                DialogUtil.openErrorDialog(String.format("%s\n * %s",
+                        "Failed to synchronize rootstraps", e.getMessage()));
+                return;
+            }
+        }
+    }
     
-                boolean immediateGen = dlg.getSelectionTab().isImmediateGenerateChecked();
-                IPath buildConfFile = dlg.getSelectionTab().getBuildConfFile();
-                genRootstrap(rootstrapName, arch, repoURLs, immediateGen, buildConfFile);
+    private void disconnectRemotehost() {
+        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
+        try {
+            dialog.run(true, true, new IRunnableWithProgress() {
+                @Override
+                public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                        InterruptedException {
+                    monitor.beginTask("Disconnecting...", 3);
+                    try {
+                        monitor.subTask("Disconnect");
+                        RemoteConnectionManager.removeConnection();
+                        monitor.worked(1);
+                        monitor.subTask("Clean rootstrap");
+                        RemoteRootstrapManager.clearRootstrap();
+                        monitor.worked(1);
+                        monitor.subTask("Update toolbar");
+                        SWTUtil.syncExec(new Runnable() {
+                             public void run() {
+                                 updateToolbarEnable();
+                             }
+                         });
+                        monitor.worked(1);
+                    } finally {
+                        monitor.done();
+                    }
+                }
+            });
+        } catch (Exception e) {
+            logger.error("Failed to close remote connection", e);
+            DialogUtil.openErrorDialog(String.format("%s\n * %s",
+                    "Failed to close remote connection", e.getMessage()));
+            return;
+        }
+    }
+
+    private void showAddDialog() {
+        if (!OSChecker.isWindows()) {
+            PkgCommandTarget target = new PkgCommandTarget(PkgTypes.DPKG);
+            IPkgCommander dpkgCommander = target.getHostCommander();
+            if (!dpkgCommander.checkPkgInstalled(PREREQUISITE_PKG)) {
+                String msg = String.format(resources.getString("GenRootDlg.Error.Miss.Prerequisite"), 
+                        PREREQUISITE_PKG, PREREQUISITE_PKG);
+                DialogUtil.openErrorDialog(msg);
+                return;
             }
         }
+
+        RootstrapGenDialog dlg = new RootstrapGenDialog(shell);
+        if (dlg.open() == RootstrapGenDialog.OK) {
+            String rootstrapName = dlg.getRootstrapName();
+            String arch = GBSArchitectureChecker.changeToSupportedArchitecture(dlg
+                    .getSelectionTab().getArchitecture());
+            List<String> repositoryURLs = dlg.getSelectionTab().getRepositoryURLs();
+            List<Repository> repoURLs = RepoManager.createRepoList(repositoryURLs);
+
+            boolean immediateGen = dlg.getSelectionTab().isImmediateGenerateChecked();
+            IPath buildConfFile = dlg.getSelectionTab().getBuildConfFile();
+            genRootstrap(rootstrapName, arch, repoURLs, immediateGen, buildConfFile);
+        }
     }
 
     private void genRootstrap(final String name, final String arch,
@@ -1106,4 +1234,12 @@ public class RootstrapView extends ViewPart {
             return "x86";
         }
     }
+    
+    private List<PlatformRootstrap> getRootstrapTableInput() {
+        if (OSChecker.isWindows()) {
+            return RemoteRootstrapManager.getUserRootstraps();
+        } else {
+            return RootstrapManager.getRootstraps();
+        }
+    }
 }
index dc79c40..924cbe8 100644 (file)
@@ -289,7 +289,7 @@ public class TizenPlatformMainWizardPage extends TizenMainWizardPage {
                         GitDescription desc = null;
                         if (config != null) {
                             String siteConfigName = config.getName();
-                            desc = GitDescManager.getDesc(siteConfigName, descPath.toOSString());
+                            desc = GitDescManager.getDesc(siteConfigName, descPath.toString());
                         }
                         Category entry = addChildEntry(fModel, platformInfo, categories);
                         TizenPlatformTemplateModel template2 = new TizenPlatformTemplateModel(