use of org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut in project linuxtools by eclipse.
the class ProviderFramework method getLaunchShortcutProviderFromId.
/**
* Get a profiling launch shortcut that is associated with the specified id.
* This looks through extensions of the extension point
* <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code>
* that have a specific id.
*
* @param id A unique identifier
* @return a profiling launch shortcut that implements <code>ProfileLaunchShortcut</code>
* and provides the necessary profiling type, or <code>null</code> if none could be found.
* @since 1.2
*/
public static ProfileLaunchShortcut getLaunchShortcutProviderFromId(String id) {
IConfigurationElement[] configs = getConfigurationElements();
for (IConfigurationElement config : configs) {
if (config.getName().equals("provider")) {
// $NON-NLS-1$
// $NON-NLS-1$
String currentId = config.getAttribute("id");
// $NON-NLS-1$
String shortcut = config.getAttribute("shortcut");
if (currentId != null && shortcut != null && currentId.equals(id)) {
try {
Object obj = config.createExecutableExtension(// $NON-NLS-1$
"shortcut");
if (obj instanceof ProfileLaunchShortcut) {
return (ProfileLaunchShortcut) obj;
}
} catch (CoreException e) {
// continue, perhaps another configuration will succeed
}
}
}
}
return null;
}
use of org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut in project linuxtools by eclipse.
the class ProviderLaunchShortcut method setDefaultProfileAttributes.
@Override
protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) {
// acquire a provider id to run.
final String providerId = ProviderFramework.getProviderIdToRun(wc, getProfilingType());
// get tool name from id.
final String providerToolName = ProviderFramework.getProviderToolNameFromId(providerId);
// get tab group associated with provider id.
final ProfileLaunchConfigurationTabGroup tabgroup = ProviderFramework.getTabGroupProviderFromId(providerId);
/**
* Certain tabs' setDefaults(ILaunchConfigurationWorkingCopy) may
* require a launch configuration dialog. Eg. CMainTab generates
* a name for the configuration based on generateName in setDefaults()
* so we can create a temporary launch configuration dialog here. With
* the exception of generateName(String), the other methods do not
* get called.
*/
ILaunchConfigurationDialog dialog = new ILaunchConfigurationDialog() {
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) {
throw new UnsupportedOperationException();
}
@Override
public void updateMessage() {
throw new UnsupportedOperationException();
}
@Override
public void updateButtons() {
throw new UnsupportedOperationException();
}
@Override
public void setName(String name) {
throw new UnsupportedOperationException();
}
@Override
public void setActiveTab(int index) {
throw new UnsupportedOperationException();
}
@Override
public void setActiveTab(ILaunchConfigurationTab tab) {
throw new UnsupportedOperationException();
}
@Override
public ILaunchConfigurationTab[] getTabs() {
return null;
}
@Override
public String getMode() {
return null;
}
@Override
public ILaunchConfigurationTab getActiveTab() {
return null;
}
@Override
public String generateName(String name) {
if (name == null) {
// $NON-NLS-1$
name = "";
}
String providerConfigutationName = generateProviderConfigurationName(name, providerToolName);
return getLaunchManager().generateLaunchConfigurationName(providerConfigutationName);
}
};
// $NON-NLS-1$
tabgroup.createTabs(dialog, "profile");
// set configuration to match default attributes for all tabs.
for (ILaunchConfigurationTab tab : tabgroup.getTabs()) {
tab.setLaunchConfigurationDialog(dialog);
tab.setDefaults(wc);
}
// get configuration shortcut associated with provider id.
ProfileLaunchShortcut shortcut = ProviderFramework.getLaunchShortcutProviderFromId(providerId);
// set attributes related to the specific profiling shortcut configuration.
shortcut.setDefaultProfileLaunchShortcutAttributes(wc);
wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_ATT, providerId);
// set tool name in configuration.
wc.setAttribute(ProviderProfileConstants.PROVIDER_CONFIG_TOOLNAME_ATT, providerToolName);
/**
* To avoid renaming an already renamed launch configuration, we can
* check the expected format of the name using regular expressions and
* skip on matches.
*/
String curConfigName = wc.getName();
// $NON-NLS-1$
Pattern configNamePattern = Pattern.compile(".+\\s\\[.+\\](\\s\\(\\d+\\))?$");
Matcher match = configNamePattern.matcher(curConfigName);
if (!match.find()) {
wc.rename(dialog.generateName(curConfigName));
}
}
use of org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut in project linuxtools by eclipse.
the class ExtensionPointTest method testShortCut.
@Test
public void testShortCut() {
// $NON-NLS-1$
ProfileLaunchShortcut shortcut = ProviderFramework.getLaunchShortcutProviderFromId(PLUGIN_ID + "1");
ProfileLaunchShortcut shortcut2 = ProviderFramework.getProfilingProvider(PROFILING_TYPE);
assertTrue(shortcut instanceof StubbyLaunchShortcut);
assertTrue(shortcut2 instanceof StubbyLaunchShortcut);
}
Aggregations