in src/main/java/org/jetbrains/plugins/spotbugs/actions/AnalyzePackageFiles.java [73:118]
void analyze(
@NotNull final AnActionEvent e,
@NotNull final Project project,
@NotNull final ToolWindow toolWindow,
@NotNull final FindBugsState state
) {
final VirtualFile directory = getDirectory(e, project);
final Module module = ModuleUtilCore.findModuleForFile(directory, project);
if (module == null) {
throw new IllegalStateException("No module found for " + directory);
}
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final String packageName = fileIndex.getPackageNameByDirectory(directory);
final boolean isTest = fileIndex.isInTestSourceContent(directory);
new FindBugsStarter(project, "Running SpotBugs analysis for package '" + packageName + "'...") {
@Override
protected void createCompileScope(@NotNull final CompilerManager compilerManager, @NotNull final Consumer<CompileScope> consumer) {
consumer.consume(compilerManager.createProjectCompileScope(project));
}
@Override
protected boolean configure(@NotNull final ProgressIndicator indicator, @NotNull final FindBugsProjects projects, final boolean justCompiled) {
final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
if (extension == null) {
throw new IllegalStateException("No compiler extension for module " + module.getName());
}
final VirtualFile compilerOutputPath = isTest ? extension.getCompilerOutputPathForTests() : extension.getCompilerOutputPath();
if (compilerOutputPath == null) {
showWarning("Source is not compiled.");
return false;
}
final File outputPath = new File(compilerOutputPath.getCanonicalPath(), packageName.replace(".", File.separator));
if (!outputPath.exists()) {
showWarning("Source is not compiled (" + outputPath + ").");
return false;
}
indicator.setText("Collecting files for analysis...");
final FindBugsProject findBugsProject = projects.get(module, isTest);
final int[] count = new int[1];
RecurseFileCollector.addFiles(project, indicator, findBugsProject, outputPath, count);
return true;
}
}.start();
}