DEBUG: Set smack rule when debugging a project
authordonghyuk.yang <donghyuk.yang@samsung.com>
Mon, 21 Apr 2014 06:28:12 +0000 (15:28 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Mon, 21 Apr 2014 06:28:12 +0000 (15:28 +0900)
Smack rule was set by sdbd before but it will be set by IDE now. So, pkg
launcher set smack rule after installing packages.

Change-Id: Ib9476418239e221f7724a9be0fc7adc563c4c40d
Signed-off-by: donghyuk.yang <donghyuk.yang@samsung.com>
org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/LaunchConfigurationProcessor.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/IPkgCommander.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/deb/DebCommanderHost.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderDevice.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderHost.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderRootstrap.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/rds/RpmRapidDeployer.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/PlatformLaunchUtil.java

index a69824b..4ee7481 100644 (file)
@@ -36,6 +36,7 @@ import org.tizen.nativeplatform.pkg.model.IPackage;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
 import org.tizen.nativeplatform.types.LaunchTypes;
 import org.tizen.nativeplatform.util.PackageUtil;
+import org.tizen.nativeplatform.util.PlatformLaunchUtil;
 import org.tizen.nativeplatform.util.PlatformProjectUtil;
 
 public class LaunchConfigurationProcessor implements ILaunchConfigurationProcessor {
@@ -83,8 +84,7 @@ public class LaunchConfigurationProcessor implements ILaunchConfigurationProcess
                 if (!installPackages(configurationIsSet, new SubProgressMonitor(monitor, 1))) {
                     descMsg = "Installation seems to be failed. Check package installation log.";
                 }
-                if (!setLaunchConfigurationForEFL(new SubProgressMonitor(monitor, 1), descMsg,
-                        isEflApp)) {
+                if (!setLaunchConfiguration(new SubProgressMonitor(monitor, 1), descMsg, isEflApp)) {
                     return false;
                 }
             } finally {
@@ -108,6 +108,7 @@ public class LaunchConfigurationProcessor implements ILaunchConfigurationProcess
             if (mode.equals(ILaunchManager.DEBUG_MODE)) {
                 pkgLauncher.debugLaunchPkgs(LaunchTypes.NONE, shell, new SubProgressMonitor(
                         monitor, 1));
+                setSmackRule();
             } else {
                 pkgLauncher.launchPkgs(shell, new SubProgressMonitor(monitor, 1));
             }
@@ -123,6 +124,38 @@ public class LaunchConfigurationProcessor implements ILaunchConfigurationProcess
 
     }
 
+    private void setSmackRule() {
+        String[] programPaths = PlatformLaunchUtil.getProgramPath(project);
+        if (programPaths == null || programPaths.length <= 0) {
+            return;
+        }
+        IPkgCommander commander = target.getDeviceCommander();
+        StringBuffer pathlist = new StringBuffer();
+        for (String path : programPaths) {
+            pathlist.append(path);
+            pathlist.append(" ");
+        }
+        String list = pathlist.toString().trim();
+        Map<String, String[]> smackInfo = PlatformLaunchUtil.getSmackInfo(commander, list);
+        if (smackInfo == null) {
+            return;
+        }
+        for (String filepath : smackInfo.keySet()) {
+            String[] labels = smackInfo.get(filepath);
+            String a_label = labels[0];
+            if (a_label != null && !a_label.isEmpty()) {
+                commander.executeBinary(getSmackRuleCommand(a_label));
+            }
+            commander.setSmackExecute(filepath, "\"\"");
+        }
+    }
+
+    private String getSmackRuleCommand(String value) {
+        value = value.replaceAll("\"", "");
+        String cmd = String.format("echo \"sdbd::home %s rwx\" | smackload", value);
+        return cmd;
+    }
+
     @SuppressWarnings("unchecked")
     private boolean installPackages(boolean configurationIsSet, IProgressMonitor monitor)
             throws CoreException {
@@ -156,7 +189,7 @@ public class LaunchConfigurationProcessor implements ILaunchConfigurationProcess
         }
     }
 
-    private boolean setLaunchConfigurationForEFL(IProgressMonitor monitor, final String descMsg,
+    private boolean setLaunchConfiguration(IProgressMonitor monitor, final String descMsg,
             final boolean isEflApp) throws CoreException {
         monitor.beginTask("", 1);
         final ILaunchConfigurationWorkingCopy wc = launchConfig.getWorkingCopy();
@@ -275,13 +308,14 @@ public class LaunchConfigurationProcessor implements ILaunchConfigurationProcess
     protected IConfiguration getBuildConfiguration() {
         return PlatformConfigurationManager.getDefaultConfiguration(project);
     }
-    
-    protected boolean questionIfNoPackagesToInstall(List<IPackage> devicePackages, List<IPackage> rootstrapPackages) {
+
+    protected boolean questionIfNoPackagesToInstall(List<IPackage> devicePackages,
+            List<IPackage> rootstrapPackages) {
         final StringBuffer msg = new StringBuffer();
         if (devicePackages.isEmpty()) {
             msg.append("There is no package to install to device.");
             msg.append("\n");
-        }        
+        }
         if (mode.equals(ILaunchManager.DEBUG_MODE) && rootstrapPackages.isEmpty()) {
             msg.append("There is no package to install to rootstrap.");
             msg.append("\n");
index fcbe3ca..fe94b12 100644 (file)
@@ -121,6 +121,8 @@ public interface IPkgCommander {
     ICommandStatus makeDir(String path);
 
     ICommandStatus removeFile(String path);
+    
+    ICommandStatus setSmackExecute(String path, String e_label);
 
     ICommandStatus changeSmack(String path, String a_label, String e_label);
 
index 17fd36f..84286e7 100644 (file)
@@ -310,4 +310,9 @@ public class DebCommanderHost implements IPkgCommander {
     @Override
     public void cancelExecution() {
     }
+
+    @Override
+    public ICommandStatus setSmackExecute(String path, String e_label) {
+        return null;
+    }
 }
index e3bdb01..ec587a3 100644 (file)
@@ -92,8 +92,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
             return new CommandStatus(IStatus.ERROR, "", syncResult.getMessage(), null);
         }
         value.add(pathOnDevice.toOSString());
-        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);
     }
 
@@ -112,7 +111,7 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
             } 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);
             }
