// write Markers info to persistent file public static void config( HashSet<MarkerRecord> allMarkerRecords, HashSet<AnnotationRecord> allAnnotationRecords) { // if(Plugin.FIRST_TIME_RUN == true){ //if the plugin is run the first time, then the marker // records need to be stored, or else, don't store marker records writeMarkerRecordIntoFile(allMarkerRecords); // writeAnnotationRecordIntoFile(allAnnotationRecords); // } }
@Override public Object execute(ExecutionEvent event) { // Plugin.isManuallyStarted = true; System.out.println("ASIDECodeAnnotateHandler.java is ran ---first line"); targetPart = HandlerUtil.getActivePart(event); IWorkbenchPartSite site = targetPart.getSite(); ISelectionProvider selectionProvider = site.getSelectionProvider(); if (selectionProvider == null) { return null; } ISelection selection = selectionProvider.getSelection(); if (selection == null) { System.out.println("selectProject = "); return null; } IResource iRes = extractSelection(selection); if (iRes == null) { System.out.println("test == null"); return null; } selectProject = iRes.getProject(); if (selectProject == null) { System.out.println("selectProject == null"); return null; } System.out.println("selectProject = " + selectProject.getName()); // the following is temporarily added here pathCollector = ModelRegistry.getPathCollectorForProject(selectProject); if (pathCollector == null) { pathCollector = new PathCollector(selectProject); } paths = pathCollector.getAllPaths(); if (paths == null) paths = Collections.synchronizedList(new ArrayList<Path>()); System.out.println( "ASIDECodeAnnotateHandler.java is ran -- start iterating files of the project"); IScriptProject scriptProject = DLTKCore.create(selectProject); if (scriptProject == null) { System.out.println("scirpt project == null"); return null; } int count = 1; // gather statistics // GatherStatistics.NumOfWarningsInEachFile(); // while tablename = ... Utils.removeAllQuestionMarkers(iRes); Plugin.projectResource = iRes; Iterator ite = Plugin.sensitive_DB_Tables.iterator(); String currentSensitiveTableName = null; // commented out Nov. 27 /*while(ite.hasNext()){ currentSensitiveTableName = (String) ite.next(); Plugin.CurrentSensitiveDBTable = currentSensitiveTableName; System.out.println("Current Table is=" + Plugin.CurrentSensitiveDBTable);*/ String currentTableName; while (!Plugin.sensitive_DB_Tables_AlphRanked .isEmpty()) { // collect the warnings that comes from one table, one throughout iteration // for each table, and put the results into the currentTableName = Plugin.sensitive_DB_Tables_AlphRanked.first(); count = 1; Plugin.allMarkerRecords.clear(); while (Plugin.sensitiveOperationsForCurrentIteration != null && Plugin.sensitiveOperationsForCurrentIteration.size() != 0) { count++; System.out.println("-----------------begin round " + count); System.out.println( "Plugin.sensitiveOperationsForCurrentIteration size =!!!" + Plugin.sensitiveOperationsForCurrentIteration.size()); IScriptFolder[] folders = null; try { folders = scriptProject.getScriptFolders(); } catch (ModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("number of folders ==" + folders.length); /*String pattern = "Exec"; process(selectProject, pattern);*/ //////////////// Plugin.sensitiveOperationsForAnotherIteration.clear(); Plugin.sensitiveOperationsForAnotherIteration = new HashSet(); // System.out.println("at the begining point: size of current " + // Plugin.sensitiveOperationsForCurrentIteration.size()); int numOfFiles = 0; for (IScriptFolder folder : folders) { String folderName = folder.getElementName(); if (!Constants.PHPLibraryFolders.contains(folderName)) { ISourceModule[] sourceModules = null; try { sourceModules = folder.getSourceModules(); } catch (ModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } numOfFiles += sourceModules.length; } } /* for(int i = 0; i < 20; i++) System.out.println("files num = " + numOfFiles);*/ System.out.println("sum of folders =" + folders.length); int currentFolderNum = 1; for (IScriptFolder folder : folders) { System.out.println("folder scanning = " + currentFolderNum + "/" + folders.length); String folderName = folder.getElementName(); System.out.println("folder name = " + folderName); if (!Constants.PHPLibraryFolders.contains(folderName)) { ISourceModule[] sourceModules = null; try { sourceModules = folder.getSourceModules(); } catch (ModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (ISourceModule tmpSourceModule : sourceModules) { System.out.println("scanning " + tmpSourceModule.getElementName()); // if it is not the first time to run CodeAnnotate on this project, then disable the // scan function, // we have already pop the marker records from the file and displayed in Eclipse // already. if (false) { } // temporarily testing /* if(Plugin.FIRST_TIME_RUN == false){ //simply display the markers based on the marker records in the file String fileDir = tmpSourceModule.getResource().getFullPath().toString(); System.out.println("all markers size = " + Plugin.allMarkerRecords.size()); HashSet<MarkerRecord> markerRecordsInSingleFile = Utils.getMarkerRecordsForSingleFile(Plugin.allMarkerRecords, fileDir); Utils.createMarkersForSingleFile(markerRecordsInSingleFile, tmpSourceModule); HashSet<AnnotationRecord> annotationRecordsInSingleFile = Utils.getAnnotationRecordsForSingleFile(Plugin.allAnnotationRecords, fileDir); Utils.createAnnotationsForSingleFile(annotationRecordsInSingleFile, tmpSourceModule); System.out.println("finished creating markers for fileDir = " + fileDir + ", markerRecordsInSingleFile size = " + markerRecordsInSingleFile.size()); }*/ else { // start scanning the files for sensitive operations // System.out.println("isourcemodule being built = " + // tmpSourceModule.getElementName().toLowerCase()); // System.out.println("full path of the source module is ---" + // tmpSourceModule.getResource().getFullPath().toString()); SensitiveOperationVisitor visitor = new SensitiveOperationVisitor( tmpSourceModule, Plugin.sensitiveOperationsForCurrentIteration, Plugin.sensitiveOperationsForAnotherIteration, Plugin.sensitiveOperations); Program root = null; try { root = Utils.getCompilationUnit(tmpSourceModule); } catch (Exception e) { // TODO Auto-generated catch block System.err.println("root = util.getcompilationUnit() throws exception!"); e.printStackTrace(); } // System.out.println("begin of traverseTopDown"); if (root == null) { System.err.println( "tmpSourceModule name = " + tmpSourceModule.getElementName() + " in " + tmpSourceModule.getPath().toString()); System.err.println("root == null"); // return null; } root.traverseTopDown(visitor); Plugin.sensitiveOperations = visitor.getSensitiveOperations(); Plugin.sensitiveOperationsForAnotherIteration = visitor.getSensitiveOperationsForAnotherIteration(); } } } currentFolderNum++; } Plugin.sensitiveOperationsForCurrentIteration.clear(); Plugin.sensitiveOperationsForCurrentIteration = new HashSet(); // System.out.println("Plugin.sensitiveOperationsForAnotherIteration size after iteration =" // + Plugin.sensitiveOperationsForAnotherIteration.size()); Plugin.sensitiveOperationsForCurrentIteration = (HashSet<SensitiveMethod>) Plugin.sensitiveOperationsForAnotherIteration.clone(); // System.out.println("after assignment, Plugin.sensitiveOperationsForCurrentIteratio size = // " + Plugin.sensitiveOperationsForCurrentIteration.size()); /*String newRuleFileName = "newRulesForIteration" + count + "th.txt"; InRunPluginDataSave.writeNewSensitiveRulesIntoFile(newRuleFileName, Plugin.sensitiveOperationsForCurrentIteration); String mappingFileName = "numOfWarningsInEachFileInIteration" + (count-1) + "th.txt";; InRunPluginDataSave.writeMappingBetweenWarningsAndFiles(mappingFileName, Plugin.numberOfWarningsInEachFile); if(count == 2){ String newTableNamesFileName = "tableNamesEncounteredInIteration" + (count-1) + "th.txt"; InRunPluginDataSave.writeTableNamesIntoFile(newTableNamesFileName, Plugin.allTableNames); String mappingFileName2 = "numOfWarningsRelatedToEachTableForIteration" + (count-1) + "th.txt"; InRunPluginDataSave.writeMappingBetweenWarningsAndFiles(mappingFileName2, Plugin.numberOfWarningsRelatedToEachTable); }*/ PostRunPluginConfig.writeMarkerRecordIntoFile( Plugin.allMarkerRecords, count, currentTableName); } //// newly added // remove the first table name in the treeset so that we focus on the next table in the next // iteration. Plugin.sensitive_DB_Tables_AlphRanked.pollFirst(); Plugin.sensitiveOperationsForCurrentIteration = RulesUtils.getSensitiveOperations(); } // commented out Nov. 27 /*GatherStatistics.writeMarkersForEachTable(Plugin.allMarkerRecords, Plugin.CurrentSensitiveDBTable); Plugin.allMarkerRecords.clear(); Plugin.allMarkerRecords = new HashSet(); count = 1; Plugin.sensitiveOperationsForCurrentIteration.clear(); Plugin.sensitiveOperationsForCurrentIteration = new HashSet(); Plugin.sensitiveOperationsForCurrentIteration = (HashSet<SensitiveMethod>) Plugin.sensitiveOperationsForCurrentIteration_backup.clone(); Plugin.sensitiveOperations.clear(); Plugin.sensitiveOperations = new HashSet(); Plugin.sensitiveOperations = (HashSet<SensitiveMethod>)Plugin.sensitiveOperations_backup.clone(); }*/ // above is temporarily added. // below are temporarily added for the analysis use // GatherStatistics.filesWithoutRequiredAccessControls(Plugin.numberOfWarningsInEachFile, // Plugin.numberOfAccessControlsInEachFile); /* * Use a Job to attach a {@link CodeAnnotateDocumentEditListener} to * each and every IDocument that is related to a ICompilationUnit in the * selected project */ /* * Job job = new MountListenerJob("Mount listener to Java file", * JavaCore.create(selectProject)); job.setPriority(Job.INTERACTIVE); * job.schedule(); */ /* Delegates all heavy lifting to {@link PathFinder} */ /*Job heavy_job = new Job("Finding paths in Project: " + selectProject.getName()) { @Override protected IStatus run(final IProgressMonitor monitor) { try { Plugin.getDefault().getWorkbench().getDisplay() .asyncExec(new Runnable() { @Override public void run() { // PathFinder.getInstance(selectProject).run(monitor); } }); } finally { monitor.done(); } return Status.OK_STATUS; } }; heavy_job.setPriority(Job.LONG); heavy_job.schedule(); */ System.out.println("finished scanning, marker records saved"); // PostRunPluginConfig.config(Plugin.allMarkerRecords, Plugin.allAnnotationRecords); // PostRunPluginConfig.writeMarkerRecordIntoFile(Plugin.allMarkerRecords, count); // GatherStatistics.readWarningStatistics(Plugin.sensitive_DB_Tables_AlphRanked, // "Update_Level5.txt"); return null; }