[Title] removed on-demand control file & some fefactoring to improve debug trace...
authoryoonki.park <yoonki.park@samsung.com>
Mon, 3 Dec 2012 08:20:16 +0000 (17:20 +0900)
committeryoonki.park <yoonki.park@samsung.com>
Mon, 3 Dec 2012 08:20:16 +0000 (17:20 +0900)
[Type]
[Module]
[Priority]
[CQ#]
[Redmine#] 6995
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I370fd7fb831cbac9f244be82e183d5235f917286

org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/DebugTool.java
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstall.java [new file with mode: 0644]
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstallMessages.java [moved from org.tizen.common.connection/src/org/tizen/common/connection/debugtools/ToolsInstallMessages.java with 58% similarity]
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstallMessages.properties [moved from org.tizen.common.connection/src/org/tizen/common/connection/debugtools/ToolsInstallMessages.properties with 50% similarity]
org.tizen.common.connection/src/org/tizen/common/connection/debugtools/ToolsInstall.java [deleted file]
org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerPanel.java

index 286d129..549d377 100755 (executable)
 
 package org.tizen.common.connection;
 
-import java.io.File;
 import java.util.ArrayList;
-import java.util.List;
 
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.RegistryFactory;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
-import org.tizen.common.connection.debugtools.DebugTool;
 import org.tizen.common.connection.preference.TizenConnectionExplorerPreferencePage;
 import org.tizen.common.connection.preference.TizenLogPreferencePage;
-import org.tizen.common.core.application.InstallPathConfig;
-import org.tizen.common.util.FileUtil;
 import org.tizen.common.util.OSChecker;
 import org.tizen.common.util.log.Logger;
 import org.tizen.sdblib.FileListingService.FileEntry;
-import org.tizen.sdblib.IDevice.Arch;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.SmartDevelopmentBridge;
 
@@ -60,7 +50,6 @@ public class ConnectionPlugin extends AbstractUIPlugin {
     public static final String PLUGIN_ID = "org.tizen.common.connection"; //$NON-NLS-1$
     public static final String ID_LOGS_VIEW = "org.tizen.common.connection.ui.LogView"; //$NON-NLS-1$
     public static final String ID_CONNECTION_VIEW = "org.tizen.common.connection.ui.ConnectionExplorer";
-    public static final String ID_DEBUGTOOLS_EXTENSION = "org.tizen.common.connection.tools"; //$NON-NLS-1$
 
     // The shared instance
     private static ConnectionPlugin plugin;
@@ -120,124 +109,6 @@ public class ConnectionPlugin extends AbstractUIPlugin {
         store.setDefault(TizenLogPreferencePage.KEY_DEFAULT_LEVEL, TizenLogPreferencePage.VALUE_DEFAULT_LEVEL);
     }
 
-    public static synchronized  List<DebugTool> getDebugTools(IDevice device) {
-        List<DebugTool> toolLists = new ArrayList<DebugTool>();
-        IExtensionRegistry x = RegistryFactory.getRegistry();
-        IConfigurationElement[] ces = x.getConfigurationElementsFor(ID_DEBUGTOOLS_EXTENSION);
-
-        try {
-            for ( IConfigurationElement ce : ces ) {
-                if (ce.getName().equals("tools")) {
-                    String packagename = ce.getAttribute("packagename");
-                    if (packagename == null)
-                    {
-                        continue;
-                    }
-                    String sourcepath = ce.getAttribute("sourcepath");
-                    if (sourcepath == null)
-                    {
-                        continue;
-                    }
-                    String description = ce.getAttribute("description");
-                    Path sourcePath = new Path(InstallPathConfig.getPlatformVersionPath() + "/" + sourcepath);
-                    File packageList = new File(sourcePath.toOSString());
-                    
-                    DebugTool dt = null;
-                    File[] packageFileList = packageList.listFiles();
-                    if ( packageFileList == null ) {
-                        continue;
-                    }
-                    for (File f : packageList.listFiles()) {
-                        if ( DebugTool.RPM_PACKAGE_TYPE.equals(FileUtil.getFileExtension(f.getName())) ) {
-                            dt = makeDebugToolFromRPM(f, device, packagename, sourcepath, description);
-                        }
-                        else {
-                            dt = makeDebugToolFromTar(f, device, packagename, sourcepath, description);
-                        }
-                        if ( dt != null ) {
-                            toolLists.add(dt);
-                        }
-                    }
-                }
-            }
-        } catch (Throwable e) {
-            Logger.error("Failed making DebugTool list for on-demand install", e);
-        }
-        return toolLists;
-    }
-
-    private static DebugTool makeDebugToolFromRPM( File f, IDevice device, String packagename, String sourcepath, String description ) {
-        String architecture = "";
-        String version = "";
-        String name = "";
-
-        // Not supported "RPM" at windows
-        //            architecture = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{ARCH}", "-p " + f.getCanonicalPath()) );
-        //            version = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{VERSION}", "-p " + f.getCanonicalPath()) );
-        //            name = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{NAME}", "-p " + f.getCanonicalPath()) );
-
-        // RPM file format : gtest-0.0.8-7.1.armv7l.rpm
-        String[] fileSplit = f.getName().split("-");
-        if ( fileSplit.length < 3 ) {
-            return null;
-        }
-        name = fileSplit[0];
-        // version is not used
-        // FIXME : Unsafe way to extract the version.
-        version = fileSplit[1];
-        String[] archSplit = fileSplit[fileSplit.length-1].split("\\.");
-        architecture = archSplit[archSplit.length-2];
-        
-        if ( !packagename.equals(name) ) {
-            return null;
-        }
-        if (device.isEmulator() && device.getArch() == Arch.X86) {
-            if ( !architecture.contains("86")) {
-                return null;
-            }
-        }
-        else {
-            if ( !architecture.contains("arm")) {
-                return null;
-            }
-        }
-
-        DebugTool dt = new DebugTool(packagename, f.getName(), sourcepath, version, description, architecture, DebugTool.RPM_PACKAGE_TYPE);
-
-        return dt;
-    }
-
-    private static DebugTool makeDebugToolFromTar( File f, IDevice device, String packagename, String sourcepath, String description ) {
-        String[] filename = f.getName().split("_");
-        if (filename.length != 3) {
-            return null;
-        }
-        if( !filename[0].equals(packagename)) {
-            return null;
-        }
-        String version = filename[1];
-        String[] arch = filename[2].split("\\.");
-        if (arch.length != 2) {
-            return null;
-        }
-        String architecture = arch[0];
-
-        if (device.isEmulator() && device.getArch() == Arch.X86) {
-            if (!architecture.equals("i386"))
-            {
-                return null;
-            }
-        } else {
-            if (!architecture.equals("armel"))
-            {
-                return null;
-            }
-        }
-
-        DebugTool dt = new DebugTool(packagename, f.getName(), sourcepath, version, description, architecture, "tar");
-        return dt;
-    }
-
     /*
      * (non-Javadoc)
      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
index 24e52f9..7d60a1d 100644 (file)
@@ -4,8 +4,9 @@
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Contact: 
- * Hoon Kang <h245.kang@samsung.com>
+ * Kangho Kim <kh5325.kim@samsung.com>
  * YoonKi Park <yoonki.park@samsung.com>
+ * Gun Kim <gune.kim@samsung.com>
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package org.tizen.common.connection.debugtools;
 
-import org.tizen.common.TizenPlatformConstants;
-import org.tizen.common.core.application.InstallPathConfig;
 
+/**
+ * A On-demand Tool to be installed to a device or an emulator.
+ * @author Gun Kim <gune.kim@samsung.com>
+ *
+ */
 public class DebugTool {
-    public static final String TOOLS_HOST_PATH = InstallPathConfig.getPlatformVersionPath();
-    public static final String RPM_QUERY_COMMAND = "rpm -q --queryformat=%s %s";
-    public static final String RPM_PACKAGE_TYPE = "rpm";
-    public static final String RPM_INSTALL_COMMAND = "rpm -i %s";
-    public static final String RPM_UPGRADE_COMMAND = "rpm -U %s";
-
     private String binaryname;
     private String packagename;
     private String sourcepath;
@@ -58,9 +56,6 @@ public class DebugTool {
     public String getBinaryname() {
         return binaryname;
     }
-    public String getControlFile() {
-        return "." + this.packagename + TizenPlatformConstants.CONTROL_EXTENSION;
-    }
     public String getVersion() {
         return version;
     }
@@ -100,5 +95,4 @@ public class DebugTool {
     public String getPackagetype() {
         return packagetype;
     }
-
 }
diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstall.java b/org.tizen.common.connection/src/org/tizen/common/connection/debugtools/OnDemandInstall.java
new file mode 100644 (file)
index 0000000..f116c7a
--- /dev/null
@@ -0,0 +1,488 @@
+/*
+ *  Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * YoonKi Park <yoonki.park@samsung.com>
+ * Gun Kim <gune.kim@samsung.com>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.common.connection.debugtools;
+
+import static org.tizen.common.util.CollectionUtil.isEmpty;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.osgi.util.NLS;
+import org.tizen.common.TizenPlatformConstants;
+import org.tizen.common.core.application.InstallPathConfig;
+import org.tizen.common.util.FileUtil;
+import org.tizen.common.util.SdbCommandUtil;
+import org.tizen.common.util.log.Logger;
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.IDevice.Arch;
+import org.tizen.sdblib.MultiLineReceiver;
+
+/**
+ * On-demand Install class to deploy SDK tools to Tizen device or an emulator.
+ * 
+ * @author Gun Kim <gune.kim@samsung.com>
+ */
+public class OnDemandInstall {
+    public static final String ID_DEBUGTOOLS_EXTENSION = "org.tizen.common.connection.tools"; //$NON-NLS-1$
+    public static final String TOOLS_HOST_PATH = InstallPathConfig.getPlatformVersionPath();
+    public static final String RPM_PACKAGE_TYPE = "rpm";
+    private static final String RPM_QUERY_COMMAND = "rpm -qa | grep %s | wc -l";
+    private static final String CMD_RESULT_SUCCESS = "0";
+    private static final String MOVE_WORKING_DIR_COMMAND = "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH;
+    private static final String REMOVE_TOOL_COMMAND = "rm -f %s";
+
+    private static final String TAR_INSTALL_COMMAND = MOVE_WORKING_DIR_COMMAND + " && tar -xf %s" + " && " + REMOVE_TOOL_COMMAND;
+    private static final String RPM_INSTALL_COMMAND = MOVE_WORKING_DIR_COMMAND + " && rpm -i %s" + " && " + REMOVE_TOOL_COMMAND;
+    private IDevice device = null;
+
+    private static IProgressMonitor nullMonitor = new OnDemandNullProgressMonitor();
+    private List<DebugTool> debugTools = null;
+    boolean blocking = false;
+
+    public OnDemandInstall(IDevice device) {
+        this.device = device;
+        debugTools = getDebugTools(device);
+    }
+
+    public OnDemandInstall(IDevice device, String packageName) {
+        this.device = device;
+        debugTools = getDebugTools(device, packageName);
+    }
+
+
+    /**
+     * Sets blocking mode.
+     * 
+     * @param blocking
+     */
+    public void setBlocking(boolean blocking) {
+        this.blocking = blocking;
+    }
+
+    private boolean checkDirectory(String dir) {
+        String cmd = "ls " + dir + TizenPlatformConstants.CMD_RESULT_CHECK;
+        String result = "";
+
+        try {
+            result = getResult(cmd);
+            if (CMD_RESULT_SUCCESS.equals(result)) {
+                return true;
+            }
+        } catch (Exception e) {
+            Logger.error(OnDemandInstallMessages.CANNOT_CHECK_DIRECTORY);
+        }
+
+        return false;
+    }
+
+
+    private void makeDirectory(String dir) {
+        String cmd = "mkdir -p -m 755 " + dir + TizenPlatformConstants.CMD_RESULT_CHECK;
+        String result = "";
+
+        try {
+            result = getResult(cmd);
+            if (CMD_RESULT_SUCCESS.equals(result) == false) {
+                Logger.error(OnDemandInstallMessages.CANNOT_CREATE_DIRECTORY);
+            }
+        } catch (Exception e) {
+            Logger.error(OnDemandInstallMessages.CANNOT_CREATE_DIRECTORY);
+        }
+    }
+
+    /**
+     * Returns true if the result of the cmd execution is equal to 0, Otherwise
+     * false.
+     * 
+     * @param cmd
+     * @return
+     * @throws CoreException
+     */
+    private String getResult(String cmd) throws Exception {
+        String result = "";
+        CommandOuputReceiver receiver = new CommandOuputReceiver();
+
+        device.executeShellCommand(cmd, receiver, 0);
+        result = receiver.getResult();
+        return result;
+    }
+
+    private boolean isInstalled(DebugTool dt) {
+        String result = "";
+        String cmd = "";
+
+        if (RPM_PACKAGE_TYPE.equals(dt.getPackagetype())) {
+            cmd = String.format(RPM_QUERY_COMMAND, dt.getPackagename());
+        } else {
+            cmd = "ls " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + dt.getPackagename() + TizenPlatformConstants.CMD_RESULT_CHECK;
+        }
+
+        try {
+            result = getResult(cmd);
+            if (RPM_PACKAGE_TYPE.equals(dt.getPackagetype())) {
+                // In case of rpm package, the result 0 means the package is not installed.
+                if (CMD_RESULT_SUCCESS.equals(result) == false) {
+                    return true;
+                }
+            } else {
+                if (CMD_RESULT_SUCCESS.equals(result)) {
+                    return true;
+                }
+            }
+        } catch (Exception e) {
+            Logger.error(NLS.bind(OnDemandInstallMessages.CANNOT_CHECK_INSTALLED, dt.getPackagename()), e);
+        }
+        return false;
+    }
+
+    /**
+     * Starts to install packages.
+     * 
+     * @param monitor
+     *            The progress monitor. Can use
+     *            {@link OnDemandInstall#getNullIProgressMonitor}
+     */
+    public void install(IProgressMonitor monitor) {
+        if (monitor == null) {
+            monitor = nullMonitor;
+        }
+        if (blocking == true) {
+            installPackage(monitor);
+        } else {
+            String threadName = "OnDemandInstallThread";
+            Runnable r = new OnDemandRunnable(monitor);
+            Thread t = new Thread(r, threadName);
+            t.start();
+        }
+    }
+
+    public void setDevice(IDevice pDevice) {
+        device = pDevice;
+    }
+
+    private boolean copyPackage(String source, String destination) {
+        return SdbCommandUtil.filePush(device, source, destination);
+    }
+
+    private void installPackage(IProgressMonitor monitor) {
+        if (isEmpty(debugTools)) {
+            return;
+        }
+        monitor.beginTask(OnDemandInstallMessages.DIALOG_INITILIZE, 100);
+        monitor.subTask("Prepare install");
+
+        // check directory exist
+        if (!checkDirectory(TizenPlatformConstants.TOOLS_TARGET_PATH)) {
+            makeDirectory(TizenPlatformConstants.TOOLS_TARGET_PATH);
+        }
+
+        monitor.worked(10);
+
+        for (DebugTool dt : debugTools) {
+            // get package list to install
+            monitor.worked(15);
+            if (verifyArchitecture(dt.getArchitecture()) == false) {
+                continue;
+            }
+
+            if (isInstalled(dt) == true) {
+                continue;
+            }
+
+            String local = TOOLS_HOST_PATH + "/" + dt.getSourcepath() + "/" + dt.getBinaryname();
+            String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + dt.getBinaryname();
+
+            if (copyPackage(local, remote) == false) {
+                Logger.error(NLS.bind(OnDemandInstallMessages.CANNOT_COPY_FILE, dt.getBinaryname()));
+                continue;
+            }
+
+            deployPackage(dt);
+        }
+        monitor.done();
+    }
+
+    private final void deployPackage(DebugTool tool) {
+        String local = TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
+        String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
+        String cmd = "";
+        String result = "";
+
+        if (copyPackage(local, remote) == false) {
+            Logger.error(NLS.bind(OnDemandInstallMessages.CANNOT_COPY_FILE, tool.getBinaryname()));
+            return;
+        }
+
+        if (RPM_PACKAGE_TYPE.equals(tool.getPackagetype())) {
+            cmd = String.format(RPM_INSTALL_COMMAND, tool.getBinaryname(), tool.getBinaryname()) + TizenPlatformConstants.CMD_RESULT_CHECK;
+        } else {
+            cmd = String.format(TAR_INSTALL_COMMAND, tool.getBinaryname(), tool.getBinaryname()) + TizenPlatformConstants.CMD_RESULT_CHECK;
+        }
+        try {
+            result = getResult(cmd);
+            if (CMD_RESULT_SUCCESS.equals(result) == false) {
+                Logger.error(NLS.bind(OnDemandInstallMessages.CANNOT_INSTALL_TOOL, tool.getPackagename(), result));
+            }
+        } catch (Exception e) {
+            Logger.error(NLS.bind(OnDemandInstallMessages.ERROR_EXECUTE_COMMAND, cmd), e);
+        }
+    }
+
+
+    class OnDemandRunnable implements Runnable {
+        IProgressMonitor monitor = null;
+
+        OnDemandRunnable(IProgressMonitor monitor) {
+            this.monitor = monitor;
+        }
+
+        @Override
+        public void run() {
+            installPackage(monitor);
+        }
+    }
+
+    /**
+     * Returns a sync progress monitor that does nothing.
+     * <p/>
+     * This object can be reused multiple times and can be used by concurrent
+     * threads.
+     */
+    public static IProgressMonitor getNullIProgressMonitor() {
+        return nullMonitor;
+    }
+
+    private static class OnDemandNullProgressMonitor implements IProgressMonitor {
+
+        @Override
+        public void beginTask(String name, int totalWork) {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void done() {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void internalWorked(double work) {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public boolean isCanceled() {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        @Override
+        public void setCanceled(boolean value) {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void setTaskName(String name) {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void subTask(String name) {
+            // TODO Auto-generated method stub
+        }
+
+        @Override
+        public void worked(int work) {
+            // TODO Auto-generated method stub
+        }
+    }
+
+    private final class CommandOuputReceiver extends MultiLineReceiver {
+        private String result = "";
+
+        @Override
+        public void processNewLines(String[] lines) {
+            result = lines[lines.length - 1];
+        }
+
+        public String getResult() {
+            return result;
+        }
+    }
+
+    /**
+     * Returns true if DebugTool is created for arm architecture, or false otherwise.
+     * @param dt
+     * @return
+     */
+    private boolean verifyArchitecture(String arch) {
+        if (arch == null) {
+            return false;
+        }
+
+        if (device.getArch() == Arch.X86) {
+            if ( arch.contains("arm")) {
+                return false;
+            }
+        }else {
+            if ( arch.contains("86")) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Returns {@link DebugTool} which is given the packageName. It can be used to install on-demand tools case by case.
+     * @param device
+     * @param packageName
+     * @return DebugTool
+     */
+    private synchronized  List<DebugTool> getDebugTools(IDevice device, String packageName) {
+        final List<DebugTool>  debugTools = getDebugTools(device);
+        List<DebugTool> toolInfo = new ArrayList<DebugTool>(1);
+
+        if (packageName != null) {
+            for (DebugTool dt : debugTools) {
+                if (packageName.equals(dt.getPackagename())) {
+                    toolInfo.add(dt);
+                }
+            }
+        }
+        return toolInfo;
+    }
+
+    private synchronized  List<DebugTool> getDebugTools(IDevice device) {
+        List<DebugTool> toolLists = new ArrayList<DebugTool>();
+        IExtensionRegistry x = RegistryFactory.getRegistry();
+        IConfigurationElement[] ces = x.getConfigurationElementsFor(ID_DEBUGTOOLS_EXTENSION);
+
+        try {
+            for ( IConfigurationElement ce : ces ) {
+                if (ce.getName().equals("tools")) {
+                    String packagename = ce.getAttribute("packagename");
+                    if (packagename == null)
+                    {
+                        continue;
+                    }
+                    String sourcepath = ce.getAttribute("sourcepath");
+                    if (sourcepath == null)
+                    {
+                        continue;
+                    }
+                    String description = ce.getAttribute("description");
+                    Path sourcePath = new Path(InstallPathConfig.getPlatformVersionPath() + "/" + sourcepath);
+                    File packageList = new File(sourcePath.toOSString());
+                    
+                    DebugTool dt = null;
+                    File[] packageFileList = packageList.listFiles();
+                    if ( packageFileList == null ) {
+                        continue;
+                    }
+                    for (File f : packageList.listFiles()) {
+                        if ( OnDemandInstall.RPM_PACKAGE_TYPE.equals(FileUtil.getFileExtension(f.getName())) ) {
+                            dt = makeDebugToolFromRPM(f, device, packagename, sourcepath, description);
+                        }
+                        else {
+                            dt = makeDebugToolFromTar(f, device, packagename, sourcepath, description);
+                        }
+                        if ( dt != null ) {
+                            toolLists.add(dt);
+                        }
+                    }
+                }
+            }
+        } catch (Throwable e) {
+            Logger.error("Failed making DebugTool list for on-demand install", e);
+        }
+        return toolLists;
+    }
+
+    private DebugTool makeDebugToolFromRPM( File f, IDevice device, String packagename, String sourcepath, String description ) {
+        String architecture = "";
+        String version = "";
+        String name = "";
+
+        // Not supported "RPM" at windows
+        //            architecture = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{ARCH}", "-p " + f.getCanonicalPath()) );
+        //            version = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{VERSION}", "-p " + f.getCanonicalPath()) );
+        //            name = HostUtil.returnExecute( String.format( DebugTool.RPM_QUERY_COMMAND, "%{NAME}", "-p " + f.getCanonicalPath()) );
+
+        // RPM file format : gtest-0.0.8-7.1.armv7l.rpm
+        String[] fileSplit = f.getName().split("-");
+        if ( fileSplit.length < 3 ) {
+            return null;
+        }
+        name = fileSplit[0];
+        // version is not used
+        // FIXME : Unsafe way to extract the version.
+        version = fileSplit[1];
+        String[] archSplit = fileSplit[fileSplit.length-1].split("\\.");
+        architecture = archSplit[archSplit.length-2];
+        
+        if ( !packagename.equals(name) ) {
+            return null;
+        }
+        if (verifyArchitecture(architecture) == false) {
+            return null;
+        }
+
+        DebugTool dt = new DebugTool(packagename, f.getName(), sourcepath, version, description, architecture, OnDemandInstall.RPM_PACKAGE_TYPE);
+
+        return dt;
+    }
+
+    private DebugTool makeDebugToolFromTar( File f, IDevice device, String packagename, String sourcepath, String description ) {
+        String[] filename = f.getName().split("_");
+        if (filename.length != 3) {
+            return null;
+        }
+        if( !filename[0].equals(packagename)) {
+            return null;
+        }
+        String version = filename[1];
+        String[] arch = filename[2].split("\\.");
+        if (arch.length != 2) {
+            return null;
+        }
+        String architecture = arch[0];
+
+        if (verifyArchitecture(architecture) == false) {
+            return null;
+        }
+
+        DebugTool dt = new DebugTool(packagename, f.getName(), sourcepath, version, description, architecture, "tar");
+        return dt;
+    }
+}
\ No newline at end of file
@@ -27,17 +27,18 @@ package org.tizen.common.connection.debugtools;
 \r
 import org.eclipse.osgi.util.NLS;\r
 \r
-public class ToolsInstallMessages extends NLS {\r
+public class OnDemandInstallMessages extends NLS {\r
 \r
-       static {\r
-               NLS.initializeMessages(ToolsInstallMessages.class.getName(), ToolsInstallMessages.class);\r
-       }\r
-       \r
-       public static String DIALOG_INITILIZE;\r
-       public static String CANNOT_CREATE_DIRECTORY;\r
-       public static String CANNOT_CHECK_DIRECTORY;\r
-       public static String CANNOT_CHECK_INSTALLED;\r
-       public static String CANNOT_COPY_FILE;\r
-       public static String CANNOT_REMOVE_CONTROLFILE;\r
-       \r
+    static {\r
+        NLS.initializeMessages(OnDemandInstallMessages.class.getName(), OnDemandInstallMessages.class);\r
+    }\r
+    \r
+    public static String DIALOG_INITILIZE;\r
+    public static String CANNOT_CREATE_DIRECTORY;\r
+    public static String CANNOT_CHECK_DIRECTORY;\r
+    public static String CANNOT_CHECK_INSTALLED;\r
+    public static String CANNOT_COPY_FILE;\r
+    public static String CANNOT_REMOVE_CONTROLFILE;\r
+    public static String CANNOT_INSTALL_TOOL;\r
+    public static String ERROR_EXECUTE_COMMAND;\r
 }\r
@@ -1,6 +1,8 @@
 DIALOG_INITILIZE=Connection Explorer is initializing. It can take a few minutes.\r
 CANNOT_CREATE_DIRECTORY=Cannot create sdk tools directory\r
 CANNOT_CHECK_DIRECTORY=Cannot check sdk tools directory\r
-CANNOT_CHECK_INSTALLED=Cannot check installed tools\r
-CANNOT_COPY_FILE=Cannot copy the file\r
+CANNOT_CHECK_INSTALLED=Cannot check installed tools ''{0}''\r
+CANNOT_COPY_FILE=Cannot copy the file ''{0}''\r
 CANNOT_REMOVE_CONTROLFILE=Cannot delete the file\r
+CANNOT_INSTALL_TOOL=Cannot install ''{0}'' due to : {1}\r
+ERROR_EXECUTE_COMMAND=Error occurred while executing command : {0}
\ No newline at end of file
diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/debugtools/ToolsInstall.java b/org.tizen.common.connection/src/org/tizen/common/connection/debugtools/ToolsInstall.java
deleted file mode 100755 (executable)
index fbac890..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- *  Common
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: 
- * Hoon Kang <h245.kang@samsung.com>
- * YoonKi Park <yoonki.park@samsung.com>
- * Gun Kim <gune.kim@samsung.com>
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-package org.tizen.common.connection.debugtools;
-
-import static org.tizen.common.util.CollectionUtil.isEmpty;
-import static org.tizen.common.util.IOUtil.tryClose;
-
-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.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.tizen.common.TizenPlatformConstants;
-import org.tizen.common.connection.ConnectionPlugin;
-import org.tizen.common.util.IOUtil;
-import org.tizen.common.util.SdbCommandUtil;
-import org.tizen.common.util.log.Logger;
-import org.tizen.sdblib.IDevice;
-import org.tizen.sdblib.SdbShellProcess;
-import org.tizen.sdblib.IDevice.Arch;
-
-class PackageInstallMonitorDialog extends ProgressMonitorDialog {
-    public PackageInstallMonitorDialog(Shell parent) {
-        super(parent);
-        int shellStyle = getShellStyle();
-        shellStyle &= ~SWT.APPLICATION_MODAL;
-        setShellStyle(shellStyle);
-    }
-}
-
-class InstallProgress implements IRunnableWithProgress {
-
-    private static final String CMD_RESULT_CHECK = "; echo $?";
-    private static final String CMD_TAR_INSTALL =
-            "rm -rf " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s && " +                    // remove old version package
-            "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && " +                              // move to directory for on-demand
-            "tar -xf %s && " +                                                                                                   // install new version package
-            "echo 'version:%s'>" + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s && " +  // create control file
-            "rm -f " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/%s";                              // remove package.tar
-
-
-    private IDevice device = null;
-
-    IProgressMonitor monitor = null;
-
-    private boolean checkDirectory(String dir) throws CoreException {
-        String cmd = "ls " + dir + CMD_RESULT_CHECK;
-        return checkExitCode(cmd, ToolsInstallMessages.CANNOT_CHECK_DIRECTORY);
-    }
-
-
-    private void makeDirectory(String dir) throws CoreException {
-        String cmd = "mkdir -p -m 755 " + dir + CMD_RESULT_CHECK ;
-        String msg = ToolsInstallMessages.CANNOT_CREATE_DIRECTORY;
-
-        if (checkExitCode(cmd, msg) == false)
-        {
-            installCoreException(msg, null);
-        }
-    }
-
-    private boolean checkExitCode( String cmd, String msg ) throws CoreException
-    {
-        boolean result = false;
-        SdbShellProcess lsProc;
-        BufferedReader br = null;
-        try {
-            lsProc = device.executeShellCommand(cmd);
-            br = new BufferedReader(new InputStreamReader(
-                    lsProc.getInputStream()));
-            String lsOut = null;
-            while (null != (lsOut = br.readLine())) {
-                if ("0".equals(lsOut)) {
-                    result = true;
-                    break;
-                }
-            }
-        } catch (IOException e) {
-            installCoreException(msg, e);
-            Logger.error(msg, e);
-        }finally
-        {
-            tryClose( br );
-        }
-        return result;
-    }
-
-    private boolean isInstalled(DebugTool dt) throws CoreException {
-        boolean ret = false;
-        BufferedReader br = null;
-        try {
-
-            SdbShellProcess echoProc = device.executeShellCommand(
-                    "cat " + TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + dt.getControlFile() + CMD_RESULT_CHECK);
-            br = new BufferedReader(new InputStreamReader(
-                    echoProc.getInputStream()));
-
-            String lsOut = null;
-            String oldVersion = null;
-            while (null != (lsOut = br.readLine())) {
-                //version:0.0.0
-                if (lsOut.toLowerCase().startsWith("version:")) {
-                    oldVersion = lsOut.split(":")[1];
-                }
-
-                if ("0".equals(lsOut)) {
-                    String v1 = normalisedVersion(oldVersion, ".", 4);
-                    String v2 = normalisedVersion(dt.getVersion(), ".", 4);
-                    if (v2.compareTo(v1) > 0) {
-                        //TODO : do install and save!
-                        ret = false;
-                    } else { //same version
-                        ret = true;
-                    }
-                    break;
-                } else
-                {
-                    ret = false;
-                }
-            }
-        } catch (IOException e) {
-            installCoreException(ToolsInstallMessages.CANNOT_CHECK_INSTALLED, e);
-            Logger.error(ToolsInstallMessages.CANNOT_CHECK_INSTALLED, e);
-        } finally {
-            tryClose( br );
-        }
-        return ret;
-
-    }
-    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();
-    }
-
-    @Override
-    public void run(IProgressMonitor pMonitor) throws InvocationTargetException, InterruptedException {
-        final List<DebugTool>  allDebugTools = ConnectionPlugin.getDebugTools(device);
-        List<DebugTool> installDebugTools = new ArrayList<DebugTool>();
-
-        if ( isEmpty( allDebugTools ) )
-        {
-            return;
-        }
-        boolean isInstalled = false;
-        for ( DebugTool dt : allDebugTools ) {
-            try {
-                isInstalled = isInstalled(dt);
-            } catch (CoreException e) {
-                Logger.error("Error to check installed", e);
-            }
-            if (isInstalled == false) {
-                installDebugTools.add(dt);
-            }
-        }
-        if ( installDebugTools.isEmpty() ) {
-            return;
-        }
-
-        this.monitor = pMonitor;
-
-        pMonitor.beginTask(ToolsInstallMessages.DIALOG_INITILIZE, 100);
-        //monitor.subTask("Prepare install");
-
-        // check directory exist
-        try {
-            if (!checkDirectory(TizenPlatformConstants.TOOLS_TARGET_PATH))
-            {
-                makeDirectory(TizenPlatformConstants.TOOLS_TARGET_PATH);
-            }
-        } catch (CoreException e) {
-            Logger.error("Error to check or make directory", e);
-        }
-
-        pMonitor.worked(10);
-
-        // get package list to install
-
-        pMonitor.worked(15);
-        String threadName = "";
-        // install loop (cp, tar)
-        for ( DebugTool dt : installDebugTools ) {
-            if (device.isEmulator() && device.getArch() == Arch.X86) {
-                if (!dt.getArchitecture().contains("86"))
-                {
-                    continue;
-                }
-            }
-            else {
-                if (!dt.getArchitecture().contains("arm"))
-                {
-                    continue;
-                }
-            }
-            
-            threadName = "OnDemandInstallThread-" + dt.getPackagename();
-            Runnable r = new OnDemandInstall(dt);
-            Thread t = new Thread(r, threadName);
-            t.start();
-        }
-        pMonitor.done();
-    }
-
-    public void setDevice(IDevice pDevice) {
-        device = pDevice;
-    }
-    
-    private boolean copyPackage(String source, String destination) {
-        return SdbCommandUtil.filePush(device, source, destination);
-    }
-    
-    private final void installTarPackage(DebugTool tool) throws CoreException {
-        String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
-        String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
-
-        // delete old version
-        try {
-            device.executeShellCommand(
-                    "cd " + TizenPlatformConstants.TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
-        } catch (IOException e) {
-            Logger.error("Failed delete old version ( " + tool.getPackagename() + " )");
-            return;
-        }
-
-        boolean isCopied = copyPackage(local, remote);
-        if (isCopied) {
-            try {
-              //make one string command for sequential executing
-                String installCommand = String.format(CMD_TAR_INSTALL, tool.getPackagename(),
-                                                                                                      tool.getBinaryname(),
-                                                                                                      tool.getVersion(), tool.getControlFile(),
-                                                                                                      tool.getBinaryname());
-                device.executeShellCommand(installCommand);
-
-            } catch (IOException e) {
-                Logger.error("Error after copied " + tool.getPackagename() , e);
-            }
-        }
-        else if (!isCopied) {
-            Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
-        }
-    }
-
-    private final void installRPMPackage(DebugTool tool) throws CoreException {
-        boolean isInstalled = false;
-        String local = DebugTool.TOOLS_HOST_PATH + "/" + tool.getSourcepath() + "/" + tool.getBinaryname();
-        String remote = TizenPlatformConstants.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
-
-        String packagename;
-
-        BufferedReader br = null;
-        SdbShellProcess sdbShell = null;
-        try {
-            sdbShell = device.executeShellCommand(String.format( DebugTool.RPM_QUERY_COMMAND, "\"%{NAME}\\n\"", tool.getPackagename()));
-            br = new BufferedReader(new InputStreamReader(sdbShell.getInputStream()));
-
-            while (null != (packagename = br.readLine())) {
-                if ( tool.getPackagename().equals(packagename)){
-                    isInstalled = true;
-                    break;
-                }
-            }
-        } catch (IOException e1) {
-            Logger.log(e1);
-        } finally {
-            IOUtil.tryClose(br);
-            if ( sdbShell != null ) {
-                sdbShell.destroy();
-            }
-        }
-
-        boolean isCopied = copyPackage(local, remote);
-        if (isCopied) {
-            String command = null;
-            if ( isInstalled ) {
-                command = String.format(DebugTool.RPM_UPGRADE_COMMAND, remote);
-            }
-            else {
-                command = String.format(DebugTool.RPM_INSTALL_COMMAND, remote);
-            }
-            try {
-                command = command + String.format("; rm -f %s", remote);
-                device.executeShellCommand(command);
-            } catch (IOException e) {
-                Logger.error("Error occurred while executing rpm command " + command , e);
-            }
-        }
-        else if (!isCopied) {
-            Logger.error("Failed file copy ( " + tool.getBinaryname() + " )");
-        }
-    }
-
-    private void installCoreException(String message, Throwable exception) throws CoreException {
-        Status status = new Status(Status.ERROR, ConnectionPlugin.PLUGIN_ID, message, exception);
-        throw new CoreException(status);
-    }
-    
-    class OnDemandInstall implements Runnable {
-        private final DebugTool tool;
-        
-        OnDemandInstall(final DebugTool tool) {
-            this.tool = tool;
-        }
-        
-        @Override
-        public void run() {
-            try {
-                if ( DebugTool.RPM_PACKAGE_TYPE.equals(tool.getPackagetype()) ) {
-                    installRPMPackage(tool);
-                }
-                else {
-                    installTarPackage(tool);
-                }
-            } catch (CoreException e) {
-                Logger.error("Error to install tools", e);
-            }
-        }
-    }
-}
-
-public class ToolsInstall {
-
-    public static void installPackages(IDevice device) {
-        final IDevice tDevice = device;
-
-        if (tDevice.isOffline()) {
-            return;
-        }
-
-        Display.getDefault().asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                final PackageInstallMonitorDialog installDialog = new PackageInstallMonitorDialog(
-                        Display.getDefault().getActiveShell());
-                try {
-                    InstallProgress installProgress = new InstallProgress();
-                    installProgress.setDevice(tDevice);
-                    installDialog.run(true, false, installProgress);
-                } catch (InvocationTargetException e) {
-                    Logger.error("Failed on-demand install", e);
-                    return;
-                } catch (InterruptedException e) {
-                    Logger.error("Failed on-demand install", e);
-                    return;
-                }
-            }
-        });
-    }
-}
index 99a0729..9951145 100755 (executable)
@@ -81,7 +81,7 @@ import org.tizen.common.connection.ddmuilib.FileDialogUtils;
 import org.tizen.common.connection.ddmuilib.Panel;
 import org.tizen.common.connection.ddmuilib.SyncProgressMonitor;
 import org.tizen.common.connection.ddmuilib.TableHelper;
-import org.tizen.common.connection.debugtools.ToolsInstall;
+import org.tizen.common.connection.debugtools.OnDemandInstall;
 import org.tizen.common.connection.preference.TizenConnectionExplorerPreferencePage;
 import org.tizen.common.connection.sdblib.dnd.FileEntryTransfer;
 import org.tizen.common.connection.ui.ConnectionUIMessages;
@@ -976,7 +976,12 @@ public class ConnectionExplorerPanel extends Panel implements IDeviceChangeListe
             return;
         }
         devicesList.add(device);
-        ToolsInstall.installPackages(device);
+
+        // Installs on demand all packages Tizen SDK needed
+        OnDemandInstall onDemand = new OnDemandInstall(device);
+        onDemand.setBlocking(false);
+        onDemand.install(OnDemandInstall.getNullIProgressMonitor());
+
         execRefresh();
     }