sysperfana/analyzetoolext/com.nokia.s60tools.analyzetool/src/com/nokia/s60tools/analyzetool/global/Util.java
changeset 1 1050670c6980
child 6 f65f740e69f9
equal deleted inserted replaced
0:5ad7ad99af01 1:1050670c6980
       
     1 /*
       
     2  * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Definitions for the class Util
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.s60tools.analyzetool.global;
       
    19 
       
    20 import java.io.BufferedInputStream;
       
    21 import java.io.File;
       
    22 import java.io.FileInputStream;
       
    23 import java.io.FileNotFoundException;
       
    24 import java.io.FileOutputStream;
       
    25 import java.io.IOException;
       
    26 import java.net.URL;
       
    27 import java.nio.channels.FileChannel;
       
    28 import java.util.AbstractList;
       
    29 import java.util.ArrayList;
       
    30 import java.util.Iterator;
       
    31 
       
    32 import org.eclipse.cdt.core.model.ICModelMarker;
       
    33 import org.eclipse.core.resources.IMarker;
       
    34 import org.eclipse.core.resources.IProject;
       
    35 import org.eclipse.core.resources.IResource;
       
    36 import org.eclipse.core.runtime.CoreException;
       
    37 import org.eclipse.core.runtime.FileLocator;
       
    38 import org.eclipse.core.runtime.IBundleGroup;
       
    39 import org.eclipse.core.runtime.IBundleGroupProvider;
       
    40 import org.eclipse.core.runtime.IPath;
       
    41 import org.eclipse.core.runtime.IProgressMonitor;
       
    42 import org.eclipse.core.runtime.IStatus;
       
    43 import org.eclipse.core.runtime.Path;
       
    44 import org.eclipse.core.runtime.Platform;
       
    45 import org.eclipse.core.runtime.Status;
       
    46 import org.eclipse.core.runtime.jobs.Job;
       
    47 import org.eclipse.jface.dialogs.MessageDialog;
       
    48 import org.eclipse.jface.preference.IPreferenceStore;
       
    49 import org.eclipse.jface.viewers.ArrayContentProvider;
       
    50 import org.eclipse.jface.viewers.LabelProvider;
       
    51 import org.eclipse.swt.SWT;
       
    52 import org.eclipse.swt.widgets.FileDialog;
       
    53 import org.eclipse.swt.widgets.Shell;
       
    54 import org.eclipse.ui.IWorkbenchPage;
       
    55 import org.eclipse.ui.IWorkbenchPart;
       
    56 import org.eclipse.ui.PlatformUI;
       
    57 import org.eclipse.ui.dialogs.ListDialog;
       
    58 import org.osgi.framework.Bundle;
       
    59 
       
    60 import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
       
    61 import com.nokia.carbide.cdt.builder.DefaultMMPViewConfiguration;
       
    62 import com.nokia.carbide.cdt.builder.EpocEngineHelper;
       
    63 import com.nokia.carbide.cdt.builder.builder.CarbideCPPBuilder;
       
    64 import com.nokia.carbide.cdt.builder.builder.CarbideCommandLauncher;
       
    65 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
       
    66 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
       
    67 import com.nokia.carbide.cpp.epoc.engine.EpocEnginePlugin;
       
    68 import com.nokia.carbide.cpp.epoc.engine.MMPDataRunnableAdapter;
       
    69 import com.nokia.carbide.cpp.epoc.engine.model.mmp.EMMPStatement;
       
    70 import com.nokia.carbide.cpp.epoc.engine.model.mmp.IMMPData;
       
    71 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AcceptedNodesViewFilter;
       
    72 import com.nokia.s60tools.analyzetool.Activator;
       
    73 import com.nokia.s60tools.analyzetool.builder.AnalyzeToolBuilder;
       
    74 import com.nokia.s60tools.analyzetool.engine.MMPInfo;
       
    75 import com.nokia.s60tools.analyzetool.engine.UseAtool;
       
    76 import com.nokia.s60tools.analyzetool.global.Constants.COMMAND_LINE_ERROR_CODE;
       
    77 
       
    78 /**
       
    79  * Provides commonly used functions.
       
    80  *
       
    81  * @author kihe
       
    82  *
       
    83  */
       
    84 public class Util {
       
    85 
       
    86     /** Contains user selection in the confirmation dialog. */
       
    87     private static boolean ret;
       
    88 
       
    89     /** Contains user selection (integer) in the selection dialog. */
       
    90     private static int retValue;
       
    91 
       
    92     /** Contains user selection (String) in the selection dialog. */
       
    93     private static String userSelection = "";
       
    94 
       
    95     /** Contains StringBuffer size. */
       
    96     private static int bufferSize = 32;
       
    97 
       
    98     /**
       
    99      * Checks is module built.
       
   100      *
       
   101      * @param modules
       
   102      *            Project modules
       
   103      * @param oneModuleName
       
   104      *            Current module
       
   105      * @return True if module found and it is build
       
   106      */
       
   107     public static boolean chechModuleBuildState(
       
   108             final AbstractList<MMPInfo> modules, final String oneModuleName) {
       
   109         Iterator<MMPInfo> iterModules = modules.iterator();
       
   110         while (iterModules.hasNext()) {
       
   111             MMPInfo oneMMPInfo = iterModules.next();
       
   112             String target = oneMMPInfo.getTarget();
       
   113             if (target == null) {
       
   114                 continue;
       
   115             } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) {
       
   116                 return oneMMPInfo.isBuildSuccesfully();
       
   117             }
       
   118 
       
   119             // target not found try remove {}
       
   120             // for example process name is
       
   121             // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]"
       
   122             // but target name is AToolMemoryLeakerDll2.dll
       
   123             CharSequence brace = "{";
       
   124             if (oneModuleName.contains(brace)) {
       
   125                 // parse braces
       
   126                 String tmpTargetName = oneModuleName.substring(0, oneModuleName
       
   127                         .indexOf('{'));
       
   128                 if (tmpTargetName != null
       
   129                         && oneMMPInfo.getTarget().equalsIgnoreCase(
       
   130                                 tmpTargetName)) {
       
   131                     return oneMMPInfo.isBuildSuccesfully();
       
   132                 }
       
   133             }
       
   134         }
       
   135         return false;
       
   136     }
       
   137 
       
   138     /**
       
   139      * Checks is AnalyzeTool libraries installed from the current SDK.
       
   140      *
       
   141      * @param cpi
       
   142      *            {@link ICarbideProjectInfo} reference
       
   143      * @return True if libraries are installed otherwise false.
       
   144      */
       
   145     public static boolean checkAtoolLibs(final ICarbideProjectInfo cpi) {
       
   146         // get active platform
       
   147         String platform = cpi.getDefaultConfiguration().getPlatformString();
       
   148 
       
   149         // get epoc root
       
   150         IPath epocRootPath = EpocEngineHelper.getEpocRootForProject(cpi.getProject());
       
   151 
       
   152         //check that epocroot path found
       
   153         if( epocRootPath == null ) {
       
   154             return false;
       
   155         }
       
   156 
       
   157         String epocroot = epocRootPath.toOSString();
       
   158         boolean found = true;
       
   159         StringBuffer fileBuffer = new StringBuffer(bufferSize);
       
   160         fileBuffer.append(Constants.CAN_NOT_FIND_LIBRARIES_MARKER);
       
   161         fileBuffer.append(": ");
       
   162         if ((Constants.BUILD_TARGET_WINSCW).equalsIgnoreCase(platform)) {
       
   163             for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) {
       
   164                 java.io.File file = new java.io.File(epocroot
       
   165                         + Constants.atoolLibsWinscw[i]);
       
   166                 if (!file.exists()) {
       
   167                     found = false;
       
   168                     fileBuffer.append(epocroot);
       
   169                     fileBuffer.append(Constants.atoolLibsWinscw[i]);
       
   170                     fileBuffer.append(' ');
       
   171                 }
       
   172             }
       
   173         } else if ((Constants.BUILD_TARGET_ARMV5).equalsIgnoreCase(platform)) {
       
   174             if (AnalyzeToolBuilder.isSBSBuildActivated(cpi)) {
       
   175                 for (int i = 0; i < Constants.atoolLibsSbs2.length; i++) {
       
   176                     java.io.File file = new java.io.File(epocroot
       
   177                             + Constants.atoolLibsSbs2[i]);
       
   178                     if (!file.exists()) {
       
   179                         found = false;
       
   180                         fileBuffer.append(epocroot);
       
   181                         fileBuffer.append(Constants.atoolLibsSbs2[i]);
       
   182                         fileBuffer.append(' ');
       
   183                     }
       
   184                 }
       
   185             } else {
       
   186                 for (int i = 0; i < Constants.atoolLibs.length; i++) {
       
   187                     java.io.File file = new java.io.File(epocroot
       
   188                             + Constants.atoolLibs[i]);
       
   189                     if (!file.exists()) {
       
   190                         found = false;
       
   191                         fileBuffer.append(epocroot);
       
   192                         fileBuffer.append(Constants.atoolLibs[i]);
       
   193                         fileBuffer.append(' ');
       
   194                     }
       
   195                 }
       
   196             }
       
   197         }
       
   198         if (!found) {
       
   199             createErrorMarker(cpi.getProject(), fileBuffer.toString());
       
   200         }
       
   201 
       
   202         return found;
       
   203     }
       
   204 
       
   205     /**
       
   206      * Copies stored memory leak analysis file to given folder.
       
   207      *
       
   208      * @param resultFile
       
   209      *            Existing results file
       
   210      * @param targetPath
       
   211      *            Where to save xml file
       
   212      * @return True if copy success otherwise False
       
   213      */
       
   214     public static boolean copyFileToFolder(final String resultFile,
       
   215             final String targetPath) {
       
   216         FileChannel inputChannel = null;
       
   217         FileChannel ouputChannel = null;
       
   218         FileInputStream inStream = null;
       
   219         FileOutputStream outStream = null;
       
   220         boolean returnValue = true;
       
   221         try {
       
   222 
       
   223             // get channel to existing file
       
   224             inStream = new FileInputStream(resultFile);
       
   225             inputChannel = inStream.getChannel();
       
   226 
       
   227             // get channel to new file
       
   228             outStream = new FileOutputStream(targetPath, false);
       
   229             ouputChannel = outStream.getChannel();
       
   230 
       
   231             // get existing file size
       
   232             final long size = inputChannel.size();
       
   233 
       
   234             // position inside the file
       
   235             long position = 0;
       
   236 
       
   237             // copy file contents if there are data to copy
       
   238             while (position < size) {
       
   239                 position += ouputChannel.transferFrom(inputChannel, position,
       
   240                         size - position);
       
   241             }
       
   242 
       
   243             // close opened channels
       
   244             inputChannel.close();
       
   245             inStream.close();
       
   246             ouputChannel.close();
       
   247             outStream.close();
       
   248         } catch (FileNotFoundException fnfe) {
       
   249             returnValue = false;
       
   250         } catch (IOException ioe) {
       
   251             returnValue = false;
       
   252         } finally {
       
   253             try {
       
   254                 if (inputChannel != null) {
       
   255                     inputChannel.close();
       
   256                     inputChannel = null;
       
   257                 }
       
   258             } catch (IOException ioe) {
       
   259                 returnValue = false;
       
   260             }
       
   261 
       
   262             try {
       
   263                 if (inStream != null) {
       
   264                     inStream.close();
       
   265                     inStream = null;
       
   266                 }
       
   267             } catch (IOException ioe) {
       
   268                 returnValue = false;
       
   269             }
       
   270 
       
   271             try {
       
   272                 if (ouputChannel != null) {
       
   273                     ouputChannel.close();
       
   274                     ouputChannel = null;
       
   275                 }
       
   276             } catch (IOException ioe) {
       
   277                 returnValue = false;
       
   278             }
       
   279 
       
   280             try {
       
   281                 if (outStream != null) {
       
   282                     outStream.close();
       
   283                     outStream = null;
       
   284                 }
       
   285             } catch (IOException ioe) {
       
   286                 returnValue = false;
       
   287             }
       
   288 
       
   289         }
       
   290 
       
   291         return returnValue;
       
   292     }
       
   293 
       
   294     /**
       
   295      * Creates AnalyzeTool related error marker for the selected project.
       
   296      *
       
   297      * @param project
       
   298      *            Project reference
       
   299      * @param errorText
       
   300      *            Error information
       
   301      */
       
   302     public static void createErrorMarker(final IProject project,
       
   303             final String errorText) {
       
   304         try {
       
   305             // check project validity
       
   306             if (project == null || !project.isOpen()) {
       
   307                 return;
       
   308             }
       
   309 
       
   310             // create marker for the project
       
   311             IMarker marker = project
       
   312                     .createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
       
   313             if (marker.exists()) {
       
   314                 // set marker attributes
       
   315                 marker.setAttribute(IMarker.SEVERITY, IMarker.PRIORITY_HIGH);
       
   316                 marker.setAttribute(IMarker.TEXT, errorText);
       
   317                 marker.setAttribute(IMarker.MESSAGE, errorText);
       
   318             }
       
   319         } catch (CoreException ce) {
       
   320             // #ifdef DEBUG
       
   321             ce.printStackTrace();
       
   322             // #endif
       
   323         }
       
   324     }
       
   325 
       
   326     /**
       
   327      * Deletes existing data file.
       
   328      *
       
   329      * @param project
       
   330      *            Project reference
       
   331      */
       
   332     public static void deleteDataFile(final IProject project) {
       
   333         String bldInfFolder = getBldInfFolder(project, false);
       
   334         String dataFileLocation = bldInfFolder + Constants.FILENAME;
       
   335         java.io.File tmpFile = new java.io.File(dataFileLocation);
       
   336         if (tmpFile.exists()) {
       
   337             tmpFile.delete();
       
   338         }
       
   339 
       
   340         String xmlFileLocation = bldInfFolder + Constants.FILENAME_CARBIDE;
       
   341         java.io.File tmpXMLFile = new java.io.File(xmlFileLocation);
       
   342         if (tmpXMLFile.exists()) {
       
   343             tmpXMLFile.delete();
       
   344         }
       
   345 
       
   346         tmpFile = null;
       
   347         tmpXMLFile = null;
       
   348     }
       
   349 
       
   350 
       
   351     /**
       
   352      * Open file save dialog.
       
   353      *
       
   354      * @param title
       
   355      *            Save dialog title
       
   356      * @param ext
       
   357      *            Used extension filters
       
   358      *
       
   359      * @param shell
       
   360      *            Used Shell reference
       
   361      *
       
   362      * @return User selected path
       
   363      */
       
   364     public static String fileSaveDialog(final String title, final String[] ext,
       
   365             final Shell shell) {
       
   366         FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
       
   367         fileDialog.setText(title);
       
   368         fileDialog.setFilterExtensions(ext);
       
   369         return fileDialog.open();
       
   370 
       
   371     }
       
   372 
       
   373     /**
       
   374      * Gets atool.exe installation folder which is specified on preferences
       
   375      * page.
       
   376      *
       
   377      * @return Atool.exe installation folder
       
   378      */
       
   379     public static String getAtoolInstallFolder() {
       
   380         // get preference store
       
   381         IPreferenceStore store = Activator.getPreferences();
       
   382 
       
   383         // create new string buffer
       
   384         StringBuffer atoolInstallFolder = new StringBuffer();
       
   385 
       
   386         boolean useInternal = store.getBoolean(Constants.USE_INTERNAL);
       
   387 
       
   388         // append atool.exe installation folder
       
   389         String folder = store.getString(Constants.ATOOL_FOLDER);
       
   390         if (useInternal) {
       
   391             atoolInstallFolder.append(getDefaultAtoolLocation());
       
   392         } else if (("").equals(folder)) {
       
   393             store.setValue(Constants.USE_INTERNAL, true);
       
   394             atoolInstallFolder.append(getDefaultAtoolLocation());
       
   395         } else if (folder.equals(Constants.DEFAULT_ATOOL_FOLDER)) {
       
   396             java.io.File file = new java.io.File(Constants.DEFAULT_ATOOL_FOLDER);
       
   397             if (file.exists()) {
       
   398                 atoolInstallFolder.append(Constants.DEFAULT_ATOOL_FOLDER);
       
   399             } else {
       
   400                 store.setValue(Constants.USE_INTERNAL, true);
       
   401                 atoolInstallFolder.append(getDefaultAtoolLocation());
       
   402             }
       
   403         } else {
       
   404             atoolInstallFolder.append(folder);
       
   405         }
       
   406         // append atool.exe to installation path
       
   407         atoolInstallFolder.append("\\atool.exe");
       
   408         return atoolInstallFolder.toString();
       
   409     }
       
   410 
       
   411     /**
       
   412      * Returns atool.exe version number Executes atool.exe via Process class and
       
   413      * parses atool.exe output to get version number.
       
   414      *
       
   415      * @param path
       
   416      *            Atool.exe path
       
   417      * @return Atool.exe version number if found otherwise "Not available"
       
   418      */
       
   419     public static String getAtoolVersionNumber(final String path) {
       
   420 
       
   421         BufferedInputStream br = null;
       
   422 
       
   423         try {
       
   424             // used atool.exe location
       
   425             String usedPath = null;
       
   426 
       
   427             // if path not given => use default location
       
   428             if (path == null) {
       
   429                 usedPath = getDefaultAtoolLocation() + "\\atool.exe";
       
   430             }
       
   431             else if( path.contains("atool.exe") ){
       
   432                 usedPath = path;
       
   433             }
       
   434             // else use given location
       
   435             else {
       
   436                 usedPath = path + "\\atool.exe";
       
   437             }
       
   438 
       
   439             // command
       
   440             String[] args = { "cmd", "/c", usedPath, "-v" };
       
   441 
       
   442             // execute command
       
   443             Process pr = Runtime.getRuntime().exec(args);
       
   444 
       
   445             // get atool.exe response to buffer
       
   446             br = new BufferedInputStream(pr
       
   447                     .getInputStream());
       
   448 
       
   449             // wait that all the input is captured
       
   450             pr.waitFor();
       
   451 
       
   452             // create new stringbuffer for the input
       
   453             StringBuffer bf = new StringBuffer("");
       
   454             int r = -1;
       
   455 
       
   456             // read atool.exe response to stringbufffer
       
   457             while ((r = br.read()) != -1) {
       
   458                 bf.append((char) r);
       
   459             }
       
   460 
       
   461             // because atool.exe response is following format
       
   462             // Version: [version number]
       
   463             // Path: [location]
       
   464             // Modified: [date and time]
       
   465             // we only need to get first row of response
       
   466             String[] array = bf.toString().split("\r\n");
       
   467 
       
   468             // check array
       
   469             if (array != null && array.length > 0) {
       
   470 
       
   471                 String version = "Version:";
       
   472 
       
   473                 // get first array
       
   474                 String versionStr = array[0];
       
   475 
       
   476                 // if first row contains "version:"
       
   477                 if (versionStr.contains(version)) {
       
   478 
       
   479                     // get atool.exe version number
       
   480                     String atoolVersionNbr = versionStr.substring(version
       
   481                             .length() + 1, versionStr.length());
       
   482 
       
   483                     if( atoolVersionNbr == null || ("").equals(atoolVersionNbr ) ) {
       
   484                         return Constants.PREFS_ATOOL_VER_NOT_FOUND;
       
   485                     }
       
   486 
       
   487                     return atoolVersionNbr;
       
   488                 }
       
   489             }
       
   490             br.close();
       
   491         } catch (Exception e) {
       
   492             e.printStackTrace();
       
   493         } finally {
       
   494             try {
       
   495                 if( br != null ) {
       
   496                     br.close();
       
   497                     br = null;
       
   498                 }
       
   499             }catch( IOException ioe ) {
       
   500                 ioe.printStackTrace();
       
   501             }
       
   502 
       
   503         }
       
   504         return Constants.PREFS_ATOOL_VER_NOT_FOUND;
       
   505     }
       
   506 
       
   507     /**
       
   508      * Returns the version number of the AnalyzeTool host-side feature, or "Unknown" if it cannot be determined
       
   509      * @return feature version string
       
   510      */
       
   511     public static String getAToolFeatureVersionNumber(){
       
   512     	String version = Constants.UNKNOWN;
       
   513     	IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
       
   514 		if (providers != null) {
       
   515 			for (IBundleGroupProvider bundleGroupProvider : providers) {
       
   516 				for (IBundleGroup feature : bundleGroupProvider.getBundleGroups()) {
       
   517 					if (feature.getIdentifier().equals("com.nokia.carbide.extensions.analyzetool")){
       
   518 						version = feature.getVersion();
       
   519 						break;
       
   520 					}
       
   521 				}
       
   522 			}
       
   523 		}
       
   524     	return version;
       
   525     }
       
   526 
       
   527     /**
       
   528      * Gets project bld.inf folder path.
       
   529      *
       
   530      * @param project
       
   531      *            Project reference
       
   532      * @param createTempFolder
       
   533      *            Flag to create atool_temp folder
       
   534      * @return Project bld.inf folder path
       
   535      */
       
   536     public static String getBldInfFolder(final IProject project,
       
   537             final boolean createTempFolder) {
       
   538         // get bld.inf directory
       
   539         ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager()
       
   540                 .getProjectInfo(project);
       
   541         if (cpi == null) {
       
   542             return "";
       
   543         }
       
   544 
       
   545         String infDir = cpi.getINFWorkingDirectory().toOSString();
       
   546 
       
   547         // create atool_temp folder if it does not exists
       
   548         if (createTempFolder) {
       
   549             UseAtool.createAToolFolderIfNeeded(infDir);
       
   550         }
       
   551 
       
   552         return infDir + "\\atool_temp\\";
       
   553     }
       
   554 
       
   555     /**
       
   556      * Gets cpp file name and path.
       
   557      *
       
   558      * @param resource
       
   559      *            One resource file
       
   560      * @return MMP file name and path if resource is mmp file, otherwise null
       
   561      */
       
   562     public static String getCPPFileNameAndPath(final IResource resource) {
       
   563         // get file extension
       
   564         String fileExt = resource.getFileExtension();
       
   565         String cppFileAndPath = null;
       
   566 
       
   567         // if file contains extension and it equals to mmp
       
   568         if (fileExt != null && fileExt.compareTo("cpp") == 0) {
       
   569             // get resource location/path
       
   570             String resourcePath = resource.getLocation().toString();
       
   571 
       
   572             // if resource path does not contain atool_temp folder
       
   573             // save resource location
       
   574             if (resourcePath.indexOf(Constants.ATOOL_TEMP) == -1) {
       
   575                 cppFileAndPath = resource.getProjectRelativePath().toString();
       
   576             }
       
   577 
       
   578         }
       
   579 
       
   580         // return cpp file name and path
       
   581         return cppFileAndPath;
       
   582     }
       
   583 
       
   584     /**
       
   585      * Returns atool.exe location inside the plugin.
       
   586      *
       
   587      * @return Atool.exe location folder could be found otherwise ""
       
   588      */
       
   589     public static String getDefaultAtoolLocation() {
       
   590         try {
       
   591             // AnalyzeTool bundle
       
   592             Bundle bunble = Platform
       
   593                     .getBundle("com.nokia.s60tools.analyzetool.corecomponents"); //$NON-NLS-1$
       
   594 
       
   595             // if bundle not found return empty path
       
   596             if( bunble == null ) {
       
   597                 return "";
       
   598             }
       
   599             // get bundle URL
       
   600             URL bundleURL = bunble.getEntry("/");
       
   601 
       
   602             // get file URL
       
   603             URL fileURL = FileLocator.toFileURL(bundleURL);
       
   604 
       
   605             // create new file
       
   606             File file = new File(fileURL.getPath());
       
   607 
       
   608             // if file exists return file path + atool.exe folder name
       
   609             if (file.exists()) {
       
   610                 return file.getAbsolutePath();
       
   611             }
       
   612             return "";
       
   613 
       
   614         } catch (Exception e) {
       
   615             e.printStackTrace();
       
   616             return "";
       
   617         }
       
   618     }
       
   619 
       
   620     /**
       
   621      * Gets last slash index for current string.
       
   622      *
       
   623      * @param line
       
   624      *            Line where to find slash index
       
   625      * @return Integer value of slash index
       
   626      */
       
   627     public static int getLastSlashIndex(final String line) {
       
   628         // get last slash index
       
   629         char slash = '/';
       
   630         int slashIndex = line.lastIndexOf(slash);
       
   631         if (slashIndex == -1) {
       
   632             char backSlash = '\\';
       
   633             slashIndex = line.lastIndexOf(backSlash);
       
   634         }
       
   635 
       
   636         return slashIndex;
       
   637     }
       
   638 
       
   639      /**
       
   640      * Check is atool.exe available.
       
   641      *
       
   642      * @return True if atool.exe found otherwise False
       
   643      */
       
   644     public static boolean isAtoolAvailable() {
       
   645         IPreferenceStore store = Activator.getPreferences();
       
   646         String folderLocation = store.getString(Constants.ATOOL_FOLDER);
       
   647 
       
   648         if (folderLocation.length() > 0) {
       
   649             if (!folderLocation.endsWith("\\")) {
       
   650                 folderLocation += "\\";
       
   651             }
       
   652 
       
   653             IPath atoolPath = new Path(folderLocation + "atool.exe");
       
   654 
       
   655             // if folder does not exists
       
   656             if (atoolPath.toFile().exists()) {
       
   657                 return true;
       
   658             }
       
   659         }
       
   660 
       
   661         return false;
       
   662     }
       
   663 
       
   664     /**
       
   665      * Checks is data file available.
       
   666      *
       
   667      * @param project
       
   668      *            Project reference
       
   669      * @return Data file path if it's available otherwise null
       
   670      */
       
   671     public static String isDataFileAvailable(final IProject project) {
       
   672         String bldInfFolder = getBldInfFolder(project, false);
       
   673         String dataFileLocation = bldInfFolder + Constants.FILENAME;
       
   674         java.io.File dataFile = new java.io.File(dataFileLocation);
       
   675         if (dataFile.exists() && dataFile.length() > 0 ) {
       
   676             return dataFileLocation;
       
   677         }
       
   678         return null;
       
   679     }
       
   680 
       
   681     /**
       
   682      * Checks is file extension .xml.
       
   683      *
       
   684      * @param filePath
       
   685      *            File location
       
   686      * @return True if file contains xml extension otherwise false
       
   687      */
       
   688     public static boolean isFileXML(final String filePath) {
       
   689         String fileNameAndExt = null;
       
   690         // get index of last backslash
       
   691         int index = Util.getLastSlashIndex(filePath);
       
   692 
       
   693         // if backslash found
       
   694         if (index != -1) {
       
   695 
       
   696             // get file name
       
   697             fileNameAndExt = filePath.substring(index + 1, filePath.length());
       
   698 
       
   699             // if file name contains xml extension
       
   700             if (fileNameAndExt.contains(".xml")) {
       
   701                 return true;
       
   702             }
       
   703         }
       
   704         return false;
       
   705 
       
   706     }
       
   707 
       
   708     /**
       
   709      * Check if current module is build.
       
   710      *
       
   711      * @param mmpFile
       
   712      *            MMP file name and path
       
   713      * @return True if module is build otherwise False
       
   714      */
       
   715     public static boolean isModuleBuild(final String mmpFile) {
       
   716         String path = null;
       
   717         // remove mmp file name for path
       
   718         int slash = Util.getLastSlashIndex(mmpFile);
       
   719         if (slash == -1) {
       
   720             return false;
       
   721         }
       
   722         path = mmpFile.substring(0, slash);
       
   723         String buildFile = path + "\\atool_temp\\BuildComplete";
       
   724         java.io.File file = new java.io.File(buildFile);
       
   725         return file.exists();
       
   726     }
       
   727 
       
   728     /**
       
   729      * Checks that belongs given module to selected project.
       
   730      *
       
   731      * @param modules
       
   732      *            Project modules
       
   733      * @param oneModuleName
       
   734      *            One module name
       
   735      * @return True if module belongs to selected project otherwise false
       
   736      */
       
   737     public static boolean isModulePartOfProject(
       
   738             final AbstractList<MMPInfo> modules, final String oneModuleName) {
       
   739         Iterator<MMPInfo> iterModules = modules.iterator();
       
   740         while (iterModules.hasNext()) {
       
   741             MMPInfo oneMMPInfo = iterModules.next();
       
   742             String target = oneMMPInfo.getTarget();
       
   743             if (target == null) {
       
   744                 continue;
       
   745             } else if (oneMMPInfo.getTarget().equalsIgnoreCase(oneModuleName)) {
       
   746                 return true;
       
   747             }
       
   748 
       
   749             // target not found try remove {}
       
   750             // for example process name is
       
   751             // "AToolMemoryLeakerDll2.dll{000a0000}[04463b81]"
       
   752             // but target name is AToolMemoryLeakerDll2.dll
       
   753             CharSequence brace = "{";
       
   754             if (oneModuleName.contains(brace)) {
       
   755                 // parse braces
       
   756                 String tmpTargetName = oneModuleName.substring(0, oneModuleName
       
   757                         .indexOf('{'));
       
   758                 if (tmpTargetName != null
       
   759                         && oneMMPInfo.getTarget().equalsIgnoreCase(
       
   760                                 tmpTargetName)) {
       
   761                     return true;
       
   762                 }
       
   763             }
       
   764         }
       
   765         return false;
       
   766     }
       
   767 
       
   768     /**
       
   769      * Gets current project targets info.
       
   770      *
       
   771      * @param project
       
   772      *            Project reference
       
   773      *
       
   774      * @return AbstractList<MMPInfo> List of project targets
       
   775      */
       
   776     public static AbstractList<MMPInfo> loadProjectTargetsInfo(
       
   777             final IProject project) {
       
   778         AbstractList<MMPInfo> targets = new ArrayList<MMPInfo>();
       
   779         if (project == null || !project.isOpen()) {
       
   780             return targets;
       
   781         }
       
   782 
       
   783         // Assumes buildConfig (ICarbideBuildConfiguration) is known
       
   784         ICarbideProjectInfo cpi = CarbideBuilderPlugin.getBuildManager()
       
   785                 .getProjectInfo(project);
       
   786         if (cpi == null) {
       
   787             return new ArrayList<MMPInfo>();
       
   788         }
       
   789 
       
   790         ICarbideBuildConfiguration buildConfig = cpi.getDefaultConfiguration();
       
   791 
       
   792         for (IPath mmpPath : EpocEngineHelper
       
   793                 .getMMPFilesForBuildConfiguration(buildConfig)) {
       
   794             Object data = EpocEnginePlugin.runWithMMPData(mmpPath,
       
   795                     new DefaultMMPViewConfiguration(buildConfig
       
   796                             .getCarbideProject().getProject(), buildConfig,
       
   797                             new AcceptedNodesViewFilter()),
       
   798                     new MMPDataRunnableAdapter() {
       
   799                         public Object run(IMMPData mmpData) {
       
   800                             // The real return value, getting a single argument
       
   801                             // setting
       
   802                             return mmpData.getSingleArgumentSettings().get(
       
   803                                     EMMPStatement.TARGET);
       
   804 
       
   805                         }
       
   806                     });
       
   807 
       
   808             // Make sure to test for and cast to proper Object type!
       
   809             int index = Util.getLastSlashIndex(mmpPath.toOSString());
       
   810             String mmpFileName = "";
       
   811             if (index != -1) {
       
   812                 mmpFileName = mmpPath.toOSString().substring(index + 1,
       
   813                         mmpPath.toOSString().length());
       
   814             }
       
   815             MMPInfo oneMMPInfo = new MMPInfo(mmpFileName);
       
   816             oneMMPInfo.setLocation(mmpPath.toOSString());
       
   817 
       
   818             String mmpStatement = (String) data; // Now we should have the
       
   819             // TARGETTYPE
       
   820             oneMMPInfo.setTarget(mmpStatement);
       
   821             targets.add(oneMMPInfo);
       
   822         }
       
   823         return targets;
       
   824     }
       
   825 
       
   826     /**
       
   827      * Opens confirmation Dialog.
       
   828      *
       
   829      * @param text
       
   830      *            Dialog info text
       
   831      * @return boolean True if user selects "Yes" False if user selects "No"
       
   832      */
       
   833     public static boolean openConfirmationDialog(final String text) {
       
   834 
       
   835         Activator.getDefault().getWorkbench().getDisplay().syncExec(
       
   836                 new Runnable() {
       
   837                     public void run() {
       
   838                         ret = MessageDialog.openQuestion(new Shell(),
       
   839                                 Constants.ANALYZE_TOOL_TITLE, text);
       
   840                     }
       
   841                 });
       
   842         return ret;
       
   843     }
       
   844 
       
   845     /**
       
   846      * Opens confirmation Dialog.
       
   847      *
       
   848      * @param text
       
   849      *            Dialog info text
       
   850      * @return int User selected index
       
   851      */
       
   852     public static int openConfirmationDialogWithCancel(final String text) {
       
   853 
       
   854         Activator.getDefault().getWorkbench().getDisplay().syncExec(
       
   855                 new Runnable() {
       
   856                     public void run() {
       
   857 
       
   858                         String[] labels = new String[3];
       
   859                         labels[0] = "Yes";
       
   860                         labels[1] = "No";
       
   861                         labels[2] = "Cancel";
       
   862                         MessageDialog mDialog = new MessageDialog(new Shell(),
       
   863                                 Constants.ANALYZE_TOOL_TITLE, null, text, 0,
       
   864                                 labels, 0);
       
   865                         mDialog.open();
       
   866                         mDialog.create();
       
   867                         retValue = mDialog.getReturnCode();
       
   868                     }
       
   869                 });
       
   870         return retValue;
       
   871     }
       
   872 
       
   873     /**
       
   874      * Opens console view.
       
   875      */
       
   876     public static void openConsoleView() {
       
   877         // sync with UI thread
       
   878         PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable(){
       
   879             public void run() {
       
   880 
       
   881                 try {
       
   882                     // get active workspace page
       
   883                     IWorkbenchPage page = Activator.getDefault().getWorkbench()
       
   884                             .getActiveWorkbenchWindow().getActivePage();
       
   885 
       
   886 
       
   887                     // display main view
       
   888                     if (page != null) {
       
   889                         IWorkbenchPart part = page.getActivePart();
       
   890 
       
   891 
       
   892                         String activePageID = part.getSite().getId();
       
   893 
       
   894                         if( activePageID.equals(Constants.ANALYZE_TOOL_VIEW_ID) || part instanceof org.eclipse.ui.navigator.CommonNavigator) {
       
   895                             page
       
   896                             .showView(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW);
       
   897                         }
       
   898 
       
   899                     }
       
   900 
       
   901                 } catch (Exception e) {
       
   902                     e.printStackTrace();
       
   903                 }
       
   904             }
       
   905         });
       
   906     }
       
   907 
       
   908     /**
       
   909      * Opens selection dialog.
       
   910      *
       
   911      * @param shell
       
   912      *            Shell reference
       
   913      * @param title
       
   914      *            Dialog title
       
   915      * @param defaultLocation
       
   916      *            Dialog default location
       
   917      * @return User selection
       
   918      */
       
   919     public static String openFileDialog(final Shell shell, final String title,
       
   920             final String defaultLocation) {
       
   921         FileDialog fileDialog = new FileDialog(shell);
       
   922         fileDialog.setText(title);
       
   923         // set the file extension filter
       
   924         String[] filterExt = { "*.*", "*.dat", "*.xml" };
       
   925         fileDialog.setFilterExtensions(filterExt);
       
   926 
       
   927         // fileDialog.setFilterPath( defaultLocation );
       
   928         return fileDialog.open();
       
   929     }
       
   930 
       
   931     /**
       
   932      * Opens selection dialog.
       
   933      *
       
   934      * @param title
       
   935      *            Dialog title
       
   936      * @param message
       
   937      *            Dialog message text
       
   938      * @param input
       
   939      *            Dialog input
       
   940      * @return Selected item
       
   941      */
       
   942     public static String openSelectionDialog(final String title,
       
   943             final String message, final AbstractList<String> input) {
       
   944         Activator.getDefault().getWorkbench().getDisplay().syncExec(
       
   945                 new Runnable() {
       
   946                     public void run() {
       
   947                         userSelection = "";
       
   948 
       
   949                         ListDialog ld = new ListDialog(new Shell());
       
   950                         ld.setAddCancelButton(true);
       
   951                         ld.setContentProvider(new ArrayContentProvider());
       
   952                         ld.setLabelProvider(new LabelProvider());
       
   953 
       
   954                         int width = 0;
       
   955                         // calculate dialog width
       
   956                         for (int i = 0; i < input.size(); i++) {
       
   957                             String tempStr = input.get(i);
       
   958 
       
   959                             if (tempStr.length() > width) {
       
   960                                 width = tempStr.length();
       
   961                             }
       
   962                         }
       
   963 
       
   964                         // set dialog width
       
   965                         // ld.setWidthInChars( width + 2 );
       
   966                         ld.setInput(input);
       
   967                         ld.setTitle(title);
       
   968                         if (message != null) {
       
   969                             ld.setMessage(message);
       
   970                         }
       
   971 
       
   972                         ld.setHelpAvailable(false);
       
   973                         ld.open();
       
   974 
       
   975                         Object[] objs = ld.getResult();
       
   976                         if (objs != null) {
       
   977                             userSelection = objs[0].toString();
       
   978                         }
       
   979 
       
   980                     }
       
   981                 });
       
   982         return userSelection;
       
   983     }
       
   984 
       
   985     /**
       
   986      * Displays error message.
       
   987      *
       
   988      * @param message
       
   989      *            Error note content
       
   990      */
       
   991     public static void showErrorMessage(final String message) {
       
   992     	
       
   993     	PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable() {
       
   994 			public void run() {
       
   995 				MessageDialog
       
   996                 .openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Constants.DIALOG_TITLE, message);		
       
   997 			}
       
   998 		});
       
   999         
       
  1000     }
       
  1001 
       
  1002     /**
       
  1003      * Displays information note.
       
  1004      *
       
  1005      * @param message
       
  1006      *            Information note content
       
  1007      */
       
  1008     public static void showMessage(final String message) {
       
  1009 
       
  1010         //sync with the UI thread
       
  1011         PlatformUI.getWorkbench().getDisplay().syncExec( new Runnable() {
       
  1012             public void run() {
       
  1013 
       
  1014                 MessageDialog
       
  1015                 .openInformation(Activator.getDefault().getWorkbench()
       
  1016                         .getDisplay().getActiveShell(), Constants.DIALOG_TITLE,
       
  1017                         message);
       
  1018             }
       
  1019         });
       
  1020 
       
  1021     }
       
  1022 
       
  1023     /**
       
  1024      * Check is atool.exe verbose output checked.
       
  1025      *
       
  1026      * @return True verbose output is checked otherwise False
       
  1027      */
       
  1028     public static boolean verboseAtoolOutput() {
       
  1029         IPreferenceStore store = Activator.getPreferences();
       
  1030         return store.getBoolean(Constants.ATOOL_VERBOSE);
       
  1031     }
       
  1032 
       
  1033     /**
       
  1034      * Creates progress dialog and clears atool.exe made changes.
       
  1035      *
       
  1036      * @param newProject
       
  1037      *            Project reference
       
  1038      */
       
  1039     public final void clearAtoolChanges(final IProject newProject) {
       
  1040 
       
  1041         // project reference
       
  1042         final IProject project = newProject;
       
  1043 
       
  1044         Job cleanJob = new Job(Constants.PROGRESSDIALOG_CLEAR_CHANGES) {
       
  1045             @Override
       
  1046             protected IStatus run(IProgressMonitor monitor) {
       
  1047 
       
  1048                 // update progress monitor state
       
  1049                 monitor.beginTask(Constants.PROGRESSDIALOG_CLEAR_CHANGES, IProgressMonitor.UNKNOWN);
       
  1050 
       
  1051                 // get project info
       
  1052                 ICarbideProjectInfo cpi = CarbideBuilderPlugin
       
  1053                         .getBuildManager().getProjectInfo(project);
       
  1054                 if (cpi == null) {
       
  1055                     return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID,
       
  1056                             IStatus.OK,
       
  1057                             Constants.PROGRESSDIALOG_CLEAN_COMPLETE, null);
       
  1058                 }
       
  1059 
       
  1060                 // new command launcher
       
  1061                 CarbideCommandLauncher cmdLauncher = new CarbideCommandLauncher(
       
  1062                         project, monitor, Constants.atoolParserIds, cpi
       
  1063                                 .getINFWorkingDirectory());
       
  1064                 cmdLauncher.startTimingStats();
       
  1065 
       
  1066                 cmdLauncher.showCommand(true);
       
  1067 
       
  1068                 cmdLauncher.writeToConsole(cmdLauncher.getTimingStats());
       
  1069 
       
  1070                 AbstractList<String> usedArguments = new ArrayList<String>();
       
  1071                 usedArguments.add("-c");
       
  1072                 if (Util.verboseAtoolOutput()) {
       
  1073                     usedArguments.add(Constants.ATOOL_SHOW_DEBUG);
       
  1074                 }
       
  1075 
       
  1076                 String[] arguments = new String[usedArguments.size()];
       
  1077                 usedArguments.toArray(arguments);
       
  1078                 int error = Constants.COMMAND_LINE_ERROR_CODE.OK.getCode();
       
  1079                 error = cmdLauncher.executeCommand(new Path(Util
       
  1080                         .getAtoolInstallFolder()), arguments,
       
  1081                         CarbideCPPBuilder.getResolvedEnvVars(cpi
       
  1082                                 .getDefaultConfiguration()), cpi
       
  1083                                 .getINFWorkingDirectory());
       
  1084 
       
  1085                 // if command line engine returns some error code => display the error
       
  1086                 if( error != Constants.COMMAND_LINE_ERROR_CODE.OK.getCode() ) {
       
  1087                 	Constants.COMMAND_LINE_ERROR_CODE errorCode = Util.getErrorCode(error);
       
  1088                 	Util.displayCommandLineError(errorCode);
       
  1089                 }
       
  1090 
       
  1091                 return new Status(IStatus.OK, Constants.ANALYZE_CONSOLE_ID,
       
  1092                         IStatus.OK, Constants.PROGRESSDIALOG_CLEAN_COMPLETE,
       
  1093                         null);
       
  1094             }
       
  1095         };
       
  1096         cleanJob.setUser(true);
       
  1097         cleanJob.schedule();
       
  1098     }
       
  1099 
       
  1100 
       
  1101     /**
       
  1102      * Compares two atool.exe version numbers and returns
       
  1103      * higher one.
       
  1104      * @param firstVersion First version number
       
  1105      * @param secondVersion Second version number
       
  1106      * @return 0 if the first one is higher, 1 if the second one is higher otherwise -1
       
  1107      */
       
  1108     public static int compareVersionNumber(String firstVersion, String secondVersion)
       
  1109     {
       
  1110 
       
  1111         // split version numbers
       
  1112         String first[] = firstVersion.split("[.]");
       
  1113         String second[] = secondVersion.split("[.]");
       
  1114 
       
  1115         // check that version numbers contains valid formatting
       
  1116         if( first == null || second == null || first.length <1 || second.length < 1 || (first.length != second.length) ) {
       
  1117             return Constants.VERSION_NUMBERS_INVALID;
       
  1118         }
       
  1119         // if version number equals => no need to check which one is higher
       
  1120         if( firstVersion.equalsIgnoreCase(secondVersion) )
       
  1121         {
       
  1122             return Constants.VERSION_NUMBERS_EQUALS;
       
  1123         }
       
  1124         // thru splitted version number
       
  1125         for( int i=0; i<first.length; i++ ) {
       
  1126         	try{
       
  1127         		int firstNumber = Integer.parseInt( first[i] );
       
  1128                 int secondNumber = Integer.parseInt( second[i] );
       
  1129 
       
  1130                 // if first and second given number equals => skip to next number
       
  1131                 if( firstNumber == secondNumber ) {
       
  1132                     continue;
       
  1133                 }
       
  1134                 else if( firstNumber > secondNumber ) {
       
  1135                     return Constants.VERSION_NUMBERS_FIRST;
       
  1136                 }
       
  1137                 else {
       
  1138                     return Constants.VERSION_NUMBERS_SECOND;
       
  1139                 }
       
  1140 
       
  1141         	}catch(NumberFormatException nfe) {
       
  1142         		nfe.printStackTrace();
       
  1143         		return Constants.VERSION_NUMBERS_INVALID;
       
  1144         	}
       
  1145         }
       
  1146         return Constants.VERSION_NUMBERS_INVALID;
       
  1147     }
       
  1148 
       
  1149  
       
  1150     /**
       
  1151      * Displays corresponding error message.
       
  1152      * @param errorCode Error code
       
  1153      */
       
  1154     public static final void displayCommandLineError( Constants.COMMAND_LINE_ERROR_CODE errorCode ) {
       
  1155     	switch(errorCode) {
       
  1156     		case EXECUTE_ERROR:
       
  1157     			Util.showErrorMessage(Constants.ERROR_ATOOL_NOT_AVAILABLE);
       
  1158     			break;
       
  1159 	    	case OK:
       
  1160 	    		// everything is OK, no need to do anything
       
  1161 	    		break;
       
  1162 	    		
       
  1163 	    	case INVALID_ARGUMENT_ERROR:
       
  1164 	    		Util.showErrorMessage("AnalyzeTool tried to execute command line engine with invalid parameters. \n\nTo avoid this go to AnalyzeTool preference page and select \"Use internal " +
       
  1165 	    				"command line engine\".");
       
  1166 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Extension tried to execute command line engine with invalid parameters.");
       
  1167 	    		break;
       
  1168 	    		
       
  1169 	       	case CANNOT_FIND_EPOCROOT:
       
  1170 	       		Util.showErrorMessage("AnalyzeTool can not find epocroot. \nCheck SDK preferences and build project again.");
       
  1171 	       		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Can not find epocroot.");
       
  1172 	    		break;
       
  1173 	    		
       
  1174 	    	case MAKEFILE_ERROR:
       
  1175 	    		Util.showErrorMessage("AnalyzeTool command line engine fails to create makefiles.\n\nTry to clean AnalyzeTool changes and build project again." +
       
  1176 	    				"\nIf problem still occurs contact AnalyzeTool development team.");
       
  1177 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Make file error.");
       
  1178 	    		break;
       
  1179 	    		
       
  1180 	      	case NO_SUPPORTED_MODULES_ERROR:
       
  1181 	      		Util.showErrorMessage("Project contains unsupported modules, this project could not build with AnalyzeTool!");
       
  1182 	      		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - No supported modules error.");
       
  1183 	    		break;
       
  1184 	    		
       
  1185 	    	case WRONG_DATA_FILE_VERSION:
       
  1186 	    		Util.showErrorMessage("Selected data file contains invalid version number. \nThis usually means that data file " +
       
  1187 	    				"format is changed and AnalyzeTool command line engine can not resolve that. \n\nTry run tests again with the newest version of AnalyzeTool.");
       
  1188 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Wrong data file version.");
       
  1189 	    		break;
       
  1190 	    	
       
  1191 	    	case ANALYZE_ERROR:
       
  1192 	    		Util.showErrorMessage("AnalyzeTool can not analyze the selected data file.\nThis problem usually occurs when selected file contains corrupted AnalyzeTool data. \nTry to run " +
       
  1193 	    				"tests again with the newest version of AnalyzeTool.");
       
  1194 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - General Analyze Error.");
       
  1195 	    		break;
       
  1196 	    		
       
  1197 	    	case SYMBOL_FILE_ERROR:
       
  1198 	    		Util.showErrorMessage("AnalyzeTool can not resolve selected symbol file(s). \n\nGo to AnalyzeTool advanced preference page and check selected symbol file(s).");
       
  1199 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Symbol file error.");
       
  1200 	    		break;
       
  1201 	    		
       
  1202 	    	case DATA_FILE_EMPTY:
       
  1203 	    		Util.showErrorMessage("Can not analyze. \n\nSelected file is empty.");
       
  1204 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Selected file is empty.");
       
  1205 	    		break;
       
  1206 	    		
       
  1207 	    	case DATA_FILE_INVALID:
       
  1208 	    		Util.showErrorMessage("Can not analyze. \n\nSelected data file does not contain AnalyzeTool data.");
       
  1209 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Invalid data file.");
       
  1210 	    		break;
       
  1211 	    		
       
  1212 	    	case RELEASABLES_ERROR:
       
  1213 	    		Util.showErrorMessage("AnalyzeTool can not copy needed files, therefore callstack can not be displayed when analyzing data." +
       
  1214 	    				"\n\nTry to clean AnalyzeTool made changes and build project again.");
       
  1215 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Releasebles error.");
       
  1216 	    		break;
       
  1217 	    		
       
  1218 	    	case RESTORE_MODULES_ERROR:
       
  1219 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Restore module error.");
       
  1220 	    		break;
       
  1221 
       
  1222 	    	case CREATING_TEMP_CPP_ERROR:
       
  1223 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Creating temp cpp file error.");
       
  1224 	    		break;
       
  1225 
       
  1226 	    	case CLEANING_TEMP_ERROR:
       
  1227 	    		Util.showErrorMessage("AnalyzeTool failed to clean project. You may have to clean changes manually.");
       
  1228 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Clean error.");
       
  1229 	    		break;
       
  1230 
       
  1231 	    	case READ_MAKEFILE_ERROR:
       
  1232 	    		Util.showErrorMessage("AnalyzeTool command line engine can not read project make files. \n\nTry to clean AnalyzeTool" +
       
  1233 	    				" made changes and build project again.");
       
  1234 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Read make file error.");
       
  1235 	    		break;
       
  1236 
       
  1237 	    	case MODIFY_MODULES_ERROR:
       
  1238 	    		Util.showErrorMessage("AnalyzeTool command line engine can not modify project modules.");
       
  1239 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Modify modules error.");
       
  1240 	    		break;
       
  1241 
       
  1242 	    	 case INVALID_MMP_DEFINED:
       
  1243 	    		 // I think this case is not possible in extension side.
       
  1244 	    		 // because we ask mmp files from Carbide
       
  1245 	    		 // however if this case happens we just log it Carbide error log
       
  1246 	    	 	Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - Invalid mmp file.");
       
  1247 	    		break;
       
  1248 
       
  1249 	    	case UNKNOWN_ERROR:
       
  1250 	    		Util.showErrorMessage("Unable to execute action for current project.");
       
  1251 	    		Activator.getDefault().logInfo(IStatus.ERROR, IStatus.ERROR, "AnalyzeTool - unknown error.");
       
  1252 	    		break;
       
  1253 
       
  1254     	}
       
  1255     }
       
  1256 
       
  1257     /**
       
  1258      * Finds correct Enum value for integer value.
       
  1259      *
       
  1260      * @param value Value to find from enum values
       
  1261      * @return Enum value if found otherwise COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR
       
  1262      */
       
  1263     public static COMMAND_LINE_ERROR_CODE getErrorCode(final int value) {
       
  1264 		 for( COMMAND_LINE_ERROR_CODE errorCode : COMMAND_LINE_ERROR_CODE.values() ) {
       
  1265 			 if( errorCode.getCode() == value ) {
       
  1266 				 return errorCode;
       
  1267 			 }
       
  1268 		 }
       
  1269 		 return COMMAND_LINE_ERROR_CODE.UNKNOWN_ERROR;
       
  1270 	 }
       
  1271 }