LAUNCH: Add method to launch debug-attach through smart launch 58/13158/2
authorhyunsik.noh <hyunsik.noh@samsung.com>
Thu, 28 Nov 2013 12:04:30 +0000 (21:04 +0900)
committerhyunsik.noh <hyunsik.noh@samsung.com>
Sun, 1 Dec 2013 08:00:40 +0000 (17:00 +0900)
Add method to launch debug-attach called by DebugHybridAppListener

Change-Id: I5df7f398002e56b00d17841301bb8ee77355ee5d
Signed-off-by: hyunsik.noh <hyunsik.noh@samsung.com>
org.tizen.common.gom/src/org/tizen/common/gom/launch/GomDebugAttachLaunchData.java [new file with mode: 0644]
org.tizen.common.gom/src/org/tizen/common/gom/launch/GomLaunchData.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/GomSmartLauncher.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/GomSmartUILauncher.java [new file with mode: 0644]
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/action/GomSmartLaunchToolbarAction.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/handler/GomSmartLaunchCycleHandler.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/handler/GomSmartLaunchHandler.java
org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/ui/GomDialog.java

diff --git a/org.tizen.common.gom/src/org/tizen/common/gom/launch/GomDebugAttachLaunchData.java b/org.tizen.common.gom/src/org/tizen/common/gom/launch/GomDebugAttachLaunchData.java
new file mode 100644 (file)
index 0000000..009158e
--- /dev/null
@@ -0,0 +1,21 @@
+package org.tizen.common.gom.launch;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
+import org.tizen.sdblib.IDevice;
+
+public class GomDebugAttachLaunchData extends GomLaunchData{
+    
+    private boolean isHybridLaunch = false;
+
+    public GomDebugAttachLaunchData(IProject project, String configurationName, String buildConfiguration, String mode,
+            LaunchShortcutExtension ext, IDevice device, boolean isHybridLaunch) {
+        super(project, configurationName, buildConfiguration, mode, ext, device);
+        this.isHybridLaunch = isHybridLaunch;
+    }
+    
+    public boolean isHybridLaunch() {
+        return isHybridLaunch;
+    }
+
+}
index 3e5223c..3678a1c 100644 (file)
@@ -33,6 +33,7 @@ import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtensio
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.common.gom.smartlaunch.GomSmartLauncher;
+import org.tizen.common.gom.smartlaunch.GomSmartUILauncher;
 import org.tizen.common.launch.ITizenLaunchConfiguration;
 import org.tizen.common.launch.ITizenNativeLaunchConfiguration;
 import org.tizen.common.launch.ITizenWebLaunchConfiguration;
