diff options
7 files changed, 40 insertions, 16 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java index 432961896e1..948130d91bf 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreator.java @@ -63,7 +63,7 @@ public class AdHocRuleCreator { .setRuleKey(adHoc.getKey()) .setIsExternal(true) .setIsAdHoc(true) - .setName(adHoc.getEngineId() + ": " + adHoc.getRuleId()) + .setName(adHoc.getEngineId() + ":" + adHoc.getRuleId()) .setScope(ALL) .setStatus(READY) .setCreatedAt(now) diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java index 295cf953716..7e302940086 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/AdHocRuleCreatorTest.java @@ -60,7 +60,7 @@ public class AdHocRuleCreatorTest { assertThat(rule.isAdHoc()).isTrue(); assertThat(rule.getId()).isGreaterThan(0); assertThat(rule.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign")); - assertThat(rule.getName()).isEqualTo("eslint: no-cond-assign"); + assertThat(rule.getName()).isEqualTo("eslint:no-cond-assign"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isNull(); assertThat(rule.getType()).isEqualTo(0); @@ -89,7 +89,7 @@ public class AdHocRuleCreatorTest { assertThat(rule.isAdHoc()).isTrue(); assertThat(rule.getId()).isGreaterThan(0); assertThat(rule.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign")); - assertThat(rule.getName()).isEqualTo("eslint: no-cond-assign"); + assertThat(rule.getName()).isEqualTo("eslint:no-cond-assign"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isNull(); assertThat(rule.getType()).isEqualTo(0); @@ -128,7 +128,7 @@ public class AdHocRuleCreatorTest { assertThat(ruleUpdated.isAdHoc()).isTrue(); assertThat(ruleUpdated.getId()).isGreaterThan(0); assertThat(ruleUpdated.getKey()).isEqualTo(RuleKey.of("external_eslint", "no-cond-assign")); - assertThat(ruleUpdated.getName()).isEqualTo("eslint: no-cond-assign"); + assertThat(ruleUpdated.getName()).isEqualTo("eslint:no-cond-assign"); assertThat(ruleUpdated.getDescription()).isNull(); assertThat(ruleUpdated.getSeverity()).isNull(); assertThat(ruleUpdated.getType()).isEqualTo(0); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java index 98ccf035b7a..921a48a1e95 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistAdHocRulesStepTest.java @@ -92,7 +92,7 @@ public class PersistAdHocRulesStepTest extends BaseStepTest { assertThat(reloaded.isAdHoc()).isTrue(); assertThat(reloaded.getType()).isEqualTo(0); assertThat(reloaded.getSeverity()).isNull(); - assertThat(reloaded.getName()).isEqualTo("eslint: no-cond-assign"); + assertThat(reloaded.getName()).isEqualTo("eslint:no-cond-assign"); assertThat(es.countDocuments(RuleIndexDefinition.INDEX_TYPE_RULE)).isEqualTo(1l); assertThat(es.getDocuments(RuleIndexDefinition.INDEX_TYPE_RULE).iterator().next().getId()).isEqualTo(Integer.toString(reloaded.getId())); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java index 241ae701379..f815d22cfab 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java @@ -27,6 +27,7 @@ import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.rule.NewAdHocRule; import org.sonar.api.rules.RuleType; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -39,14 +40,21 @@ public class DefaultAdHocRuleTest { @Test public void store() { SensorStorage storage = mock(SensorStorage.class); - new DefaultAdHocRule(storage) + DefaultAdHocRule rule = new DefaultAdHocRule(storage) .engineId("engine") .ruleId("ruleId") .name("name") .description("desc") .severity(Severity.BLOCKER) - .type(RuleType.CODE_SMELL) - .save(); + .type(RuleType.CODE_SMELL); + rule.save(); + + assertThat(rule.engineId()).isEqualTo("engine"); + assertThat(rule.ruleId()).isEqualTo("ruleId"); + assertThat(rule.name()).isEqualTo("name"); + assertThat(rule.description()).isEqualTo("desc"); + assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); + assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL); verify(storage).store(any(DefaultAdHocRule.class)); } diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java index 5fa89151689..30e86e986f5 100644 --- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java +++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java @@ -88,12 +88,6 @@ public class ScannerReportWriter { } } - public File writeComponentExternalIssues(int componentRef, Iterable<ScannerReport.ExternalIssue> issues) { - File file = fileStructure.fileFor(FileStructure.Domain.EXTERNAL_ISSUES, componentRef); - Protobuf.writeStream(issues, file, false); - return file; - } - public File writeComponentChangedLines(int componentRef, ScannerReport.ChangedLines changedLines) { File file = fileStructure.fileFor(FileStructure.Domain.CHANGED_LINES, componentRef); Protobuf.write(changedLines, file); diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java index 6791f83a5f4..cd92d2af88b 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java @@ -109,7 +109,7 @@ public class ScannerReportReaderTest { ScannerReportWriter writer = new ScannerReportWriter(dir); ScannerReport.ExternalIssue issue = ScannerReport.ExternalIssue.newBuilder() .build(); - writer.writeComponentExternalIssues(1, asList(issue)); + writer.appendComponentExternalIssue(1, issue); assertThat(underTest.readComponentExternalIssues(1)).hasSize(1); assertThat(underTest.readComponentExternalIssues(200)).isEmpty(); diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java index ffcd97aaa8f..0b426b0092e 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java @@ -28,6 +28,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.core.util.CloseableIterator; import org.sonar.core.util.Protobuf; +import org.sonar.scanner.protocol.Constants; import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; import org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue; import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType; @@ -126,7 +127,7 @@ public class ScannerReportWriterTest { .setMsg("the message") .build(); - underTest.writeComponentExternalIssues(1, asList(issue)); + underTest.appendComponentExternalIssue(1, issue); assertThat(underTest.hasComponentData(FileStructure.Domain.EXTERNAL_ISSUES, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.EXTERNAL_ISSUES, 1); @@ -137,6 +138,27 @@ public class ScannerReportWriterTest { } @Test + public void write_adhoc_rule() { + + // write data + ScannerReport.AdHocRule rule = ScannerReport.AdHocRule.newBuilder() + .setEngineId("eslint") + .setRuleId("123") + .setName("Foo") + .setDescription("Description") + .setSeverity(Constants.Severity.BLOCKER) + .setType(ScannerReport.IssueType.BUG) + .build(); + underTest.appendAdHocRule(rule); + + File file = underTest.getFileStructure().adHocRules(); + assertThat(file).exists().isFile(); + try (CloseableIterator<ScannerReport.AdHocRule> read = Protobuf.readStream(file, ScannerReport.AdHocRule.parser())) { + assertThat(Iterators.size(read)).isEqualTo(1); + } + } + + @Test public void write_changed_lines() { assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isFalse(); |