@@ -190,7 +189,46 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
             String msgLog = status.getException().toString();
             String log = String.format("[Exception]%s:%s", cmdLog, msgLog);
             printResultLog(log);
-        }            
+        }
+        return status;
+    }
+
+    @Override
+    public ICommandStatus setSmackExecute(String path, String e_label) {
+        // 1. change smack information
+        StringBuffer sbCommand = new StringBuffer("chsmack");
+        // Something is wrong if access information is empty
+        // In case of this, smack may be not supported.
+        if (!e_label.isEmpty()) {
+            sbCommand.append(String.format(" -e %s", e_label));
+        }
+        sbCommand.append(String.format(" %s", path));
+        // 2. check the changing
+        sbCommand.append(String.format(";chsmack %s", path));
+        String command = sbCommand.toString();
+        ICommandStatus status = execute(command, null, false, false);
+        if (status.isOk()) {
+            List<String> value = status.getValues();
+            String e_result = "";
+            if (value.size() > 0) {
+                String line = value.get(0);
+                for (String info : line.split(" ")) {
+                    if (info.startsWith("execute")) {
+                        String[] e = info.split("=");
+                        if (e.length == 2) {
+                            e_result = e[1];
+                        }
+                    }
+                }
+            }
+            if (e_label.equals("\"\"") && e_result.isEmpty()) {
+                printResultLog(String.format("[RDS] Change smack: %s %s", path, e_label));
+            } else if (e_label.equals(e_result)) {
+                printResultLog(String.format("[RDS] Change smack: %s %s", path, e_label));
+            } else {
+                return null;
+            }
+        }
         return status;
     }
 
@@ -328,8 +366,8 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         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);
     }
 
@@ -345,8 +383,8 @@ public class RpmCommanderDevice extends RpmCommanderCommon {
         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);
         }
index 22df753..56edfc3 100644 (file)
@@ -158,4 +158,9 @@ public class RpmCommanderHost extends RpmCommanderCommon {
     public ICommandStatus executeBinary(String binary) {
         return null;
     }
+
+    @Override
+    public ICommandStatus setSmackExecute(String path, String e_label) {
+        return null;
+    }
 }
index b10f8e2..e9ebfdc 100644 (file)
@@ -263,4 +263,9 @@ public class RpmCommanderRootstrap extends RpmCommanderCommon {
     public ICommandStatus executeBinary(String binary) {
         return null;
     }
+
+    @Override
+    public ICommandStatus setSmackExecute(String path, String e_label) {
+        return null;
+    }
 }
index 4bfec33..6a73093 100644 (file)
@@ -17,6 +17,7 @@ import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.model.IPackage;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
 import org.tizen.nativeplatform.util.CommandLauncherUtil;
