diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-04-23 11:45:03 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-04-26 20:20:53 +0200 |
commit | 5958b88243b4d4db54cdb20fb91fc45fac34e9d3 (patch) | |
tree | e409139da361b6be16b9ab45159c0e380197601f /sonar-scanner-engine/src | |
parent | 601f29b81dab124ceacbce88caac687d70a298c6 (diff) | |
download | sonarqube-5958b88243b4d4db54cdb20fb91fc45fac34e9d3.tar.gz sonarqube-5958b88243b4d4db54cdb20fb91fc45fac34e9d3.zip |
SONAR-10544 Set effort for external issues
Diffstat (limited to 'sonar-scanner-engine/src')
6 files changed, 102 insertions, 7 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java index 4a5e35e96f4..99100318b68 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/externalissue/ExternalIssueImporter.java @@ -107,9 +107,12 @@ public class ExternalIssueImporter { InputFile file = findFile(context, location.filePath); if (file != null) { newLocation - .message(location.message) .on(file); + if (location.message != null) { + newLocation.message(location.message); + } + if (location.textRange != null) { if (location.textRange.startColumn != null) { TextPointer start = file.newPointer(location.textRange.startLine, location.textRange.startColumn); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java index e13e64d6b85..add4404b2a9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java @@ -39,7 +39,7 @@ public class ReportParserTest { System.out.println(Paths.get("org/sonar/scanner/externalissue/report.json").toAbsolutePath()); Report report = parser.parse(); - assertThat(report.issues).hasSize(3); + assertThat(report.issues).hasSize(4); assertThat(report.issues[0].engineId).isEqualTo("eslint"); assertThat(report.issues[0].ruleId).isEqualTo("rule1"); assertThat(report.issues[0].severity).isEqualTo("MAJOR"); @@ -52,6 +52,19 @@ public class ReportParserTest { assertThat(report.issues[0].primaryLocation.textRange.endColumn).isEqualTo(4); assertThat(report.issues[0].primaryLocation.textRange.endLine).isEqualTo(3); assertThat(report.issues[0].secondaryLocations).isNull(); + + assertThat(report.issues[3].engineId).isEqualTo("eslint"); + assertThat(report.issues[3].ruleId).isEqualTo("rule3"); + assertThat(report.issues[3].severity).isEqualTo("MAJOR"); + assertThat(report.issues[3].effortMinutes).isNull(); + assertThat(report.issues[3].type).isEqualTo("BUG"); + assertThat(report.issues[3].secondaryLocations).hasSize(2); + assertThat(report.issues[3].secondaryLocations[0].filePath).isEqualTo("file1.js"); + assertThat(report.issues[3].secondaryLocations[0].message).isEqualTo("fix the bug here"); + assertThat(report.issues[3].secondaryLocations[0].textRange.startLine).isEqualTo(1); + assertThat(report.issues[3].secondaryLocations[1].filePath).isEqualTo("file2.js"); + assertThat(report.issues[3].secondaryLocations[1].message).isNull(); + assertThat(report.issues[3].secondaryLocations[1].textRange.startLine).isEqualTo(2); } private Path path(String reportName) { @@ -121,4 +134,12 @@ public class ReportParserTest { exception.expectMessage("missing mandatory field 'filePath'"); parser.parse(); } + + @Test + public void fail_if_message_not_set_in_primaryLocation() { + ReportParser parser = new ReportParser(path("report_missing_message.json")); + exception.expect(IllegalStateException.class); + exception.expectMessage("missing mandatory field 'message'"); + parser.parse(); + } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java index 6d406300c3b..92e01b6491d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggersTest; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.Constants.Severity; @@ -111,18 +110,23 @@ public class ExternalIssuesMediumTest { assertThat(issue.getTextRange().getStartOffset()).isEqualTo(0); assertThat(issue.getTextRange().getEndOffset()).isEqualTo(24); - // One file-level issue in helloscala + // One file-level issue in helloscala, with secondary location List<ExternalIssue> externalIssues2 = result.externalIssuesFor(result.inputFile("xources/hello/helloscala.xoo")); assertThat(externalIssues2).hasSize(1); issue = externalIssues2.iterator().next(); - assertThat(issue.getFlowCount()).isZero(); + assertThat(issue.getFlowCount()).isEqualTo(2); assertThat(issue.getMsg()).isEqualTo("fix the bug here"); assertThat(issue.getRuleKey()).isEqualTo("rule3"); assertThat(issue.getSeverity()).isEqualTo(Severity.MAJOR); assertThat(issue.getType()).isEqualTo(IssueType.BUG); assertThat(issue.hasTextRange()).isFalse(); - + assertThat(issue.getFlow(0).getLocationCount()).isOne(); + assertThat(issue.getFlow(0).getLocation(0).getTextRange().getStartLine()).isOne(); + assertThat(issue.getFlow(1).getLocationCount()).isOne(); + assertThat(issue.getFlow(1).getLocation(0).getTextRange().getStartLine()).isEqualTo(3); + + // one issue is located in a non-existing file assertThat(logs.logs()).contains("External issues ignored for 1 unknown files, including: invalidFile"); diff --git a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/sample/externalIssues.json b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/sample/externalIssues.json index 0e50bedd8dc..539533af78f 100644 --- a/sonar-scanner-engine/src/test/resources/mediumtest/xoo/sample/externalIssues.json +++ b/sonar-scanner-engine/src/test/resources/mediumtest/xoo/sample/externalIssues.json @@ -50,7 +50,21 @@ "primaryLocation": { "message": "fix the bug here", "filePath": "xources/hello/helloscala.xoo" - } + }, + "secondaryLocations": [ + { + "filePath": "xources/hello/HelloJava.xoo", + "textRange": { + "startLine": 1 + } + }, + { + "filePath": "xources/hello/HelloJava.xoo", + "textRange": { + "startLine": 3 + } + } + ] } ] }
\ No newline at end of file diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report.json b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report.json index 06627d7106b..b951311436b 100644 --- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report.json +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report.json @@ -39,6 +39,31 @@ "message": "fix the bug here", "filePath": "file3.js" } + }, + { + "engineId": "eslint", + "ruleId": "rule3", + "severity": "MAJOR", + "type": "BUG", + "primaryLocation": { + "message": "fix the bug here", + "filePath": "file3.js" + }, + "secondaryLocations": [ + { + "message": "fix the bug here", + "filePath": "file1.js", + "textRange": { + "startLine": 1 + } + }, + { + "filePath": "file2.js", + "textRange": { + "startLine": 2 + } + } + ] } ] } diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report_missing_message.json b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report_missing_message.json new file mode 100644 index 00000000000..c191559faf7 --- /dev/null +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/externalissue/report_missing_message.json @@ -0,0 +1,28 @@ +{ +"issues" : [ + { + "engineId": "eslint", + "ruleId": "rule1", + "severity": "MAJOR", + "type": "CODE_SMELL", + "primaryLocation": { + "message": "fix the issue here", + "filePath": "file1.js", + "textRange": { + "startLine": 1, + "endLine": 2 + } + } + }, + { + "engineId": "eslint", + "ruleId": "rule2", + "severity": "MAJOR", + "type": "BUG", + "primaryLocation": { + "filePath": "file1.js" + } + } +] +} + |