--- /dev/null
+/*\r
+ * Messages.java\r
+ *\r
+ * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact:\r
+ * YoonKi Park <yoonki.park@samsung.com>\r
+ * Hoon Kang <h245.kang@samsung.com>\r
+ *\r
+ * This program and the accompanying materials are made available\r
+ * under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+package com.samsung.tizen.common.connection.debugtools;\r
+\r
+import java.util.MissingResourceException;\r
+import java.util.ResourceBundle;\r
+\r
+public class Messages {\r
+ private static final String BUNDLE_NAME = "com.samsung.tizen.common.connection.debugtools.messages"; //$NON-NLS-1$\r
+\r
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle\r
+ .getBundle(BUNDLE_NAME);\r
+\r
+ private Messages() {\r
+ }\r
+ \r
+ public static String getString(String key) {\r
+ // TODO Auto-generated method stub\r
+ try {\r
+ return RESOURCE_BUNDLE.getString(key);\r
+ } catch (MissingResourceException e) {\r
+ return '!' + key + '!';\r
+ }\r
+ }\r
+ \r
+ public static String getString(String key, Object binding) {\r
+ // TODO Auto-generated method stub\r
+ try {\r
+ return RESOURCE_BUNDLE.getString(key);\r
+ } catch (MissingResourceException e) {\r
+ return '!' + key + '!';\r
+ }\r
+ }\r
+ private static String messageBind(String message, Object[] args, String argZero, String argOne) {\r
+ int length = message.length();\r
+ //estimate correct size of string buffer to avoid growth\r
+ int bufLen = length + (args.length * 5);\r
+ if (argZero != null)\r
+ bufLen += argZero.length() - 3;\r
+ if (argOne != null)\r
+ bufLen += argOne.length() - 3;\r
+ StringBuffer buffer = new StringBuffer(bufLen < 0 ? 0 : bufLen);\r
+ for (int i = 0; i < length; i++) {\r
+ char c = message.charAt(i);\r
+ switch (c) {\r
+ case '{' :\r
+ int index = message.indexOf('}', i);\r
+ // if we don't have a matching closing brace then...\r
+ if (index == -1) {\r
+ buffer.append(c);\r
+ break;\r
+ }\r
+ i++;\r
+ if (i >= length) {\r
+ buffer.append(c);\r
+ break;\r
+ }\r
+ // look for a substitution\r
+ int number = -1;\r
+ try {\r
+ number = Integer.parseInt(message.substring(i, index));\r
+ } catch (NumberFormatException e) {\r
+ throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);\r
+ }\r
+ if (number == 0 && argZero != null)\r
+ buffer.append(argZero);\r
+ else if (number == 1 && argOne != null)\r
+ buffer.append(argOne);\r
+ else {\r
+ if (number >= args.length || number < 0) {\r
+ buffer.append("<missing argument>"); //$NON-NLS-1$\r
+ i = index;\r
+ break;\r
+ }\r
+ buffer.append(args[number]);\r
+ }\r
+ i = index;\r
+ break;\r
+ case '\'' :\r
+ // if a single quote is the last char on the line then skip it\r
+ int nextIndex = i + 1;\r
+ if (nextIndex >= length) {\r
+ buffer.append(c);\r
+ break;\r
+ }\r
+ char next = message.charAt(nextIndex);\r
+ // if the next char is another single quote then write out one\r
+ if (next == '\'') {\r
+ i++;\r
+ buffer.append(c);\r
+ break;\r
+ }\r
+ // otherwise we want to read until we get to the next single quote\r
+ index = message.indexOf('\'', nextIndex);\r
+ // if there are no more in the string, then skip it\r
+ if (index == -1) {\r
+ buffer.append(c);\r
+ break;\r
+ }\r
+ // otherwise write out the chars inside the quotes\r
+ buffer.append(message.substring(nextIndex, index));\r
+ i = index;\r
+ break;\r
+ default :\r
+ buffer.append(c);\r
+ }\r
+ }\r
+ return buffer.toString();\r
+ }\r
+}\r
-package com.samsung.tizen.common.connection.explorer;
+package com.samsung.tizen.common.connection.debugtools;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import com.samsung.tizen.common.connection.ConnectionPlugin;
import com.samsung.tizen.common.properties.InstallPathConfig;
import com.samsung.tizen.sdblib.IDevice;
import com.samsung.tizen.sdblib.SdbCommandRejectedException;
class InstallProgress implements IRunnableWithProgress {
- final private String DEVELOPER_PATH = "/home/developer/";
- final private String TOOLS_TARGET_PATH = "/home/developer/sdk_tools/";
- final private String TOOLS_HOST_PATH = InstallPathConfig.getSDKPath()
- + "/SDK/develop-tool/";
+ final private String TOOLS_TARGET_PATH = "/home/developer/sdk_tools";
+ final private String TOOLS_HOST_PATH = InstallPathConfig.getSDKPath();
final private String CMD_RESULT_CHECK = "; echo $?";
private IDevice device = null;
boolean makeResult = false;
SdbShellProcess lsProc;
try {
- lsProc = device.executeShellCommand("mkdir " + dir
+ lsProc = device.executeShellCommand("mkdir -p -m 755 " + dir
+ CMD_RESULT_CHECK);
BufferedReader br = new BufferedReader(new InputStreamReader(
lsProc.getInputStream()));
return makeResult;
}
- private ArrayList<String> getPackageList() {
- ArrayList<String> packageList = new ArrayList<String>();
- try {
- Process lsProc = Runtime.getRuntime().exec(
- "ls " + TOOLS_HOST_PATH + " -1");
- BufferedReader br = new BufferedReader(new InputStreamReader(
- lsProc.getInputStream()));
-
- String lsMsg = null;
- while (null != (lsMsg = br.readLine())) {
- if (lsMsg.contains(".tar") && lsMsg.contains("_")) {
- packageList.add(lsMsg);
- }
- }
- br.close();
- return packageList;
-
- } catch (IOException e) {
- return packageList;
- }
- }
-
- private boolean isInstalled(String packageFile) {
+ private boolean isInstalled(DebugTool dt) {
boolean ret = false;
try {
- SdbShellProcess lsProc = device.executeShellCommand("ls "
- + TOOLS_TARGET_PATH + "."
- + getPackageNameFromFileName(packageFile) + ".txt"
- + CMD_RESULT_CHECK);
+
+ SdbShellProcess echoProc = device
+ .executeShellCommand("cat "
+ + TOOLS_TARGET_PATH + "/" + dt.getControlFile() + CMD_RESULT_CHECK);
BufferedReader br = new BufferedReader(new InputStreamReader(
- lsProc.getInputStream()));
+ echoProc.getInputStream()));
+
String lsOut = null;
String lastOut = null;
+ String oldVersion = null;
while (null != (lsOut = br.readLine())) {
+ //version:0.0.0
+ if (lsOut.toLowerCase().startsWith("version:")) {
+ oldVersion = lsOut.split(":")[1];
+ }
lastOut = lsOut;
}
- if (null != lastOut && lastOut.equals("0")) {
- ret = true;
- }
+ if (null != lastOut) {
+ if (lastOut.equals("0")) {
+ String v1 = normalisedVersion(oldVersion,".",4);
+ String v2 = normalisedVersion(dt.getVersion(),".",4);
+ if (v2.compareTo(v1) > 0) {
+ //TODO : do install and save!
+ removeOldPackage(dt.getPackagename());
+ ret = false;
+ } else {//same version
+ ret = true;
+ }
+ }
+ else
+ ret = false;
+ } else
+ ret = false;
br.close();
} catch (IOException e) {
return true;
return ret;
}
-
- private boolean copyPackage(String packageFile) {
+ private String normalisedVersion (String version, String sep, int maxWidth) {
+ String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
+ StringBuilder sb = new StringBuilder();
+ for (String s : split) {
+ sb.append(String.format("%" + maxWidth + 's', s));
+ }
+ return sb.toString();
+ }
+ private void removeOldPackage(String packagename) {
+ try {
+ SdbShellProcess echoProc = device.executeShellCommand("rm -rf " + TOOLS_TARGET_PATH + "/" + packagename);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ private boolean copyPackage(String source, String destination) {
boolean pushResult = false;
try {
SyncService syncService = device.getSyncService();
- SyncResult pushSyncResult = syncService.pushFile(TOOLS_HOST_PATH
- + packageFile, TOOLS_TARGET_PATH + packageFile,
+ SyncResult pushSyncResult = syncService.pushFile(source, destination,
SyncService.getNullProgressMonitor());
if (SyncService.RESULT_OK == pushSyncResult.getCode()) {
pushResult = true;
}
}
- private void makeInstallFile(String packageName) {
+ private void saveControlfile(String controlFile,String version) {
try {
SdbShellProcess echoProc = device
- .executeShellCommand("echo installed > "
- + TOOLS_TARGET_PATH + "." + packageName + ".txt");
+ .executeShellCommand("echo 'version:"+version+ "' >"
+ + TOOLS_TARGET_PATH + "/" + controlFile );
BufferedReader br = new BufferedReader(new InputStreamReader(
echoProc.getInputStream()));
while (null != br.readLine()) {
private void removeTar(String packageFile) {
try {
- SdbShellProcess echoProc = device.executeShellCommand("rm "
- + TOOLS_TARGET_PATH + packageFile);
+ SdbShellProcess echoProc = device.executeShellCommand("cd "
+ + TOOLS_TARGET_PATH + " && rm " + packageFile);
+
BufferedReader br = new BufferedReader(new InputStreamReader(
echoProc.getInputStream()));
while (null != br.readLine()) {
}
}
- final private void installPackage(String packageFile) {
- String packageName = getPackageNameFromFileName(packageFile);
- boolean isCopied = copyPackage(packageFile);
+ final private void installPackage(DebugTool tool) {
+ String local = TOOLS_HOST_PATH+"/"+tool.getSourcepath() + "/" + tool.getBinaryname();
+ String remote = TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
+
+ // delete old version
+ try {
+ SdbShellProcess echoProc = device.executeShellCommand("cd "
+ + TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ boolean isCopied = copyPackage(local, remote);
monitor.worked(5);
if (isCopied) {
- unzipPackage(packageFile);
+ unzipPackage( tool.getBinaryname());
monitor.worked(2);
- makeInstallFile(packageName);
+ saveControlfile( tool.getControlFile(),tool.getVersion());
monitor.worked(1);
- removeTar(packageFile);
+ removeTar(tool.getBinaryname());
monitor.worked(1);
}
}
- private String getPackageNameFromFileName(String fileName) {
- String packageName = null;
- String[] packageElement = fileName.split("_");
- if (null != packageElement && packageElement.length > 1) {
- packageName = packageElement[0];
- }
- return packageName;
- }
-
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- // mkdir /home/developer/sdk_tools/
final IProgressMonitor fmonitor = monitor;
this.monitor = monitor;
- monitor.beginTask("Package Install Progress", 100);
- monitor.subTask("Prepare install");
- // make derectory
- if (!checkDirectory(TOOLS_TARGET_PATH)) {
- if (checkDirectory(DEVELOPER_PATH)) {
- // mkdir 'home/developer/sdk_tools'
- makeDirectory(TOOLS_TARGET_PATH);
- } else {
- // mkdir 'home/developer'
- makeDirectory(DEVELOPER_PATH);
- // mkdir 'home/developer/sdk_tools'
- makeDirectory(TOOLS_TARGET_PATH);
- }
- }
-
- // if (!checkDirectory(TOOLS_TARGET_PATH)) {
- // makeDirectory(TOOLS_TARGET_PATH);
- // }
+
+ monitor.beginTask(Messages.getString("debugtools.initilize"), 100);
+ //monitor.subTask("Prepare install");
+
+ // check directory exist
+ if (!checkDirectory(TOOLS_TARGET_PATH))
+ makeDirectory(TOOLS_TARGET_PATH);
monitor.worked(10);
// get package list to install
- final ArrayList<String> packageList = getPackageList();
+ final List<DebugTool> debugTools = ConnectionPlugin.getDebugTools();
monitor.worked(15);
// install loop (cp, tar)
- int packageCnt = packageList.size();
- for (int i = 0; i < packageCnt; i++) {
- final boolean isInstalled = isInstalled(packageList.get(i));
- monitor.subTask("Install "
- + getPackageNameFromFileName(packageList.get(i)));
- monitor.worked(1);
- final int index = i;
+ for (int i=0 ; i<debugTools.size(); i++) {
+ final DebugTool dt = (DebugTool)debugTools.get(i);
+
+ if (device.isEmulator()) {
+ if (!dt.getArchitecture().equals("i386"))
+ continue;
+ }
+ else {
+ if (!dt.getArchitecture().equals("armel"))
+ continue;
+ }
+
+ final boolean isInstalled = isInstalled(dt);
+
Thread thread = new Thread(null, new Runnable() {
@Override
public void run() {
if (!isInstalled) {
- installPackage(packageList.get(index));
+ installPackage(dt);
} else {
fmonitor.worked(7);
}
}
-public class PackageInstaller {
+public class ToolsInstall {
public static void installPackages(IDevice device) {
final IDevice tDevice = device;
- if (device.isEmulator()) {
+ if (tDevice.isOffline()) {
return;
}
Display.getDefault().asyncExec(new Runnable() {
-
- private void delay() {
- if (tDevice.isOffline()) {
- for (int i = 0; i < 30; i++) {
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- if (tDevice.isOnline()) {
- break;
- }
- }
- }
- }
-
@Override
public void run() {
- delay();
- if (tDevice.isOffline()) {
- return;
- }
final PackageInstallMonitorDialog installDialog = new PackageInstallMonitorDialog(
Display.getDefault().getActiveShell());
try {
} catch (InterruptedException e) {
return;
}
-
}
});