true
job is set as user level job that prompts dialog.
+ */
+ public ShowMethodCallLocationsJob(String jobName, String mainTaskMessage, String componentName, String methodName, boolean isUserJob) {
+ super(jobName);
+ this.mainTaskMessage = mainTaskMessage;
+ this.componentName = componentName;
+ this.methodName = methodName;
+ setUser(isUserJob);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IStatus run(IProgressMonitor monitor) {
+
+ progressMonitor = monitor;
+ IStatus status;
+
+ try {
+
+ progressMonitor.beginTask(mainTaskMessage, 100);
+
+ AppDepSettings settings = AppDepSettings.getActiveSettings();
+
+ SdkInformation sdkInfo = settings.getCurrentlyUsedSdk();
+ String epocRootPath = sdkInfo.getEpocRootDir();
+
+ progressMonitor.subTask(Messages.getString("ShowMethodCallLocationsJob.SearchingFiles_SubTask_Msg") +"\n" +componentName +"'..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ filesBelongsToComponent = getUsedComponentSourceFiles(settings, componentName, epocRootPath);
+ //Limit number of files simple founding part of the method name, to decrease project files
+ setSearchString(methodName);
+
+ checkIfCancelled();
+ progressMonitor.subTask(Messages.getString("ShowMethodCallLocationsJob.SearchingBldInf_SubTask_Msg")); //$NON-NLS-1$
+ progressMonitor.worked(CREATING_PROJECT_STEPS);
+
+ //Finds and sets source files as IFile to variables
+ String bldFile = getBldInfFileName(filesBelongsToComponent);
+
+ //If the project already exist, just executing the search
+ if(isProjectAllreadyExistingAndOpenIfClosed(bldFile, progressMonitor)){
+
+ progressMonitor.worked(SEARCH_AND_INDEX_STEPS);
+ checkIfCancelled();
+ executeSearch(searchString);
+ status = Status.OK_STATUS;
+
+ }
+ //otherwise first create a project, wait until indexed, and then execute the search
+ else{
+ //Create a job to create project by bld.inf file if needed, and then execute search
+ progressMonitor.subTask(Messages.getString("ShowMethodCallLocationsJob.CreatingProjectFromBldInf_SubTask_Msg") +"\n" +bldFile +"'..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ checkIfCancelled();
+ status = createAndRunProjectCreatingJobAndExecuteSearch(bldFile, progressMonitor);
+ progressMonitor.worked(CREATING_PROJECT_STEPS);
+
+ if(status.getSeverity() == IStatus.ERROR){
+ this.cancel();
+ }
+ else{
+ startIndexingAndSearch();
+ status = Job.ASYNC_FINISH;
+ }
+ }
+
+ } catch (JobCancelledByUserException e) {
+ // Job cancel because of user request
+ this.cancel();
+ status = Status.CANCEL_STATUS;
+ }catch (Exception e) {
+ // Job cancel because of an exception
+ e.printStackTrace();
+ String errMsg = Messages.getString("CreateProjectJob.Err_Msg") + ": " + e.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
+ status = reportError(e, errMsg);
+ this.cancel();
+ }
+ return status;
+ }
+
+ /**
+ * Reports error to user.
+ * @param e Encountered exception.
+ * @param errMsg Error message.
+ * @return status object.
+ */
+ private IStatus reportError(Exception e, String errMsg) {
+ IStatus status;
+ status = new Status(
+ Status.ERROR,Platform.PI_RUNTIME,
+ Status.ERROR,errMsg, e);
+ AppDepConsole.getInstance().println(errMsg, IConsolePrintUtility.MSG_ERROR);
+ return status;
+ }
+
+ /**
+ * Gets all source files belonging to the given component.
+ * @param settings Tool settings.
+ * @param componentName component name to search method call locations from.
+ * @param epocRootPath EPOCROOT path
+ * @return Source file name array
+ * @throws CannotFoundFileException
+ * @throws CacheFileDoesNotExistException
+ * @throws CacheIndexNotReadyException
+ * @throws IOException
+ */
+ private String[] getUsedComponentSourceFiles(AppDepSettings settings,
+ String componentName, String epocRootPath)
+ throws CannotFoundFileException, IOException, CacheIndexNotReadyException, CacheFileDoesNotExistException {
+
+ ISourcesFinder finder = SourceFinderFactory.createSourcesFinder(AppDepConsole.getInstance());
+ String variant = MainViewDataPopulator.getTargetPlatformIdStringForComponent(settings, componentName);
+ String build = settings.getBuildType().getBuildTypeName();
+ String [] files = finder.findSourceFiles(componentName, variant, build, epocRootPath);
+ return files;
+ }
+
+ /**
+ * Sets search string based on the method name.
+ * @param methodName Method name.
+ */
+ private void setSearchString(String methodName) {
+ String shortMethodName = methodName;
+ int start = methodName.indexOf("::"); //$NON-NLS-1$
+ if(start != -1){
+ shortMethodName = methodName.substring(start + 2);
+
+ }
+ int end = shortMethodName.indexOf("("); //$NON-NLS-1$
+ if(end != -1){
+ shortMethodName = shortMethodName.substring(0, end);
+ }
+
+ String longMethodNameWithOutParams;
+ if(methodName.indexOf("(") != -1){ //$NON-NLS-1$
+ longMethodNameWithOutParams = methodName.substring(0, methodName.indexOf("(")); //$NON-NLS-1$
+ }else{
+ longMethodNameWithOutParams = methodName;
+ }
+
+ searchString = longMethodNameWithOutParams;// methodName;// shortMethodName;
+ }
+
+
+ /**
+ * Seeks all files by bld.inf file and set them to filesInBldInf
+ * and seeks all bld.inf to add them to bldInfFiles
+ * @param files File name array.
+ * @return bld.inf file path and an empty string if not found.
+ * @throws URISyntaxException
+ * @throws JobCancelledByUserException
+ */
+ private String getBldInfFileName(String[] files) throws URISyntaxException, JobCancelledByUserException {
+ //Opening project(s) where source files belongs to
+ IProjectFinder prjFinder = ProjectFinderFactory.createProjectFinder(AppDepConsole.getInstance(), progressMonitor);
+ Vectortrue
if project is found from workspace, otherwise false
.
+ * @throws IOException
+ * @throws CoreException
+ */
+ private boolean isProjectAllreadyExistingAndOpenIfClosed(String bldFile, IProgressMonitor monitor) throws IOException, CoreException {
+
+ IPath path = new Path(bldFile);
+ IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
+
+ if(files.length > 0){
+
+ IProject prj = files[0].getProject();
+ if(prj.isOpen()){
+ return true;
+ }
+ else{
+ prj.open(monitor);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Creates query and execute the search
+ * @param searchText Search text
+ * @throws JobCancelledByUserException
+ */
+ private void executeSearch(final String searchText){
+
+ progressMonitor.subTask(Messages.getString("ShowMethodCallLocationsJob.ExcecutingSearch_SubTask_Msg")); //$NON-NLS-1$
+
+ final IResource[] resources = createResourcesTable();
+
+
+ DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "Starting to execute search with " +resources.length +" resources..."); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Runnable runSeach = new Runnable(){
+ public void run(){
+ try {
+ if(progressMonitor.isCanceled()){
+ cancelProgress();
+ }else{
+ ISearchQuery query = null;
+ //Query is created by CDT:s interal API
+ query = getSearchQuery(searchText, resources);
+ //Start to listen search query for noticing done() when its completed
+ NewSearchUI.addQueryListener(getIQueryListener());
+ NewSearchUI.activateSearchResultView();
+ NewSearchUI.runQueryInBackground(query);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ AppDepConsole.getInstance().println(Messages.getString("ShowMethodCallLocationsJob.UnableToExecuteSearch_ErrMsg_Part2") +e, AppDepConsole.MSG_ERROR); //$NON-NLS-1$
+ errorProgress(Messages.getString("ShowMethodCallLocationsJob.UnableToExecuteSearch_ErrMsg_Part1"), e); //$NON-NLS-1$
+ }
+ }
+
+ };
+
+ // Showing a visible message in its own thread
+ // in order not to cause invalid thread access
+ Display.getDefault().asyncExec(runSeach);
+ }
+
+ /**
+ * Get search query.
+ * + * This method is using CDT:s internal API:s and if public access to {@link PDOMSearchPatternQuery} + * is provided, implementation should be changed to use public implementation. + * Internal API is used, because of ready made implementation of find functions and methods references + * is found in there. + * @param searchText, text to search, without parameters. Cut search String before first brace "(". + * With parameters and braces, you don't get any results. + * @param resources + * @return query to give to Search engine. + * @throws CoreException + */ + private ISearchQuery getSearchQuery( + final String searchText, final IResource[] resources) + throws CoreException { + + // get the list of elements for the scope + List