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,
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,
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
PlatformProjectDependentBuilder.getInstance(),
PlatformProjectDependentPackager.getInstance(), true);
PreferencesManager.setDefaultValues();
- CommandLauncherUtil.clearPlatformTempDir();
+ CommandUtil.clearPlatformTempDir();
}
/*
--- /dev/null
+/*
+ * 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);
+ }
+
+
+}
*
*/
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
import java.io.IOException;
import java.util.ArrayList;
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) {
*
*/
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
import static org.tizen.common.util.IOUtil.tryClose;
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 {
throws InterruptedException {
// generate script
- String scriptCmd = CommandLauncherUtil.genSudoExecuteExpectScript(command);
+ String scriptCmd = ScriptProvider.genSudoExecuteExpectScript(command);
if (scriptCmd == null) {
throw new InterruptedException("Generating execution script failed!");
}
} catch (InterruptedException e) {
throw e;
} finally {
- CommandLauncherUtil.cleanUpScript(scriptCmd, true);
+ ScriptProvider.cleanUpScript(scriptCmd, true);
}
return result;
}
throws InterruptedException {
// generate script
- String scriptCmd = CommandLauncherUtil.genSudoExecuteScript(command);
+ String scriptCmd = ScriptProvider.genSudoExecuteScript(command);
if (scriptCmd == null) {
throw new InterruptedException("Generating execution script failed!");
}
} catch (InterruptedException e) {
throw e;
} finally {
- CommandLauncherUtil.cleanUpScript(scriptCmd);
+ ScriptProvider.cleanUpScript(scriptCmd);
}
return result;
}
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) {
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!");
}
} catch (InterruptedException e) {
throw e;
} finally {
- CommandLauncherUtil.cleanUpScript(scriptCmd);
+ ScriptProvider.cleanUpScript(scriptCmd);
}
return result;
}
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()));
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;
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+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);
+ }
+}
*
*/
-package org.tizen.nativeplatform.util;
+package org.tizen.nativeplatform.command.launcher;
import static org.tizen.common.util.IOUtil.tryClose;
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) {
// 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;
}
// 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;
-/*
- * 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;
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
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) {
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()) {
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;
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;
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)
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();
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()) {
}
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);
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;
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;
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();
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", "");
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...");
// 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);
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>();
// 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(" ");
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();
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 {
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 {
@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();
inferior.setSuspended();
waitForInterrupt(inferior);
- CommandLauncherUtil.cleanUpScript(interruptCmd);
+ ScriptProvider.cleanUpScript(interruptCmd);
// super.interrupt(inferior);
} else {
BufferedWriter bw;
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 {
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"));
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;
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 {
String result = "";
String command = makeCommand(DpkgTool.statusCommand(pkg));
try {
- result = CommandLauncher.executeOutput(command);
+ result = HostCommandLauncher.executeOutput(command);
} catch (InterruptedException e) {
e.printStackTrace();
return false;
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;
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 {
}
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);
}
String command = RpmTool.fileNameCommand(filePath);
try {
- result = CommandLauncher.executeOutput(command);
+ result = HostCommandLauncher.executeOutput(command);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
String command = RpmTool.fileFullVerCommand(filePath);
try {
- result = CommandLauncher.executeOutput(command);
+ result = HostCommandLauncher.executeOutput(command);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
String command = String.format("file %s", filePath);
try {
- result = CommandLauncher.executeOutput(command);
+ result = HostCommandLauncher.executeOutput(command);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
String command = String.format("file %s", filePath);
try {
- result = CommandLauncher.executeOutput(command);
+ result = HostCommandLauncher.executeOutput(command);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
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;
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);
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);
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());
}
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());
}
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());
}
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());
}
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());
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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 {
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());
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());
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;
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;
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;
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));
}
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 {
/*
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:
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;
}
}
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;
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()) {
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()) {
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;
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;
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}
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 {
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();
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();
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;
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) {
}
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 {
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>();
}
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;
}
}
--- /dev/null
+/*
+ * 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;
+ }
+ }
+}
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;
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;
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
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",
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;
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));
}
}
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!");
// 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 {
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);
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) {
}
}
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);
}
}
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();
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;
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();
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();
+ }
+ }
}
import java.io.FilenameFilter;
import org.eclipse.core.runtime.Path;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
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));
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";
}
}
+ 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();
public static String getUserRootstrapPathOfXml(String id) {
String rootstrapPath = getUserRootstrapPath(id);
-
return getRootstrapPathOfXml(rootstrapPath);
}
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();
+ }
}
--- /dev/null
+/*
+ * 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();
+ }
+}
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 :
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;
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;
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);
@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");
@Override
public void widgetDefaultSelected(SelectionEvent e) {
- // Nothing to do
}
-
});
-
+ if (OSChecker.isWindows()) {
+ updateToolbarEnable();
+ }
}
private void createRootstrapTableComposite(Composite parent) {
tableViewer.setLabelProvider(new TableViewerProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
- tableViewer.setInput(RootstrapManager.getRootstraps());
+ tableViewer.setInput(getRootstrapTableInput());
tableViewer.getTable().addSelectionListener(new SelectionListener() {
};
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,
return "x86";
}
}
+
+ private List<PlatformRootstrap> getRootstrapTableInput() {
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getUserRootstraps();
+ } else {
+ return RootstrapManager.getRootstraps();
+ }
+ }
}
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(