summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorCamilo Bernal2012-11-05 12:19:56 (EST)
committer Roland Grunberg2012-11-07 16:47:36 (EST)
commitceb7b1cd92518d6f342c31e5f819514f462999ad (patch)
tree89b0cb79c08f1e1311cbe48b03a844e24416995c
parent7ad467290a4371eb668f6009ba06a5a624603f04 (diff)
downloadorg.eclipse.linuxtools-ceb7b1cd92518d6f342c31e5f819514f462999ad.zip
org.eclipse.linuxtools-ceb7b1cd92518d6f342c31e5f819514f462999ad.tar.gz
org.eclipse.linuxtools-ceb7b1cd92518d6f342c31e5f819514f462999ad.tar.bz2
Bug 393811: Prompt user on configuration creation when no config is available.refs/changes/17/8517/4
Modify ProviderLaunchShortcut#findLaunchConfiguration logic to only prompt when there are configs available for the project being profiled, but none for the default tool set in the project's properties/preferences. Add null check to resources acquired from a launch configuration working copy before attempting to access them. This is to avoid a null pointer exception in ProviderLaunchConfigurationDelegate#getProviderIdToRun. Change-Id: Id87f6d0f8970135dba060d989e54f2db038c0ed0 Reviewed-on: https://git.eclipse.org/r/8517 Reviewed-by: Roland Grunberg <rgrunber@redhat.com> IP-Clean: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchConfigurationDelegate.java24
-rw-r--r--profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java82
2 files changed, 47 insertions, 59 deletions
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchConfigurationDelegate.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchConfigurationDelegate.java
index d836560..cc69811 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchConfigurationDelegate.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchConfigurationDelegate.java
@@ -71,17 +71,19 @@ public class ProviderLaunchConfigurationDelegate extends
if (wc != null) {
try {
IResource[] resources = wc.getMappedResources();
- for (int i = 0; i < resources.length; ++i) {
- IResource resource = resources[i];
- if (resource instanceof IProject) {
- IProject project = (IProject)resource;
- ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project),
- ProviderProfileConstants.PLUGIN_ID);
- Boolean use_project_settings = store.getBoolean(ProviderProfileConstants.USE_PROJECT_SETTINGS + type);
- if (use_project_settings.booleanValue() == true) {
- String provider = store.getString(ProviderProfileConstants.PREFS_KEY + type);
- if (!provider.equals(""))
- providerId = provider;
+ if(resources != null){
+ for (int i = 0; i < resources.length; ++i) {
+ IResource resource = resources[i];
+ if (resource instanceof IProject) {
+ IProject project = (IProject)resource;
+ ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project),
+ ProviderProfileConstants.PLUGIN_ID);
+ Boolean use_project_settings = store.getBoolean(ProviderProfileConstants.USE_PROJECT_SETTINGS + type);
+ if (use_project_settings.booleanValue() == true) {
+ String provider = store.getString(ProviderProfileConstants.PREFS_KEY + type);
+ if (!provider.equals(""))
+ providerId = provider;
+ }
}
}
}
diff --git a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
index 7917c20..9ebe6cb 100644
--- a/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
+++ b/profiling/org.eclipse.linuxtools.profiling.launch/src/org/eclipse/linuxtools/internal/profiling/launch/provider/launch/ProviderLaunchShortcut.java
@@ -83,35 +83,46 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
return null;
}
+ // true if a configuration exists for current project and program
+ boolean existsConfigForProject = false;
+
+ // true if a configuration exists for current project, program and
+ // the default provider
+ boolean existsConfigForTool = false;
- boolean exists = false;
- ILaunchConfiguration[] configs = null;
try {
- configs = getLaunchManager().getLaunchConfigurations(getLaunchConfigType());
-
- // attributes for which a configuration can be considered valid for
- // the current tool and profiling type
- String[] relevantAttributes = new String[] {
- ProviderProfileConstants.PROVIDER_CONFIG_ATT,
- ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME,
- ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME };
-
- // check that there a exists a valid configuration for the current
- // tool and profiling type
- for (ILaunchConfiguration cfg : configs) {
- if (equalAttributes(config, cfg, relevantAttributes)) {
- exists = true;
- break;
+ String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
+ String programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
+ ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(getLaunchConfigType());
+
+ for(ILaunchConfiguration currConfig : configs){
+ String curProjectName = currConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
+ String curProgramName = currConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, "");
+
+ // check that current configuration belongs to the current project/program
+ if(curProjectName.equals(projectName) && curProgramName.equals(programName)){
+ existsConfigForProject = true;
+ String curProviderId = currConfig.getAttribute(ProviderProfileConstants.PROVIDER_CONFIG_ATT, "");
+
+ // check that current configuration has the same provider as the provider to run.
+ if(curProviderId.equals(providerId)){
+ existsConfigForTool = true;
+ break;
+ }
}
}
} catch (CoreException e) {
- exists = true;
+ // a configuration might be corrupted, skip prompting logic
+ // and fall back to default behavior
+ existsConfigForProject = true;
+ existsConfigForTool = true;
}
- // automatically create a configuration if there are none available
- if (configs == null || configs.length == 0) {
+ // automatically create a configuration if there are none available for
+ // the current project/program
+ if (!existsConfigForProject) {
createConfiguration(bin);
- } else if (!exists) {
+ } else if (!existsConfigForTool) {
String provider = ProviderFramework
.getProviderToolNameFromId(providerId);
@@ -120,8 +131,8 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
// prompt message
String promptMsg = MessageFormat.format(
- Messages.ProviderLaunchConfigurationPrompt_0, new String[] {
- profileType, provider });
+ Messages.ProviderLaunchConfigurationPrompt_0,
+ (Object[]) new String[] { profileType, provider });
MessageBox prompt = new MessageBox(getActiveWorkbenchShell(),
SWT.ICON_QUESTION | SWT.YES | SWT.NO);
@@ -135,31 +146,6 @@ public class ProviderLaunchShortcut extends ProfileLaunchShortcut implements IEx
return super.findLaunchConfiguration(bin, mode);
}
- /**
- * Check whether configurations <code>cfg1</code> and <code>cfg2</code>
- * share specified attributes <code>attributes</code>
- *
- * @param cfg1 a launch configuration
- * @param cfg2 a launch configuration
- * @param attributes attributes to compare
- * @return <code>true</code> if specified attributes are equal on both configuration, <code>false</code> otherwise.
- */
- private boolean equalAttributes(ILaunchConfiguration cfg1,
- ILaunchConfiguration cfg2, String[] attributes) {
- try {
- for (String attribute : attributes) {
- String cfg1Attribute = cfg1.getAttribute(attribute, "");
- String cfg2Attribute = cfg2.getAttribute(attribute, "");
- if (!cfg1Attribute.equals(cfg2Attribute)) {
- return false;
- }
- }
- } catch (CoreException e) {
- return false;
- }
- return true;
- }
-
@Override
protected void setDefaultProfileAttributes(ILaunchConfigurationWorkingCopy wc) {