id="org.tizen.nativeide.toolchain.sbi.gcc45.platform.base"
isAbstract="false"
name="%Platform.proj.toolchain"
- osList="linux"
+ osList="linux,win32"
superClass="org.tizen.nativeide.toolchain.sbi.gnu.base">
<builder
autoBuildTarget="all"
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;
+import org.tizen.common.util.OSChecker;
public class CommandUtil {
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 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()));
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.createProcess(command, workingDir, newEnv, includeStdErr);
+ } else {
+ return LocalCommandUtil.createProcess(command, workingDir, newEnv, includeStdErr);
}
-
- 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;
+ public static String makeTempDirectory() {
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.makeTempDirectory();
+ } else {
+ return LocalCommandUtil.makeTempDirectory();
}
-
- return temp.getPath();
}
public static boolean clearPlatformTempDir() {
- return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.clearPlatformTempDir();
+ } else {
+ return LocalCommandUtil.clearPlatformTempDir();
+ }
}
public static boolean clearCachingDir() {
- boolean result = FileUtil.recursiveDelete(new File(getCachingDir()));
- return result;
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.clearCachingDir();
+ } else {
+ return LocalCommandUtil.clearCachingDir();
+ }
}
public static boolean clearWorkingDir() {
- boolean result = FileUtil.recursiveDelete(new File(getWorkingDir()));
- return result;
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.clearWorkingDir();
+ } else {
+ return LocalCommandUtil.clearWorkingDir();
+ }
}
public static boolean clearCoredumpDir() {
- boolean result = FileUtil.recursiveDelete(new File(getCoredumpDir()));
- return result;
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.clearCoredumpDir();
+ } else {
+ return LocalCommandUtil.clearCoredumpDir();
+ }
}
public static String getCachingDir() {
- return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
- .toOSString();
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.getCachingDir();
+ } else {
+ return LocalCommandUtil.getCachingDir();
+ }
}
public static String getCachingDir(IProject project) {
- return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
- .append(project.getName()).toOSString();
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.getCachingDir(project);
+ } else {
+ return LocalCommandUtil.getCachingDir(project);
+ }
}
public static String getWorkingDir() {
- return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COMMAND_DIR)
- .toOSString();
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.getWorkingDir();
+ } else {
+ return LocalCommandUtil.getWorkingDir();
+ }
}
public static String getCoredumpDir() {
- return new Path(PlatformFileUtil.getTmpDir()).append(DEFAULT_PLATFORM_COREDUMP_DIR)
- .toOSString();
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.getCoredumpDir();
+ } else {
+ return LocalCommandUtil.getCoredumpDir();
+ }
}
-
-
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);
- }
+ if (OSChecker.isWindows()) {
+ return RemoteCommandUtil.verifySudoPasswd(passwd);
+ } else {
+ return LocalCommandUtil.verifySudoPasswd(passwd);
}
- return result;
}
public static String getRandomNum() {
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.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 LocalCommandUtil {
+
+ public static final Logger logger = LoggerFactory.getLogger(LocalCommandUtil.class);
+
+ 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 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 boolean clearPlatformTempDir() {
+ return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
+ }
+
+ public static String getCachingDir() {
+ return new Path(PlatformFileUtil.getTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_CACHING_DIR)
+ .toOSString();
+ }
+
+ public static String getCachingDir(IProject project) {
+ return new Path(PlatformFileUtil.getTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_CACHING_DIR)
+ .append(project.getName()).toOSString();
+ }
+
+ public static String getWorkingDir() {
+ return new Path(PlatformFileUtil.getTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_COMMAND_DIR)
+ .toOSString();
+ }
+
+ public static String getCoredumpDir() {
+ return new Path(PlatformFileUtil.getTmpDir()).append(CommandUtil.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;
+ }
+}
--- /dev/null
+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 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.nativeplatform.password.SudoPasswdManager;
+
+public class LocalScriptProvider {
+
+ public static final Logger logger = LoggerFactory.getLogger(LocalScriptProvider.class);
+
+ public static synchronized String genCacheChecksumScript(IProject project, String filePaths) {
+ BufferedWriter bw = null;
+ File cacheChecksumScript = null;
+ String cachingDir = CommandUtil.getCachingDir(project);
+ String workingDir = CommandUtil.getWorkingDir();
+ try {
+ FileUtils.mkdirs(new File(workingDir), true);
+ } catch (IOException e1) {
+ logger.error(String.format("Failed to make directory: %s", workingDir), e1);
+ return null;
+ }
+ try {
+ String randomNum = CommandUtil.getRandomNum();
+ String fileName = ScriptProvider.CACHE_CHECKSUM_FILENAME + "_" + randomNum + ScriptProvider.SHELL_EXT;
+ cacheChecksumScript = new File(new Path(workingDir).append(fileName).toOSString());
+ if (!cacheChecksumScript.createNewFile()) {
+ if (!cacheChecksumScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ cacheChecksumScript.getAbsoluteFile()));
+ return null;
+ }
+ if (!cacheChecksumScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ cacheChecksumScript.getAbsoluteFile()));
+ return null;
+ }
+ }
+ bw = new BufferedWriter(new FileWriter(cacheChecksumScript));
+ bw.write("#!/bin/sh -ee");
+ bw.newLine();
+ bw.write(String.format("rm -rf %s/*", cachingDir));
+ bw.newLine();
+ bw.write(String.format("mkdir -p %s", cachingDir));
+ bw.newLine();
+ bw.write(String.format("cd %s", cachingDir));
+ bw.newLine();
+ bw.write(String.format("for file in `ls %s`", filePaths));
+ bw.newLine();
+ bw.write("do");
+ bw.newLine();
+ bw.write(" checksum=`md5sum ${file} | awk '{print $1}'`");
+ bw.newLine();
+ bw.write(" pkgfile=`basename ${file}`");
+ bw.newLine();
+ bw.write(" pkgdir=\"${pkgfile}_${checksum}\"");
+ bw.newLine();
+ bw.write(" rm -rf ${pkgdir}");
+ bw.newLine();
+ bw.write(" mkdir ${pkgdir}");
+ bw.newLine();
+ bw.write(" cd ${pkgdir}");
+ bw.newLine();
+ bw.write(" rpm2cpio ${file} | cpio -idm --quiet");
+ bw.newLine();
+ bw.write(" echo \"key: ${pkgdir}\"");
+ bw.newLine();
+ bw.write(" cd ..");
+ bw.newLine();
+ bw.write(" find ${pkgdir} -type f -printf '\"%p\"\\n' | xargs md5sum");
+ bw.newLine();
+ bw.write("done");
+ cacheChecksumScript.setExecutable(true);
+ } catch (IOException e) {
+ if (cacheChecksumScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ cacheChecksumScript.getAbsoluteFile()), e);
+ cleanUpScript(cacheChecksumScript.getAbsolutePath());
+ }
+ return null;
+ } finally {
+ tryClose(bw);
+ }
+
+ return cacheChecksumScript.getAbsolutePath();
+ }
+
+ // return generate expect script and return script path
+ public static String genSudoExecuteExpectScript(String command) {
+ String passwd = SudoPasswdManager.getSudoPassword();
+ File expectScript = null;
+ File shellScript = null;
+ BufferedWriter bw = null;
+ String workingDir = CommandUtil.getWorkingDir();
+ try {
+ 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 = CommandUtil.getRandomNum();
+ String exitStatusFileName = ScriptProvider.EXIT_VALUE_FILENAME + "_" + randomNum;
+ String expectScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum + ScriptProvider.EXPECT_EXT;
+ String runScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum + ScriptProvider.SHELL_EXT;
+ File exitStatusScript = new File(new Path(workingDir).append(exitStatusFileName)
+ .toOSString());
+ try {
+ // create expect script file
+ expectScript = new File(new Path(workingDir).append(expectScriptName).toOSString());
+ if (!expectScript.createNewFile()) {
+ if (!expectScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ expectScript.getAbsoluteFile()));
+ return null;
+ }
+ if (!expectScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ expectScript.getAbsoluteFile()));
+ return null;
+ }
+ }
+ bw = new BufferedWriter(new FileWriter(expectScript));
+ bw.write("#!/usr/bin/expect --");
+ bw.newLine();
+ bw.write(String.format("spawn sh -c \"%s;echo \\$? > %s\"", command,
+ exitStatusScript.getAbsolutePath()));
+ bw.newLine();
+ bw.write("while (1) {");
+ bw.newLine();
+ bw.write(" expect {");
+ bw.newLine();
+ bw.write(" \"password for\" {");
+ bw.newLine();
+ bw.write(String.format("send \"%s\\r\"", passwd));
+ bw.newLine();
+ bw.write(" }");
+ bw.newLine();
+ bw.write(" eof {");
+ bw.newLine();
+ bw.write(" return");
+ bw.newLine();
+ bw.write(" }");
+ bw.newLine();
+ bw.write(" }");
+ bw.newLine();
+ bw.write("}");
+ bw.newLine();
+ bw.close();
+ expectScript.setExecutable(true);
+
+ shellScript = new File(new Path(workingDir).append(runScriptName).toOSString());
+ if (!shellScript.createNewFile()) {
+ if (!shellScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ shellScript.getAbsoluteFile()));
+ return null;
+ }
+ if (!shellScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ shellScript.getAbsoluteFile()));
+ return null;
+ }
+ }
+ bw = new BufferedWriter(new FileWriter(shellScript));
+ bw.write("#!/bin/bash -ee");
+ bw.newLine();
+ bw.write(expectScript.getAbsolutePath());
+ bw.newLine();
+ bw.write(String.format("EXIT_CODE=`cat %s`", exitStatusScript.getAbsolutePath()));
+ bw.newLine();
+ bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
+ bw.newLine();
+ bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
+ bw.newLine();
+ bw.write(" exit 1");
+ bw.newLine();
+ bw.write("fi");
+ bw.newLine();
+ shellScript.setExecutable(true);
+ } catch (IOException e) {
+ if (shellScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ shellScript.getAbsoluteFile()), e);
+ cleanUpScript(shellScript.getPath());
+ }
+ if (expectScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ expectScript.getAbsoluteFile()), e);
+ cleanUpScript(expectScript.getPath());
+ }
+ return null;
+ } finally {
+ tryClose(bw);
+ }
+
+ // execute script
+ return shellScript.getPath();
+ }
+
+ // return generate shell script and return script path
+ public static String genSudoExecuteScript(String command) {
+ String passwd = SudoPasswdManager.getSudoPassword();
+ File shellScript = null;
+ BufferedWriter bw = null;
+ String workingDir = CommandUtil.getWorkingDir();
+ try {
+ FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
+ } catch (IOException e1) {
+ logger.error(String.format("Failed to make directory: %s", workingDir), e1);
+ return null;
+ }
+ String scriptFile = getSudoAskScript(passwd);
+ if (scriptFile == null) {
+ return null;
+ }
+ String randomNum = CommandUtil.getRandomNum();
+ String exitStatusFileName = ScriptProvider.EXIT_VALUE_FILENAME + "_" + randomNum;
+ String runScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum + ScriptProvider.SHELL_EXT;
+ File exitStatusScript = new File(new Path(workingDir).append(exitStatusFileName)
+ .toOSString());
+ try {
+ shellScript = new File(new Path(workingDir).append(runScriptName).toOSString());
+ if (!shellScript.createNewFile()) {
+ if (!shellScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ shellScript.getAbsoluteFile()));
+ return null;
+ }
+ if (!shellScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ shellScript.getAbsoluteFile()));
+ return null;
+ }
+ }
+ String _command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k %s;echo $? > %s",
+ scriptFile, command, exitStatusScript.getAbsolutePath());
+ bw = new BufferedWriter(new FileWriter(shellScript));
+ bw.write("#!/bin/bash -ee");
+ bw.newLine();
+ bw.write(_command);
+ bw.newLine();
+ bw.write(String.format("EXIT_CODE=`cat %s`", exitStatusScript.getAbsolutePath()));
+ bw.newLine();
+ bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
+ bw.newLine();
+ bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
+ bw.newLine();
+ bw.write(" exit 1");
+ bw.newLine();
+ bw.write("fi");
+ bw.newLine();
+ shellScript.setExecutable(true);
+ } catch (IOException e) {
+ if (shellScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ shellScript.getPath()), e);
+ cleanUpScript(shellScript.getPath());
+ }
+ return null;
+ } finally {
+ tryClose(bw);
+ }
+
+ // execute script
+ return shellScript.getPath();
+ }
+
+ // generate interrupt script for platform debugging and return script path
+ public static String genDebugginInterruptScript(Process process) {
+ String passwd = SudoPasswdManager.getSudoPassword();
+ File interruptScript = null;
+ BufferedWriter bw = null;
+ String workingDir = CommandUtil.getWorkingDir();
+ try {
+ FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
+ } catch (IOException e1) {
+ logger.error(String.format("Failed to make directory: %s", workingDir), e1);
+ e1.printStackTrace();
+ }
+ try {
+ // get process id
+ Field f = process.getClass().getDeclaredField("pid");
+ f.setAccessible(true);
+ String pid = f.get(process).toString();
+
+ // create interrupt script file
+ String randomNum = CommandUtil.getRandomNum();
+ String scriptName = ScriptProvider.DEBUGGING_INTERRUPT_SHELLNAME + "_" + randomNum + ScriptProvider.SHELL_EXT;
+ interruptScript = new File(new Path(workingDir).append(scriptName).toOSString());
+ if (!interruptScript.createNewFile()) {
+ if (!interruptScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ interruptScript.getAbsoluteFile()));
+ throw new IOException();
+ }
+ if (!interruptScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ interruptScript.getAbsoluteFile()));
+ throw new IOException();
+ }
+ }
+ bw = new BufferedWriter(new FileWriter(interruptScript));
+ bw.write("#!/bin/sh");
+ bw.newLine();
+ bw.write("proctree() {");
+ bw.newLine();
+ bw.write(" local _pid=$1");
+ bw.newLine();
+ bw.write(" for _child in $(ps -o pid --no-headers --ppid ${_pid}); do");
+ bw.newLine();
+ bw.write(" proctree ${_child}");
+ bw.newLine();
+ bw.write(" done");
+ bw.newLine();
+ bw.write(" user=`ps -o user --no-headers --pid ${_pid}`");
+ bw.newLine();
+ bw.write(" if [ \"x${user}\" = \"xroot\" ]; then");
+ bw.newLine();
+ bw.write(String.format(" echo \"%s\" | sudo -S kill -SIGINT ${_pid}", passwd));
+ bw.newLine();
+ bw.write(" exit 0");
+ bw.newLine();
+ bw.write(" fi");
+ bw.newLine();
+ bw.write("}");
+ bw.newLine();
+ bw.write(String.format("proctree %s", pid));
+ bw.newLine();
+ bw.write("exit -1");
+ bw.newLine();
+ interruptScript.setExecutable(true);
+ } catch (SecurityException e) {
+ if (interruptScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ interruptScript.getPath()), e);
+ cleanUpScript(interruptScript.getPath());
+ }
+ return null;
+ } catch (NoSuchFieldException e) {
+ logger.error(e.getMessage());
+ return null;
+ } catch (IllegalArgumentException e) {
+ if (interruptScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ interruptScript.getPath()), e);
+ cleanUpScript(interruptScript.getPath());
+ }
+ return null;
+ } catch (IllegalAccessException e) {
+ logger.error(e.getMessage());
+ return null;
+ } catch (IOException e) {
+ if (interruptScript != null) {
+ logger.error(String.format("Failed to write file: %s",
+ interruptScript.getPath()), e);
+ cleanUpScript(interruptScript.getPath());
+ }
+ return null;
+ } finally {
+ tryClose(bw);
+ }
+ return interruptScript.getPath();
+ }
+
+ public static String getSudoAskScript(String passwd) {
+ String workingDir = CommandUtil.getWorkingDir();
+ try {
+ if (!new File(workingDir).exists()) {
+ FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
+ }
+ } catch (IOException e1) {
+ logger.error(String.format("Failed to make directory: %s", workingDir), e1);
+ return null;
+ }
+ BufferedWriter bw = null;
+ File sudoAskScript = null;
+ try {
+ sudoAskScript = new File(new Path(workingDir).append("sudo_ask.sh").toOSString());
+ if (!sudoAskScript.createNewFile()) {
+ if (!sudoAskScript.delete()) {
+ logger.error(String.format("Failed to remove file: %s",
+ sudoAskScript.getAbsolutePath()));
+ return null;
+ }
+ if (!sudoAskScript.createNewFile()) {
+ logger.error(String.format("Failed to create file: %s",
+ sudoAskScript.getAbsolutePath()));
+ return null;
+ }
+ }
+ bw = new BufferedWriter(new FileWriter(sudoAskScript));
+ bw.write("#!/bin/bash");
+ bw.newLine();
+ bw.write(String.format("echo %s", passwd));
+ bw.close();
+ sudoAskScript.setExecutable(true);
+ } catch (IOException e) {
+ if (sudoAskScript != null) {
+ logger.error(
+ String.format("Failed to write file: %s", sudoAskScript.getAbsolutePath()),
+ e);
+ cleanUpScript(sudoAskScript.getPath());
+ }
+ } finally {
+ tryClose(bw);
+ }
+
+ return sudoAskScript.getPath();
+ }
+
+ public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
+ if (scriptFile == null || scriptFile.isEmpty()) {
+ return false;
+ }
+ File script = new File(scriptFile);
+ if (script.exists()) {
+ if (!script.delete()) {
+ logger.error(String.format("Failed to remove script file: %s", scriptFile));
+ return false;
+ }
+ }
+ String scriptFileName = script.getName();
+
+ if (removeExpectScript) {
+ String expectScriptFileName = scriptFileName.substring(0,
+ scriptFileName.lastIndexOf('.'));
+ expectScriptFileName = expectScriptFileName + ScriptProvider.EXPECT_EXT;
+ String expectScriptFile = new Path(scriptFile).removeLastSegments(1)
+ .append(expectScriptFileName)
+ .toOSString();
+ File expectFile = new File(expectScriptFile);
+ if (expectFile.exists()) {
+ if (!expectFile.delete()) {
+ logger.error(String.format("Failed to remove expect script file: %s",
+ expectScriptFile));
+ return false;
+ }
+ }
+ }
+
+ String[] strs = scriptFileName.split("_");
+ String num = strs[strs.length - 1];
+ num = num.substring(0, num.lastIndexOf('.'));
+ String exitValuefileName = ScriptProvider.EXIT_VALUE_FILENAME + "_" + num;
+ String exitStatusFile = new Path(scriptFile).removeLastSegments(1)
+ .append(exitValuefileName)
+ .toOSString();
+ File exitFile = new File(exitStatusFile);
+ if (exitFile.exists()) {
+ if (!exitFile.delete()) {
+ logger.error(String.format("Failed to remove exit status file: %s", exitStatusFile));
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean cleanUpScript(String scriptFile) {
+ return cleanUpScript(scriptFile, false);
+ }
+}
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;
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
return tempDir;
}
- public static boolean clearPlatformTempDir() {
- return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
- }
-
public static boolean clearCachingDir() {
String dir = getCachingDir();
return clearDir(dir);
}
return result;
}
+
+ public static boolean clearPlatformTempDir() {
+ if (RemoteConnectionManager.connected()) {
+ return clearCachingDir() && clearWorkingDir() && clearCoredumpDir();
+ }
+ return false;
+ }
public static String getCachingDir() {
- return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+ return new Path(PlatformFileUtil.getRemoteTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_CACHING_DIR)
.toString();
}
public static String getCachingDir(IProject project) {
- return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_CACHING_DIR)
+ return new Path(PlatformFileUtil.getRemoteTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_CACHING_DIR)
.append(project.getName()).toString();
}
public static String getWorkingDir() {
- return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_COMMAND_DIR)
+ return new Path(PlatformFileUtil.getRemoteTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_COMMAND_DIR)
.toString();
}
public static String getCoredumpDir() {
- return new Path(PlatformFileUtil.getRemoteTmpDir()).append(DEFAULT_PLATFORM_COREDUMP_DIR)
+ return new Path(PlatformFileUtil.getRemoteTmpDir()).append(CommandUtil.DEFAULT_PLATFORM_COREDUMP_DIR)
.toString();
}
if (passwd == null || passwd.isEmpty()) {
return false;
}
- String scriptFile = RemoteScriptProvider.getSudoAskScript(passwd);
+ String scriptFile = ScriptProvider.getSudoAskScript(passwd);
if (scriptFile == null) {
return false;
}
try {
String command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k true",
scriptFile);
- result = RemoteHostCommandLauncher.execute(command);
+ result = HostCommandLauncher.execute(command);
} catch (InterruptedException e) {
e.printStackTrace();
if (scriptFile != null) {
logger.error(String.format("Failed to execute script file: %s",
scriptFile));
- RemoteScriptProvider.cleanUpScript(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);
- }
}
+++ /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;
- }
-}
package org.tizen.nativeplatform.command.launcher;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
+import static org.tizen.common.util.IOUtil.tryClose;
+
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.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;
}
String shellScriptPath = null;
String expectScriptPath = null;
PrintWriter pw = null;
- String workingDir = RemoteCommandUtil.getWorkingDir();
+ String workingDir = CommandUtil.getWorkingDir();
+
+ String randomNum = CommandUtil.getRandomNum();
+ String exitStatusFileName = ScriptProvider.EXIT_VALUE_FILENAME + "_" + randomNum;
+ String expectScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum
+ + ScriptProvider.EXPECT_EXT;
+ String runScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum
+ + ScriptProvider.SHELL_EXT;
+ String exitStatusScriptPath = (new Path(workingDir).append(exitStatusFileName).toString());
- 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());
+ 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.write("}");
pw.write('\n');
pw.close();
-
+
IRemoteItem item = filetool.getFile(expectScriptPath, new NullProgressMonitor());
if (item.exists()) {
item.setExecutable(true);
}
shellScriptPath = new Path(workingDir).append(runScriptName).toString();
- filetool.createFile(shellScriptPath, new NullProgressMonitor());
- out = filetool.getOutputStream(shellScriptPath, IRemoteFileTools.NONE, new NullProgressMonitor());
+ 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('\n');
pw.write("fi");
pw.close();
-
+
item = filetool.getFile(shellScriptPath, new NullProgressMonitor());
if (item.exists()) {
item.setExecutable(true);
}
// execute script
- //return shellScript.getPath();
+ // return shellScript.getPath();
return shellScriptPath;
}
public static String genSudoExecuteScript(String command) {
String passwd = SudoPasswdManager.getSudoPassword();
PrintWriter pw = null;
- String workingDir = RemoteCommandUtil.getWorkingDir();
+ String workingDir = CommandUtil.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 randomNum = CommandUtil.getRandomNum();
+ String exitStatusFileName = ScriptProvider.EXIT_VALUE_FILENAME + "_" + randomNum;
+ String runScriptName = ScriptProvider.RUN_SUDO_SHELLNAME + "_" + randomNum
+ + ScriptProvider.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());
+ 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('\n');
pw.write("fi");
pw.write('\n');
-
+
IRemoteItem item = filetool.getFile(scriptPath, new NullProgressMonitor());
if (item.exists()) {
item.setExecutable(true);
}
public static String getSudoAskScript(String passwd) {
- String workingDir = RemoteCommandUtil.getWorkingDir();
+ String workingDir = CommandUtil.getWorkingDir();
PrintWriter pw = null;
String remoteFilePath = null;
try {
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());
+ OutputStream out = filetool.getOutputStream(remoteFilePath, IRemoteFileTools.NONE,
+ new NullProgressMonitor());
pw = new PrintWriter(out);
pw.write("#!/bin/bash");
pw.write('\n');
}
return remoteFilePath;
}
-
+
public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
if (scriptFile == null || scriptFile.isEmpty()) {
return false;
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));
+ 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);
+ logger.error(String.format("Failed to remove script file: %s", scriptFile), e);
return false;
} catch (RemoteOperationException e) {
e.printStackTrace();
if (removeExpectScript) {
String expectScriptFileName = scriptFileName.substring(0,
scriptFileName.lastIndexOf('.'));
- expectScriptFileName = expectScriptFileName + EXPECT_EXT;
- String expectScriptFile = new Path(scriptFile).removeLastSegments(1).append(expectScriptFileName).toString();
+ expectScriptFileName = expectScriptFileName + ScriptProvider.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());
+ 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));
+ 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) {
+ } catch (RemoteConnectionException e) {
e.printStackTrace();
- logger.error(String.format("Failed to remove expect script file: %s", expectScriptFile), e);
+ 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);
+ 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);
+ 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();
+ String exitValuefileName = ScriptProvider.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));
+ 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());
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 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.nativeplatform.password.SudoPasswdManager;
+import org.tizen.common.util.OSChecker;
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 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
* @return The path of script file.
*/
public static synchronized String genCacheChecksumScript(IProject project, String filePaths) {
- BufferedWriter bw = null;
- File cacheChecksumScript = null;
- String cachingDir = CommandUtil.getCachingDir(project);
- String workingDir = CommandUtil.getWorkingDir();
- try {
- FileUtils.mkdirs(new File(workingDir), true);
- } catch (IOException e1) {
- logger.error(String.format("Failed to make directory: %s", workingDir), e1);
- return null;
- }
- try {
- String randomNum = CommandUtil.getRandomNum();
- String fileName = CACHE_CHECKSUM_FILENAME + "_" + randomNum + SHELL_EXT;
- cacheChecksumScript = new File(new Path(workingDir).append(fileName).toOSString());
- if (!cacheChecksumScript.createNewFile()) {
- if (!cacheChecksumScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- cacheChecksumScript.getAbsoluteFile()));
- return null;
- }
- if (!cacheChecksumScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- cacheChecksumScript.getAbsoluteFile()));
- return null;
- }
- }
- bw = new BufferedWriter(new FileWriter(cacheChecksumScript));
- bw.write("#!/bin/sh -ee");
- bw.newLine();
- bw.write(String.format("rm -rf %s/*", cachingDir));
- bw.newLine();
- bw.write(String.format("mkdir -p %s", cachingDir));
- bw.newLine();
- bw.write(String.format("cd %s", cachingDir));
- bw.newLine();
- bw.write(String.format("for file in `ls %s`", filePaths));
- bw.newLine();
- bw.write("do");
- bw.newLine();
- bw.write(" checksum=`md5sum ${file} | awk '{print $1}'`");
- bw.newLine();
- bw.write(" pkgfile=`basename ${file}`");
- bw.newLine();
- bw.write(" pkgdir=\"${pkgfile}_${checksum}\"");
- bw.newLine();
- bw.write(" rm -rf ${pkgdir}");
- bw.newLine();
- bw.write(" mkdir ${pkgdir}");
- bw.newLine();
- bw.write(" cd ${pkgdir}");
- bw.newLine();
- bw.write(" rpm2cpio ${file} | cpio -idm --quiet");
- bw.newLine();
- bw.write(" echo \"key: ${pkgdir}\"");
- bw.newLine();
- bw.write(" cd ..");
- bw.newLine();
- bw.write(" find ${pkgdir} -type f -printf '\"%p\"\\n' | xargs md5sum");
- bw.newLine();
- bw.write("done");
- cacheChecksumScript.setExecutable(true);
- } catch (IOException e) {
- if (cacheChecksumScript != null) {
- logger.error(String.format("Failed to write file: %s",
- cacheChecksumScript.getAbsoluteFile()), e);
- cleanUpScript(cacheChecksumScript.getAbsolutePath());
- }
- return null;
- } finally {
- tryClose(bw);
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.genCacheChecksumScript(project, filePaths);
+ } else {
+ return LocalScriptProvider.genCacheChecksumScript(project, filePaths);
}
-
- return cacheChecksumScript.getAbsolutePath();
}
// return generate expect script and return script path
public static String genSudoExecuteExpectScript(String command) {
- String passwd = SudoPasswdManager.getSudoPassword();
- File expectScript = null;
- File shellScript = null;
- BufferedWriter bw = null;
- String workingDir = CommandUtil.getWorkingDir();
- try {
- 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 = CommandUtil.getRandomNum();
- String exitStatusFileName = EXIT_VALUE_FILENAME + "_" + randomNum;
- String expectScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + EXPECT_EXT;
- String runScriptName = RUN_SUDO_SHELLNAME + "_" + randomNum + SHELL_EXT;
- File exitStatusScript = new File(new Path(workingDir).append(exitStatusFileName)
- .toOSString());
- try {
- // create expect script file
- expectScript = new File(new Path(workingDir).append(expectScriptName).toOSString());
- if (!expectScript.createNewFile()) {
- if (!expectScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- expectScript.getAbsoluteFile()));
- return null;
- }
- if (!expectScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- expectScript.getAbsoluteFile()));
- return null;
- }
- }
- bw = new BufferedWriter(new FileWriter(expectScript));
- bw.write("#!/usr/bin/expect --");
- bw.newLine();
- bw.write(String.format("spawn sh -c \"%s;echo \\$? > %s\"", command,
- exitStatusScript.getAbsolutePath()));
- bw.newLine();
- bw.write("while (1) {");
- bw.newLine();
- bw.write(" expect {");
- bw.newLine();
- bw.write(" \"password for\" {");
- bw.newLine();
- bw.write(String.format("send \"%s\\r\"", passwd));
- bw.newLine();
- bw.write(" }");
- bw.newLine();
- bw.write(" eof {");
- bw.newLine();
- bw.write(" return");
- bw.newLine();
- bw.write(" }");
- bw.newLine();
- bw.write(" }");
- bw.newLine();
- bw.write("}");
- bw.newLine();
- bw.close();
- expectScript.setExecutable(true);
-
- shellScript = new File(new Path(workingDir).append(runScriptName).toOSString());
- if (!shellScript.createNewFile()) {
- if (!shellScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- shellScript.getAbsoluteFile()));
- return null;
- }
- if (!shellScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- shellScript.getAbsoluteFile()));
- return null;
- }
- }
- bw = new BufferedWriter(new FileWriter(shellScript));
- bw.write("#!/bin/bash -ee");
- bw.newLine();
- bw.write(expectScript.getAbsolutePath());
- bw.newLine();
- bw.write(String.format("EXIT_CODE=`cat %s`", exitStatusScript.getAbsolutePath()));
- bw.newLine();
- bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
- bw.newLine();
- bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
- bw.newLine();
- bw.write(" exit 1");
- bw.newLine();
- bw.write("fi");
- bw.newLine();
- shellScript.setExecutable(true);
- } catch (IOException e) {
- if (shellScript != null) {
- logger.error(String.format("Failed to write file: %s",
- shellScript.getAbsoluteFile()), e);
- cleanUpScript(shellScript.getPath());
- }
- if (expectScript != null) {
- logger.error(String.format("Failed to write file: %s",
- expectScript.getAbsoluteFile()), e);
- cleanUpScript(expectScript.getPath());
- }
- return null;
- } finally {
- tryClose(bw);
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.genSudoExecuteExpectScript(command);
+ } else {
+ return LocalScriptProvider.genSudoExecuteExpectScript(command);
}
-
- // execute script
- return shellScript.getPath();
}
// return generate shell script and return script path
public static String genSudoExecuteScript(String command) {
- String passwd = SudoPasswdManager.getSudoPassword();
- File shellScript = null;
- BufferedWriter bw = null;
- String workingDir = CommandUtil.getWorkingDir();
- try {
- FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
- } catch (IOException e1) {
- logger.error(String.format("Failed to make directory: %s", workingDir), e1);
- return null;
- }
- String scriptFile = getSudoAskScript(passwd);
- if (scriptFile == null) {
- return null;
- }
- 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)
- .toOSString());
- try {
- shellScript = new File(new Path(workingDir).append(runScriptName).toOSString());
- if (!shellScript.createNewFile()) {
- if (!shellScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- shellScript.getAbsoluteFile()));
- return null;
- }
- if (!shellScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- shellScript.getAbsoluteFile()));
- return null;
- }
- }
- String _command = String.format("SUDO_ASKPASS=\"%s\" sudo -A -k %s;echo $? > %s",
- scriptFile, command, exitStatusScript.getAbsolutePath());
- bw = new BufferedWriter(new FileWriter(shellScript));
- bw.write("#!/bin/bash -ee");
- bw.newLine();
- bw.write(_command);
- bw.newLine();
- bw.write(String.format("EXIT_CODE=`cat %s`", exitStatusScript.getAbsolutePath()));
- bw.newLine();
- bw.write("if [ \"$EXIT_CODE\" != \"0\" ]; then");
- bw.newLine();
- bw.write(" echo \"EXIT CODE=${EXIT_CODE}\" >&2");
- bw.newLine();
- bw.write(" exit 1");
- bw.newLine();
- bw.write("fi");
- bw.newLine();
- shellScript.setExecutable(true);
- } catch (IOException e) {
- if (shellScript != null) {
- logger.error(String.format("Failed to write file: %s",
- shellScript.getPath()), e);
- cleanUpScript(shellScript.getPath());
- }
- return null;
- } finally {
- tryClose(bw);
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.genSudoExecuteScript(command);
+ } else {
+ return LocalScriptProvider.genSudoExecuteScript(command);
}
-
- // execute script
- return shellScript.getPath();
}
// generate interrupt script for platform debugging and return script path
public static String genDebugginInterruptScript(Process process) {
- String passwd = SudoPasswdManager.getSudoPassword();
- File interruptScript = null;
- BufferedWriter bw = null;
- String workingDir = CommandUtil.getWorkingDir();
- try {
- FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
- } catch (IOException e1) {
- logger.error(String.format("Failed to make directory: %s", workingDir), e1);
- e1.printStackTrace();
- }
- try {
- // get process id
- Field f = process.getClass().getDeclaredField("pid");
- f.setAccessible(true);
- String pid = f.get(process).toString();
-
- // create interrupt script file
- String randomNum = CommandUtil.getRandomNum();
- String scriptName = DEBUGGING_INTERRUPT_SHELLNAME + "_" + randomNum + SHELL_EXT;
- interruptScript = new File(new Path(workingDir).append(scriptName).toOSString());
- if (!interruptScript.createNewFile()) {
- if (!interruptScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- interruptScript.getAbsoluteFile()));
- throw new IOException();
- }
- if (!interruptScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- interruptScript.getAbsoluteFile()));
- throw new IOException();
- }
- }
- bw = new BufferedWriter(new FileWriter(interruptScript));
- bw.write("#!/bin/sh");
- bw.newLine();
- bw.write("proctree() {");
- bw.newLine();
- bw.write(" local _pid=$1");
- bw.newLine();
- bw.write(" for _child in $(ps -o pid --no-headers --ppid ${_pid}); do");
- bw.newLine();
- bw.write(" proctree ${_child}");
- bw.newLine();
- bw.write(" done");
- bw.newLine();
- bw.write(" user=`ps -o user --no-headers --pid ${_pid}`");
- bw.newLine();
- bw.write(" if [ \"x${user}\" = \"xroot\" ]; then");
- bw.newLine();
- bw.write(String.format(" echo \"%s\" | sudo -S kill -SIGINT ${_pid}", passwd));
- bw.newLine();
- bw.write(" exit 0");
- bw.newLine();
- bw.write(" fi");
- bw.newLine();
- bw.write("}");
- bw.newLine();
- bw.write(String.format("proctree %s", pid));
- bw.newLine();
- bw.write("exit -1");
- bw.newLine();
- interruptScript.setExecutable(true);
- } catch (SecurityException e) {
- if (interruptScript != null) {
- logger.error(String.format("Failed to write file: %s",
- interruptScript.getPath()), e);
- cleanUpScript(interruptScript.getPath());
- }
- return null;
- } catch (NoSuchFieldException e) {
- logger.error(e.getMessage());
- return null;
- } catch (IllegalArgumentException e) {
- if (interruptScript != null) {
- logger.error(String.format("Failed to write file: %s",
- interruptScript.getPath()), e);
- cleanUpScript(interruptScript.getPath());
- }
- return null;
- } catch (IllegalAccessException e) {
- logger.error(e.getMessage());
- return null;
- } catch (IOException e) {
- if (interruptScript != null) {
- logger.error(String.format("Failed to write file: %s",
- interruptScript.getPath()), e);
- cleanUpScript(interruptScript.getPath());
- }
- return null;
- } finally {
- tryClose(bw);
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.genDebugginInterruptScript(process);
+ } else {
+ return LocalScriptProvider.genDebugginInterruptScript(process);
}
- return interruptScript.getPath();
}
public static String getSudoAskScript(String passwd) {
- String workingDir = CommandUtil.getWorkingDir();
- try {
- if (!new File(workingDir).exists()) {
- FileUtils.mkdirs(new File(CommandUtil.getWorkingDir()), true);
- }
- } catch (IOException e1) {
- logger.error(String.format("Failed to make directory: %s", workingDir), e1);
- return null;
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.getSudoAskScript(passwd);
+ } else {
+ return LocalScriptProvider.getSudoAskScript(passwd);
}
- BufferedWriter bw = null;
- File sudoAskScript = null;
- try {
- sudoAskScript = new File(new Path(workingDir).append("sudo_ask.sh").toOSString());
- if (!sudoAskScript.createNewFile()) {
- if (!sudoAskScript.delete()) {
- logger.error(String.format("Failed to remove file: %s",
- sudoAskScript.getAbsolutePath()));
- return null;
- }
- if (!sudoAskScript.createNewFile()) {
- logger.error(String.format("Failed to create file: %s",
- sudoAskScript.getAbsolutePath()));
- return null;
- }
- }
- bw = new BufferedWriter(new FileWriter(sudoAskScript));
- bw.write("#!/bin/bash");
- bw.newLine();
- bw.write(String.format("echo %s", passwd));
- bw.close();
- sudoAskScript.setExecutable(true);
- } catch (IOException e) {
- if (sudoAskScript != null) {
- logger.error(
- String.format("Failed to write file: %s", sudoAskScript.getAbsolutePath()),
- e);
- cleanUpScript(sudoAskScript.getPath());
- }
- } finally {
- tryClose(bw);
- }
-
- return sudoAskScript.getPath();
}
-
- public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
- if (scriptFile == null || scriptFile.isEmpty()) {
- return false;
- }
- File script = new File(scriptFile);
- if (script.exists()) {
- if (!script.delete()) {
- logger.error(String.format("Failed to remove script file: %s", scriptFile));
- return false;
- }
- }
- String scriptFileName = script.getName();
-
- if (removeExpectScript) {
- String expectScriptFileName = scriptFileName.substring(0,
- scriptFileName.lastIndexOf('.'));
- expectScriptFileName = expectScriptFileName + EXPECT_EXT;
- String expectScriptFile = new Path(scriptFile).removeLastSegments(1)
- .append(expectScriptFileName)
- .toOSString();
- File expectFile = new File(expectScriptFile);
- if (expectFile.exists()) {
- if (!expectFile.delete()) {
- logger.error(String.format("Failed to remove expect script file: %s",
- expectScriptFile));
- 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)
- .toOSString();
- File exitFile = new File(exitStatusFile);
- if (exitFile.exists()) {
- if (!exitFile.delete()) {
- logger.error(String.format("Failed to remove exit status file: %s", exitStatusFile));
- return false;
- }
+ public static boolean cleanUpScript(String scriptFile, boolean removeExpectScript) {
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.cleanUpScript(scriptFile, removeExpectScript);
+ } else {
+ return LocalScriptProvider.cleanUpScript(scriptFile, removeExpectScript);
}
- return true;
}
public static boolean cleanUpScript(String scriptFile) {
- return cleanUpScript(scriptFile, false);
+ if (OSChecker.isWindows()) {
+ return RemoteScriptProvider.cleanUpScript(scriptFile, false);
+ } else {
+ return LocalScriptProvider.cleanUpScript(scriptFile, false);
+ }
}
}
import org.tizen.nativeplatform.pkg.commander.IPkgModelMaker;
import org.tizen.nativeplatform.pkg.commander.factory.PkgModelMakerFactory;
import org.tizen.nativeplatform.pkg.model.IPackage;
+import org.tizen.nativeplatform.rootstrap.LocalRootstrapManager;
import org.tizen.nativeplatform.rootstrap.RootstrapManager;
import org.tizen.nativeplatform.ui.adapter.ExtraPkgTableViewerAdapter;
import org.tizen.nativeplatform.ui.listener.ExtraPkgTableHoverListener;
import org.slf4j.LoggerFactory;
import org.tizen.nativeplatform.launch.wizards.PlatformCoredumpLaunchWizard;
import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget;
+import org.tizen.nativeplatform.rootstrap.LocalRootstrapManager;
import org.tizen.nativeplatform.rootstrap.RootstrapManager;
import org.tizen.nativeplatform.rootstrap.SnapshotURLParser;
import org.tizen.nativeplatform.views.model.ICheckTreeItem;
rootstraps.clear();
if (wizard.getCoredumpModel() != null) {
if (wizard.getCoredumpModel().isX86coredump()) {
- for (PlatformRootstrap r : RootstrapManager
- .getRootstraps(RootstrapManager.LIST_X86)) {
+ for (PlatformRootstrap r : RootstrapManager.getRootstraps(LocalRootstrapManager.LIST_X86)) {
if (r.isInitialized()) {
rootstraps.add(r);
}
}
} else if (wizard.getCoredumpModel().isArmcoredump()) {
- for (PlatformRootstrap r : RootstrapManager
- .getRootstraps(RootstrapManager.LIST_ARM)) {
+ for (PlatformRootstrap r : RootstrapManager.getRootstraps(LocalRootstrapManager.LIST_ARM)) {
if (r.isInitialized()) {
rootstraps.add(r);
}
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.Wizard;
import org.tizen.common.util.DialogUtil;
-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 = false;
- if (OSChecker.isWindows()) {
- result = CommandUtil.verifySudoPasswd(password);
- } else {
- result = RemoteCommandUtil.verifySudoPasswd(password);
- }
+ boolean result = CommandUtil.verifySudoPasswd(password);
if (!result) {
throw new InterruptedException(resources
.getString("Msg.Failed.Verify.Passwd"));
package org.tizen.nativeplatform.pkg.commander;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+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.tizen.common.util.OSChecker;
import org.tizen.nativecommon.build.SmartBuildInterface;
import org.tizen.nativeplatform.pkg.commander.deb.DebCommanderHost;
import org.tizen.nativeplatform.pkg.commander.rpm.RpmCommanderDevice;
import org.tizen.nativeplatform.pkg.commander.rpm.RpmCommanderHost;
+import org.tizen.nativeplatform.pkg.commander.rpm.RpmCommanderRemoteHost;
+import org.tizen.nativeplatform.pkg.commander.rpm.RpmCommanderRemoteRootstrap;
import org.tizen.nativeplatform.pkg.commander.rpm.RpmCommanderRootstrap;
import org.tizen.nativeplatform.preferences.PreferencesManager;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
import org.tizen.nativeplatform.types.CmdTargetTypes;
import org.tizen.nativeplatform.types.PkgTypes;
import org.tizen.nativeplatform.views.model.PlatformRootstrap;
setRootstrap(rootstrap);
http_proxy = PreferencesManager.getHttpProxyURL();
}
-
+
public void setPkgType(PkgTypes type) {
this.type = type;
}
public PlatformRootstrap getRootstrap() {
return rootstrap;
}
-
+
public PkgTypes getPkgType() {
- return type;
+ return type;
}
-
+
public IPkgCommander getCommander(CmdTargetTypes type) {
return getCommander(type, true);
}
-
+
public IPkgCommander getCommander(CmdTargetTypes type, boolean useConsoleLog) {
if (type.equals(CmdTargetTypes.HOST)) {
return getHostCommander(useConsoleLog);
}
return null;
}
-
+
public IPkgCommander getHostCommander(boolean useConsoleLog) {
if (hsCommander == null) {
if (type.equals(PkgTypes.RPM)) {
- hsCommander = new RpmCommanderHost(useConsoleLog);
- hsCommander.setHttpProxy(http_proxy);
+ if (OSChecker.isWindows()) {
+ hsCommander = new RpmCommanderRemoteHost(useConsoleLog);
+ } else {
+ hsCommander = new RpmCommanderHost(useConsoleLog);
+ hsCommander.setHttpProxy(http_proxy);
+ }
} else if (type.equals(PkgTypes.DPKG)) {
hsCommander = new DebCommanderHost();
}
public IPkgCommander getHostCommander() {
return getHostCommander(true);
}
-
+
public IPkgCommander getDeviceCommander(boolean useConsoleLog) {
if (dvCommander == null) {
if (type.equals(PkgTypes.RPM)) {
public IPkgCommander getDeviceCommander() {
return getDeviceCommander(true);
}
-
+
public IPkgCommander getRootstrapCommander(boolean useConsoleLog) {
if (rtCommander == null) {
if (type.equals(PkgTypes.RPM)) {
if (isSetRootstrap()) {
IPath basePath = rootstrap.getPath();
- String rootPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(
- basePath);
- rtCommander = new RpmCommanderRootstrap(new Path(rootPath));
- rtCommander.setHttpProxy(http_proxy);
+ if (OSChecker.isWindows()) {
+ String rootstrapBasepath = basePath.append("local").append("BUILD-ROOTS")
+ .toString();
+ try {
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools()
+ .getFileTool();
+ boolean exists = filetool.hasDirectory(rootstrapBasepath.toString(),
+ new NullProgressMonitor());
+ if (exists) {
+ IRemoteItem[] items = filetool.listItems(rootstrapBasepath,
+ new NullProgressMonitor());
+ for (IRemoteItem item : items) {
+ if (item.isDirectory()) {
+ String scratchPath = item.getPath();
+ String dirname = new Path(scratchPath).lastSegment()
+ .toString();
+ if (dirname.startsWith("scratch.")) {
+ rtCommander = new RpmCommanderRemoteRootstrap(new Path(
+ scratchPath));
+ }
+ }
+ }
+ }
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ } catch (CancelException e) {
+ e.printStackTrace();
+ }
+ } else {
+ String rootPath = SmartBuildInterface.getInstance()
+ .getPlatformRootstrapPath(basePath);
+ rtCommander = new RpmCommanderRootstrap(new Path(rootPath));
+ rtCommander.setHttpProxy(http_proxy);
+ }
}
} else if (type.equals(PkgTypes.DPKG)) {
return null;
package org.tizen.nativeplatform.pkg.commander.rpm;
-import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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;
public PackageManagerOutputReceiver getOutputReceiver() {
return rec;
}
-
+
public void cancelExecution() {
if (rec != null) {
rec.setCancel(true);
}
public String getArchFromFile(String filePath) {
- String result = "";
- if (!new File(filePath).exists()) {
- return result;
- }
- String command = RpmTool.fileArchCommand(filePath);
- try {
- result = HostCommandLauncher.executeOutput(command);
- // result = hostExecute(command);
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- String[] name = result.split(",");
- if (name.length > 0) {
- return name[0];
- } else {
- return "";
- }
+ return "";
}
public String getNameFromFile(String filePath) {
- String result = "";
- if (!new File(filePath).exists()) {
- return result;
- }
- String command = RpmTool.fileNameCommand(filePath);
- try {
- result = HostCommandLauncher.executeOutput(command);
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- String[] name = result.split(",");
- if (name.length > 0) {
- return name[0];
- } else {
- return "";
- }
+ return "";
}
public String getVerFromFile(String filePath) {
- String result = "";
- if (!new File(filePath).exists()) {
- return result;
- }
- String command = RpmTool.fileFullVerCommand(filePath);
- try {
- result = HostCommandLauncher.executeOutput(command);
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- String[] name = result.split(",");
- if (name.length > 0) {
- return name[0];
- } else {
- return "";
- }
+ return "";
}
public String[] getArch(String pkg) {
@Override
public boolean is80386File(String filePath) {
- String result = "";
- if (!new File(filePath).exists()) {
- return false;
- }
- String command = String.format("file %s", filePath);
- try {
- result = HostCommandLauncher.executeOutput(command);
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- if (result.contains("80386")) {
- return true;
- }
return false;
}
@Override
public boolean isArmFile(String filePath) {
- String result = "";
- if (!new File(filePath).exists()) {
- return false;
- }
- String command = String.format("file %s", filePath);
- try {
- result = HostCommandLauncher.executeOutput(command);
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- if (result.contains("ARM")) {
- return true;
- }
return false;
}
/*
* Following error can be occurred in case of using zypper.
*
- * 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
+ * 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 (monitor != null) {
monitor.worked(1);
origStatus.setInstallInfo(PkgInstallTypes.INSTALLED);
}
/*
- * Package pkg = pkgMap.get(name);
- * if (pkg == null) {
- * pkgMap.put(name, new Package(name, version, Package.INSTALLINFO.INSTALLED, "", arch));
- * } else {
- * pkg.setInstalledVersion(version);
- * pkg.setInstallInfo(Package.INSTALLINFO.INSTALLED);
- * }
+ * Package pkg = pkgMap.get(name); if (pkg == null) {
+ * pkgMap.put(name, new Package(name, version,
+ * Package.INSTALLINFO.INSTALLED, "", arch)); } else {
+ * pkg.setInstalledVersion(version);
+ * pkg.setInstallInfo(Package.INSTALLINFO.INSTALLED); }
*/
}
}
}
if (result != null) {
printResultLog(String.format("Get repository list: %d", result.size()));
- //printResultLog(result.toString());
+ // printResultLog(result.toString());
} else {
printResultLog("Failed to get repository list");
}
}
return ret;
}
-
+
public String canonicalizePath(String path) {
String command = String.format(CMD_READLINK, path);
PackageManagerOutputReceiver hrec = getNewOuputReceiver();
}
return result;
}
-
+
private Map<String, PkgStatus> getWhatProvidesWithRpm(String capability) {
String command = makeCommand(RpmTool.whatProvideCommand(capability));
- ICommandStatus status = execute(command, null, true);
+ ICommandStatus status = execute(command, null, true);
Map<String, PkgStatus> result = new HashMap<String, PkgStatus>();
if (status == null || !status.isOk()) {
return result;
continue;
}
String key = s.substring(0, index).trim();
- String value = s.substring(index+1).trim();
+ String value = s.substring(index + 1).trim();
if (key.equals("Name")) {
pkgName = value;
} else if (key.equals("Version")) {
if (!value.isEmpty()) {
pkgVersion += "-" + value;
}
- }
- }
+ }
+ }
}
Package pkg = new Package(pkgName, pkgVersion, pkgArchitecture);
PkgStatus newStatus = new PkgStatus(pkg);
result.put(pkgName, newStatus);
return result;
}
-
+
@Override
public Map<String, PkgStatus> getWhatProvides(String capability, TOOL type) {
if (type == TOOL.ZYPPER) {
protected void pringInfoLog(String log) {
printLog(getInfoString(log));
}
-
+
protected void activateConsole() {
if (rec != null) {
rec.getMsgConsoleStream().getConsole().activate();
return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
}
SyncResult syncResult = syncService.push(srcPath,
- device.getFileEntry(pathOnDevice.removeLastSegments(1).toOSString()));// Fixxed
+ device.getFileEntry(pathOnDevice.removeLastSegments(1).toString()));// Fixxed
if (!syncResult.isOk()) {
return new CommandStatus(IStatus.ERROR, "", syncResult.getMessage(), null);
}
value.add(pathOnDevice.toString());
- printResultLog(String.format("[RDS] Copied file: %s \n " +
- "-> %s", srcPath, dstPath));
+ printResultLog(String.format("[RDS] Copied file: %s \n " + "-> %s", srcPath, dstPath));
return new CommandStatus(IStatus.OK, value, null);
}
} catch (IOException e) {
return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
}
- SyncResult syncResult = syncService.push(filePath, device.getFileEntry(TMP_DIR));// Fixxed
+ SyncResult syncResult = syncService.push(filePath, device.getFileEntry(TMP_DIR));// Fixxed
if (!syncResult.isOk()) {
return new CommandStatus(IStatus.ERROR, "", syncResult.getMessage(), null);
}
String msgLog = status.getException().toString();
String log = String.format("[Exception]%s:%s", cmdLog, msgLog);
printResultLog(log);
- }
+ }
return status;
}
return execute(command, rec, monitor, true);
}
- protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
- int timeout, IProgressMonitor monitor) {
+ protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec, int timeout,
+ IProgressMonitor monitor) {
return execute(command, rec, timeout, monitor, true);
}
return status;
}
- protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec,
- int timeout, IProgressMonitor monitor, boolean printlog) {
+ protected ICommandStatus execute(String command, PackageManagerOutputReceiver rec, int timeout,
+ IProgressMonitor monitor, boolean printlog) {
if (printlog) {
printCommandLog(command);
}
package org.tizen.nativeplatform.pkg.commander.rpm;
+import java.io.File;
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.model.PkgStatus;
+import org.tizen.nativeplatform.pkg.tools.RpmTool;
import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
import org.tizen.nativeplatform.types.CmdTargetTypes;
return null;
}
+ public String getArchFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String command = RpmTool.fileArchCommand(filePath);
+ try {
+ result = HostCommandLauncher.executeOutput(command);
+ // result = hostExecute(command);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
+ public String getNameFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String command = RpmTool.fileNameCommand(filePath);
+ try {
+ result = HostCommandLauncher.executeOutput(command);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
+ public String getVerFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String command = RpmTool.fileFullVerCommand(filePath);
+ try {
+ result = HostCommandLauncher.executeOutput(command);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
+ @Override
+ public boolean is80386File(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return false;
+ }
+ String command = String.format("file %s", filePath);
+ try {
+ result = HostCommandLauncher.executeOutput(command);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+ if (result.contains("80386")) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isArmFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return false;
+ }
+ String command = String.format("file %s", filePath);
+ try {
+ result = HostCommandLauncher.executeOutput(command);
+ } catch (InterruptedException e) {
+ logger.error(e.getMessage(), e);
+ }
+ if (result.contains("ARM")) {
+ return true;
+ }
+ return false;
+ }
+
@Override
public ICommandStatus makeDir(String path) {
return null;
package org.tizen.nativeplatform.pkg.commander.rpm;
+import java.io.File;
import java.util.Map;
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.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
+import org.tizen.common.util.FileUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
import org.tizen.nativeplatform.pkg.model.PkgStatus;
+import org.tizen.nativeplatform.pkg.tools.RpmTool;
import org.tizen.nativeplatform.pkgmgr.PackageManagerOutputReceiver;
+import org.tizen.nativeplatform.remote.connection.RemoteConnectionManager;
import org.tizen.nativeplatform.types.CmdTargetTypes;
public class RpmCommanderRemoteHost extends RpmCommanderCommon {
return null;
}
+ public String getArchFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String filename = FileUtil.getFileNameFromPath(filePath);
+ if (!RemoteConnectionManager.connected()) {
+ return "";
+ }
+ String homeDir = RemoteConnectionManager.getRemoteTools().getUserhome();
+ String remotepath = new Path(homeDir).append("tmp").append(filename).toString();
+ try {
+ IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+ copytool.uploadFileToFile(filePath, remotepath);
+ String command = RpmTool.fileArchCommand(remotepath);
+ result = HostCommandLauncher.executeOutput(command);
+ filetool.removeFile(remotepath, new NullProgressMonitor());
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (CancelException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ }
+
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
+ public String getNameFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String filename = FileUtil.getFileNameFromPath(filePath);
+ if (!RemoteConnectionManager.connected()) {
+ return "";
+ }
+ String homeDir = RemoteConnectionManager.getRemoteTools().getUserhome();
+ String remotepath = new Path(homeDir).append("tmp").append(filename).toString();
+ try {
+ IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+ copytool.uploadFileToFile(filePath, remotepath);
+ String command = RpmTool.fileNameCommand(remotepath);
+ result = HostCommandLauncher.executeOutput(command);
+ filetool.removeFile(remotepath, new NullProgressMonitor());
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (CancelException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ }
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
+ public String getVerFromFile(String filePath) {
+ String result = "";
+ if (!new File(filePath).exists()) {
+ return result;
+ }
+ String filename = FileUtil.getFileNameFromPath(filePath);
+ if (!RemoteConnectionManager.connected()) {
+ return "";
+ }
+ String homeDir = RemoteConnectionManager.getRemoteTools().getUserhome();
+ String remotepath = new Path(homeDir).append("tmp").append(filename).toString();
+ try {
+ IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+ copytool.uploadFileToFile(filePath, remotepath);
+ String command = RpmTool.fileFullVerCommand(remotepath);
+ result = HostCommandLauncher.executeOutput(command);
+ filetool.removeFile(remotepath, new NullProgressMonitor());
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (CancelException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ logger.error(e.getMessage(), e);
+ }
+ String[] name = result.split(",");
+ if (name.length > 0) {
+ return name[0];
+ } else {
+ return "";
+ }
+ }
+
@Override
public ICommandStatus makeDir(String path) {
return null;
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.eclipse.ptp.remotetools.core.IRemoteCopyTools;
+import org.eclipse.ptp.remotetools.exception.CancelException;
+import org.eclipse.ptp.remotetools.exception.RemoteConnectionException;
+import org.eclipse.ptp.remotetools.exception.RemoteOperationException;
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.remote.connection.RemoteConnectionManager;
-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 class RpmCommanderRemoteRootstrap extends RpmCommanderRootstrap {
public RpmCommanderRemoteRootstrap(IPath rootPath) {
- super(CONSOLE_NAME);
- this.rootPath = rootPath;
- actionBeforeUsingZypper();
+ super(rootPath);
}
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);
- }
+ super(rootPath, useConsoleLog);
}
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) {
+ IRemoteCopyTools copytool = RemoteConnectionManager.getRemoteTools().getCopyTool();
+ copytool.uploadFileToFile(filePath, toFilePath.toString());
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
+ } catch (CancelException e) {
+ e.printStackTrace();
return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
}
- value.add(pathOnRootstrap.toOSString());
+ value.add(pathOnRootstrap.toString());
}
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;
- }
}
public class RpmCommanderRootstrap 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;
+ protected static final String CONSOLE_NAME = "Rootstrap Internal";
+ protected static final String REMOVE_PKGS = "rpm-x86-arm";
+ protected final CmdTargetTypes CMD_TYPE = CmdTargetTypes.ROOTSTRAP;
- private IPath rootPath;
+ protected IPath rootPath;
public RpmCommanderRootstrap(IPath rootPath) {
super(CONSOLE_NAME);
protected void actionBeforeUsingZypper() {
/*
- * (with --nodeps --force)
- * Error: Subprocess failed.
- * Error: RPM failed:
+ * (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
IPath pathOnRootstrap = new Path(TMP_DIR).append(filename);
IPath toFilePath = rootPath.append(pathOnRootstrap);
try {
- FileUtil.copyTo(filePath, toFilePath.toOSString());
+ FileUtil.copyTo(filePath, toFilePath.toString());
} catch (IOException e) {
return new CommandStatus(IStatus.ERROR, "", e.getMessage(), e);
}
- value.add(pathOnRootstrap.toOSString());
+ value.add(pathOnRootstrap.toString());
}
return new CommandStatus(IStatus.OK, value, null);
}
}
private String getChrootedCommand(String cmd) {
- return String.format("chroot %s sh -c \"%s\"", rootPath.toOSString(), cmd);
+ return String.format("chroot %s sh -c \"%s\"", rootPath.toString(), cmd);
}
protected PackageManagerOutputReceiver getNewOuputReceiver() {
IPath toFilePath = rootPath.append(pathOnRootstrap);
String passwd = SudoPasswdManager.getSudoPassword();
String command = String.format("echo %s | sudo -S cp %s %s", passwd, srcPath,
- toFilePath.toOSString());
+ toFilePath.toString());
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());
+ toFilePath.toString()));
+ value.add(pathOnRootstrap.toString());
return new CommandStatus(IStatus.OK, value, null);
}
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());
+ String command = String.format("echo %s | sudo -S rm -f %s", passwd, toFilePath.toString());
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());
+ printResultLog(String.format("Removed file: %s", toFilePath.toString()));
+ value.add(pathOnRootstrap.toString());
return new CommandStatus(IStatus.OK, value, null);
}
IPath toFilePath = rootPath.append(pathOnRootstrap);
String passwd = SudoPasswdManager.getSudoPassword();
String command = String.format("echo %s | sudo -S mkdir -p %s", passwd,
- toFilePath.toOSString());
+ toFilePath.toString());
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());
+ printResultLog(String.format("Make dir: %s", toFilePath.toString()));
+ value.add(pathOnRootstrap.toString());
return new CommandStatus(IStatus.OK, value, null);
}
public ICommandStatus getMd5Checksum(String path) {
String command = String.format("md5sum %s", path);
ICommandStatus status;
- status = RootstrapCommandLauncher.execute(command, rootPath.toOSString(), null, null);
+ status = RootstrapCommandLauncher.execute(command, rootPath.toString(), null, null);
if (status.isOk()) {
printResultLog(String.format("[RDS] Checked checksum: %s", path));
}
private PkgCommandTarget target = null;
public BuildsystemTab(Shell shell, TabFolder folder, PkgCommandTarget target) {
- super(shell, folder, target.getCommander(CmdTargetTypes.ROOTSTRAP));
+ super(shell, folder, target.getCommander(CmdTargetTypes.HOST), target
+ .getCommander(CmdTargetTypes.ROOTSTRAP));
this.target = target;
}
package org.tizen.nativeplatform.pkgmgr.ui;
-import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
protected static final ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_NAME);
protected IPkgCommander commander = null;
+ protected IPkgCommander hostCommander = null;
- public CommonTab(Shell shell, TabFolder folder, IPkgCommander commander) {
+ public CommonTab(Shell shell, TabFolder folder, IPkgCommander hostCommander,
+ IPkgCommander commander) {
this.shell = shell;
this.folder = folder;
this.commander = commander;
+ this.hostCommander = hostCommander;
}
abstract protected CopyOnWriteArrayList<Repository> getRepositoryList();
String[] fileNames = fd.getFileNames();
final List<String> selectedFiles = new ArrayList<String>();
for (String fileName : fileNames) {
- selectedFiles.add(new File(firstFilePath).getParent() + "/" + fileName);
+ IPath path = new Path(firstFilePath).removeLastSegments(1).append(fileName);
+ selectedFiles.add(path.toString());
}
handleInstallLocalPackageButton(selectedFiles);
if (localPackageFileList != null) {
List<String> localPackageNameList = new ArrayList<String>();
for (String filePath : localPackageFileList) {
- localPackageNameList.add(commander.getNameFromFile(filePath));
+
+ localPackageNameList.add(hostCommander.getNameFromFile(filePath));
}
for (PkgStatus pkg : getPackageList()) {
String pkgName = pkg.getPackage().getName();
private List<Repository> repositories = new ArrayList<Repository>();
public DeviceTab(Shell shell, TabFolder folder, PkgCommandTarget target) {
- super(shell, folder, target.getCommander(CmdTargetTypes.DEVICE));
+ super(shell, folder, target.getCommander(CmdTargetTypes.HOST), target
+ .getCommander(CmdTargetTypes.DEVICE));
this.target = target;
repositories.clear();
repositories.addAll(getRepositoryList());
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) {
+
+ 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) {
+
+ public static boolean createConnection(String host, String user, String pass,
+ String connectionName, IProgressMonitor monitor) {
try {
IRemoteConnection conn = getConnection(connectionName);
if (conn == null) {
conn.open(new SubProgressMonitor(monitor, 1));
monitor.subTask("Setting remote tools...");
String userhome = conn.getWorkingDirectory();
- RemoteToolsConnection toolsConn = (RemoteToolsConnection)conn;
+ RemoteToolsConnection toolsConn = (RemoteToolsConnection) conn;
IRemoteExecutionManager execMgr = toolsConn.createExecutionManager();
RemoteTools remoteTools = new RemoteTools(host, user, pass, userhome, execMgr);
monitor.worked(1);
connectionMap.put(connectionName, remoteTools);
+ } else {
+ RemoteTools remoteTools = connectionMap.get(connectionName);
+ if (remoteTools == null) {
+ monitor.beginTask("Reconnectiong...", 1);
+ conn.setAddress(host);
+ conn.setUsername(user);
+ conn.setPassword(pass);
+ if (!conn.isOpen()) {
+ conn.open(new SubProgressMonitor(monitor, 1));
+ }
+ String userhome = conn.getWorkingDirectory();
+ RemoteToolsConnection toolsConn = (RemoteToolsConnection) conn;
+ IRemoteExecutionManager execMgr = toolsConn.createExecutionManager();
+ remoteTools = new RemoteTools(host, user, pass, userhome, execMgr);
+ connectionMap.put(connectionName, remoteTools);
+ }
}
} catch (org.eclipse.ptp.remotetools.exception.RemoteConnectionException e) {
e.printStackTrace();
}
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) {
connectionMap.remove(name);
}
}
-
+
private static void closeConnection(String name) {
IRemoteConnection conn = getConnection(name);
if (conn != null) {
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();
}
return manager;
}
-
+
public static IRemoteConnection getConnection(String name) {
IRemoteConnectionManager manager = getConnectionManager();
if (manager != null) {
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;
if (proxyInfo != null) {
String protocol = proxyInfo[0];
String host = proxyInfo[1];
- String port = proxyInfo[2];
+ 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);
}
if (rootstrapDir.exists()) {
- if (!HostCommandLauncher.executeSudoWithExpect(command, rootstrapDir.getParent(), env,
- "Platform Internal", monitor)) {
+ if (!HostCommandLauncher.executeSudoWithExpect(command, rootstrapDir.getParent(),
+ env, "Platform Internal", monitor)) {
return false;
}
} else {
// copy
String rootstrapBasePath = rootstrapDir.getParent();
HostCommandLauncher.execute(String.format("mkdir -p %s", rootstrapBasePath));
- HostCommandLauncher.executeSudo(String.format("sudo -S mv %s/%s %s/", tempDirPath, id,
- 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();
+ tempDirPath = CommandUtil.makeTempDirectory();
latestTempRootstrap = new PlatformRootstrap(id, id, arch, tempDirPath, null, "", false);
// use rogen
if (proxyInfo != null) {
String protocol = proxyInfo[0];
String host = proxyInfo[1];
- String port = proxyInfo[2];
+ 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);
boolean exists = false;
try {
- exists = RemoteConnectionManager.getRemoteTools().getFileTool().hasDirectory(rootstrapDir.toString(), new NullProgressMonitor());
+ exists = RemoteConnectionManager.getRemoteTools().getFileTool()
+ .hasDirectory(rootstrapDir.toString(), new NullProgressMonitor());
} catch (RemoteOperationException e) {
e.printStackTrace();
} catch (RemoteConnectionException e) {
e.printStackTrace();
}
if (exists) {
- if (!RemoteHostCommandLauncher.executeSudoWithExpect(command, rootstrapDir.removeLastSegments(1).toString(), env,
- "Platform Internal", monitor)) {
- return false;
- }
+ throw new InterruptedException(String.format("The rootstrap already exists.\n[%s]",
+ rootstrapDir.toString()));
} else {
- if (!RemoteHostCommandLauncher.executeSudoWithExpect(command, tempDirPath, env,
+ if (!HostCommandLauncher.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));
+ 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 remoteGenerate(String rootstrapPath, String arch, List<Repository> reposURLs,
- IPath confFile, IProgressMonitor monitor) throws InterruptedException {
+ 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());
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 path = RootstrapUtil.getRemoteUserRootstrapPath(id);
+ return remoteRemove(id, arch, path);
+ }
+
+ public static boolean remoteRemove(String id, String arch, String path)
+ throws InterruptedException {
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));
+ HostCommandLauncher.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));
+ HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
}
- RemoteHostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path), null);
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path), null);
} catch (RemoteOperationException e) {
e.printStackTrace();
return false;
--- /dev/null
+package org.tizen.nativeplatform.rootstrap;\r
+\r
+public interface IRootstrapManager {\r
+\r
+}\r
--- /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.io.File;
+import java.io.FilenameFilter;
+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.Path;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.nativecommon.build.SmartBuildInterface;
+import org.tizen.nativecommon.build.exception.SBIException;
+import org.tizen.nativecommon.build.model.Rootstrap;
+import org.tizen.nativecommon.build.model.SBIModel;
+import org.tizen.nativeplatform.build.PlatformConfigurationManager;
+import org.tizen.nativeplatform.command.launcher.CommandUtil;
+import org.tizen.nativeplatform.command.launcher.HostCommandLauncher;
+import org.tizen.nativeplatform.repo.commander.RepoManager;
+import org.tizen.nativeplatform.repo.model.Repository;
+import org.tizen.nativeplatform.util.RootstrapUtil;
+import org.tizen.nativeplatform.views.model.PlatformRootstrap;
+
+public class LocalRootstrapManager {
+
+ 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;
+
+ protected static List<PlatformRootstrap> rootstraps = new ArrayList<PlatformRootstrap>();
+ protected static List<PlatformRootstrap> userRootstraps = new ArrayList<PlatformRootstrap>();
+ protected static PlatformRootstrap selectedRootstrap;
+ protected static Set<IRootstrapChangedListener> changedListener = new HashSet<IRootstrapChangedListener>();
+
+ protected static boolean init;
+ protected static final String URL_SEP_REGEXP = "[|]";
+
+ protected static final Logger logger = LoggerFactory.getLogger(LocalRootstrapManager.class);
+
+ private synchronized static void initialize() {
+
+ SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+ try {
+ List<String> lists = sbi.getRootstrapList();
+ for (String id : lists) {
+ String type = sbi.getSupportToolchainTypeFromRootstrapID(id);
+ if (!type.equals(PlatformRootstrap.SUPPORTED_TOOLCHAIN_TYPE)) {
+ 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 = new File(path).exists() ? true : false;
+ addRootstrap(new PlatformRootstrap(id, rootName, arch, version, path, reposURLs,
+ confFile, initialized, isDefault));
+ }
+ } catch (SBIException e) {
+ logger.error("Failed to initialize rootstraps", e);
+ e.printStackTrace();
+ }
+
+ init = true;
+ }
+
+ public static PlatformRootstrap addRootstrap(PlatformRootstrap rootstrap) {
+ rootstraps.add(rootstrap);
+ SBIModel.addRootstrap(rootstrap, true);
+ notifyChangedRootstrap();
+ return rootstrap;
+ }
+
+ public static boolean removeRootstrap(String id) {
+ PlatformRootstrap rootstrap = getRootstrap(id);
+ if (rootstrap != null) {
+ try {
+ // removeBaseFileSystem(rootstrap.getId(), rootstrap.getArch());
+ BaseFileSystemGenerator.remove(rootstrap.getId(), rootstrap.getArch());
+ } catch (InterruptedException e) {
+ logger.error(String.format("Failed to rootstrap: [%s]", id), e);
+ e.printStackTrace();
+ return false;
+ }
+ rootstraps.remove(rootstrap);
+ // removeSBIPluginXML(rootstrap);
+ XMLPluginGenerator.remove(rootstrap.getId());
+ SBIModel.removeRootstrap(rootstrap);
+ notifyChangedRootstrap();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean exportRootstrap(PlatformRootstrap rootstrap, String exportFilePath,
+ IProgressMonitor monitor) throws InterruptedException {
+
+ // make temp directory
+ String tempDirPath = CommandUtil.makeTempDirectory();
+
+ try {
+ // rootstrapPath = /home/sdk/tizen-sdk-data/user-rootstraps/latest
+ // workingPath = /home/sdk/tizen-sdk-data/user-rootstraps/
+ // chrootPath =
+ // /home/sdk/tizen-sdk-data/user-rootstraps/latest/local/BUILD-ROOTS/scratch.i586.0
+ String rootstrapPath = rootstrap.getPath().toOSString();
+ String workingPath = rootstrap.getPath().removeLastSegments(1).toOSString();
+ SmartBuildInterface sbi = SmartBuildInterface.getInstance();
+ String chrootPath = sbi.getPlatformRootstrapPath(rootstrapPath);
+ if (chrootPath == null || chrootPath.isEmpty()) {
+ return false;
+ }
+ String scratchName = new Path(chrootPath).lastSegment();
+ if (!scratchName.startsWith("scratch.")) {
+ return false;
+ }
+ String rootstrapID = rootstrap.getId();
+ 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 (!HostCommandLauncher
+ .executeSudo(
+ String.format(
+ "sudo -S tar cvzf %s/rootstrap2.tar.gz %s/local/BUILD-ROOTS/%s --exclude=home/abuild --exclude=etc/passwd",
+ tempDirPath, rootstrapID, scratchName), workingPath,
+ "Platform Internal", monitor)) {
+ return false;
+ }
+
+ // copy xml
+ String pluginFileName = rootstrap.getId() + ".xml";
+ String pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
+ pluginFileName).toOSString();
+ if (!HostCommandLauncher.execute(String.format("cp %s %s/", pluginPath, tempDirPath))) {
+ return false;
+ }
+
+ // zip them together
+ 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
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath));
+ }
+ }
+
+ public static PlatformRootstrap importRootstrap(String importFilePath, IProgressMonitor monitor)
+ throws InterruptedException {
+
+ PlatformRootstrap result = null;
+ String pluginPath = null;
+ String rootstrapPath = null;
+
+ // make temp directory
+ String tempDirPath = CommandUtil.makeTempDirectory();
+
+ try {
+ // extract "tar" archive
+ if (!HostCommandLauncher.execute(String.format("tar xvf %s", importFilePath),
+ tempDirPath, "Platform Internal", monitor)) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("Extracting rootsrap failed!");
+ }
+
+ // find rootstrap id
+ File tempDir = new File(tempDirPath);
+ File[] xmlFiles = tempDir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ if (name.endsWith(".xml")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
+ if (xmlFiles == null || xmlFiles.length == 0) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("There is no SBI plugin file(*.xml)");
+ }
+ String pluginFilePath = xmlFiles[0].getPath().toString();
+ String pluginFileName = new File(pluginFilePath).getName();
+ String pluginId = pluginFileName.split("\\.xml")[0];
+
+ // check already exist?
+ if (getRootstrap(pluginId) != null) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("There already exists the rootrap with same id!");
+ }
+
+ // copy xml
+ pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
+ pluginFileName).toOSString();
+ HostCommandLauncher.execute(String.format("cp %s %s", pluginFilePath, pluginPath));
+
+ // reload
+ try {
+ SBIModel.reinitialize();
+ } catch (SBIException e) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("SBIModel initialization failed!");
+ }
+ result = createRootstrapFromSBIPlugin(pluginId);
+ if (result == null) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("Loading SBI plugin failed!");
+ }
+
+ // extracting file system
+ rootstrapPath = result.getPath().toOSString();
+ File baseDirDir = new File(rootstrapPath).getParentFile();
+ if (!baseDirDir.exists()) {
+ if (!baseDirDir.mkdir()) {
+ throw new InterruptedException(String.format("Failed to make directory: %s",
+ baseDirDir.toString()));
+ }
+ } else if (new File(rootstrapPath).exists()) {
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath),
+ null);
+ }
+
+ 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 (!HostCommandLauncher.executeSudo(
+ String.format("sudo -S tar xvf %s/rootstrap2.tar.gz", tempDirPath),
+ baseDirDir.getPath(), "Platform Internal", monitor)) {
+ cleanUpRootstrap(pluginPath, rootstrapPath);
+ throw new InterruptedException("Extracting rootsrap failed!");
+ }
+
+ return result;
+ } finally {
+ // remove temporary directory
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath), null);
+ }
+ }
+
+ private static void cleanUpRootstrap(String pluginPath, String rootstrapPath)
+ throws InterruptedException {
+ if (pluginPath != null) {
+ HostCommandLauncher.execute(String.format("rm -rf %s", pluginPath));
+ try {
+ SBIModel.reinitialize();
+ } catch (SBIException e1) {
+ throw new InterruptedException(e1.getMessage());
+ }
+ }
+ if (rootstrapPath != null) {
+ HostCommandLauncher
+ .executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
+ }
+ }
+
+ public static void clearRootstrap() {
+ rootstraps.clear();
+ notifyChangedRootstrap();
+ }
+
+ 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> 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();
+ }
+
+ public static void updateRootstrap(PlatformRootstrap rootstrap) {
+ if (rootstrap != null) {
+ try {
+ XMLPluginGenerator
+ .generate(rootstrap.getId(), rootstrap.getName(), rootstrap.getArch(),
+ rootstrap.getVersion(), rootstrap.getPath().toOSString(),
+ rootstrap.getJustRepoURLs(), rootstrap.getConfFile(),
+ rootstrap.isDefault());
+ SBIModel.updateRootstrap(rootstrap);
+ 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 : 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();
+ }
+ }
+
+ public static void removeLatestTempDirForRootstrap() {
+ PlatformRootstrap tempRootstrap = BaseFileSystemGenerator.getLatestTempRootstrap();
+ if (tempRootstrap == null) {
+ return;
+ }
+ String id = tempRootstrap.getId();
+ String arch = tempRootstrap.getArch();
+ String path = tempRootstrap.getPath().toOSString();
+ if (id == null || arch == null || path == null || id.isEmpty() || arch.isEmpty()
+ || path.isEmpty()) {
+ return;
+ }
+ try {
+ if (!path.isEmpty() && new File(path).exists()) {
+ // check sub-directory
+ String checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/proc", path,
+ id, arch);
+ if (new File(checkDir).exists()) {
+ 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()) {
+ HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
+ }
+ checkDir = String.format("%s/%s/", path, id);
+ if (new File(checkDir).exists()) {
+ HostCommandLauncher.execute(String.format("rm -rf %s", checkDir));
+ }
+ // remove
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
+ }
+ } 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.generate(RootstrapUtil.getUserRootstrapPath(id), arch,
+ reposURLs, confFile, monitor)) {
+ initialized = true;
+ } else {
+ return null;
+ }
+ }
+
+ // generate SBI plugins
+ if (XMLPluginGenerator.generate(id, name, arch, version, null, reposURLs, confFile)) {
+ return new PlatformRootstrap(id, name, arch, RootstrapUtil.getUserRootstrapPath(id),
+ reposURLs, confFile, initialized, false);
+ } else {
+ if (immediateGen) {
+ // removeBaseFileSystem(id, arch);
+ BaseFileSystemGenerator.remove(id, arch);
+ }
+ return null;
+ }
+ }
+
+ private static PlatformRootstrap createRootstrapFromSBIPlugin(String id) {
+ Rootstrap rootstrap = SBIModel.getRootstrapById(id);
+ if (rootstrap == null) {
+ return null;
+ }
+
+ List<Repository> reposURLs = new ArrayList<Repository>();
+ String urlStr = rootstrap.getPropertyValue(PlatformRootstrap.PROPERTY_REPO_URLS);
+ if (urlStr != null) {
+ int idx = 0;
+ for (String url : urlStr.split(URL_SEP_REGEXP)) {
+ String name = String.format("url%d", idx++);
+ if (RepoManager.isLocalUrl(url)) {
+ reposURLs.add(new Repository(name, url.trim(), RepoManager.LOCAL_REPO_TYPE));
+ } else {
+ reposURLs.add(new Repository(name, url.trim(), RepoManager.REMOTE_REPO_TYPE));
+ }
+ }
+ }
+
+ String confFile = rootstrap.getPropertyValue(PlatformRootstrap.PROPERTY_CONFIGURATION_FILE);
+
+ return new PlatformRootstrap(id, rootstrap.getName(), rootstrap.getArch(), rootstrap
+ .getPath().toOSString(), reposURLs, confFile, true, rootstrap.isDefault());
+ }
+}
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.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.command.launcher.HostCommandLauncher;
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 = "[|]";
+public class RemoteRootstrapManager extends LocalRootstrapManager {
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();
return;
}
try {
- IRemoteItem[] items = filetool.listItems(remotepluginPath, new NullProgressMonitor());
- for(IRemoteItem item : items) {
+ 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")) {
+ if (ext != null && 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);
+ copytool.downloadFileToFile(remotepath, localpath);
}
} catch (RemoteOperationException e) {
e.printStackTrace();
}
monitor.worked(1);
monitor.subTask("Reinitializing rootstraps...");
-
+
SBIModel.reinitialize();
monitor.worked(1);
monitor.subTask("Adding rootstraps...");
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);
+ 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)) {
} catch (CancelException e) {
e.printStackTrace();
}
- }
+ }
addRootstrap(new PlatformRootstrap(id, rootName, arch, version, path, reposURLs,
confFile, initialized, isDefault));
}
userRootstraps.add(rootstrap);
}
SBIModel.addRootstrap(rootstrap, true);
- RootstrapManager.notifyChangedRootstrap();
+ notifyChangedRootstrap();
return rootstrap;
}
PlatformRootstrap rootstrap = getRootstrap(id);
if (rootstrap != null) {
try {
- BaseFileSystemGenerator.remoteRemove(rootstrap.getId(), rootstrap.getArch());
+ BaseFileSystemGenerator.remoteRemove(rootstrap.getId(), rootstrap.getArch(),
+ rootstrap.getPath().toString());
} catch (InterruptedException e) {
logger.error(String.format("Failed to rootstrap: [%s]", id), e);
e.printStackTrace();
}
XMLPluginGenerator.remoteRemove(rootstrap.getId());
SBIModel.removeRootstrap(rootstrap);
- RootstrapManager.notifyChangedRootstrap();
+ 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();
+ userRootstraps.clear();
+ notifyChangedRootstrap();
}
public static List<PlatformRootstrap> getX86Rootstrap() {
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 (rootstrap != null) {
try {
XMLPluginGenerator
- .remoteGenerate(rootstrap.getId(), rootstrap.getName(), rootstrap.getArch(),
- rootstrap.getVersion(), rootstrap.getPath().toOSString(),
- rootstrap.getJustRepoURLs(), rootstrap.getConfFile(),
- rootstrap.isDefault());
+ .remoteGenerate(rootstrap.getId(), rootstrap.getName(),
+ rootstrap.getArch(), rootstrap.getVersion(), rootstrap.getPath()
+ .toOSString(), rootstrap.getJustRepoURLs(), rootstrap
+ .getConfFile(), rootstrap.isDefault());
SBIModel.updateRootstrap(rootstrap);
- RemoteRootstrapManager.notifyChangedRootstrap();
+ notifyChangedRootstrap();
} catch (SBIException e) {
logger.error(String.format("Failed to update rootstrap: [%s]", rootstrap.getId()),
e);
}
}
- 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());
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()) {
+ if (id == null || arch == null || path == null || id.isEmpty() || arch.isEmpty()
+ || path.isEmpty()) {
return;
}
try {
path, id, arch);
exists = filetool.hasDirectory(checkDir, new NullProgressMonitor());
if (exists) {
- RemoteHostCommandLauncher.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);
+ 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));
+ HostCommandLauncher.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));
+ HostCommandLauncher.execute(String.format("rm -rf %s", checkDir));
}
// remove
- RemoteHostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
+ HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
}
}
} catch (RemoteOperationException e) {
boolean initialized = false;
String id = name;
if (immediateGen) {
- if (BaseFileSystemGenerator.remoteGenerate(RootstrapUtil.getRemoteUserRootstrapPath(id), arch,
- reposURLs, confFile, monitor)) {
+ 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);
+ return new PlatformRootstrap(id, name, arch,
+ RootstrapUtil.getRemoteUserRootstrapPath(id), reposURLs, confFile, initialized,
+ false);
} else {
if (immediateGen) {
BaseFileSystemGenerator.remoteRemove(id, arch);
import org.eclipse.core.runtime.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.tizen.common.util.OSChecker;
import org.tizen.nativecommon.build.SmartBuildInterface;
import org.tizen.nativecommon.build.exception.SBIException;
import org.tizen.nativecommon.build.model.Rootstrap;
public class RootstrapManager {
- 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 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(RootstrapManager.class);
-
- private RootstrapManager() {
- }
-
- private synchronized static void initialize() {
-
- SmartBuildInterface sbi = SmartBuildInterface.getInstance();
- try {
- List<String> lists = sbi.getRootstrapList();
- for (String id : lists) {
- String type = sbi.getSupportToolchainTypeFromRootstrapID(id);
- if (!type.equals(PlatformRootstrap.SUPPORTED_TOOLCHAIN_TYPE)) {
- 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 = new File(path).exists() ? true : false;
- addRootstrap(new PlatformRootstrap(id, rootName, arch, version, path, reposURLs,
- confFile, initialized, isDefault));
- }
- } catch (SBIException e) {
- logger.error("Failed to initialize rootstraps", e);
- e.printStackTrace();
- }
-
- init = true;
- }
-
public static PlatformRootstrap addRootstrap(PlatformRootstrap rootstrap) {
- rootstraps.add(rootstrap);
- SBIModel.addRootstrap(rootstrap, true);
- RootstrapManager.notifyChangedRootstrap();
- return rootstrap;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.addRootstrap(rootstrap);
+ } else {
+ return LocalRootstrapManager.addRootstrap(rootstrap);
+ }
}
public static boolean removeRootstrap(String id) {
- PlatformRootstrap rootstrap = getRootstrap(id);
- if (rootstrap != null) {
- try {
- // removeBaseFileSystem(rootstrap.getId(), rootstrap.getArch());
- BaseFileSystemGenerator.remove(rootstrap.getId(), rootstrap.getArch());
- } catch (InterruptedException e) {
- logger.error(String.format("Failed to rootstrap: [%s]", id), e);
- e.printStackTrace();
- return false;
- }
- rootstraps.remove(rootstrap);
- // removeSBIPluginXML(rootstrap);
- XMLPluginGenerator.remove(rootstrap.getId());
- SBIModel.removeRootstrap(rootstrap);
- RootstrapManager.notifyChangedRootstrap();
- return true;
- } else {
- return false;
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.removeRootstrap(id);
+ } else {
+ return LocalRootstrapManager.removeRootstrap(id);
+ }
}
public static boolean exportRootstrap(PlatformRootstrap rootstrap, String exportFilePath,
IProgressMonitor monitor) throws InterruptedException {
-
- // make temp directory
- String tempDirPath = CommandUtil.makeTempDirectory();
-
- try {
- // rootstrapPath = /home/sdk/tizen-sdk-data/user-rootstraps/latest
- // workingPath = /home/sdk/tizen-sdk-data/user-rootstraps/
- // chrootPath =
- // /home/sdk/tizen-sdk-data/user-rootstraps/latest/local/BUILD-ROOTS/scratch.i586.0
- String rootstrapPath = rootstrap.getPath().toOSString();
- String workingPath = rootstrap.getPath().removeLastSegments(1).toOSString();
- SmartBuildInterface sbi = SmartBuildInterface.getInstance();
- String chrootPath = sbi.getPlatformRootstrapPath(rootstrapPath);
- if (chrootPath == null || chrootPath.isEmpty()) {
- return false;
- }
- String scratchName = new Path(chrootPath).lastSegment();
- if (!scratchName.startsWith("scratch.")) {
- return false;
- }
- String rootstrapID = rootstrap.getId();
- 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 (!HostCommandLauncher
- .executeSudo(
- String.format(
- "sudo -S tar cvzf %s/rootstrap2.tar.gz %s/local/BUILD-ROOTS/%s --exclude=home/abuild --exclude=etc/passwd",
- tempDirPath, rootstrapID, scratchName), workingPath,
- "Platform Internal", monitor)) {
- return false;
- }
-
- // copy xml
- String pluginFileName = rootstrap.getId() + ".xml";
- String pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
- pluginFileName).toOSString();
- if (!HostCommandLauncher.execute(String.format("cp %s %s/", pluginPath, tempDirPath))) {
- return false;
- }
-
- // zip them together
- 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
- HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath));
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.exportRootstrap(rootstrap, exportFilePath, monitor);
+ } else {
+ return LocalRootstrapManager.exportRootstrap(rootstrap, exportFilePath, monitor);
+ }
}
public static PlatformRootstrap importRootstrap(String importFilePath, IProgressMonitor monitor)
throws InterruptedException {
-
- PlatformRootstrap result = null;
- String pluginPath = null;
- String rootstrapPath = null;
-
- // make temp directory
- String tempDirPath = CommandUtil.makeTempDirectory();
-
- try {
- // extract "tar" archive
- if (!HostCommandLauncher.execute(String.format("tar xvf %s", importFilePath), tempDirPath,
- "Platform Internal", monitor)) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("Extracting rootsrap failed!");
- }
-
- // find rootstrap id
- File tempDir = new File(tempDirPath);
- File[] xmlFiles = tempDir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- if (name.endsWith(".xml")) {
- return true;
- } else {
- return false;
- }
- }
- });
- if (xmlFiles == null || xmlFiles.length == 0) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("There is no SBI plugin file(*.xml)");
- }
- String pluginFilePath = xmlFiles[0].getPath().toString();
- String pluginFileName = new File(pluginFilePath).getName();
- String pluginId = pluginFileName.split("\\.xml")[0];
-
- // check already exist?
- if (RootstrapManager.getRootstrap(pluginId) != null) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("There already exists the rootrap with same id!");
- }
-
- // copy xml
- pluginPath = new Path(SmartBuildInterface.getInstance().getPluginPath()).append(
- pluginFileName).toOSString();
- HostCommandLauncher.execute(String.format("cp %s %s", pluginFilePath, pluginPath));
-
- // reload
- try {
- SBIModel.reinitialize();
- } catch (SBIException e) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("SBIModel initialization failed!");
- }
- result = createRootstrapFromSBIPlugin(pluginId);
- if (result == null) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("Loading SBI plugin failed!");
- }
-
- // extracting file system
- rootstrapPath = result.getPath().toOSString();
- File baseDirDir = new File(rootstrapPath).getParentFile();
- if (!baseDirDir.exists()) {
- if (!baseDirDir.mkdir()) {
- throw new InterruptedException(String.format("Failed to make directory: %s",
- baseDirDir.toString()));
- }
- } else if (new File(rootstrapPath).exists()) {
- HostCommandLauncher
- .executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
- }
-
- 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 (!HostCommandLauncher.executeSudo(
- String.format("sudo -S tar xvf %s/rootstrap2.tar.gz", tempDirPath),
- baseDirDir.getPath(), "Platform Internal", monitor)) {
- cleanUpRootstrap(pluginPath, rootstrapPath);
- throw new InterruptedException("Extracting rootsrap failed!");
- }
-
- return result;
- } finally {
- // remove temporary directory
- HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", tempDirPath), null);
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.importRootstrap(importFilePath, monitor);
+ } else {
+ return LocalRootstrapManager.importRootstrap(importFilePath, monitor);
+ }
}
-
- private static void cleanUpRootstrap(String pluginPath, String rootstrapPath)
- throws InterruptedException {
- if (pluginPath != null) {
- HostCommandLauncher.execute(String.format("rm -rf %s", pluginPath));
- try {
- SBIModel.reinitialize();
- } catch (SBIException e1) {
- throw new InterruptedException(e1.getMessage());
- }
- }
- if (rootstrapPath != null) {
- HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", rootstrapPath), null);
- }
+
+ public static void clearRootstrap() {
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.clearRootstrap();
+ } else {
+ LocalRootstrapManager.clearRootstrap();
+ }
}
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);
- }
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getRootstraps(listType);
+ } else {
+ return LocalRootstrapManager.getRootstraps(listType);
+ }
}
public static List<PlatformRootstrap> getRootstraps() {
- checkInit();
- return rootstraps;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getRootstraps();
+ } else {
+ return LocalRootstrapManager.getRootstraps();
+ }
+ }
+
+ public static List<PlatformRootstrap> getUserRootstraps() {
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getUserRootstraps();
+ } else {
+ return LocalRootstrapManager.getRootstraps();
+ }
}
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;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getX86Rootstrap();
+ } else {
+ return LocalRootstrapManager.getX86Rootstrap();
+ }
}
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;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getArmRootstrap();
+ } else {
+ return LocalRootstrapManager.getArmRootstrap();
+ }
}
public static List<PlatformRootstrap> getInitializedRootstrap() {
- checkInit();
- List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
- for (PlatformRootstrap r : rootstraps) {
- if (r.isInitialized()) {
- list.add(r);
- }
- }
- return list;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getInitializedRootstrap();
+ } else {
+ return LocalRootstrapManager.getInitializedRootstrap();
+ }
}
public static List<PlatformRootstrap> getNonInitializedRootstrap() {
- checkInit();
- List<PlatformRootstrap> list = new ArrayList<PlatformRootstrap>();
- for (PlatformRootstrap r : rootstraps) {
- if (!r.isInitialized()) {
- list.add(r);
- }
- }
- return list;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getNonInitializedRootstrap();
+ } else {
+ return LocalRootstrapManager.getNonInitializedRootstrap();
+ }
}
public static String getRootstrapId(String name) {
- checkInit();
- for (PlatformRootstrap r : rootstraps) {
- if (r.getName().equals(name)) {
- return r.getId();
- }
- }
- return "";
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getRootstrapId(name);
+ } else {
+ return LocalRootstrapManager.getRootstrapId(name);
+ }
}
public static PlatformRootstrap getRootstrap(String id) {
- checkInit();
- for (PlatformRootstrap r : rootstraps) {
- if (r.getId().equals(id)) {
- return r;
- }
- }
- return null;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getRootstrap(id);
+ } else {
+ return LocalRootstrapManager.getRootstrap(id);
+ }
}
public static PlatformRootstrap getDefaultRootstrap(String arch) {
- return findDefaultRootstrap(arch);
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getDefaultRootstrap(arch);
+ } else {
+ return LocalRootstrapManager.getDefaultRootstrap(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;
-
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.findDefaultRootstrap(arch);
+ } else {
+ return LocalRootstrapManager.findDefaultRootstrap(arch);
+ }
}
public static boolean existsRootstrap(String id) {
- checkInit();
- for (PlatformRootstrap r : rootstraps) {
- if (r.getId().equals(id)) {
- return true;
- }
- }
- return false;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.existsRootstrap(id);
+ } else {
+ return LocalRootstrapManager.existsRootstrap(id);
+ }
}
- public static void reinitialize() {
- init = false;
- rootstraps.clear();
- initialize();
+ public static void reinitialize(IProgressMonitor monitor) {
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.reinitialize(monitor);
+ } else {
+ LocalRootstrapManager.reinitialize(monitor);
+ }
}
public static void updateRootstrap(PlatformRootstrap rootstrap) {
- if (rootstrap != null) {
- try {
- XMLPluginGenerator
- .generate(rootstrap.getId(), rootstrap.getName(), rootstrap.getArch(),
- rootstrap.getVersion(), rootstrap.getPath().toOSString(),
- rootstrap.getJustRepoURLs(), rootstrap.getConfFile(),
- rootstrap.isDefault());
- SBIModel.updateRootstrap(rootstrap);
- RootstrapManager.notifyChangedRootstrap();
- } catch (SBIException e) {
- logger.error(String.format("Failed to update rootstrap: [%s]", rootstrap.getId()),
- e);
- e.printStackTrace();
- }
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.updateRootstrap(rootstrap);
+ } else {
+ LocalRootstrapManager.updateRootstrap(rootstrap);
+ }
}
public static void setSelectedRootstrap(PlatformRootstrap selected) {
- for (PlatformRootstrap r : rootstraps) {
- if (r.isChecked()) {
- r.setChecked(false);
- }
- }
- selected.setChecked(true);
- selectedRootstrap = selected;
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.setSelectedRootstrap(selected);
+ } else {
+ LocalRootstrapManager.setSelectedRootstrap(selected);
+ }
}
public static void setSelectedRootstrap(String id) {
- for (PlatformRootstrap r : RootstrapManager.getRootstraps()) {
- if (id.equals(r.getId())) {
- setSelectedRootstrap(r);
- break;
- }
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.setSelectedRootstrap(id);
+ } else {
+ LocalRootstrapManager.setSelectedRootstrap(id);
+ }
}
public static void resetSelectedRootstrap() {
- for (PlatformRootstrap r : rootstraps) {
- if (r.isChecked()) {
- r.setChecked(false);
- }
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.resetSelectedRootstrap();
+ } else {
+ LocalRootstrapManager.resetSelectedRootstrap();
+ }
}
public static boolean isInitialized(String rootId) {
- PlatformRootstrap root = getRootstrap(rootId);
- if (root != null) {
- return root.isInitialized();
- } else {
- return false;
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.isInitialized(rootId);
+ } else {
+ return LocalRootstrapManager.isInitialized(rootId);
+ }
}
public static boolean checkInitialized(String rootId) {
- PlatformRootstrap root = getRootstrap(rootId);
- if (root != null) {
- return root.checkInitialized();
- } else {
- return false;
- }
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.checkInitialized(rootId);
+ } else {
+ return LocalRootstrapManager.checkInitialized(rootId);
+ }
}
public static PlatformRootstrap getSelectedRootstrap() {
- return selectedRootstrap;
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.getSelectedRootstrap();
+ } else {
+ return LocalRootstrapManager.getSelectedRootstrap();
+ }
}
public static synchronized void addListener(IRootstrapChangedListener listener) {
- changedListener.add(listener);
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.addListener(listener);
+ } else {
+ LocalRootstrapManager.addListener(listener);
+ }
}
public static synchronized void removeListener(IRootstrapChangedListener listener) {
- changedListener.remove(listener);
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.removeListener(listener);
+ } else {
+ LocalRootstrapManager.removeListener(listener);
+ }
}
public static synchronized void notifyChangedRootstrap() {
-
- Iterator<IRootstrapChangedListener> ite = changedListener.iterator();
- while (ite.hasNext()) {
- IRootstrapChangedListener tl = ite.next();
- if (tl != null) {
- tl.rootstrapChanged();
- }
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.notifyChangedRootstrap();
+ } else {
+ LocalRootstrapManager.notifyChangedRootstrap();
+ }
}
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();
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.notifyChangedSelectionListener(rootName);
+ } else {
+ LocalRootstrapManager.notifyChangedSelectionListener(rootName);
+ }
}
public static void removeLatestTempDirForRootstrap() {
- PlatformRootstrap tempRootstrap = BaseFileSystemGenerator.getLatestTempRootstrap();
- if (tempRootstrap == null) {
- return;
- }
- String id = tempRootstrap.getId();
- String arch = tempRootstrap.getArch();
- String path = tempRootstrap.getPath().toOSString();
- if (id == null || arch == null || path == null ||
- id.isEmpty() || arch.isEmpty() || path.isEmpty()) {
- return;
- }
- try {
- if (!path.isEmpty() && new File(path).exists()) {
- // check sub-directory
- String checkDir = String.format("%s/%s/local/BUILD-ROOTS/scratch.%s.0/proc",
- path, id, arch);
- if (new File(checkDir).exists()) {
- 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()) {
- HostCommandLauncher.executeSudo(String.format("sudo -S umount %s", checkDir));
- }
- checkDir = String.format("%s/%s/", path, id);
- if (new File(checkDir).exists()) {
- HostCommandLauncher.execute(String.format("rm -rf %s", checkDir));
- }
- // remove
- HostCommandLauncher.executeSudo(String.format("sudo -S rm -rf %s", path));
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- logger.error(String.format("Failed to remove temp rootstrap directory: %s", path), e);
- }
+ if (OSChecker.isWindows()) {
+ RemoteRootstrapManager.removeLatestTempDirForRootstrap();
+ } else {
+ LocalRootstrapManager.removeLatestTempDirForRootstrap();
+ }
}
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.generate(RootstrapUtil.getUserRootstrapPath(id), arch,
- reposURLs, confFile, monitor)) {
- initialized = true;
- } else {
- return null;
- }
- }
-
- // generate SBI plugins
- if (XMLPluginGenerator.generate(id, name, arch, version, null, reposURLs, confFile)) {
- return new PlatformRootstrap(id, name, arch, RootstrapUtil.getUserRootstrapPath(id),
- reposURLs, confFile, initialized, false);
- } else {
- if (immediateGen) {
- // removeBaseFileSystem(id, arch);
- BaseFileSystemGenerator.remove(id, arch);
- }
- return null;
- }
- }
-
- private static PlatformRootstrap createRootstrapFromSBIPlugin(String id) {
- Rootstrap rootstrap = SBIModel.getRootstrapById(id);
- if (rootstrap == null) {
- return null;
- }
-
- List<Repository> reposURLs = new ArrayList<Repository>();
- String urlStr = rootstrap.getPropertyValue(PlatformRootstrap.PROPERTY_REPO_URLS);
- if (urlStr != null) {
- int idx = 0;
- for (String url : urlStr.split(URL_SEP_REGEXP)) {
- String name = String.format("url%d", idx++);
- if (RepoManager.isLocalUrl(url)) {
- reposURLs.add(new Repository(name, url.trim(), RepoManager.LOCAL_REPO_TYPE));
- } else {
- reposURLs.add(new Repository(name, url.trim(), RepoManager.REMOTE_REPO_TYPE));
- }
- }
- }
-
- String confFile = rootstrap.getPropertyValue(PlatformRootstrap.PROPERTY_CONFIGURATION_FILE);
-
- return new PlatformRootstrap(id, rootstrap.getName(), rootstrap.getArch(), rootstrap
- .getPath().toOSString(), reposURLs, confFile, true, rootstrap.isDefault());
+ if (OSChecker.isWindows()) {
+ return RemoteRootstrapManager.generate(name, arch, version, reposURLs, immediateGen, confFile, monitor);
+ } else {
+ return LocalRootstrapManager.generate(name, arch, version, reposURLs, immediateGen, confFile, monitor);
+ }
}
}
attrArch.setValue(arch);
Attr attrPath = doc.createAttribute(ATTR_PATH);
if (path == null) {
- attrPath.setValue(RootstrapUtil.getUserRootstrapPathOfXml(name));
+ attrPath.setValue(RootstrapUtil.getUserRootstrapXmlPath(name));
} else {
attrPath.setValue(RootstrapUtil.getRootstrapPathOfXml(path));
}
attrArch.setValue(arch);
Attr attrPath = doc.createAttribute(ATTR_PATH);
if (path == null) {
- attrPath.setValue(RootstrapUtil.getUserRootstrapPathOfXml(name));
+ attrPath.setValue(RootstrapUtil.getRemoteUserRootstrapXmlPath(name));
} else {
attrPath.setValue(RootstrapUtil.getRootstrapPathOfXml(path));
}
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();
+ return new Path(userhome).append(REMOTE_TIZEN_SDK_DIR_NAME).append(USER_ROOSTRAP_BASE_DIR_NAME).append(id).toString();
}
public static String getBaseUserRootstrapPath() {
.toOSString();
}
- public static String getUserRootstrapPathOfXml(String id) {
+ public static String getRemoteUserRootstrapXmlPath(String id) {
+ String rootstrapPath = getRemoteUserRootstrapPath(id);
+ return getRootstrapPathOfXml(rootstrapPath);
+ }
+
+ public static String getUserRootstrapXmlPath(String id) {
String rootstrapPath = getUserRootstrapPath(id);
return getRootstrapPathOfXml(rootstrapPath);
}
import java.util.List;
import org.eclipse.core.runtime.IPath;
+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.common.util.OSChecker;
import org.tizen.nativecommon.build.model.Rootstrap;
+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;
}
public PlatformRootstrap(String id, String name, String arch, String version,
- String rootstrapPath, List<Repository> reposURLs, String confFile,
- boolean initialized, boolean isDefault) {
+ String rootstrapPath, List<Repository> reposURLs, String confFile, boolean initialized,
+ boolean isDefault) {
super(id, name, SUPPORTED_TOOLCHAIN_TYPE, version, arch, new Path(rootstrapPath), isDefault);
this.reposURLs = reposURLs;
this.initialized = initialized;
}
public boolean checkInitialized() {
- boolean exists = new File(getPath().toOSString()).exists() ? true : false;
+ boolean exists = false;
+ if (OSChecker.isWindows()) {
+ exists = remoteCheckInitialized();
+ } else {
+ exists = new File(getPath().toOSString()).exists() ? true : false;
+ }
setInitialized(exists);
return exists;
}
+ public boolean remoteCheckInitialized() {
+ String strPath = path.toString();
+ boolean exists = false;
+ try {
+ IRemoteFileTools filetool = RemoteConnectionManager.getRemoteTools().getFileTool();
+ exists = filetool.hasDirectory(strPath, new NullProgressMonitor());
+ } catch (RemoteOperationException e) {
+ e.printStackTrace();
+ } catch (RemoteConnectionException e) {
+ e.printStackTrace();
+ } catch (CancelException e) {
+ e.printStackTrace();
+ }
+ return exists;
+ }
+
public List<Repository> getRepoList() {
return reposURLs;
}
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.command.launcher.CommandUtil;
import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget;
import org.tizen.nativeplatform.pkgmgr.PkgMgrInitializer;
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;
private IProject project;
private Shell shell;
-
+
private Map<String, Thread> threadMap = new HashMap<String, Thread>();
private static final String PLATFORM_PERSPECTIVE_ID = "org.tizen.nativeplatform.perspective";
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");
+ 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");
+ 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);
});
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");
tableViewer.setLabelProvider(new TableViewerProvider());
tableViewer.setContentProvider(new ArrayContentProvider());
- tableViewer.setInput(getRootstrapTableInput());
+ tableViewer.setInput(RootstrapManager.getUserRootstraps());
tableViewer.getTable().addSelectionListener(new SelectionListener() {
};
actionExport.setText(resources.getString("View.Contextmenu.Export"));
}
-
+
private void updateToolbarEnable() {
ToolItem[] items = toolBar.getItems();
if (RemoteConnectionManager.connected()) {
items[3].setEnabled(false);
}
}
-
+
private void showConnectDialog() {
RemoteConnectionDialog dlg = new RemoteConnectionDialog(shell);
if (dlg.open() == Dialog.OK) {
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
- try {
+ 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();
- }
- }
- });
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ monitor.beginTask("Synchronizing...", 2);
+ try {
+ monitor.subTask("Synchronizing rootstraps...");
+ RootstrapManager.reinitialize(new SubProgressMonitor(monitor, 1));
+ monitor.subTask("Clear platform temp directory");
+ CommandUtil.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",
}
}
}
-
+
private void disconnectRemotehost() {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
try {
RemoteConnectionManager.removeConnection();
monitor.worked(1);
monitor.subTask("Clean rootstrap");
- RemoteRootstrapManager.clearRootstrap();
+ RootstrapManager.clearRootstrap();
monitor.worked(1);
monitor.subTask("Update toolbar");
SWTUtil.syncExec(new Runnable() {
- public void run() {
- updateToolbarEnable();
- }
- });
+ public void run() {
+ updateToolbarEnable();
+ rootDescText.setText("");
+ }
+ });
monitor.worked(1);
} finally {
monitor.done();
}
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;
- }
+ 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();
}
private void genRootstrap(final String name, final String arch,
- final List<Repository> repoURLs, final boolean immediateGen,
- final IPath buildConfFile) {
+ final List<Repository> repoURLs, final boolean immediateGen, final IPath buildConfFile) {
// generate rootstrap here
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
monitor.beginTask(resources.getString("GenRootDlg.Progress.Msg.Generating"), -1);
- generatedRootstrap = null;
generatedRootstrap = RootstrapManager.generate(name, arch,
PlatformRootstrap.DEFAULT_VERSION, repoURLs, immediateGen,
buildConfFile, monitor);
PlatformConfigurationManager.setBuildTargetName(config, newTargetId);
RootstrapManager.setSelectedRootstrap(rootstrap);
RootstrapManager.notifyChangedRootstrap();
-
ManagedBuildManager.saveBuildInfo(project, true);
}
resources.getString("GenRootDlg.Progress.Msg.Generating"),
-1);
if (!BaseFileSystemGenerator.generate(
- selected.getPath().toString(), selected.getJustRepoURLs(),
+ selected.getPath().toString(), selected.getJustRepoURLs(),
selected.getArch(), selected.getConfFile(), monitor)) {
throw new InterruptedException(
"Generating base file system failed!");
Table table = tableViewer.getTable();
TableItem[] item = table.getSelection();
final PlatformRootstrap selected = (PlatformRootstrap) item[0].getData();
-
- // default rootstrap cannot be removed!
PlatformRootstrap defaultRootstrap = RootstrapManager.getDefaultRootstrap(selected
.getArch());
+
if (defaultRootstrap == null) {
String msg = String.format("%s %s",
resources.getString("Action.Msg.Error.RemoveDefault"),
return "x86";
}
}
-
- private List<PlatformRootstrap> getRootstrapTableInput() {
- if (OSChecker.isWindows()) {
- return RemoteRootstrapManager.getUserRootstraps();
- } else {
- return RootstrapManager.getRootstraps();
- }
- }
}