FixLaunchConfigpublic class FixLaunchConfig extends Thread Class to fix the launch configuration of a project if the java package
defined in the manifest has been changed.
This fix can be done synchronously, or asynchronously.
start() will start a thread that will do the fix.
run() will do the fix in the current thread.
By default, the fix first display a dialog to the user asking if he/she wants to
do the fix. This can be overriden by calling setDisplayPrompt(false) . |
Fields Summary |
---|
private org.eclipse.core.resources.IProject | mProject | private String | mOldPackage | private String | mNewPackage | private boolean | mDisplayPrompt |
Methods Summary |
---|
private static org.eclipse.debug.core.ILaunchConfiguration[] | findConfigs(java.lang.String projectName)Looks for and returns all existing Launch Configuration object for a
specified project.
// get the launch manager
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
// now get the config type for our particular android type.
ILaunchConfigurationType configType = manager.
getLaunchConfigurationType(LaunchConfigDelegate.ANDROID_LAUNCH_TYPE_ID);
// create a temp list to hold all the valid configs
ArrayList<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
try {
ILaunchConfiguration[] configs = manager.getLaunchConfigurations(configType);
for (ILaunchConfiguration config : configs) {
if (config.getAttribute(
IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
"").equals(projectName)) { //$NON-NLS-1$
list.add(config);
}
}
} catch (CoreException e) {
}
return list.toArray(new ILaunchConfiguration[list.size()]);
| public void | run()Fix the Launch configurations.
if (mDisplayPrompt) {
// ask the user if he really wants to fix the launch config
boolean res = AdtPlugin.displayPrompt(
"Launch Configuration Update",
"The package definition in the manifest changed.\nDo you want to update your Launch Configuration(s)?");
if (res == false) {
return;
}
}
// get the list of config for the project
String projectName = mProject.getName();
ILaunchConfiguration[] configs = findConfigs(mProject.getName());
// loop through all the config and update the package
for (ILaunchConfiguration config : configs) {
try {
// get the working copy so that we can make changes.
ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
// get the attributes for the activity
String activity = config.getAttribute(LaunchConfigDelegate.ATTR_ACTIVITY,
""); //$NON-NLS-1$
// manifests can define activities that are not in the defined package,
// so we need to make sure the activity is inside the old package.
if (activity.startsWith(mOldPackage)) {
// create the new activity
activity = mNewPackage + activity.substring(mOldPackage.length());
// put it in the copy
copy.setAttribute(LaunchConfigDelegate.ATTR_ACTIVITY, activity);
// save the config
copy.doSave();
}
} catch (CoreException e) {
// couldn't get the working copy. we output the error in the console
String msg = String.format("Failed to modify %1$s: %2$s", projectName,
e.getMessage());
AdtPlugin.printErrorToConsole(mProject, msg);
}
}
| public void | setDisplayPrompt(boolean displayPrompt)Set the display prompt. If true run()/start() first ask the user if he/she wants
to fix the Launch Config
mDisplayPrompt = displayPrompt;
|
|