Convert Carbide 2.x source mappings to 3.x mappings
authorSteve Sobek <steve.sobek@nokia.com>
Thu, 13 May 2010 13:18:55 -0500
changeset 1354 7d157fa7163d
parent 1353 4d68939cc6db
child 1355 38b3bd9892d4
Convert Carbide 2.x source mappings to 3.x mappings
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildManagerUtils.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildManagerUtils.java	Thu May 13 13:18:55 2010 -0500
@@ -0,0 +1,37 @@
+package com.nokia.carbide.cdt.internal.builder;
+
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+
+public class CarbideBuildManagerUtils {
+	
+	/**
+	 * In launch configs, convert from the source container mapping type in
+	 * Carbide 2.x to its equivalent in 3.x
+	 * @throws Exception - any exception will be propagated to its caller
+	 */
+	public static void convertSourceMappings2xTo3x() throws Exception {
+		ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager();
+		ILaunchConfiguration[] launchConfigSet = launchMgr.getLaunchConfigurations();
+		for (int i = 0; i < launchConfigSet.length; i++) {
+			ILaunchConfigurationWorkingCopy configuration = launchConfigSet[i].getWorkingCopy();
+			String locator = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String) null);
+			if (locator == null)
+				continue;
+			
+			// originally intended to parse XML in locator and make sure we're replacing the only right XML
+			// element types, but decided the string to replace is uniquely used with one element type
+			if (locator.indexOf("com.nokia.cdt.debug.cw.symbian.containerType.mapping") != -1)  { //$NON-NLS-1$
+				// create a new XML source locator with the string changed
+				String newLocator = locator.replaceAll(
+						"com.nokia.cdt.debug.cw.symbian.containerType.mapping", //$NON-NLS-1$
+						"com.nokia.cdt.debug.common.containerType.mapping"); //$NON-NLS-1$
+				configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, newLocator);
+				configuration.doSave();
+			}
+		}
+	}
+
+}