From 04a3aa217fe8e4e33a9ca6d99fe47ed581d12a44 Mon Sep 17 00:00:00 2001 From: "donghyuk.yang" Date: Thu, 27 Jun 2013 18:47:45 +0900 Subject: [PATCH] [Title] Separated common class from launch shortcut classes --- .../PlatformProjectAttachLaunchShortcut.java | 270 +----------------- .../PlatformProjectCommonLaunchShortcut.java | 303 +++++++++++++++++++++ .../PlatformProjectCoredumpLaunchShortcut.java | 129 +-------- .../ui/shortcut/PlatformProjectLaunchShortcut.java | 262 +----------------- 4 files changed, 313 insertions(+), 651 deletions(-) create mode 100644 org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCommonLaunchShortcut.java diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectAttachLaunchShortcut.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectAttachLaunchShortcut.java index 88476aa..b658451 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectAttachLaunchShortcut.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectAttachLaunchShortcut.java @@ -27,19 +27,10 @@ package org.tizen.nativeplatform.launch.ui.shortcut; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; -import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; -import org.eclipse.cdt.debug.internal.ui.launch.CApplicationLaunchShortcut; import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.ICDebuggerPage; @@ -49,183 +40,24 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; -import org.eclipse.debug.core.sourcelookup.ISourceContainer; -import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; -import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementListSelectionDialog; -import org.tizen.common.connection.ConnectionPlugin; -import org.tizen.common.util.DialogUtil; -import org.tizen.nativecommon.build.SmartBuildInterface; import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants; -import org.tizen.nativecommon.launch.TizenLaunchMessages; -import org.tizen.nativeplatform.build.PlatformConfigurationManager; import org.tizen.nativeplatform.launch.ITizenLaunchConfigurationConstants; -import org.tizen.nativeplatform.launch.PlatformLaunchMessages; import org.tizen.nativeplatform.launch.wizards.PlatformAttachLaunchWizard; -import org.tizen.nativeplatform.launch.wizards.PlatformLaunchUtils; import org.tizen.nativeplatform.launch.wizards.PlatformLaunchWizardDialog; -import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget; -import org.tizen.nativeplatform.rootstrap.RootstrapManager; -import org.tizen.nativeplatform.views.model.PlatformRootstrap; -import org.tizen.sdblib.IDevice; + @SuppressWarnings("restriction") -public class PlatformProjectAttachLaunchShortcut extends CApplicationLaunchShortcut { +public class PlatformProjectAttachLaunchShortcut extends PlatformProjectCommonLaunchShortcut { - private String programPath = null; - private boolean reinstallOp = true; - private boolean selectPkgOp = true; private String procName = ""; - private IDevice device = null; private int pid; - private PkgCommandTarget target = null; - - private ISourceLookupDirector fLocator; - - public void launch(IProject project, String mode) { - searchAndLaunch(new Object[] { project }, mode); - } - - @Override - public void launch(IEditorPart editor, String mode) { - searchAndLaunch(new Object[] { editor.getEditorInput() }, mode); - } - - @Override - public void launch(ISelection selection, String mode) { - if (selection instanceof IStructuredSelection) { - searchAndLaunch(((IStructuredSelection) selection).toArray(), mode); - } - } - - private void searchAndLaunch(final Object[] elements, String mode) { - device = ConnectionPlugin.getDefault().getCurrentDevice(); - if (device == null) { - DialogUtil.openErrorDialog(TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE); - return; - } - if (!device.isRoot()) { - DialogUtil.openErrorDialog(PlatformLaunchMessages.DEVICE_IS_NOT_ROOT_ON); - return; - } - - if (elements != null && elements.length > 0) { - int nElements = elements.length; - for (int i = 0; i < nElements; i++) { - if (elements[i] instanceof IAdaptable) { - IResource r = (IResource) ((IAdaptable) elements[i]) - .getAdapter(IResource.class); - if (r != null) { - IProject project = r.getProject(); - if (project != null) { - ILaunchConfiguration config = findLaunchConfiguration(project, mode); - if (config != null) { - DebugUITools.launch(config, mode); - } - } - } - } - } - } - } - - protected ILaunchConfiguration findLaunchConfiguration(IProject project, String mode) { - ILaunchConfiguration configuration = null; - // Set the default debugger based on the active toolchain on the project - // (if possible) - ICDebugConfiguration debugConfig = null; - ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); - ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); - String configId = configDesc.getId(); - ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault() - .getActiveDebugConfigurations(); - int matchLength = 0; - for (int i = 0; i < debugConfigs.length; ++i) { - ICDebugConfiguration dc = debugConfigs[i]; - String[] patterns = dc.getSupportedBuildConfigPatterns(); - if (patterns != null) { - for (int j = 0; j < patterns.length; ++j) { - if (patterns[j].length() > matchLength && configId.matches(patterns[j])) { - debugConfig = dc; - matchLength = patterns[j].length(); - } - } - } - } - - if (debugConfig == null) { - // Prompt the user if more then 1 debugger. - debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); - List debugList = new ArrayList( - debugConfigs.length); - for (int i = 0; i < debugConfigs.length; i++) { - if (debugConfigs[i] - .supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - if (debugConfigs[i].getName().contains("Tizen")) //$NON-NLS-1$ - debugList.add(debugConfigs[i]); - } - } - debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]); - if (debugConfigs.length == 1) - debugConfig = debugConfigs[0]; - else if (debugConfigs.length > 1) - debugConfig = chooseDebugConfig(debugConfigs, mode); - } - - configuration = createConfiguration(project, debugConfig, mode); - - return configuration; - } - - private ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) { - ILabelProvider provider = new LabelProvider() { - public String getText(Object element) { - if (element == null) { - return ""; //$NON-NLS-1$ - } else if (element instanceof ICDebugConfiguration) { - return ((ICDebugConfiguration) element).getName(); - } - return element.toString(); - } - }; - ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider); - dialog.setElements(debugConfigs); - dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode)); - dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode)); - dialog.setMultipleSelection(false); - int result = dialog.open(); - provider.dispose(); - if (result == Window.OK) { - return (ICDebugConfiguration) dialog.getFirstResult(); - } - return null; - } - - private void setPkgCommandTarget(IProject project) { - IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); - IConfiguration defaultConfig = info.getDefaultConfiguration(); - String targetId = PlatformConfigurationManager.getBuildTargetName(defaultConfig); - String rootId = SmartBuildInterface.getInstance().getRootstrapIDFromTargetID(targetId); - PlatformRootstrap rootstrap = RootstrapManager.getRootstrap(rootId); - target = new PkgCommandTarget(device, rootstrap); - } protected ILaunchConfiguration createConfiguration(IProject project, ICDebugConfiguration debugConfig, String mode) { @@ -271,8 +103,7 @@ public class PlatformProjectAttachLaunchShortcut extends CApplicationLaunchShort } // Load up the debugger page to set the defaults. There should - // probably be a separate - // extension point for this. + // probably be a separate extension point for this. ICDebuggerPage page = CDebugUIPlugin.getDefault().getDebuggerPage(debugConfig.getID()); setSourceContainer(project, wc); page.setDefaults(wc); @@ -311,101 +142,6 @@ public class PlatformProjectAttachLaunchShortcut extends CApplicationLaunchShort } } - private void setSourceContainer(IProject project, ILaunchConfigurationWorkingCopy configuration) { - /* - * IManagedBuildInfo info = ManagedBuildManager.getBuildInfo( project ) - * ; IConfiguration config = info.getDefaultConfiguration(); String - * targetId = PlatformConfigurationManager.getBuildTargetName(config); - * String rootId = - * SmartBuildInterface.getInstance().getRootstrapIDFromTargetID - * (targetId); PlatformRootstrap rootstrap = - * RootstrapManager.getRootstrap(rootId); - */ - PlatformRootstrap rootstrap = target.getRootstrap(); - - String basePath = rootstrap.getPath().toOSString(); - PlatformLaunchUtils launchUtils = new PlatformLaunchUtils(target); - String rootstrapPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(basePath); - DirectorySourceContainer container = new DirectorySourceContainer(new Path(rootstrapPath), - true); - MappingSourceContainer mappingContainer = new MappingSourceContainer("Source mapping"); - MapEntrySourceContainer entry = new MapEntrySourceContainer(); - String[] infos = launchUtils.getProjectInfo(project); - String backend = String.format("/usr/src/debug/%s-%s", infos[0], infos[1]); - String local = project.getLocation().toOSString(); - - entry.setBackendPath(new Path(backend)); - entry.setLocalPath(new Path(local)); - mappingContainer.addMapEntry(entry); - - if (fLocator != null) { - fLocator.dispose(); - fLocator = null; - } - - String memento = null; - String type = null; - try { - memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, - (String) null); - type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, - (String) null); - if (type == null) { - type = configuration.getType().getSourceLocatorId(); - } - } catch (CoreException e) { - return; - } - - if (type == null) { - return; - } - - try { - ISourceLocator locator = getLaunchManager().newSourceLocator(type); - if (!(locator instanceof AbstractSourceLookupDirector)) { - // migrate to the new source lookup infrastructure - memento = null; // don't use old memento - type = configuration.getType().getSourceLocatorId(); - if (type == null) { - return; - } - locator = getLaunchManager().newSourceLocator(type); - if (!(locator instanceof AbstractSourceLookupDirector)) { - return; - } - } - fLocator = (AbstractSourceLookupDirector) locator; - if (memento == null) { - fLocator.initializeDefaults(configuration); - } else { - fLocator.initializeFromMemento(memento, configuration); - } - } catch (CoreException e) { - return; - } - - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null); - - int length = fLocator.getSourceContainers().length; - ISourceContainer[] containers = new ISourceContainer[length + 2]; - containers[0] = mappingContainer; - containers[1] = container; - containers[2] = fLocator.getSourceContainers()[0]; - - fLocator.setSourceContainers(containers); - - try { - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, - fLocator.getMemento()); - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, - fLocator.getId()); - } catch (CoreException e) { - e.printStackTrace(); - } - } - @Override protected ILaunchConfigurationType getCLaunchConfigType() { return getLaunchManager().getLaunchConfigurationType( diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCommonLaunchShortcut.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCommonLaunchShortcut.java new file mode 100644 index 0000000..d5301b6 --- /dev/null +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCommonLaunchShortcut.java @@ -0,0 +1,303 @@ +/* + * Native Platform + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Donghyuk Yang + * DongHee Yang + * Kangho Kim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.nativeplatform.launch.ui.shortcut; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.ICDebugConfiguration; +import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; +import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; +import org.eclipse.cdt.debug.internal.ui.launch.CApplicationLaunchShortcut; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.model.ISourceLocator; +import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; +import org.tizen.common.connection.ConnectionPlugin; +import org.tizen.common.util.DialogUtil; +import org.tizen.nativecommon.build.SmartBuildInterface; +import org.tizen.nativecommon.launch.TizenLaunchMessages; +import org.tizen.nativeplatform.build.PlatformConfigurationManager; +import org.tizen.nativeplatform.launch.PlatformLaunchMessages; +import org.tizen.nativeplatform.launch.wizards.PlatformLaunchUtils; +import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget; +import org.tizen.nativeplatform.rootstrap.RootstrapManager; +import org.tizen.nativeplatform.views.model.PlatformRootstrap; +import org.tizen.sdblib.IDevice; + +@SuppressWarnings("restriction") +abstract public class PlatformProjectCommonLaunchShortcut extends CApplicationLaunchShortcut { + + protected String programPath = null; + protected boolean reinstallOp = true; + protected boolean selectPkgOp = true; + protected IDevice device = null; + protected PkgCommandTarget target = null; + + protected ISourceLookupDirector fLocator; + + public void launch(IProject project, String mode) { + searchAndLaunch(new Object[] { project }, mode); + } + + @Override + public void launch(IEditorPart editor, String mode) { + searchAndLaunch(new Object[] { editor.getEditorInput() }, mode); + } + + @Override + public void launch(ISelection selection, String mode) { + if (selection instanceof IStructuredSelection) { + searchAndLaunch(((IStructuredSelection) selection).toArray(), mode); + } + } + + protected void searchAndLaunch(final Object[] elements, String mode) { + device = ConnectionPlugin.getDefault().getCurrentDevice(); + if (device == null) { + DialogUtil.openErrorDialog(TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE); + return; + } + if (!device.isRoot()) { + DialogUtil.openErrorDialog(PlatformLaunchMessages.DEVICE_IS_NOT_ROOT_ON); + return; + } + + if (elements != null && elements.length > 0) { + int nElements = elements.length; + for (int i = 0; i < nElements; i++) { + if (elements[i] instanceof IAdaptable) { + IResource r = (IResource) ((IAdaptable) elements[i]) + .getAdapter(IResource.class); + if (r != null) { + IProject project = r.getProject(); + if (project != null) { + ILaunchConfiguration config = findLaunchConfiguration(project, mode); + if (config != null) { + DebugUITools.launch(config, mode); + } + } + } + } + } + } + } + + protected ILaunchConfiguration findLaunchConfiguration(IProject project, String mode) { + ILaunchConfiguration configuration = null; + // Set the default debugger based on the active toolchain on the project + // (if possible) + ICDebugConfiguration debugConfig = null; + ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); + String configId = configDesc.getId(); + ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault() + .getActiveDebugConfigurations(); + int matchLength = 0; + for (int i = 0; i < debugConfigs.length; ++i) { + ICDebugConfiguration dc = debugConfigs[i]; + String[] patterns = dc.getSupportedBuildConfigPatterns(); + if (patterns != null) { + for (int j = 0; j < patterns.length; ++j) { + if (patterns[j].length() > matchLength && configId.matches(patterns[j])) { + debugConfig = dc; + matchLength = patterns[j].length(); + } + } + } + } + + if (debugConfig == null) { + // Prompt the user if more then 1 debugger. + debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); + List debugList = new ArrayList( + debugConfigs.length); + for (int i = 0; i < debugConfigs.length; i++) { + if (debugConfigs[i] + .supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { + if (debugConfigs[i].getName().contains("Tizen")) //$NON-NLS-1$ + debugList.add(debugConfigs[i]); + } + } + debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]); + if (debugConfigs.length == 1) + debugConfig = debugConfigs[0]; + else if (debugConfigs.length > 1) + debugConfig = chooseDebugConfig(debugConfigs, mode); + } + + configuration = createConfiguration(project, debugConfig, mode); + return configuration; + } + + protected ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) { + ILabelProvider provider = new LabelProvider() { + public String getText(Object element) { + if (element == null) { + return ""; //$NON-NLS-1$ + } else if (element instanceof ICDebugConfiguration) { + return ((ICDebugConfiguration) element).getName(); + } + return element.toString(); + } + }; + ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider); + dialog.setElements(debugConfigs); + dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode)); + dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode)); + dialog.setMultipleSelection(false); + int result = dialog.open(); + provider.dispose(); + if (result == Window.OK) { + return (ICDebugConfiguration) dialog.getFirstResult(); + } + return null; + } + + protected void setPkgCommandTarget(IProject project) { + IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); + IConfiguration defaultConfig = info.getDefaultConfiguration(); + String targetId = PlatformConfigurationManager.getBuildTargetName(defaultConfig); + String rootId = SmartBuildInterface.getInstance().getRootstrapIDFromTargetID(targetId); + PlatformRootstrap rootstrap = RootstrapManager.getRootstrap(rootId); + target = new PkgCommandTarget(device, rootstrap); + } + + abstract protected ILaunchConfiguration createConfiguration(IProject project, + ICDebugConfiguration debugConfig, String mode); + + protected void setSourceContainer(IProject project, ILaunchConfigurationWorkingCopy configuration) { + PlatformRootstrap rootstrap = target.getRootstrap(); + + String basePath = rootstrap.getPath().toOSString(); + PlatformLaunchUtils launchUtils = new PlatformLaunchUtils(target); + String rootstrapPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(basePath); + DirectorySourceContainer container = new DirectorySourceContainer(new Path(rootstrapPath), + true); + MappingSourceContainer mappingContainer = new MappingSourceContainer("Source mapping"); + MapEntrySourceContainer entry = new MapEntrySourceContainer(); + String[] infos = launchUtils.getProjectInfo(project); + String backend = String.format("/usr/src/debug/%s-%s", infos[0], infos[1]); + String local = project.getLocation().toOSString(); + + entry.setBackendPath(new Path(backend)); + entry.setLocalPath(new Path(local)); + mappingContainer.addMapEntry(entry); + + if (fLocator != null) { + fLocator.dispose(); + fLocator = null; + } + + String memento = null; + String type = null; + try { + memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, + (String) null); + type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, + (String) null); + if (type == null) { + type = configuration.getType().getSourceLocatorId(); + } + } catch (CoreException e) { + return; + } + + if (type == null) { + return; + } + + try { + ISourceLocator locator = getLaunchManager().newSourceLocator(type); + if (!(locator instanceof AbstractSourceLookupDirector)) { + // migrate to the new source lookup infrastructure + memento = null; // don't use old memento + type = configuration.getType().getSourceLocatorId(); + if (type == null) { + return; + } + locator = getLaunchManager().newSourceLocator(type); + if (!(locator instanceof AbstractSourceLookupDirector)) { + return; + } + } + fLocator = (AbstractSourceLookupDirector) locator; + if (memento == null) { + fLocator.initializeDefaults(configuration); + } else { + fLocator.initializeFromMemento(memento, configuration); + } + } catch (CoreException e) { + return; + } + + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null); + + int length = fLocator.getSourceContainers().length; + ISourceContainer[] containers = new ISourceContainer[length + 2]; + containers[0] = mappingContainer; + containers[1] = container; + containers[2] = fLocator.getSourceContainers()[0]; + + fLocator.setSourceContainers(containers); + + try { + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, + fLocator.getMemento()); + configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, + fLocator.getId()); + } catch (CoreException e) { + e.printStackTrace(); + } + } +} diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCoredumpLaunchShortcut.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCoredumpLaunchShortcut.java index b77683c..669de34 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCoredumpLaunchShortcut.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectCoredumpLaunchShortcut.java @@ -27,158 +27,34 @@ package org.tizen.nativeplatform.launch.ui.shortcut; -import java.util.ArrayList; -import java.util.List; - import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.internal.ui.launch.CApplicationLaunchShortcut; import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.ICDebuggerPage; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants; import org.tizen.nativeplatform.Activator; import org.tizen.nativeplatform.launch.ITizenLaunchConfigurationConstants; import org.tizen.nativeplatform.launch.PlatformLaunchMessages; @SuppressWarnings("restriction") -public class PlatformProjectCoredumpLaunchShortcut extends CApplicationLaunchShortcut { +public class PlatformProjectCoredumpLaunchShortcut extends PlatformProjectCommonLaunchShortcut { private static final String APPLICATION_PATH_INPUT_DIALOG_TITLE = "Input Tizen Application Path"; private static final String APPLICATION_PATH_INPUT_DIALOG_TEXT = "Input Tizen Application Path : "; - public void launch(IProject project, String mode) { - searchAndLaunch(new Object[] { project }, mode); - } - - @Override - public void launch(IEditorPart editor, String mode) { - searchAndLaunch(new Object[] { editor.getEditorInput() }, mode); - } - - @Override - public void launch(ISelection selection, String mode) { - if (selection instanceof IStructuredSelection) { - searchAndLaunch(((IStructuredSelection) selection).toArray(), mode); - } - } - - private void searchAndLaunch(final Object[] elements, String mode) { - if (elements != null && elements.length > 0) { - int nElements = elements.length; - for (int i = 0; i < nElements; i++) { - if (elements[i] instanceof IAdaptable) { - IResource r = (IResource) ((IAdaptable) elements[i]) - .getAdapter(IResource.class); - if (r != null) { - IProject project = r.getProject(); - if (project != null) { - ILaunchConfiguration config = findLaunchConfiguration(project, mode); - if (config != null) { - DebugUITools.launch(config, mode); - } - } - } - } - } - } - } - - protected ILaunchConfiguration findLaunchConfiguration(IProject project, String mode) { - ILaunchConfiguration configuration = null; - // Set the default debugger based on the active toolchain on the project - // (if possible) - ICDebugConfiguration debugConfig = null; - ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); - ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); - String configId = configDesc.getId(); - ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault() - .getActiveDebugConfigurations(); - int matchLength = 0; - for (int i = 0; i < debugConfigs.length; ++i) { - ICDebugConfiguration dc = debugConfigs[i]; - String[] patterns = dc.getSupportedBuildConfigPatterns(); - if (patterns != null) { - for (int j = 0; j < patterns.length; ++j) { - if (patterns[j].length() > matchLength && configId.matches(patterns[j])) { - debugConfig = dc; - matchLength = patterns[j].length(); - } - } - } - } - - if (debugConfig == null) { - // Prompt the user if more then 1 debugger. - debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); - List debugList = new ArrayList( - debugConfigs.length); - for (int i = 0; i < debugConfigs.length; i++) { - if (debugConfigs[i] - .supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - if (debugConfigs[i].getName().contains("Tizen")) //$NON-NLS-1$ - debugList.add(debugConfigs[i]); - } - } - debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]); - if (debugConfigs.length == 1) - debugConfig = debugConfigs[0]; - else if (debugConfigs.length > 1) - debugConfig = chooseDebugConfig(debugConfigs, mode); - } - - configuration = createConfiguration(project, debugConfig, mode); - - return configuration; - } - - private ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) { - ILabelProvider provider = new LabelProvider() { - public String getText(Object element) { - if (element == null) { - return ""; //$NON-NLS-1$ - } else if (element instanceof ICDebugConfiguration) { - return ((ICDebugConfiguration) element).getName(); - } - return element.toString(); - } - }; - ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider); - dialog.setElements(debugConfigs); - dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode)); - dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode)); - dialog.setMultipleSelection(false); - int result = dialog.open(); - provider.dispose(); - if (result == Window.OK) { - return (ICDebugConfiguration) dialog.getFirstResult(); - } - return null; - } - protected ILaunchConfiguration createConfiguration(IProject project, ICDebugConfiguration debugConfig, String mode) { ILaunchConfiguration config = null; @@ -214,8 +90,7 @@ public class PlatformProjectCoredumpLaunchShortcut extends CApplicationLaunchSho } // Load up the debugger page to set the defaults. There should - // probably be a separate - // extension point for this. + // probably be a separate extension point for this. ICDebuggerPage page = CDebugUIPlugin.getDefault().getDebuggerPage(debugConfig.getID()); page.setDefaults(wc); diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectLaunchShortcut.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectLaunchShortcut.java index 9518701..8a8c8e6 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectLaunchShortcut.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/launch/ui/shortcut/PlatformProjectLaunchShortcut.java @@ -31,15 +31,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.ICDebugConfiguration; -import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; -import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; -import org.eclipse.cdt.debug.internal.ui.launch.CApplicationLaunchShortcut; import org.eclipse.cdt.debug.mi.core.IMILaunchConfigurationConstants; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.ICDebuggerPage; @@ -49,188 +43,29 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.debug.core.model.ISourceLocator; -import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; -import org.eclipse.debug.core.sourcelookup.ISourceContainer; -import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; -import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ElementListSelectionDialog; -import org.tizen.common.connection.ConnectionPlugin; -import org.tizen.common.util.DialogUtil; -import org.tizen.nativecommon.build.SmartBuildInterface; import org.tizen.nativecommon.launch.TizenLaunchConfigurationConstants; -import org.tizen.nativecommon.launch.TizenLaunchMessages; -import org.tizen.nativeplatform.build.PlatformConfigurationManager; import org.tizen.nativeplatform.launch.ITizenLaunchConfigurationConstants; -import org.tizen.nativeplatform.launch.PlatformLaunchMessages; import org.tizen.nativeplatform.launch.wizards.PlatformLaunchUtils; import org.tizen.nativeplatform.launch.wizards.PlatformLaunchWizard; import org.tizen.nativeplatform.launch.wizards.PlatformLaunchWizardDialog; import org.tizen.nativeplatform.launch.wizards.SelectItemDialog; -import org.tizen.nativeplatform.pkg.commander.PkgCommandTarget; import org.tizen.nativeplatform.pkgmgr.model.LocalPackage; -import org.tizen.nativeplatform.rootstrap.RootstrapManager; import org.tizen.nativeplatform.util.PlatformProjectUtil; -import org.tizen.nativeplatform.views.model.PlatformRootstrap; -import org.tizen.sdblib.IDevice; @SuppressWarnings("restriction") -public class PlatformProjectLaunchShortcut extends CApplicationLaunchShortcut { +public class PlatformProjectLaunchShortcut extends PlatformProjectCommonLaunchShortcut { private static final String APP_PROJ_DEFAULT_SELECTION = "[Not required]"; - private String programPath = null; private String appProjectName = null; private List packages = null; - private boolean reinstallOp = true; - private boolean selectPkgOp = true; - private IDevice device = null; - private PkgCommandTarget target = null; - - private ISourceLookupDirector fLocator; - - public void launch(IProject project, String mode) { - searchAndLaunch(new Object[] { project }, mode); - } - - @Override - public void launch(IEditorPart editor, String mode) { - searchAndLaunch(new Object[] { editor.getEditorInput() }, mode); - } - - @Override - public void launch(ISelection selection, String mode) { - if (selection instanceof IStructuredSelection) { - searchAndLaunch(((IStructuredSelection) selection).toArray(), mode); - } - } - - private void searchAndLaunch(final Object[] elements, String mode) { - device = ConnectionPlugin.getDefault().getCurrentDevice(); - if (device == null) { - DialogUtil.openErrorDialog(TizenLaunchMessages.CANNOT_CONNECT_TO_DEVICE); - return; - } - if (!device.isRoot()) { - DialogUtil.openErrorDialog(PlatformLaunchMessages.DEVICE_IS_NOT_ROOT_ON); - return; - } - - if (elements != null && elements.length > 0) { - int nElements = elements.length; - for (int i = 0; i < nElements; i++) { - if (elements[i] instanceof IAdaptable) { - IResource r = (IResource) ((IAdaptable) elements[i]) - .getAdapter(IResource.class); - if (r != null) { - IProject project = r.getProject(); - if (project != null) { - ILaunchConfiguration config = findLaunchConfiguration(project, mode); - if (config != null) { - DebugUITools.launch(config, mode); - } - } - } - } - } - } - } - - protected ILaunchConfiguration findLaunchConfiguration(IProject project, String mode) { - ILaunchConfiguration configuration = null; - // Set the default debugger based on the active toolchain on the project - // (if possible) - ICDebugConfiguration debugConfig = null; - ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); - ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); - String configId = configDesc.getId(); - ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault() - .getActiveDebugConfigurations(); - int matchLength = 0; - for (int i = 0; i < debugConfigs.length; ++i) { - ICDebugConfiguration dc = debugConfigs[i]; - String[] patterns = dc.getSupportedBuildConfigPatterns(); - if (patterns != null) { - for (int j = 0; j < patterns.length; ++j) { - if (patterns[j].length() > matchLength && configId.matches(patterns[j])) { - debugConfig = dc; - matchLength = patterns[j].length(); - } - } - } - } - - if (debugConfig == null) { - // Prompt the user if more then 1 debugger. - debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); - List debugList = new ArrayList( - debugConfigs.length); - for (int i = 0; i < debugConfigs.length; i++) { - if (debugConfigs[i] - .supportsMode(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { - if (debugConfigs[i].getName().contains("Tizen")) //$NON-NLS-1$ - debugList.add(debugConfigs[i]); - } - } - debugConfigs = (ICDebugConfiguration[]) debugList.toArray(new ICDebugConfiguration[0]); - if (debugConfigs.length == 1) - debugConfig = debugConfigs[0]; - else if (debugConfigs.length > 1) - debugConfig = chooseDebugConfig(debugConfigs, mode); - } - - configuration = createConfiguration(project, debugConfig, mode); - - return configuration; - } - - private ICDebugConfiguration chooseDebugConfig(ICDebugConfiguration[] debugConfigs, String mode) { - ILabelProvider provider = new LabelProvider() { - public String getText(Object element) { - if (element == null) { - return ""; //$NON-NLS-1$ - } else if (element instanceof ICDebugConfiguration) { - return ((ICDebugConfiguration) element).getName(); - } - return element.toString(); - } - }; - ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), provider); - dialog.setElements(debugConfigs); - dialog.setTitle(getDebugConfigDialogTitleString(debugConfigs, mode)); - dialog.setMessage(getDebugConfigDialogMessageString(debugConfigs, mode)); - dialog.setMultipleSelection(false); - int result = dialog.open(); - provider.dispose(); - if (result == Window.OK) { - return (ICDebugConfiguration) dialog.getFirstResult(); - } - return null; - } - - private void setPkgCommandTarget(IProject project) { - IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); - IConfiguration defaultConfig = info.getDefaultConfiguration(); - String targetId = PlatformConfigurationManager.getBuildTargetName(defaultConfig); - String rootId = SmartBuildInterface.getInstance().getRootstrapIDFromTargetID(targetId); - PlatformRootstrap rootstrap = RootstrapManager.getRootstrap(rootId); - target = new PkgCommandTarget(device, rootstrap); - } protected ILaunchConfiguration createConfiguration(IProject project, ICDebugConfiguration debugConfig, String mode) { @@ -303,12 +138,6 @@ public class PlatformProjectLaunchShortcut extends CApplicationLaunchShortcut { return config; } - @Override - protected ILaunchConfigurationType getCLaunchConfigType() { - return getLaunchManager().getLaunchConfigurationType( - "org.tizen.nativeplatform.launch.PlatformLaunchConfigurationType"); - } - private boolean setLaunchConfiguration(IProject project, String mode) { IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); IConfiguration defaultConfig = info.getDefaultConfiguration(); @@ -339,7 +168,6 @@ public class PlatformProjectLaunchShortcut extends CApplicationLaunchShortcut { programPath = null; } } - // programPath = launchUtil.getProgramPath(project); packages = null; reinstallOp = true; selectPkgOp = false; @@ -361,89 +189,9 @@ public class PlatformProjectLaunchShortcut extends CApplicationLaunchShortcut { return false; } - private void setSourceContainer(IProject project, ILaunchConfigurationWorkingCopy configuration) { - PlatformRootstrap rootstrap = target.getRootstrap(); - String basePath = rootstrap.getPath().toOSString(); - PlatformLaunchUtils launchUtils = new PlatformLaunchUtils(target); - String rootstrapPath = SmartBuildInterface.getInstance().getPlatformRootstrapPath(basePath); - DirectorySourceContainer container = new DirectorySourceContainer(new Path(rootstrapPath), - true); - MappingSourceContainer mappingContainer = new MappingSourceContainer("Source mapping"); - MapEntrySourceContainer entry = new MapEntrySourceContainer(); - String[] infos = launchUtils.getProjectInfo(project); - String backend = String.format("/usr/src/debug/%s-%s", infos[0], infos[1]); - String local = project.getLocation().toOSString(); - - entry.setBackendPath(new Path(backend)); - entry.setLocalPath(new Path(local)); - mappingContainer.addMapEntry(entry); - - if (fLocator != null) { - fLocator.dispose(); - fLocator = null; - } - - String memento = null; - String type = null; - try { - memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, - (String) null); - type = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, - (String) null); - if (type == null) { - type = configuration.getType().getSourceLocatorId(); - } - } catch (CoreException e) { - return; - } - - if (type == null) { - return; - } - - try { - ISourceLocator locator = getLaunchManager().newSourceLocator(type); - if (!(locator instanceof AbstractSourceLookupDirector)) { - // migrate to the new source lookup infrastructure - memento = null; // don't use old memento - type = configuration.getType().getSourceLocatorId(); - if (type == null) { - return; - } - locator = getLaunchManager().newSourceLocator(type); - if (!(locator instanceof AbstractSourceLookupDirector)) { - return; - } - } - fLocator = (AbstractSourceLookupDirector) locator; - if (memento == null) { - fLocator.initializeDefaults(configuration); - } else { - fLocator.initializeFromMemento(memento, configuration); - } - } catch (CoreException e) { - return; - } - - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null); - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String) null); - - int length = fLocator.getSourceContainers().length; - ISourceContainer[] containers = new ISourceContainer[length + 2]; - containers[0] = mappingContainer; - containers[1] = container; - containers[2] = fLocator.getSourceContainers()[0]; - - fLocator.setSourceContainers(containers); - - try { - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, - fLocator.getMemento()); - configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, - fLocator.getId()); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Override + protected ILaunchConfigurationType getCLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType( + "org.tizen.nativeplatform.launch.PlatformLaunchConfigurationType"); } } -- 2.7.4