sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/builder/AnalyzeToolBuilder.java
changeset 15 0367d2db2c06
parent 6 f65f740e69f9
equal deleted inserted replaced
14:bb339882c6e9 15:0367d2db2c06
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 package com.nokia.s60tools.analyzetool.builder;
    18 package com.nokia.s60tools.analyzetool.builder;
    19 
    19 
       
    20 import java.text.MessageFormat;
    20 import java.util.AbstractList;
    21 import java.util.AbstractList;
    21 import java.util.ArrayList;
    22 import java.util.ArrayList;
    22 import java.util.Iterator;
    23 import java.util.Iterator;
    23 import java.util.List;
    24 import java.util.List;
    24 import java.util.Locale;
    25 import java.util.Locale;
    31 import org.eclipse.core.runtime.IStatus;
    32 import org.eclipse.core.runtime.IStatus;
    32 import org.eclipse.core.runtime.Path;
    33 import org.eclipse.core.runtime.Path;
    33 import org.eclipse.core.runtime.Status;
    34 import org.eclipse.core.runtime.Status;
    34 import org.eclipse.core.runtime.jobs.Job;
    35 import org.eclipse.core.runtime.jobs.Job;
    35 import org.eclipse.jface.preference.IPreferenceStore;
    36 import org.eclipse.jface.preference.IPreferenceStore;
    36 import org.eclipse.ui.PlatformUI;
    37 import org.eclipse.swt.SWT;
    37 
    38 
       
    39 import com.nokia.carbide.cdt.builder.BuildArgumentsInfo;
    38 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    40 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
    39 import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
    41 import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
    40 import com.nokia.carbide.cdt.builder.builder.CarbideCommandLauncher;
    42 import com.nokia.carbide.cdt.builder.builder.CarbideCommandLauncher;
    41 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    43 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
    42 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    44 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
    43 import com.nokia.carbide.cdt.builder.BuildArgumentsInfo;
       
    44 import com.nokia.s60tools.analyzetool.Activator;
    45 import com.nokia.s60tools.analyzetool.Activator;
    45 import com.nokia.s60tools.analyzetool.global.Constants;
    46 import com.nokia.s60tools.analyzetool.global.Constants;
    46 import com.nokia.s60tools.analyzetool.global.Util;
    47 import com.nokia.s60tools.analyzetool.global.Util;
    47 import com.nokia.s60tools.analyzetool.ui.CustomInputDialog;
       
    48 
    48 
    49 /**
    49 /**
    50  * Base class for AnalyzeTool builders.
    50  * Base class for AnalyzeTool builders.
    51  *
    51  * 
    52  * This class modifies Carbide builder settings during the AnalyzeTool build.
    52  * This class modifies Carbide builder settings during the AnalyzeTool build.
    53  * This class can be used to built whole project or selected components with
    53  * This class can be used to built whole project or selected components with
    54  * AnalyzeTool
    54  * AnalyzeTool
    55  *
    55  * 
    56  * @author kihe
    56  * @author kihe
    57  *
    57  * 
    58  */
    58  */
    59 public class AnalyzeToolBuilder extends CarbideCPPBuilder {
    59 public class AnalyzeToolBuilder extends CarbideCPPBuilder {
    60 
    60 
    61 	/** Pre-builder id. */
    61 	/** Pre-builder id. */
    62 	public static final String AT_BUILDER_ID = "com.nokia.s60tools.analyzetool.analyzeToolPreBuilder";
    62 	public static final String AT_BUILDER_ID = "com.nokia.s60tools.analyzetool.analyzeToolPreBuilder";
    70 	/** Verbose atool.exe output? */
    70 	/** Verbose atool.exe output? */
    71 	private boolean verbose;
    71 	private boolean verbose;
    72 
    72 
    73 	/**
    73 	/**
    74 	 * Gets shared instance of CarbideCommandLauncher.
    74 	 * Gets shared instance of CarbideCommandLauncher.
    75 	 *
    75 	 * 
    76 	 * @return CarbideCommandLauncher reference
    76 	 * @return CarbideCommandLauncher reference
    77 	 */
    77 	 */
    78 	protected static CarbideCommandLauncher getCarbideCommandLauncher() {
    78 	protected static CarbideCommandLauncher getCarbideCommandLauncher() {
    79 		return cmdLauncher;
    79 		return cmdLauncher;
    80 	}
    80 	}
    81 
    81 
    82 	/**
    82 	/**
    83 	 * Checks is SBS v2 build activated for the project.
    83 	 * Checks is SBS v2 build activated for the project.
    84 	 *
    84 	 * 
    85 	 * @param cpi
    85 	 * @param cpi
    86 	 *            ICarbideProjectInfo
    86 	 *            ICarbideProjectInfo
    87 	 * @return True if SBS v2 build is activated otherwise False
    87 	 * @return True if SBS v2 build is activated otherwise False
    88 	 */
    88 	 */
    89 	public static boolean isSBSBuildActivated(final ICarbideProjectInfo cpi) {
    89 	public static boolean isSBSBuildActivated(final ICarbideProjectInfo cpi) {
   102 					Object[] objs = new Object[1];
   102 					Object[] objs = new Object[1];
   103 					objs[0] = project;
   103 					objs[0] = project;
   104 					Boolean obj = (Boolean) oneMethod.invoke(
   104 					Boolean obj = (Boolean) oneMethod.invoke(
   105 							CarbideBuilderPlugin.getBuildManager(), objs);
   105 							CarbideBuilderPlugin.getBuildManager(), objs);
   106 					return obj.booleanValue();
   106 					return obj.booleanValue();
   107 
       
   108 				}
   107 				}
   109 			}
   108 			}
   110 		} catch (ClassNotFoundException cnfe) {
   109 		} catch (ClassNotFoundException cnfe) {
   111 			cnfe.printStackTrace();
   110 			cnfe.printStackTrace();
   112 			return false;
   111 			return false;
   125 		}
   124 		}
   126 		return false;
   125 		return false;
   127 	}
   126 	}
   128 
   127 
   129 	/**
   128 	/**
   130 	 * Ask data file name from the user and after that executes atool.exe.
       
   131 	 *
       
   132 	 * @param monitor
       
   133 	 *            {@link IProgressMonitor} reference
       
   134 	 * @param cpi
       
   135 	 *            {@link ICarbideProjectInfo} reference
       
   136 	 * @param files
       
   137 	 *            Used mmp files
       
   138 	 *
       
   139 	 * @return COMMAND_LINE_ERROR_CODE.OK if no errors, otherwise error code
       
   140 	 */
       
   141 	private int askFileNameAndBuild(final IProgressMonitor monitor,
       
   142 			final ICarbideProjectInfo cpi, final List<IFile> files) {
       
   143 		// ask for the user data file name
       
   144 		CustomInputDialog dialog = new CustomInputDialog(
       
   145 				Constants.ANALYZE_TOOL_TITLE,
       
   146 				Constants.DIALOG_INPUT_DATA_FILE_NAME, "");
       
   147 		dialog.open();
       
   148 
       
   149 		//get data file name
       
   150 		String dataFileName = dialog.getUserInput();
       
   151 		int errorCode = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
       
   152 		// user press "Cancel"
       
   153 		if (dataFileName == null || ("").equals(dataFileName)) {
       
   154 			buildCancelled(monitor, true);
       
   155 		} else { // if user specify data file name
       
   156 			errorCode = executeAtool(dataFileName, Constants.ATOOL_INST,
       
   157 					Constants.LOGGING_S60, files, cpi, monitor);
       
   158 		}
       
   159 		return errorCode;
       
   160 	}
       
   161 
       
   162 	/**
       
   163 	 * Ask logging mode from the user.
       
   164 	 *
       
   165 	 * @return User selected logging mode
       
   166 	 */
       
   167 	private String askLoggingMode() {
       
   168 
       
   169 		IPreferenceStore store = Activator.getPreferences();
       
   170 
       
   171 		// logging modes
       
   172 		AbstractList<String> modes = new ArrayList<String>();
       
   173 		modes.add(Constants.PREFS_EXT);
       
   174 
       
   175 		// if fast data gathering mode is enabled => add to selection list
       
   176 		if( store.getBoolean(Constants.LOGGING_FAST_ENABLED ) ) {
       
   177 			modes.add(Constants.PREFS_EXT_FAST);
       
   178 		}
       
   179 		modes.add(Constants.PREFS_S60);
       
   180 
       
   181 		// open selection dialog
       
   182 		String userSelection = Util.openSelectionDialog(
       
   183 				Constants.DIALOG_SELECT_LOGGING_MODE, null, modes);
       
   184 
       
   185 		// get used logging mode for the atool.exe
       
   186 		// user selected logging mode can not be used straight because it is
       
   187 		// different in the UI and which atool.exe uses
       
   188 		String modeSelection = "";
       
   189 		if (userSelection == Constants.PREFS_EXT) {
       
   190 			modeSelection = Constants.LOGGING_EXT;
       
   191 		} else if (userSelection == Constants.PREFS_S60) {
       
   192 			modeSelection = Constants.LOGGING_S60;
       
   193 		} else if( userSelection == Constants.PREFS_EXT_FAST) {
       
   194 			modeSelection = Constants.LOGGING_EXT_FAST;
       
   195 		}
       
   196 		return modeSelection;
       
   197 	}
       
   198 
       
   199 	/**
       
   200 	 * Cancels AnalyzeTool build.
   129 	 * Cancels AnalyzeTool build.
   201 	 *
   130 	 * 
   202 	 * @param monitor
   131 	 * @param monitor
   203 	 *            Currently running progress monitor
   132 	 *            Currently running progress monitor
   204 	 * @param continueBuild
   133 	 * @param continueBuild
   205 	 *            False stops the whole build chain (including Carbide and other builders)
   134 	 *            False stops the whole build chain (including Carbide and other
   206 	 *            otherwise other than AnalyzeTool builds are executed normally.
   135 	 *            builders) otherwise other than AnalyzeTool builds are executed
       
   136 	 *            normally.
   207 	 */
   137 	 */
   208 	public final void buildCancelled(final IProgressMonitor monitor,
   138 	public final void buildCancelled(final IProgressMonitor monitor,
   209 			final boolean continueBuild) {
   139 			final boolean continueBuild) {
   210 
   140 
   211 		IPreferenceStore store = Activator.getPreferences();
   141 		IPreferenceStore store = Activator.getPreferences();
   219 					Constants.BUILD_CANCELLED);
   149 					Constants.BUILD_CANCELLED);
   220 
   150 
   221 			// update monitor state
   151 			// update monitor state
   222 			monitor.setCanceled(true);
   152 			monitor.setCanceled(true);
   223 			monitor.done();
   153 			monitor.done();
   224 
       
   225 		}
   154 		}
   226 
   155 
   227 		boolean promptMPPChange = store.getBoolean(Constants.PREFS_PROMPT_MMP);
   156 		boolean promptMPPChange = store.getBoolean(Constants.PREFS_PROMPT_MMP);
   228 		boolean manageDeps = store.getBoolean(Constants.PREFS_MANAGE_DEPS);
   157 		boolean manageDeps = store.getBoolean(Constants.PREFS_MANAGE_DEPS);
   229 		boolean useConcBuild = store.getBoolean(Constants.PREFS_CONC_BUILD);
   158 		boolean useConcBuild = store.getBoolean(Constants.PREFS_CONC_BUILD);
   248 		super.forgetLastBuiltState();
   177 		super.forgetLastBuiltState();
   249 	}
   178 	}
   250 
   179 
   251 	/**
   180 	/**
   252 	 * Builds user selected components.
   181 	 * Builds user selected components.
   253 	 *
   182 	 * 
   254 	 * Normally this method is called from the CompileSymbianComponent
   183 	 * Normally this method is called from the CompileSymbianComponent
   255 	 *
   184 	 * 
   256 	 * @param selectedFiles
   185 	 * @param selectedFiles
   257 	 *            User selected files
   186 	 *            User selected files
   258 	 */
   187 	 */
   259 	public final void buildComponents(final List<IFile> selectedFiles) {
   188 	public final void buildComponents(final List<IFile> selectedFiles) {
   260 		// create new job
   189 		// create new job
   276 									.getINFWorkingDirectory());
   205 									.getINFWorkingDirectory());
   277 					cmdLauncher.showCommand(true);
   206 					cmdLauncher.showCommand(true);
   278 
   207 
   279 					// run pre steps for the build
   208 					// run pre steps for the build
   280 					if (!runPreSteps(cmdLauncher, monitor, cpi)) {
   209 					if (!runPreSteps(cmdLauncher, monitor, cpi)) {
   281 						return new Status(IStatus.OK, Constants.ANALYZE_TOOL_TITLE,
   210 						return new Status(IStatus.OK,
   282 								IStatus.OK, Constants.CANCELLED, null);
   211 								Constants.ANALYZE_TOOL_TITLE, IStatus.OK,
       
   212 								Constants.CANCELLED, null);
   283 					}
   213 					}
   284 
   214 
   285 					// build selected components
   215 					// build selected components
   286 					runBuild(Constants.ATOOL_INST, monitor, cpi, selectedFiles);
   216 					runBuild(Constants.ATOOL_INST, monitor, cpi, selectedFiles);
   287 
   217 
   288 					// run post steps
   218 					// run post steps
   289 					runPostSteps(cpi);
   219 					runPostSteps(cpi);
   290 
   220 
   291 					//after the build is finished => open the console view
   221 					// after the build is finished => open the console view
   292 					Util.openConsoleView();
   222 					Util.openConsoleView();
   293 				} finally {
   223 				} finally {
   294 					monitor.done();
   224 					monitor.done();
   295 				}
   225 				}
   296 				return new Status(IStatus.OK, Constants.ANALYZE_TOOL_TITLE,
   226 				return new Status(IStatus.OK, Constants.ANALYZE_TOOL_TITLE,
   302 		buildJob.schedule();
   232 		buildJob.schedule();
   303 	}
   233 	}
   304 
   234 
   305 	/**
   235 	/**
   306 	 * Checks that platform is ARMV5, GCEE or WINSCW
   236 	 * Checks that platform is ARMV5, GCEE or WINSCW
   307 	 *
   237 	 * 
   308 	 * @param cpi
   238 	 * @param cpi
   309 	 *            ICarbideProjectInfo
   239 	 *            ICarbideProjectInfo
   310 	 * @return True if platform is set to ARMV5, GCCE or WINSCW otherwise False
   240 	 * @return True if platform is set to ARMV5, GCCE or WINSCW otherwise False
   311 	 */
   241 	 */
   312 	public final boolean checkPlatform(final ICarbideProjectInfo cpi) {
   242 	public final boolean checkPlatform(final ICarbideProjectInfo cpi) {
   313 		String platform = cpi.getDefaultConfiguration().getPlatformString();
   243 		String platform = cpi.getDefaultConfiguration().getPlatformString();
   314 		if ( platform.equals(Constants.BUILD_TARGET_ARMV5) || platform.equals(Constants.BUILD_TARGET_WINSCW)
   244 		if (platform.equals(Constants.BUILD_TARGET_ARMV5)
   315 				|| platform.equals(Constants.BUILD_TARGET_GCEE) ) {
   245 				|| platform.equals(Constants.BUILD_TARGET_WINSCW)
       
   246 				|| platform.equals(Constants.BUILD_TARGET_GCEE)) {
   316 			return true;
   247 			return true;
   317 		}
   248 		}
   318 		return false;
   249 		return false;
   319 	}
   250 	}
   320 
   251 
   321 	/**
   252 	/**
   322 	 * Executes atool.exe with options.
   253 	 * Executes atool.exe with options.
   323 	 *
   254 	 * 
   324 	 * @param dataFileName
   255 	 * @param path
   325 	 *            Used data file name
   256 	 *            log path
       
   257 	 * @param fileName
       
   258 	 *            log file name
   326 	 * @param type
   259 	 * @param type
   327 	 *            Type of execution. Possible types ATOOL_INST or ATOOL_UNINST
   260 	 *            Type of execution. Possible types ATOOL_INST or ATOOL_UNINST
   328 	 * @param loggingModeCommand
   261 	 * @param loggingModeCommand
   329 	 *            Used logging mode
   262 	 *            Used logging mode
   330 	 * @param userSelectedMmpFiles
   263 	 * @param userSelectedMmpFiles
   331 	 *            List of user selected mmp files
   264 	 *            List of user selected mmp files
   332 	 * @param cpi
   265 	 * @param cpi
   333 	 *            ICarbideProjectInfo reference
   266 	 *            ICarbideProjectInfo reference
   334 	 * @param monitor
   267 	 * @param monitor
   335 	 *            Progress monitor reference
   268 	 *            Progress monitor reference
   336 	 *
   269 	 * 
   337 	 * @return COMMAND_LINE_ERROR_CODE.OK if no errors, otherwise error code
   270 	 * @return COMMAND_LINE_ERROR_CODE.OK if no errors, otherwise error code
   338 	 */
   271 	 */
   339 	protected final int executeAtool(final String dataFileName,
   272 	protected final int executeAtool(final String path, final String fileName,
   340 			final String type, final String loggingModeCommand,
   273 			final String type, final String loggingModeCommand,
   341 			final List<IFile> userSelectedMmpFiles,
   274 			final List<IFile> userSelectedMmpFiles,
   342 			final ICarbideProjectInfo cpi, final IProgressMonitor monitor) {
   275 			final ICarbideProjectInfo cpi, final IProgressMonitor monitor) {
   343 
   276 
   344 		// get used platform
   277 		// get used platform
   345 		String platform = cpi.getDefaultConfiguration().getPlatformString().toLowerCase(Locale.US);
   278 		String platform = cpi.getDefaultConfiguration().getPlatformString()
       
   279 				.toLowerCase(Locale.US);
   346 
   280 
   347 		// get build target
   281 		// get build target
   348 		String buildTarget = cpi.getDefaultConfiguration().getTargetString().toLowerCase(Locale.US);
   282 		String buildTarget = cpi.getDefaultConfiguration().getTargetString()
       
   283 				.toLowerCase(Locale.US);
   349 
   284 
   350 		// used arguments to atool.exe
   285 		// used arguments to atool.exe
   351 		AbstractList<String> usedArguments = new ArrayList<String>();
   286 		AbstractList<String> usedArguments = new ArrayList<String>();
   352 
   287 
   353 		// which logging mode is used
   288 		// which logging mode is used
   354 		if( loggingModeCommand.equalsIgnoreCase(Constants.LOGGING_EXT) )
   289 		if (loggingModeCommand.equalsIgnoreCase(Constants.LOGGING_EXT_FAST)) {
   355 		{
       
   356 			usedArguments.add(Constants.ATOOL_INST_E);
       
   357 		}
       
   358 		else if( loggingModeCommand.equalsIgnoreCase(Constants.LOGGING_EXT_FAST)) {
       
   359 			usedArguments.add(Constants.ATOOL_INST_EF);
   290 			usedArguments.add(Constants.ATOOL_INST_EF);
   360 		}
   291 		} else {
   361 		else
       
   362 		{
       
   363 			usedArguments.add(Constants.ATOOL_INST_I);
   292 			usedArguments.add(Constants.ATOOL_INST_I);
   364 		}
   293 			// if path is set
   365 
   294 			if (path != null && !("").equals(path)) {
   366 		// if data file is set
   295 				usedArguments.add("-fp");
   367 		if (dataFileName != null && !("").equals(dataFileName)) {
   296 				usedArguments.add(path);
   368 			usedArguments.add("-f");
   297 			}
   369 			usedArguments.add(dataFileName);
   298 
       
   299 			// if file name is set
       
   300 			if (fileName != null && !("").equals(fileName)) {
       
   301 				usedArguments.add("-f");
       
   302 				usedArguments.add(fileName);
       
   303 			}
   370 		}
   304 		}
   371 
   305 
   372 		// if "verbose atool.exe output" is enabled
   306 		// if "verbose atool.exe output" is enabled
   373 		if (verbose) {
   307 		if (verbose) {
   374 			usedArguments.add(Constants.ATOOL_SHOW_DEBUG);
   308 			usedArguments.add(Constants.ATOOL_SHOW_DEBUG);
   375 		}
   309 		}
   376 
   310 
   377 		// get callstack size
   311 		// get callstack size
   378 		IPreferenceStore store = Activator.getPreferences();
   312 		IPreferenceStore store = Activator.getPreferences();
   379 		if( store.getBoolean(Constants.USE_CALLSTACK_SIZE) ) {
   313 		if (store.getBoolean(Constants.USE_CALLSTACK_SIZE)) {
   380 			int callstackSize = store.getInt(Constants.CALLSTACK_SIZE);
   314 			int callstackSize = store.getInt(Constants.CALLSTACK_SIZE);
   381 			usedArguments.add(Constants.CALLSTACK_SIZE_OPTION);
   315 			usedArguments.add(Constants.CALLSTACK_SIZE_OPTION);
   382 			usedArguments.add(Integer.toString(callstackSize));
   316 			usedArguments.add(Integer.toString(callstackSize));
   383 		}
   317 		}
   384 
   318 
   385 		//add build command
   319 		// add build command
   386 		// if project using SBSv2 build system
   320 		// if project using SBSv2 build system
   387 		boolean sbsBuild = isSBSBuildActivated(cpi);
   321 		boolean sbsBuild = isSBSBuildActivated(cpi);
   388 		if (sbsBuild) {
   322 		if (sbsBuild) {
   389 			usedArguments.add("sbs");
   323 			usedArguments.add("sbs");
   390 			usedArguments.add("-c");
   324 			usedArguments.add("-c");
   391 			StringBuffer buildCommand = new StringBuffer();
   325 			StringBuffer buildCommand = new StringBuffer();
   392 			buildCommand.append(platform);
   326 			buildCommand.append(platform);
   393 			buildCommand.append('_');
   327 			buildCommand.append('_');
   394 			buildCommand.append(buildTarget);
   328 			buildCommand.append(buildTarget);
   395 			usedArguments.add(buildCommand.toString());
   329 			usedArguments.add(buildCommand.toString());
   396 		}
   330 		} else // use abld
   397 		else //use abld 
       
   398 		{
   331 		{
   399 			usedArguments.add("abld");
   332 			usedArguments.add("abld");
   400 			usedArguments.add("build");
   333 			usedArguments.add("build");
   401 			usedArguments.add(platform);
   334 			usedArguments.add(platform);
   402 			usedArguments.add(buildTarget);
   335 			usedArguments.add(buildTarget);
   405 		int errorCode = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
   338 		int errorCode = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
   406 		// if user has selected custom setup of components =>build them
   339 		// if user has selected custom setup of components =>build them
   407 		// this means that call is come from CompileSymbianComponent class
   340 		// this means that call is come from CompileSymbianComponent class
   408 		if (userSelectedMmpFiles != null && !userSelectedMmpFiles.isEmpty()) {
   341 		if (userSelectedMmpFiles != null && !userSelectedMmpFiles.isEmpty()) {
   409 
   342 
   410 			//get atool.exe command
   343 			// get atool.exe command
   411 			Iterator<IFile> files = userSelectedMmpFiles.iterator();
   344 			Iterator<IFile> files = userSelectedMmpFiles.iterator();
   412 			while(files.hasNext()) {
   345 			while (files.hasNext()) {
   413 				IFile file = files.next();
   346 				IFile file = files.next();
   414 				IPath location = file.getLocation();
   347 				IPath location = file.getLocation();
   415 
   348 
   416 				String mmpFileName = getMMPFileName(location, true);
   349 				String mmpFileName = getMMPFileName(location, true);
   417 				if( mmpFileName == null || ("").equals(mmpFileName)) {
   350 				if (mmpFileName == null || ("").equals(mmpFileName)) {
   418 					continue;
   351 					continue;
   419 				}
   352 				}
   420 
   353 
   421 				// if this is first mmp file add it parameter list
   354 				// if this is first mmp file add it parameter list
   422 				usedArguments.add("-p");
   355 				usedArguments.add("-p");
   423 				usedArguments.add(mmpFileName);
   356 				usedArguments.add(mmpFileName);
   424 			}
   357 			}
   425 
   358 
   426 			//now the command is ready
   359 			// now the command is ready
   427 			//execute command
   360 			// execute command
   428 			// execute atool.exe via CommandLauncher class
   361 			// execute atool.exe via CommandLauncher class
   429 			cmdLauncher.showCommand(true);
   362 			cmdLauncher.showCommand(true);
   430 			String[] arguments = new String[usedArguments.size()];
   363 			String[] arguments = new String[usedArguments.size()];
   431 		    usedArguments.toArray(arguments);
   364 			usedArguments.toArray(arguments);
   432 		    errorCode = cmdLauncher.executeCommand(new Path(Util
   365 
   433 					.getAtoolInstallFolder()), arguments,
   366 			errorCode = cmdLauncher.executeCommand(new Path(Util
   434 					CarbideCPPBuilder.getResolvedEnvVars(cpi
   367 					.getAtoolInstallFolder()), arguments, CarbideCPPBuilder
   435 							.getDefaultConfiguration()), cpi
   368 					.getResolvedEnvVars(cpi.getDefaultConfiguration()), cpi
   436 							.getINFWorkingDirectory());
   369 					.getINFWorkingDirectory());
   437 
       
   438 
   370 
   439 			// if user press "Cancel"
   371 			// if user press "Cancel"
   440 			if (monitor.isCanceled()) {
   372 			if (monitor.isCanceled()) {
   441 				buildCancelled(monitor, false);
   373 				buildCancelled(monitor, false);
   442 				monitor.done();
   374 				monitor.done();
   470 
   402 
   471 			// Carbide build is finished
   403 			// Carbide build is finished
   472 			// now remove AnalyzeTool made modifications
   404 			// now remove AnalyzeTool made modifications
   473 			// if project contains build erros => only uninstrument mmp
   405 			// if project contains build erros => only uninstrument mmp
   474 			// file
   406 			// file
   475 			if (CarbideCPPBuilder.projectHasBuildErrors(cpi
   407 			if (CarbideCPPBuilder.projectHasBuildErrors(cpi.getProject())) {
   476 					.getProject())) {
       
   477 				usedArguments.set(0, Constants.ATOOL_UNINST_FAILED);
   408 				usedArguments.set(0, Constants.ATOOL_UNINST_FAILED);
   478 			}
   409 			}
   479 
   410 
   480 			// project succesfully build => uninstrumet project
   411 			// project succesfully build => uninstrumet project
   481 			runUninstrument(Constants.ATOOL_UNINST, cpi, monitor);
   412 			runUninstrument(Constants.ATOOL_UNINST, cpi, monitor);
   482 
       
   483 		}
   413 		}
   484 		// if build from bld.inf file
   414 		// if build from bld.inf file
   485 		else if (cpi.isBuildingFromInf()) {
   415 		else if (cpi.isBuildingFromInf()) {
   486 			cmdLauncher.showCommand(true);
   416 			cmdLauncher.showCommand(true);
       
   417 
   487 			String[] arguments = new String[usedArguments.size()];
   418 			String[] arguments = new String[usedArguments.size()];
   488 		    usedArguments.toArray(arguments);
   419 			usedArguments.toArray(arguments);
   489 		    errorCode = cmdLauncher.executeCommand(new Path(Util.getAtoolInstallFolder()),
   420 			errorCode = cmdLauncher.executeCommand(new Path(Util
   490 					arguments,
   421 					.getAtoolInstallFolder()), arguments, CarbideCPPBuilder
   491 					CarbideCPPBuilder.getResolvedEnvVars(cpi
   422 					.getResolvedEnvVars(cpi.getDefaultConfiguration()), cpi
   492 							.getDefaultConfiguration()), cpi
   423 					.getINFWorkingDirectory());
   493 							.getINFWorkingDirectory());
       
   494 
   424 
   495 			if (mmpFiles != null) {
   425 			if (mmpFiles != null) {
   496 				mmpFiles.clear();
   426 				mmpFiles.clear();
   497 			}
   427 			}
   498 
   428 
   509 			for (int i = 0; i < mmpFiles.size(); i++) {
   439 			for (int i = 0; i < mmpFiles.size(); i++) {
   510 				usedArguments.add("-p");
   440 				usedArguments.add("-p");
   511 				usedArguments.add(mmpFiles.get(i));
   441 				usedArguments.add(mmpFiles.get(i));
   512 			}
   442 			}
   513 			cmdLauncher.showCommand(true);
   443 			cmdLauncher.showCommand(true);
       
   444 
   514 			String[] arguments = new String[usedArguments.size()];
   445 			String[] arguments = new String[usedArguments.size()];
   515 		    usedArguments.toArray(arguments);
   446 			usedArguments.toArray(arguments);
   516 		    errorCode = cmdLauncher.executeCommand(new Path(Util
   447 			errorCode = cmdLauncher.executeCommand(new Path(Util
   517 					.getAtoolInstallFolder()), arguments,
   448 					.getAtoolInstallFolder()), arguments, CarbideCPPBuilder
   518 					CarbideCPPBuilder.getResolvedEnvVars(cpi
   449 					.getResolvedEnvVars(cpi.getDefaultConfiguration()), cpi
   519 							.getDefaultConfiguration()), cpi
   450 					.getINFWorkingDirectory());
   520 							.getINFWorkingDirectory());
       
   521 
   451 
   522 			// if user press "Cancel"
   452 			// if user press "Cancel"
   523 			if (monitor.isCanceled()) {
   453 			if (monitor.isCanceled()) {
   524 				buildCancelled(monitor, false);
   454 				buildCancelled(monitor, false);
   525 				monitor.done();
   455 				monitor.done();
   528 		return errorCode;
   458 		return errorCode;
   529 	}
   459 	}
   530 
   460 
   531 	/**
   461 	/**
   532 	 * Parses mmp file from the entered path
   462 	 * Parses mmp file from the entered path
   533 	 * @param fileLocation MMP file location with path.
   463 	 * 
   534 	 * @param sbsBuild Is sbsv2 build system activated
   464 	 * @param fileLocation
   535 	 * @return MMP file name without path. If SBSv2 is not activated the MMP 
   465 	 *            MMP file location with path.
   536 	 * 		 file is returned without file extension.
   466 	 * @param sbsBuild
   537 	 */
   467 	 *            Is sbsv2 build system activated
   538 	public String getMMPFileName(IPath fileLocation, boolean sbsBuild)
   468 	 * @return MMP file name without path. If SBSv2 is not activated the MMP
   539 	{
   469 	 *         file is returned without file extension.
       
   470 	 */
       
   471 	public String getMMPFileName(IPath fileLocation, boolean sbsBuild) {
   540 		// because mmp file contains project related path
   472 		// because mmp file contains project related path
   541 		// we need to parse mmp file name
   473 		// we need to parse mmp file name
   542 		int index = Util.getLastSlashIndex(fileLocation.toString());
   474 		int index = Util.getLastSlashIndex(fileLocation.toString());
   543 		String mmpFileName = null;
   475 		String mmpFileName = null;
   544 		if (index == -1) {
   476 		if (index == -1) {
   545 			// mmp file is incorrect => skip this file
   477 			// mmp file is incorrect => skip this file
   546 			return mmpFileName;
   478 			return mmpFileName;
   547 		}
   479 		}
   548 
   480 
   549 		// parse mmp file name
   481 		// parse mmp file name
   550 		mmpFileName = fileLocation.toString().substring(
   482 		mmpFileName = fileLocation.toString().substring(index + 1,
   551 				index + 1, fileLocation.toString().length());
   483 				fileLocation.toString().length());
   552 
   484 
   553 		//if not using the SBS2 builds => needs to remove mmp file name extension
   485 		// if not using the SBS2 builds => needs to remove mmp file name
   554 		if( !sbsBuild && mmpFileName.endsWith(".mmp")) {
   486 		// extension
   555 			mmpFileName = mmpFileName.substring(0, mmpFileName.length()-4);
   487 		if (!sbsBuild && mmpFileName.endsWith(".mmp")) {
       
   488 			mmpFileName = mmpFileName.substring(0, mmpFileName.length() - 4);
   556 		}
   489 		}
   557 		return mmpFileName;
   490 		return mmpFileName;
   558 	}
   491 	}
   559 
   492 
   560 
       
   561 	/**
   493 	/**
   562 	 * Runs AnalyzeTool build.
   494 	 * Runs AnalyzeTool build.
   563 	 *
   495 	 * 
   564 	 * @param type
   496 	 * @param type
   565 	 *            Type of execution. Possible types ATOOL_INST or ATOOL_UNINST
   497 	 *            Type of execution. Possible types ATOOL_INST or ATOOL_UNINST
   566 	 * @param monitor
   498 	 * @param monitor
   567 	 *            Progress monitor reference
   499 	 *            Progress monitor reference
   568 	 * @param cpi
   500 	 * @param cpi
   573 	 */
   505 	 */
   574 	protected final boolean runBuild(final String type,
   506 	protected final boolean runBuild(final String type,
   575 			final IProgressMonitor monitor, final ICarbideProjectInfo cpi,
   507 			final IProgressMonitor monitor, final ICarbideProjectInfo cpi,
   576 			final List<IFile> files) {
   508 			final List<IFile> files) {
   577 
   509 
   578 		// check AnalyzeTool libraries if the AnalyzeTool libraries missing =>
       
   579 		// creates error marker for the project and cancels build
       
   580 		if( !Util.checkAtoolLibs(cpi) )
       
   581 		{
       
   582 			buildCancelled(monitor, false);
       
   583 			return false;
       
   584 		}
       
   585 
       
   586 		// get preference store
   510 		// get preference store
   587 		IPreferenceStore store = Activator.getPreferences();
   511 		IPreferenceStore store = Activator.getPreferences();
   588 
   512 
   589 		// get active logging mode
   513 		// get active logging mode
   590 		String loggingMode = store.getString(Constants.LOGGING_MODE);
   514 		String loggingMode = store.getString(Constants.LOGGING_MODE);
   591 		String s60FileNameMode = store.getString(Constants.S60_LOG_FILE_MODE);
   515 
   592 		verbose = store.getBoolean(Constants.ATOOL_VERBOSE);
   516 		verbose = store.getBoolean(Constants.ATOOL_VERBOSE);
   593 
   517 
   594 		// possible error code from command line engine
   518 		// possible error code from command line engine
   595 		int errorCode = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
   519 		int errorCode = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
   596 
   520 
   597 		// if logging mode is set to "ask always"
   521 		// if logging mode is set to "ask always"
   598 		// ask for user used logging mode
   522 		// ask for user used logging mode
   599 		if (Constants.LOGGING_ASK_ALLWAYS.equals(loggingMode)) {
   523 		if (Constants.LOGGING_ASK_ALLWAYS.equals(loggingMode)) {
   600 			String modeSelection = askLoggingMode();
   524 
       
   525 			String[] outputMode = Util.openOutputModeDialog();
   601 
   526 
   602 			// user press "Cancel"
   527 			// user press "Cancel"
   603 			if (modeSelection == null || ("").equals(modeSelection)) {
   528 			if (outputMode == null) {
   604 				buildCancelled(monitor, true);
   529 				buildCancelled(monitor, true);
   605 				return false;
   530 				return false;
   606 			}
   531 			}
   607 			// if user selects S60 log file and mode
   532 			// if user selects S60 log file and mode
   608 			// and data file must ask for user
   533 			// and data file must ask for user
   609 			else if (Constants.LOGGING_S60.equals(modeSelection)
   534 			else if (Constants.LOGGING_S60.equals(outputMode[0])) {
   610 					&& Constants.LOGGING_S60_USER_SPECIFIED
   535 				String logPath = outputMode[1];
   611 							.equals(s60FileNameMode)) {
   536 				String logFileName = outputMode[2];
   612 				errorCode = askFileNameAndBuild(monitor, cpi, files);
   537 
       
   538 				errorCode = executeAtool(logPath, logFileName, type,
       
   539 						outputMode[0], files, cpi, monitor);
   613 			} else { // no need to ask data file for the user => just build
   540 			} else { // no need to ask data file for the user => just build
   614 						// with
   541 				// with
   615 				// user selected logging mode
   542 				// user selected logging mode
   616 				errorCode = executeAtool(null, type, modeSelection, files, cpi, monitor);
   543 				errorCode = executeAtool(null, null, type, outputMode[0],
   617 			}
   544 						files, cpi, monitor);
   618 
   545 			}
   619 		}
   546 		}
   620 		// if used logging mode is s60
   547 		// if used logging mode is s60
   621 		// and data file name must ask for the user
   548 		// and data file name must ask for the user
   622 		else if (Constants.LOGGING_S60.equals(loggingMode)
   549 		else if (Constants.LOGGING_S60.equals(loggingMode)) {
   623 				&& Constants.LOGGING_S60_USER_SPECIFIED.equals(s60FileNameMode)) {
   550 			String path = store.getString(Constants.DEVICE_LOG_FILE_PATH);
   624 			errorCode = askFileNameAndBuild(monitor, cpi, files);
   551 			String fileName = store.getString(Constants.DEVICE_LOG_FILE_NAME);
       
   552 
       
   553 			errorCode = executeAtool(path, fileName, type, loggingMode, files,
       
   554 					cpi, monitor);
   625 		}
   555 		}
   626 		// build with selected mode
   556 		// build with selected mode
   627 		else {
   557 		else {
   628 			errorCode = executeAtool(null, type, loggingMode, files, cpi, monitor);
   558 			errorCode = executeAtool(null, null, type, loggingMode, files, cpi,
   629 		}
   559 					monitor);
   630 
   560 		}
   631 
   561 
   632 		// no errors from command line engine
   562 		// no errors from command line engine
   633 		if( errorCode == Constants.COMMAND_LINE_ERROR_CODE.OK.getCode() ) {
   563 		if (errorCode == Constants.COMMAND_LINE_ERROR_CODE.OK.getCode()) {
   634 			return true;
   564 			return true;
   635 		}
   565 		}
   636 
   566 
   637 		// if some error code is returned from command line engine display it to user
   567 		// if some error code is returned from command line engine display it to
   638 		// and cancel build
   568 		// user and cancel build
   639 		Constants.COMMAND_LINE_ERROR_CODE error = Util.getErrorCode(errorCode);
   569 		Constants.COMMAND_LINE_ERROR_CODE error = Util.getErrorCode(errorCode);
   640 		Util.displayCommandLineError(error);
   570 		Util.displayCommandLineError(error);
   641 		buildCancelled(monitor, false);
   571 		buildCancelled(monitor, false);
   642 		return false;
   572 		return false;
   643 	}
   573 	}
   644 
   574 
   645 	/**
   575 	/**
   646 	 * After the built is finished set preferences back to normal.
   576 	 * After the built is finished set preferences back to normal.
   647 	 * @param cpi ICarbideProjectInfo refernece
   577 	 * 
       
   578 	 * @param cpi
       
   579 	 *            ICarbideProjectInfo refernece
   648 	 */
   580 	 */
   649 	public final void runPostSteps(ICarbideProjectInfo cpi) {
   581 	public final void runPostSteps(ICarbideProjectInfo cpi) {
   650 
   582 
   651 		IPreferenceStore store = Activator.getPreferences();
   583 		IPreferenceStore store = Activator.getPreferences();
   652 		boolean keepFilesSync = store.getBoolean(Constants.PREFS_KEEP_IN_SYNC);
   584 		boolean keepFilesSync = store.getBoolean(Constants.PREFS_KEEP_IN_SYNC);
   654 		boolean manageDeps = store.getBoolean(Constants.PREFS_MANAGE_DEPS);
   586 		boolean manageDeps = store.getBoolean(Constants.PREFS_MANAGE_DEPS);
   655 		boolean useConcBuild = store.getBoolean(Constants.PREFS_CONC_BUILD);
   587 		boolean useConcBuild = store.getBoolean(Constants.PREFS_CONC_BUILD);
   656 
   588 
   657 		// try to load ProjectUIPlugin class
   589 		// try to load ProjectUIPlugin class
   658 		try {
   590 		try {
   659 			Class.forName("com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils");
   591 			Class
       
   592 					.forName("com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils");
   660 
   593 
   661 			// no need to keep project files in sync
   594 			// no need to keep project files in sync
   662 			// this should fix the mmp selection dialog prompt
   595 			// this should fix the mmp selection dialog prompt
   663 			com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils
   596 			com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils
   664 					.setKeepProjectsInSync(keepFilesSync);
   597 					.setKeepProjectsInSync(keepFilesSync);
   665 		} catch (ClassNotFoundException cnte) {
   598 		} catch (ClassNotFoundException cnte) {
   666 			//Do nothing by design
   599 			// Do nothing by design
   667 		}
   600 		}
   668 
   601 
   669 		// set builder preference to not prompt mmp file change dialog
   602 		// set builder preference to not prompt mmp file change dialog
   670 		IPreferenceStore cStore = CarbideBuilderPlugin.getDefault()
   603 		IPreferenceStore cStore = CarbideBuilderPlugin.getDefault()
   671 				.getPreferenceStore();
   604 				.getPreferenceStore();
   672 
       
   673 
   605 
   674 		// add existing/default values of Carbide builder settings
   606 		// add existing/default values of Carbide builder settings
   675 		cStore
   607 		cStore
   676 				.setValue(
   608 				.setValue(
   677 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_MMP_CHANGED_ACTION_PROMPT,
   609 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_MMP_CHANGED_ACTION_PROMPT,
   683 		cStore
   615 		cStore
   684 				.setValue(
   616 				.setValue(
   685 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING,
   617 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING,
   686 						useConcBuild);
   618 						useConcBuild);
   687 
   619 
   688 
       
   689 		// try to remove -debug parameter from the build arguments list
   620 		// try to remove -debug parameter from the build arguments list
   690 		try {
   621 		try {
   691 			//get build configuration
   622 			// get build configuration
   692 			ICarbideBuildConfiguration config = cpi.getDefaultConfiguration();
   623 			ICarbideBuildConfiguration config = cpi.getDefaultConfiguration();
   693 
   624 
   694 			//get build arguments info
   625 			// get build arguments info
   695 			BuildArgumentsInfo info = config.getBuildArgumentsInfoCopy();
   626 			BuildArgumentsInfo info = config.getBuildArgumentsInfoCopy();
   696 
   627 
   697 			//get used platform
   628 			// get used platform
   698 			String platform = config.getPlatformString();
   629 			String platform = config.getPlatformString();
   699 
   630 
   700 			String debug = "-debug";
   631 			String debug = "-debug";
   701 			String abldArgs = info.abldBuildArgs;
   632 			String abldArgs = info.abldBuildArgs;
   702 
   633 
   703 			//if platform is set to ARMV5 or GCCE
   634 			// if platform is set to ARMV5 or GCCE
   704 			if ( platform.contains(Constants.BUILD_TARGET_ARMV5) || platform.contains(Constants.BUILD_TARGET_GCEE)) {
   635 			if (platform.contains(Constants.BUILD_TARGET_ARMV5)
   705 
   636 					|| platform.contains(Constants.BUILD_TARGET_GCEE)) {
   706 				//get "-debug" string index
   637 
       
   638 				// get "-debug" string index
   707 				int index = abldArgs.indexOf(debug);
   639 				int index = abldArgs.indexOf(debug);
   708 
   640 
   709 				//if abld build arguments contains only "-debug" parameter
   641 				// if abld build arguments contains only "-debug" parameter
   710 				if( abldArgs.equals(debug) ) {
   642 				if (abldArgs.equals(debug)) {
   711 					info.abldBuildArgs = "";
   643 					info.abldBuildArgs = "";
   712 					config.setBuildArgumentsInfo(info);
   644 					config.setBuildArgumentsInfo(info);
   713 				}
   645 				}
   714 				//remove just "-debug" word
   646 				// remove just "-debug" word
   715 				else if( abldArgs.contains(debug) && index != -1 ) {
   647 				else if (abldArgs.contains(debug) && index != -1) {
   716 					info.abldBuildArgs = abldArgs.substring(0,index) + abldArgs.substring(index+debug.length(), abldArgs.length());
   648 					info.abldBuildArgs = abldArgs.substring(0, index)
       
   649 							+ abldArgs.substring(index + debug.length(),
       
   650 									abldArgs.length());
   717 					config.setBuildArgumentsInfo(info);
   651 					config.setBuildArgumentsInfo(info);
   718 				}
   652 				}
   719 			}
   653 			}
   720 
   654 
   721 		}catch( java.lang.NoSuchMethodError nsme ) {
   655 		} catch (java.lang.NoSuchMethodError nsme) {
   722 			//Do nothing by design
   656 			// Do nothing by design
   723 			//user might run AT with too old Carbide version
   657 			// user might run AT with too old Carbide version
   724 		}catch( Exception e ) {
   658 		} catch (Exception e) {
   725 			e.printStackTrace();
   659 			e.printStackTrace();
   726 		}
   660 		}
   727 
   661 
   728 		//after the build is finished => open the console view
   662 		// after the build is finished => open the console view
   729 		Util.openConsoleView();
   663 		Util.openConsoleView();
   730 	}
   664 	}
   731 
   665 
   732 	/**
   666 	/**
   733 	 * Checks is atool.exe available and modifies Carbide preferences.
   667 	 * Checks is atool.exe available and modifies Carbide preferences.
   734 	 *
   668 	 * 
   735 	 * @param launcher
   669 	 * @param launcher
   736 	 *            Command launcher
   670 	 *            Command launcher
   737 	 * @param monitor
   671 	 * @param monitor
   738 	 *            Progress monitor
   672 	 *            Progress monitor
   739 	 * @param cpi
   673 	 * @param cpi
   741 	 * @return True if all checks are OK, otherwise False
   675 	 * @return True if all checks are OK, otherwise False
   742 	 */
   676 	 */
   743 	protected final boolean runPreSteps(final CarbideCommandLauncher launcher,
   677 	protected final boolean runPreSteps(final CarbideCommandLauncher launcher,
   744 			final IProgressMonitor monitor, final ICarbideProjectInfo cpi) {
   678 			final IProgressMonitor monitor, final ICarbideProjectInfo cpi) {
   745 
   679 
   746 
       
   747 		// set command launchers
   680 		// set command launchers
   748 		cmdLauncher = launcher;
   681 		cmdLauncher = launcher;
   749 
   682 
   750 		// check is atool.exe available
   683 		// check is atool.exe available
   751 		if (!Util.isAtoolAvailable()) {
   684 		if (!Util.isAtoolAvailable()) {
   752 			launcher.writeToConsole(Constants.INFO_ATOOL_NOT_AVAILABLE);
   685 			launcher.writeToConsole(Constants.INFO_ATOOL_NOT_AVAILABLE);
   753 			buildCancelled(monitor, false);
   686 			buildCancelled(monitor, false);
   754 			Util.showErrorMessage(Constants.ERROR_ATOOL_NOT_AVAILABLE);
   687 			Util.showMessageDialog(Constants.CLE_VERSION_MISMATCH,
   755 			return false;
   688 					Constants.ERROR_ATOOL_NOT_AVAILABLE, SWT.ICON_ERROR);
   756 		}
   689 
   757 		
   690 			return false;
   758 		// check AnalyzeTool version, 1.6.0 and forward versions is supported
   691 		}
   759 		String atoolVersion = Util.getAtoolVersionNumber(Util.getAtoolInstallFolder());
   692 
   760 		int compared = Util.compareVersionNumber(atoolVersion, Constants.MIN_VERSION);
   693 		// check supported AnalyzeTool version
   761 		if( compared == Constants.VERSION_NUMBERS_SECOND || compared == Constants.VERSION_NUMBERS_INVALID ) {
   694 		String atoolVersion = Util.getAtoolVersionNumber(Util
       
   695 				.getAtoolInstallFolder());
       
   696 		int compared = Util.compareVersionNumber(atoolVersion,
       
   697 				Constants.MIN_CLE_SUPPORTED);
       
   698 		if (compared == Constants.VERSION_NUMBERS_SECOND
       
   699 				|| compared == Constants.VERSION_NUMBERS_INVALID) {
       
   700 			launcher.writeToConsole(MessageFormat.format(
       
   701 					Constants.CLE_OLDER_THAN_MIN, Constants.MIN_CLE_SUPPORTED));
   762 			buildCancelled(monitor, false);
   702 			buildCancelled(monitor, false);
   763 			Util.showMessage(Constants.TOO_OLD_ENGINE);
   703 			Util.showMessageDialog(Constants.CLE_VERSION_MISMATCH,
       
   704 					MessageFormat.format(Constants.CLE_OLDER_THAN_MIN,
       
   705 							Constants.MIN_CLE_SUPPORTED), SWT.ICON_ERROR);
   764 			return false;
   706 			return false;
   765 		}
   707 		}
   766 
   708 
   767 		/**
   709 		/**
   768 		 *
   710 		 * 
   769 		 * Below is code a sample which are related to the AT-682,
   711 		 * Below is code a sample which are related to the AT-682, but it is
   770 		 * but it is decided to let out from current release.
   712 		 * decided to let out from current release. String coreVersion =
   771 		String coreVersion = Util.getAtoolCoreVersion(cpi.getProject());
   713 		 * Util.getAtoolCoreVersion(cpi.getProject()); compared =
   772 		compared = Util.compareVersionNumber(coreVersion, atoolVersion);
   714 		 * Util.compareVersionNumber(coreVersion, atoolVersion); if( compared !=
   773 		if( compared != Constants.VERSION_NUMBERS_EQUALS ) 
   715 		 * Constants.VERSION_NUMBERS_EQUALS ) { boolean retValue =
   774 		{
   716 		 * Util.openConfirmationDialog(
   775 			boolean retValue = Util.openConfirmationDialog("AnalyzeTool command line engine and AnalyzeTool core version mismatch.\n" +
   717 		 * "AnalyzeTool command line engine and AnalyzeTool core version mismatch.\n"
   776 					"This usually leads to problems.\n\nDo you want to continue?");
   718 		 * + "This usually leads to problems.\n\nDo you want to continue?"); if(
   777 			if( !retValue ) {
   719 		 * !retValue ) { buildCancelled(monitor, false); return false; } }
   778 				buildCancelled(monitor, false);
   720 		 */
   779 				return false;	
       
   780 			}
       
   781 		}
       
   782 		*/
       
   783 		// remove existing error markers
   721 		// remove existing error markers
   784 		try {
   722 		try {
   785 			CarbideCPPBuilder.removeAllMarkers(cpi.getProject());
   723 			CarbideCPPBuilder.removeAllMarkers(cpi.getProject());
   786 		}catch (CoreException ce) {
   724 		} catch (CoreException ce) {
   787 			ce.printStackTrace();
   725 			ce.printStackTrace();
   788 			return false;
   726 			return false;
   789 		}
   727 		}
   790 		
   728 
   791 		// check used platform
   729 		// check used platform
   792 		if (!checkPlatform(cpi)) {
   730 		if (!checkPlatform(cpi)) {
   793 			buildCancelled(monitor, Util
   731 			buildCancelled(monitor, Util
   794 					.openConfirmationDialog(Constants.PLATFORM_NOT_SUPPORTED));
   732 					.openConfirmationDialog(Constants.PLATFORM_NOT_SUPPORTED));
   795 			return false;
   733 			return false;
   796 		}
   734 		}
   797 
   735 
   798 		// check AnalyzeTool libraries if the AnalyzeTool libraries missing =>
   736 		// check AnalyzeTool libraries
   799 		// creates error marker for the project and cancels build
   737 		final String libsCheck = Util.checkAtoolLibs(cpi);
   800 		if( !Util.checkAtoolLibs(cpi) )
   738 		if (!libsCheck.equals(Constants.ATOOL_LIBS_OK)) {
   801 		{
   739 			Util.showMessageDialog(Constants.DIALOG_TITLE, libsCheck,
   802 			PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable() {
   740 					SWT.ICON_ERROR);
   803 				public void run() {
       
   804 					// show error message for the user
       
   805 					Util.showMessage(Constants.CAN_NOT_FIND_LIBRARIES);
       
   806 				}
       
   807 			});
       
   808 			buildCancelled(monitor, false);
   741 			buildCancelled(monitor, false);
   809 			return false;
   742 			return false;
   810 		}
   743 		}
   811 
   744 
   812 		// use CarbideCPPBuilder to bldmake bldfiles for selected project
   745 		// use CarbideCPPBuilder to bldmake bldfiles for selected project
   829 			// no need to keep project files in sync
   762 			// no need to keep project files in sync
   830 			// this should fix the mmp selection dialog prompt
   763 			// this should fix the mmp selection dialog prompt
   831 			com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils
   764 			com.nokia.carbide.cpp.project.ui.utils.ProjectUIUtils
   832 					.setKeepProjectsInSync(false);
   765 					.setKeepProjectsInSync(false);
   833 		} catch (ClassNotFoundException cnfe) {
   766 		} catch (ClassNotFoundException cnfe) {
   834 			//Do nothing by design
   767 			// Do nothing by design
   835 		}
   768 		}
   836 
   769 
   837 		// set builder preference to not prompt mmp file change dialog
   770 		// set builder preference to not prompt mmp file change dialog
   838 		IPreferenceStore cStore = CarbideBuilderPlugin.getDefault()
   771 		IPreferenceStore cStore = CarbideBuilderPlugin.getDefault()
   839 				.getPreferenceStore();
   772 				.getPreferenceStore();
   844 		boolean manageDeps = cStore
   777 		boolean manageDeps = cStore
   845 				.getBoolean(com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_MANAGE_DEPENDENCIES);
   778 				.getBoolean(com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_MANAGE_DEPENDENCIES);
   846 		boolean useConcBuild = cStore
   779 		boolean useConcBuild = cStore
   847 				.getBoolean(com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING);
   780 				.getBoolean(com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING);
   848 
   781 
   849 		//store existing values
   782 		// store existing values
   850 		store.setValue(Constants.PREFS_PROMPT_MMP, promptMPPChange);
   783 		store.setValue(Constants.PREFS_PROMPT_MMP, promptMPPChange);
   851 		store.setValue(Constants.PREFS_MANAGE_DEPS, manageDeps);
   784 		store.setValue(Constants.PREFS_MANAGE_DEPS, manageDeps);
   852 		store.setValue(Constants.PREFS_CONC_BUILD, useConcBuild);
   785 		store.setValue(Constants.PREFS_CONC_BUILD, useConcBuild);
   853 		// add custom values for AnalyzeTool build
   786 		// add custom values for AnalyzeTool build
   854 		cStore
   787 		cStore
   861 						false);
   794 						false);
   862 		cStore
   795 		cStore
   863 				.setValue(
   796 				.setValue(
   864 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING,
   797 						com.nokia.carbide.cdt.builder.BuilderPreferenceConstants.PREF_USE_CONCURRENT_BUILDING,
   865 						false);
   798 						false);
   866 		
   799 
   867 		// try to add -debug parameter to the build arguments list
   800 		// try to add -debug parameter to the build arguments list
   868 		try {
   801 		try {
   869 			//get selected build configuration
   802 			// get selected build configuration
   870 			ICarbideBuildConfiguration config = cpi.getDefaultConfiguration();
   803 			ICarbideBuildConfiguration config = cpi.getDefaultConfiguration();
   871 
   804 
   872 			//get build arguments info
   805 			// get build arguments info
   873 			BuildArgumentsInfo info = config.getBuildArgumentsInfoCopy();
   806 			BuildArgumentsInfo info = config.getBuildArgumentsInfoCopy();
   874 
   807 
   875 			//get selected platform
   808 			// get selected platform
   876 			String platform = cpi.getDefaultConfiguration().getPlatformString();
   809 			String platform = cpi.getDefaultConfiguration().getPlatformString();
   877 
   810 
   878 			//if platform is ARMV5 or GCCE and the "-debug" parameter is not set => we need set the parameter
   811 			// if platform is ARMV5 or GCCE and the "-debug" parameter is not
   879 			if ( (platform.contains(Constants.BUILD_TARGET_ARMV5) || platform.contains(Constants.BUILD_TARGET_GCEE)) && !info.abldBuildArgs.contains("-debug") ) {
   812 			// set => we need set the parameter
   880 				if( info.abldBuildArgs.length() > 0 && !info.abldBuildArgs.endsWith(" ") ) {
   813 			if ((platform.contains(Constants.BUILD_TARGET_ARMV5) || platform
       
   814 					.contains(Constants.BUILD_TARGET_GCEE))
       
   815 					&& !info.abldBuildArgs.contains("-debug")) {
       
   816 				if (info.abldBuildArgs.length() > 0
       
   817 						&& !info.abldBuildArgs.endsWith(" ")) {
   881 					info.abldBuildArgs += " ";
   818 					info.abldBuildArgs += " ";
   882 				}
   819 				}
   883 				info.abldBuildArgs += "-debug";
   820 				info.abldBuildArgs += "-debug";
   884 				config.setBuildArgumentsInfo(info);
   821 				config.setBuildArgumentsInfo(info);
   885 			}
   822 			}
   886 
   823 		}
   887 		}
   824 		// catch NoSuchMethodError because is it possible to use older versions
   888 		//catch NoSuchMethodError because is it possible to use older versions where this method is not available
   825 		// where this method is not available
   889 		catch( java.lang.NoSuchMethodError nsme)
   826 		catch (java.lang.NoSuchMethodError nsme) {
   890 		{
   827 			// Do nothing by design
   891 			//Do nothing by design
   828 		}
   892 		}
       
   893 
       
   894 		return true;
   829 		return true;
   895 	}
   830 	}
   896 
   831 
   897 	/**
   832 	/**
   898 	 * Executes uninstrument for the project.
   833 	 * Executes uninstrument for the project.
   899 	 * @param command Uninstrument command
   834 	 * 
   900 	 * @param cpi ICarbideProjectInfo reference
   835 	 * @param command
   901 	 * @param monitor IProgressMonitor reference
   836 	 *            Uninstrument command
   902 	 */
   837 	 * @param cpi
   903 	public void runUninstrument(String command, ICarbideProjectInfo cpi, IProgressMonitor monitor)
   838 	 *            ICarbideProjectInfo reference
   904 	{
   839 	 * @param monitor
       
   840 	 *            IProgressMonitor reference
       
   841 	 */
       
   842 	public void runUninstrument(String command, ICarbideProjectInfo cpi,
       
   843 			IProgressMonitor monitor) {
   905 		cmdLauncher.showCommand(true);
   844 		cmdLauncher.showCommand(true);
   906 		String[] arguments = new String[1];
   845 		String[] arguments = new String[1];
   907 	    arguments[0] = command;
   846 		arguments[0] = command;
   908 		int error = cmdLauncher.executeCommand(new Path(Util
   847 		int error = cmdLauncher.executeCommand(new Path(Util
   909 				.getAtoolInstallFolder()),arguments,
   848 				.getAtoolInstallFolder()), arguments, CarbideCPPBuilder
   910 				CarbideCPPBuilder.getResolvedEnvVars(cpi
   849 				.getResolvedEnvVars(cpi.getDefaultConfiguration()), cpi
   911 						.getDefaultConfiguration()), cpi
   850 				.getINFWorkingDirectory());
   912 					.getINFWorkingDirectory());
   851 
   913 		
       
   914 		// if some occurs => display it to user
   852 		// if some occurs => display it to user
   915 		if( error != Constants.COMMAND_LINE_ERROR_CODE.OK.getCode() ) {
   853 		if (error != Constants.COMMAND_LINE_ERROR_CODE.OK.getCode()) {
   916 			Constants.COMMAND_LINE_ERROR_CODE errorCode = Util.getErrorCode(error);
   854 			Constants.COMMAND_LINE_ERROR_CODE errorCode = Util
       
   855 					.getErrorCode(error);
   917 			Util.displayCommandLineError(errorCode);
   856 			Util.displayCommandLineError(errorCode);
   918 		}
   857 		}
   919 	}
   858 	}
   920 }
   859 }