+import org.tizen.nativeplatform.util.PlatformLaunchUtil;
 
 public class RpmRapidDeployer {
     private IProject project;
@@ -81,7 +82,7 @@ public class RpmRapidDeployer {
         }
         Map<String, String[]> smackInfo = null;
         if (isDeviceCommander()) {
-            smackInfo = getSmackInfo(copyFileList);
+            smackInfo = PlatformLaunchUtil.getSmackInfo(commander, copyFileList);
             if (smackInfo == null) {
                 return false;
             }
@@ -181,58 +182,6 @@ public class RpmRapidDeployer {
         return true;
     }
 
-    private Map<String, String[]> getSmackInfo(String fileList) {
-        Map<String, String[]> smackInfo = new HashMap<String, String[]>();
-        String[] args;
-        if (fileList.length() > CommandLauncherUtil.LIMIT_COMMAND_LENGTH) {
-            args = CommandLauncherUtil.splitCommandArgs(fileList);
-        } else {
-            args = new String[1];
-            args[0] = fileList;
-        }
-        for (String arg : args) {
-            if (arg.isEmpty()) {
-                continue;
-            }
-            ICommandStatus status = commander.getSmack(arg);
-            if (status == null || !status.isOk()) {
-                logger.error(String.format("Failed to get smack info [%s]", fileList));
-                return null;
-            }
-            List<String> result = status.getValues();
-            if (result == null) {
-                logger.error(String.format("Failed to get smack info [%s]", fileList));
-                return null;
-            }
-            for (String line : result) {
-                String targetFile = "";
-                String labels[] = { "", "" };
-                for (String info : line.split(" ")) {
-                    if (info.startsWith("access=")) {
-                        String[] a_label = info.split("=");
-                        if (a_label.length == 2) {
-                            labels[0] = a_label[1].trim();
-                        }
-                    } else if (info.startsWith("execute")) {
-                        String[] e_label = info.split("=");
-                        if (e_label.length == 2) {
-                            labels[1] = e_label[1].trim();
-                        }
-                    } else {
-                        targetFile = info;
-                    }
-                }
-                if (targetFile.isEmpty()) {
-                    logger.error(String.format("Failed to get smack info [%s]", fileList));
-                    return null;
-                } else {
-                    smackInfo.put(targetFile, labels);
-                }
-            }
-        }
-        return smackInfo;
-    }
-
     // compare source data and target data. divide all files into four list parts.
     private String groupFiles(Map<String, String> sourceChecksums,
             Map<String, String> targetChecksums, List<String> copyList, List<String> addList,
index bebd7ca..0308f2a 100644 (file)
@@ -34,7 +34,9 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -60,6 +62,7 @@ import org.tizen.nativecommon.launch.TizenLaunchCommand;
 import org.tizen.nativecommon.launch.TizenLaunchMessages;
 import org.tizen.nativeplatform.IPlatformXMLStore;
 import org.tizen.nativeplatform.launch.PlatformLaunchMessages;
+import org.tizen.nativeplatform.pkg.commander.ICommandStatus;
 import org.tizen.nativeplatform.pkg.commander.IPkgCommander;
 import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget;
 import org.tizen.nativeplatform.types.CmdTargetTypes;
@@ -267,6 +270,20 @@ public class PlatformLaunchUtil {
             return null;
         }
     }
+    
+    public static String[] getProgramPath(IProject project, String appId) {
+        IPlatformXMLStore store = PlatformProjectUtil.getManifestXmlStore(project);
+        if (store.loadXml()) {
+            List<String> files = store.getExecutableFiles(appId);
+            if (files != null && files.size() > 0) {
+                return files.toArray(new String[0]);
+            } else {
+                return null;
+            }
+        } else {
+            return null;
+        }
+    }
 
     public static String[] getAppId(IProject project) {
         IPlatformXMLStore store = PlatformProjectUtil.getManifestXmlStore(project);
@@ -366,4 +383,56 @@ public class PlatformLaunchUtil {
             return null;
         }
     }
+    
+    public static Map<String, String[]> getSmackInfo(IPkgCommander commander, String fileList) {
+        Map<String, String[]> smackInfo = new HashMap<String, String[]>();
+        String[] args;
+        if (fileList.length() > CommandLauncherUtil.LIMIT_COMMAND_LENGTH) {
+            args = CommandLauncherUtil.splitCommandArgs(fileList);
+        } else {
+            args = new String[1];
+            args[0] = fileList;
+        }
+        for (String arg : args) {
+            if (arg.isEmpty()) {
+                continue;
+            }
+            ICommandStatus status = commander.getSmack(arg);
+            if (status == null || !status.isOk()) {
+                logger.error(String.format("Failed to get smack info [%s]", fileList));
+                return null;
+            }
+            List<String> result = status.getValues();
+            if (result == null) {
+                logger.error(String.format("Failed to get smack info [%s]", fileList));
+                return null;
+            }
+            for (String line : result) {
+                String targetFile = "";
+                String labels[] = { "", "" };
+                for (String info : line.split(" ")) {
+                    if (info.startsWith("access=")) {
+                        String[] a_label = info.split("=");
+                        if (a_label.length == 2) {
+                            labels[0] = a_label[1].trim();
+                        }
+                    } else if (info.startsWith("execute")) {
+                        String[] e_label = info.split("=");
+                        if (e_label.length == 2) {
+                            labels[1] = e_label[1].trim();
+                        }
+                    } else {
+                        targetFile = info;
+                    }
+                }
+                if (targetFile.isEmpty()) {
+                    logger.error(String.format("Failed to get smack info [%s]", fileList));
+                    return null;
+                } else {
+                    smackInfo.put(targetFile, labels);
+                }
+            }
+        }
+        return smackInfo;
+    }
 }