@@ -43,18 +44,27 @@ public class GomLaunchData {
     
     private Logger logger = LoggerFactory.getLogger(getClass());
     
-    private IProject project;
-    private ILaunchConfiguration launchConfiguration;
-    private String launchConfigurationName;
-    private String buildConfiguration;
-    private String mode;
-    private LaunchShortcutExtension ext;
-    private IDevice device;
+    private IProject project = null;
+    private ILaunchConfiguration launchConfiguration = null;
+    private String launchConfigurationName = null;
+    private String buildConfiguration = null;
+    private String mode = null;
+    private LaunchShortcutExtension ext = null;
+    private IDevice device = null;
     
+    /**
+     * This is a value object has various information needed to launch Tizen project.
+     * @param project Tizen project.
+     * @param configurationName Launch configuration name(make new one if it is not exist).
+     * @param buildConfiguration Configuration name to build Tizen native project(not need for Tizen web project).
+     * it uses current build configuration if this argument is null.
+     * @param mode Three type of launch mode: Run, Debug, Dynamic Analyzer
+     * @param ext Launch shortcut extension.
+     * @param device Device to launch Tizen project. It determines device later if this argument is null.
+     */
     public GomLaunchData(IProject project, String configurationName, String buildConfiguration, String mode, LaunchShortcutExtension ext, IDevice device)
     {
         this.project = project;
-        this.launchConfiguration = null;
         this.launchConfigurationName = configurationName;
         this.buildConfiguration = buildConfiguration;
         this.mode = mode;
@@ -62,13 +72,17 @@ public class GomLaunchData {
         this.device = device;
     }
     
-    //launch add
+    /**
+     * This is a value object has various information needed to launch Tizen project.
+     * It get the values from previous launch.
+     * @param launch previous launch.
+     * @throws CoreException
+     */
     public GomLaunchData(ILaunch launch)
     {
         launchConfiguration = launch.getLaunchConfiguration();
         launchConfigurationName = launchConfiguration.getName();
         mode = launch.getLaunchMode();
-        this.device = null;
         String config_device_id = null;
         try {
         config_device_id = launchConfiguration.getAttribute(GomSmartLauncher.ATTR_CONFIG_DEVICE_ID,
@@ -103,7 +117,10 @@ public class GomLaunchData {
     {
         return launchConfigurationName;
     }
-    
+    /**
+     * This method returns short information from launch configuration.
+     * @return
+     */
     public String getDataInfo()
     {
         if(device != null) {
index 1fc2728..4126316 100644 (file)
  */
 package org.tizen.common.gom.smartlaunch;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
 import org.eclipse.debug.ui.DebugUITools;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.activities.WorkbenchActivityHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.common.gom.launch.GomLaunchData;
 import org.tizen.common.gom.launch.IGomSmartLaunchShortcut;
 import org.tizen.common.gom.smartlaunch.messages.GomMessages;
-import org.tizen.common.gom.smartlaunch.ui.GomDialog;
 import org.tizen.common.util.ProjectUtil;
 import org.tizen.common.util.SWTUtil;
 import org.tizen.sdblib.IDevice;
@@ -48,13 +55,26 @@ public class GomSmartLauncher {
     
     public static final String ATTR_CONFIG_DEVICE_ID = "org.tizen.common.launch.device.id";
     public static final String ATTR_CONFIG_DEVICE_IS_EMULATOR = "org.tizen.common.launch.device.emulator";
-    
     public static final String ATTR_CONFIG_NO_DEVICE = "";
+    private static final String DEBUG_ATTACH = "Attach";
+    
+    public static enum MODES  {
+        RUN(ILaunchManager.RUN_MODE),
+        DEBUG(ILaunchManager.DEBUG_MODE),
+        PROFILE(ILaunchManager.PROFILE_MODE);
+        
+        private String mode;
+        
+        private MODES(String mode) {
+            this.mode = mode;
+        }
+        public String getMode() {
+            return mode;
+        }
+    }
     
-    private static GomDialog gomDialog = null;
-
     private final static Logger logger = LoggerFactory.getLogger(GomSmartLauncher.class);
-
+    
     public static void smartLaunch(final GomLaunchData data) {
         if(data.getLaunchConfiguration() == null) {
             
@@ -76,64 +96,66 @@ public class GomSmartLauncher {
         }
     }
     
-    public static void openDialog(IWorkbenchWindow window) {
-        if(gomDialog == null) {
-            if(existTizenProjectBeforeDialogOpen(window)) {
-                gomDialog = new GomDialog(window.getShell());
-                if(gomDialog.open() == Window.OK) {
-                    IProject project = gomDialog.getProject();
-                    if(existProjectAndDeviceBeforeLaunch(project, window)) {
-                        smartLaunch(getLaunchData(gomDialog));
-                    }
-                }
-                gomDialog = null;
-            } else {
-                MessageDialog.openError(window.getShell(), GomMessages.SMARTLAUNCH_FAIL, GomMessages.SMARTLAUNCH_NO_PROJECT);
-            }
-        }
-    }
-    
-    private static GomLaunchData getLaunchData(GomDialog dialog) {
-        GomLaunchData data = new GomLaunchData(dialog.getProject(), dialog.getConfigurationName(), dialog.getBuildConfiguration()
-                , dialog.getMode(), dialog.getLaunchShortcutExtension(), null);
-        return data;
-    }
-    
-    private static boolean existTizenProjectBeforeDialogOpen(IWorkbenchWindow window) {
+    public static boolean isExistProjectAndDevice(IProject project, IWorkbenchWindow window) {
         boolean result = false;
-        
-        if(window != null) {
-            IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
-            if(projects.length != 0) {
-                for(IProject project: projects) {
-                    if(ProjectUtil.isTizenProject(project)) {
-                        result = true;
-                        break;
-                    }
-                }
-            }
-        }
-        
-        return result;
-    }
-
-    public static boolean existProjectAndDeviceBeforeLaunch(IProject project, IWorkbenchWindow window) {
-        boolean result = false;
-        
+        String message = null;
         if(!project.exists()) {
-            MessageDialog.openError(window.getShell(), GomMessages.SMARTLAUNCH_FAIL, NLS.bind(GomMessages.SMARTLAUNCH_UNEXIST_PROJECT, project.getName()));
+            message = NLS.bind(GomMessages.SMARTLAUNCH_UNEXIST_PROJECT, project.getName());
         } else {
             if(ProjectUtil.isTizenNativeProject(project)) {
                 IDevice selectedDevice = ConnectionPlugin.getDefault().getCurrentDevice();
                 if(selectedDevice != null) {
                     result = true;
                 } else {
-                    MessageDialog.openError(window.getShell(), GomMessages.SMARTLAUNCH_FAIL, GomMessages.SMARTLAUNCH_DISCONNECTED_DEVICE);
+                    message = GomMessages.SMARTLAUNCH_DISCONNECTED_DEVICE;
                 }
             } else {
                 result = true;
             }
         }
+        if(message != null) {
+            logger.error(message);
+            if(window != null) {
+                MessageDialog.openError(window.getShell(),  GomMessages.SMARTLAUNCH_FAIL, message);
+            }
+        }
         return result;
     }
+    
+    public static List getShortcuts(IProject project, String mode) {
+        LaunchConfigurationManager mgr = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
+        List allShortcuts = mgr.getLaunchShortcuts(project);
+        Iterator iter = allShortcuts.iterator();
+        List filteredShortcuts = new ArrayList();
+        while (iter.hasNext()) {
+            LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
+            if (!WorkbenchActivityHelper.filterItem(ext)) {
+                Set modes = ext.getModes(); // supported launch modes
+                Iterator modeIter = modes.iterator();
+                while (modeIter.hasNext()) {
+                    String modee = (String) modeIter.next();
+                    if (modee.equals(mode)) {
+                        filteredShortcuts.add(ext);
+                    }
+                }
+            }
+        }
+        return filteredShortcuts;
+    }
+    
+    public static LaunchShortcutExtension getDebugAttachShortcut(IProject project) {
+        String mode = MODES.DEBUG.mode;
+        List shortcuts = getShortcuts(project, mode);
+        LaunchShortcutExtension ext = null;
+        Iterator iter = shortcuts.iterator();
+        while (iter.hasNext()) {
+            ext = (LaunchShortcutExtension) iter.next();
+            String label= ext.getContextLabel(mode);
+            if(label.contains(DEBUG_ATTACH)) {
+                System.out.println(label);
+                break;
+            }
+        }
+        return ext;
+    }
 }
diff --git a/org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/GomSmartUILauncher.java b/org.tizen.common.gom/src/org/tizen/common/gom/smartlaunch/GomSmartUILauncher.java
new file mode 100644 (file)
index 0000000..0dc296a
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Common
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: 
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * Hyunsik Noh <hyunsik.noh@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.gom.smartlaunch;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.gom.launch.GomLaunchData;
+import org.tizen.common.gom.smartlaunch.messages.GomMessages;
+import org.tizen.common.gom.smartlaunch.ui.GomDialog;
+import org.tizen.common.util.ProjectUtil;
+
+public class GomSmartUILauncher {
+    
+    private static GomDialog gomDialog = null;
+
+    private final static Logger logger = LoggerFactory.getLogger(GomSmartUILauncher.class);
+
+    public static void openDialog(IWorkbenchWindow window) {
+        if(gomDialog == null) {
+            if(existTizenProjectBeforeDialogOpen(window)) {
+                gomDialog = new GomDialog(window.getShell());
+                if(gomDialog.open() == Window.OK) {
+                    IProject project = gomDialog.getProject();
+                    if(GomSmartLauncher.isExistProjectAndDevice(project, window)) {
+                        GomSmartLauncher.smartLaunch(getLaunchData(gomDialog));
+                    }
+                }
+                gomDialog = null;
+            } else {
+                MessageDialog.openError(window.getShell(), GomMessages.SMARTLAUNCH_FAIL, GomMessages.SMARTLAUNCH_NO_PROJECT);
+            }
+        }
+    }
+    
+    private static GomLaunchData getLaunchData(GomDialog dialog) {
+        GomLaunchData data = new GomLaunchData(dialog.getProject(), dialog.getConfigurationName(), dialog.getBuildConfiguration()
+                , dialog.getMode(), dialog.getLaunchShortcutExtension(), null);
+        return data;
+    }
+    
+    private static boolean existTizenProjectBeforeDialogOpen(IWorkbenchWindow window) {
+        boolean result = false;
+        
+        if(window != null) {
+            IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+            if(projects.length != 0) {
+                for(IProject project: projects) {
+                    if(ProjectUtil.isTizenProject(project)) {
+                        result = true;
+                        break;
+                    }
+                }
+            }
+        }
+        
+        return result;
+    }
+}
index 54c4d6b..506c8af 100644 (file)
@@ -42,6 +42,7 @@ import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
 import org.tizen.common.gom.launch.GomLaunchData;
 import org.tizen.common.gom.smartlaunch.GomSmartLauncher;
+import org.tizen.common.gom.smartlaunch.GomSmartUILauncher;
 import org.tizen.common.gom.smartlaunch.GomSmartLaunchManager;
 import org.tizen.common.gom.smartlaunch.messages.GomMessages;
 
@@ -74,12 +75,12 @@ public class GomSmartLaunchToolbarAction implements IWorkbenchWindowPulldownDele
         if(recentIndex > -1)
         {
             GomLaunchData data = list.get(recentIndex);
-            if(GomSmartLauncher.existProjectAndDeviceBeforeLaunch(data.getProject(), window)) {
+            if(GomSmartLauncher.isExistProjectAndDevice(data.getProject(), window)) {
                 new GomSmartLaunchAction(data).run();
             }
         }else
         {
-            GomSmartLauncher.openDialog(window);
+            GomSmartUILauncher.openDialog(window);
         }
     }
 
@@ -126,7 +127,7 @@ public class GomSmartLaunchToolbarAction implements IWorkbenchWindowPulldownDele
             @Override
             public void run()
             {
-                GomSmartLauncher.openDialog(window);
+                GomSmartUILauncher.openDialog(window);
             }
         };
         addAction.setText(GomMessages.SMARTLAUNCH_NEW);
index b403a12..f54ccfa 100644 (file)
@@ -50,6 +50,7 @@ import org.eclipse.ui.internal.CycleBaseHandler;
 import org.eclipse.ui.internal.WorkbenchPage;
 import org.tizen.common.gom.launch.GomLaunchData;
 import org.tizen.common.gom.smartlaunch.GomSmartLaunchManager;
+import org.tizen.common.gom.smartlaunch.GomSmartUILauncher;
 import org.tizen.common.gom.smartlaunch.GomSmartLauncher;
 import org.tizen.common.gom.smartlaunch.messages.GomMessages;
 import org.tizen.sdblib.IDevice;
@@ -242,7 +243,7 @@ public class GomSmartLaunchCycleHandler extends CycleBaseHandler {
 
         if (selectedItem instanceof GomLaunchData) {
             GomLaunchData data = (GomLaunchData)selectedItem;
-            if(GomSmartLauncher.existProjectAndDeviceBeforeLaunch(data.getProject(), window)) {
+            if(GomSmartLauncher.isExistProjectAndDevice(data.getProject(), window)) {
                 GomSmartLauncher.smartLaunch(data);
             }
         }
index 731d054..885801f 100644 (file)
@@ -30,14 +30,14 @@ import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.handlers.HandlerUtil;
-import org.tizen.common.gom.smartlaunch.GomSmartLauncher;
+import org.tizen.common.gom.smartlaunch.GomSmartUILauncher;
 
 public class GomSmartLaunchHandler extends AbstractHandler {
 
     @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
         IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
-        GomSmartLauncher.openDialog(window);
+        GomSmartUILauncher.openDialog(window);
         return null;
     }
 }
index 65deaaf..4785439 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Set;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunchManager;
 import org.eclipse.debug.internal.ui.DebugUIPlugin;
 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
@@ -54,6 +55,8 @@ import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.activities.WorkbenchActivityHelper;
 import org.tizen.common.ITizenNativeProject;
 import org.tizen.common.TizenHelpContextIds;
+import org.tizen.common.gom.smartlaunch.GomSmartLauncher;
+import org.tizen.common.gom.smartlaunch.GomSmartLauncher.MODES;
 import org.tizen.common.gom.smartlaunch.messages.GomMessages;
 import org.tizen.common.util.FilenameUtil;
 import org.tizen.common.util.OSChecker;
@@ -71,10 +74,10 @@ public class GomDialog extends TitleAreaDialog{
     private Combo comboBuildConfiguration;
     private Combo comboShortcut;
     
-    private String[] modes= {ILaunchManager.RUN_MODE, ILaunchManager.DEBUG_MODE, ILaunchManager.PROFILE_MODE};
+    private String[] modes= {MODES.RUN.getMode(), MODES.DEBUG.getMode(), MODES.PROFILE.getMode()};
     private List<IProject> projectList = new ArrayList<IProject>();
     private List<String> configList = new ArrayList<String>();
-    private List filteredShortCuts = null;
+    private List filteredShortcuts = null;
     
     private String configurationName;
     private IProject project;
@@ -368,7 +371,7 @@ public class GomDialog extends TitleAreaDialog{
             public void widgetSelected(SelectionEvent e)
             {
                 Combo combo = (Combo) e.widget;
-                ext = (LaunchShortcutExtension)filteredShortCuts.get(combo.getSelectionIndex());
+                ext = (LaunchShortcutExtension)filteredShortcuts.get(combo.getSelectionIndex());
             }
 
             @Override
@@ -397,28 +400,16 @@ public class GomDialog extends TitleAreaDialog{
     private void setShortcutCombo() {
         comboShortcut.removeAll();
         
-        LaunchConfigurationManager mgr = DebugUIPlugin.getDefault().getLaunchConfigurationManager();
-        List allShortCuts = mgr.getLaunchShortcuts(project);
-        Iterator iter = allShortCuts.iterator();
-        filteredShortCuts = new ArrayList();
+        filteredShortcuts = GomSmartLauncher.getShortcuts(project, mode);
+        Iterator iter = filteredShortcuts.iterator();
         while (iter.hasNext()) {
             LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
-            if (!WorkbenchActivityHelper.filterItem(ext)) {
-                Set modes = ext.getModes(); // supported launch modes
-                Iterator modeIter = modes.iterator();
-                while (modeIter.hasNext()) {
-                    String modee = (String) modeIter.next();
-                    if (modee.equals(mode)) {
-                        filteredShortCuts.add(ext);
-                        comboShortcut.add(ext.getContextLabel(mode));
-                    }
-                }
-            }
+            comboShortcut.add(ext.getContextLabel(mode));
         }
         
         if(setComboSelectDefault(comboShortcut))
         {
-            ext = (LaunchShortcutExtension)filteredShortCuts.get(0);
+            ext = (LaunchShortcutExtension)filteredShortcuts.get(0);
         }
     }