From 3605dcf578cd6fba4f0626868e1d019af8bd76da Mon Sep 17 00:00:00 2001 From: guwirth Date: Tue, 15 Jun 2021 18:20:16 +0200 Subject: [PATCH] make save measures for InputFiles more robust - use validateRecovery and continue if error recovery is enabled --- .../org/sonar/plugins/cxx/CxxSquidSensor.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java index e75b4ef967..d5e2fe881d 100644 --- a/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java +++ b/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java @@ -358,23 +358,21 @@ private CxxSquidConfiguration createConfiguration() { } private void save(Collection sourceCodeFiles) { - // don't publish metrics on modules, which were not analyzed - // otherwise hierarchical multi-module projects will contain wrong metrics ( == 0) - // see also AggregateMeasureComputer - if (sourceCodeFiles.isEmpty()) { - return; - } - for (var sourceCodeFile : sourceCodeFiles) { - var sourceFile = (SourceFile) sourceCodeFile; - var ioFile = new File(sourceFile.getKey()); - InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().is(ioFile)); - - saveMeasures(inputFile, sourceFile); - saveViolations(inputFile, sourceFile); - saveFileLinesContext(inputFile, sourceFile); - saveCpdTokens(inputFile, sourceFile); - saveHighlighting(inputFile, sourceFile); + try { + var sourceFile = (SourceFile) sourceCodeFile; + var ioFile = new File(sourceFile.getKey()); + InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().is(ioFile)); + + saveMeasures(inputFile, sourceFile); + saveViolations(inputFile, sourceFile); + saveFileLinesContext(inputFile, sourceFile); + saveCpdTokens(inputFile, sourceFile); + saveHighlighting(inputFile, sourceFile); + } catch (IllegalStateException e) { + var msg = "Cannot save all measures for file '" + sourceCodeFile.getKey() + "'"; + CxxUtils.validateRecovery(msg, e, context.config()); + } } }