To save issues
- Get the violations/ISsues for the files analyzed
- For each file contains violations/ Issues
- Get the violations ( one file may contain more than one violations or Issue )
- Get the Input file and create new issue from context and save Issue
-------------------------------------------------------------------------------------------------
private void saveIssues() {
Violations violations = null;
try {
violations = getReport();
LOG.info("Call saveIssues *********************");
Iterable<InputFile> files = fileSystem.inputFiles(fileSystem.predicates().hasType(InputFile.Type.MAIN));
files.forEach(f -> LOG.info("******* inputfiles FILENAME INSIDE DIRECTORY filename=" + f.filename() + "\n relativePath="+ f.relativePath()+"\n absolutePath="+f.absolutePath()));
for (com.plugin.sonar.report.foo.File file : violations.getFile()) {
String baseDir = fileSystem.baseDir().getCanonicalPath();
String srcDirectory = context.config().get(SONAR_SOURCES).orElseThrow(RuntimeException::new);
String configDirectory = context.config().get(SONAR_CONFIG).orElseThrow(RuntimeException::new);
String astFilepath = configDirectory + File.separator + AST_FOLDER;
String srcFilePath = baseDir + File.separator + srcDirectory + File.separator;
LOG.info("baseDir=" + baseDir);
LOG.info("srcDirectory=" + srcDirectory);
LOG.info("configDirectory=" + configDirectory);
LOG.info("astFilepath=" + astFilepath);
LOG.info("srcFilePath=" + srcFilePath);
LOG.info(("file.getName()="+file.getName()));
//replacing ast folder path
String astReplaceSrcPath = file.getName().replace(astFilepath, srcFilePath);
LOG.info("astReplaceSrcPath=" + astReplaceSrcPath);
for (Violation violation : file.getViolation()) {
getResourceAndSaveIssue(violation, file.getName());
}
}
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
}
}
No comments:
Post a Comment