Promise<Object> (@NotNull final PlaybackContext context) { final ActionCallback actionCallback = new ActionCallbackProfilerStopper(); if (StringUtil.isNotEmpty(myOptions.downloadFileUrl)) { if (StringUtil.isEmpty(myOptions.toolShortName)) { LOGGER.error("myOptions.toolShortName cannot be null if you want to download file for test"); } else { downloadTestRequiredFile(myOptions.toolShortName, myOptions.downloadFileUrl); } } @NotNull Project project = context.getProject(); InspectionManagerEx inspectionManagerEx = (InspectionManagerEx)InspectionManager.getInstance(project); final InspectionProfileManager profileManager = InspectionProfileManager.getInstance(project); InspectionProfileImpl profile = profileManager.getCurrentProfile(); if (StringUtil.isNotEmpty(myOptions.toolShortName)) { profile.disableAllTools(project); profile.enableTool(myOptions.toolShortName, project); } List<Tools> enabledInspectionTools = profile.getAllEnabledInspectionTools(project); if (!ArrayUtil.isEmpty(myOptions.inspectionTrueFields)) { setInspectionFields(enabledInspectionTools, myOptions.inspectionTrueFields, true); } if (!ArrayUtil.isEmpty(myOptions.inspectionFalseFields)) { setInspectionFields(enabledInspectionTools, myOptions.inspectionFalseFields, false); } NamedScope namedScope = NamedScopesHolder.getScope(project, myOptions.scopeName); AnalysisScope analysisScope = null; if (namedScope != null) { analysisScope = new AnalysisScope(GlobalSearchScopesCore.filterScope(project, namedScope), project); } else { if (StringUtil.isNotEmpty(myOptions.directory)) { VirtualFile directory = VfsUtil.findRelativeFile(ProjectUtil.guessProjectDir(project), myOptions.directory); if (directory != null) { PsiDirectory psiDirectory = ReadAction.compute(() -> PsiManager.getInstance(project).findDirectory(directory)); if (psiDirectory != null) { analysisScope = new AnalysisScope(psiDirectory); } } } } if (analysisScope == null) { analysisScope = new AnalysisScope(project); } @SuppressWarnings("TestOnlyProblems") GlobalInspectionContextImpl inspectionContext = new GlobalInspectionContextImpl(project, inspectionManagerEx.getContentManager()) { @Override public void addView(@NotNull InspectionResultsView view, @NotNull String title, boolean isOffline) { super.addView(view, title, isOffline); ToolWindow resultWindow = ProblemsView.getToolWindow(project); if (resultWindow != null && myOptions.hideResults) { resultWindow.hide(); } } @Override protected void notifyInspectionsFinished(@NotNull AnalysisScope scope) { super.notifyInspectionsFinished(scope); context.message(PerformanceTestingBundle.message("command.inspection.finish"), getLine()); if (enabledInspectionTools.size() == 1 && !myOptions.hideResults) { try { File tempDirectory = FileUtil.createTempDirectory("inspection", "result"); final InspectionResultsView view = getView(); if (view != null) { ExportToXMLActionKt.dumpToXml(view.getCurrentProfile(), view.getTree(), view.getProject(), view.getGlobalInspectionContext(), tempDirectory.toPath()); File[] files = tempDirectory.listFiles(); if (files != null) { for (File file : files) { if (file.isHidden()) { continue; } String identifier = buildIdentifier(file.getName(), myOptions.inspectionTrueFields, project); context.message("#########", getLine()); context.message(file.getName(), getLine()); context.message( ArrayUtil.isEmpty(myOptions.inspectionTrueFields) ? null : StringUtil.join(myOptions.inspectionTrueFields, "-"), getLine()); context.message(project.getName(), getLine()); context.message("#########", getLine()); Path path = file.toPath(); context.message(path.toString(), getLine()); long warningCount; try (Stream<String> lines = Files.lines(path).filter(line -> line.contains("<problem>"))) { warningCount = lines.count(); } if (ApplicationManagerEx.isInIntegrationTest()) { if (warningCount < Integer.MAX_VALUE) { Path perfMetricsPath = Paths.get(PathManager.getLogPath()).resolve("performance-metrics").resolve("inspectionMetrics.json"); ResultsToFileProcessor.writeMetricsToJson(perfMetricsPath, "inspection_execution", (int)warningCount, null); } else { LOGGER.error("warningCount is greater than Integer.MAX_VALUE"); } } reportStatisticsToTeamCity(identifier, String.valueOf(warningCount)); saveArtifact(path, identifier); } } else { LOGGER.error("tempDirectory.listFiles() is null"); } } } catch (IOException ex) { LOGGER.error(ex); } } actionCallback.setDone(); } }; inspectionContext.setExternalProfile(profile); inspectionContext.doInspections(analysisScope); return Promises.toPromise(actionCallback); }