Skip to content

Commit

Permalink
Use latest release of sonar-plugin-api. Update tests accordingly.
Browse files Browse the repository at this point in the history
  • Loading branch information
irina-batinic-sonarsource committed Aug 10, 2023
1 parent ff5afac commit 5e317f1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ExternalRuleLoader {
private static final String DESCRIPTION_ONLY_URL = "See description of %s rule <code>%s</code> at the <a href=\"%s\">%s website</a>.";
private static final String DESCRIPTION_WITH_URL = "<p>%s</p> <p>See more at the <a href=\"%s\">%s website</a>.</p>";
private static final String DESCRIPTION_FALLBACK = "This is external rule <code>%s:%s</code>. No details are available.";
public static final Version API_VERSION_SUPPORTING_CLEAN_CODE_IMPACTS_AND_ATTIBUTES = Version.create(10, 1);
public static final Version API_VERSION_SUPPORTING_CLEAN_CODE_IMPACTS_AND_ATTRIBUTES = Version.create(10, 1);

private final String linterKey;
private final String linterName;
Expand All @@ -87,7 +87,7 @@ public ExternalRuleLoader(String linterKey, String linterName, String pathToMeta
this.languageKey = languageKey;

isCleanCodeImpactsAndAttributesSupported = sonarRuntime != null &&
sonarRuntime.getApiVersion().isGreaterThanOrEqual(API_VERSION_SUPPORTING_CLEAN_CODE_IMPACTS_AND_ATTIBUTES);
sonarRuntime.getApiVersion().isGreaterThanOrEqual(API_VERSION_SUPPORTING_CLEAN_CODE_IMPACTS_AND_ATTRIBUTES);

loadMetadataFile(pathToMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,16 @@ private void setDescriptionFromHtml(NewRule rule) {
private void setMetadataFromJson(NewRule rule) {
Map<String, Object> ruleMetadata = getMetadata(rule.key());
rule.setName(getString(ruleMetadata, "title"));
rule.setSeverity(getUpperCaseString(ruleMetadata, "defaultSeverity"));
String type = getUpperCaseString(ruleMetadata, "type");
rule.setType(RuleType.valueOf(type));

if (isSupported(10, 1)) {
Object code = ruleMetadata.get("code");
if (code != null) {
setCodeAttributeFromJson(rule, (Map<String, Object>) code);
}
}
rule.setSeverity(getUpperCaseString(ruleMetadata, "defaultSeverity"));
String type = getUpperCaseString(ruleMetadata, "type");
rule.setType(RuleType.valueOf(type));
rule.setStatus(RuleStatus.valueOf(getUpperCaseString(ruleMetadata, "status")));
rule.setTags(getStringArray(ruleMetadata, "tags"));
getScopeIfPresent(ruleMetadata, "scope").ifPresent(rule::setScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void test_repository_10_0() {
"MAJOR",
"42min",
null,
Map.of(),
Map.of(RELIABILITY, MEDIUM),
Set.of()
);

Expand All @@ -136,7 +136,7 @@ public void test_repository_10_0() {
"MAJOR",
"5min",
null,
Map.of(),
Map.of(MAINTAINABILITY, MEDIUM),
Set.of("tag1", "tag2")
);

Expand All @@ -148,7 +148,7 @@ public void test_repository_10_0() {
"INFO",
"5min",
null,
Map.of(),
Map.of(SECURITY, LOW),
Set.of()
);

Expand All @@ -160,7 +160,7 @@ public void test_repository_10_0() {
"BLOCKER",
"5min",
null,
Map.of(),
Map.of(MAINTAINABILITY, HIGH),
Set.of()
);

Expand All @@ -172,7 +172,7 @@ public void test_repository_10_0() {
"MINOR",
"5min",
null,
Map.of(),
Map.of(RELIABILITY, LOW),
Set.of()
);

Expand All @@ -184,7 +184,7 @@ public void test_repository_10_0() {
"MAJOR",
"5min",
null,
Map.of(),
Map.of(SECURITY, MEDIUM),
Set.of()
);

Expand All @@ -209,7 +209,7 @@ public void test_repository_10_1() {
"MAJOR",
"42min",
null,
Map.of(),
Map.of(RELIABILITY, MEDIUM),
Set.of()
);

Expand Down Expand Up @@ -245,7 +245,7 @@ public void test_repository_10_1() {
"MINOR",
"5min",
null,
Map.of(),
Map.of(RELIABILITY, LOW),
Set.of()
);

Expand All @@ -257,7 +257,7 @@ public void test_repository_10_1() {
"MINOR",
"5min",
null,
Map.of(),
Map.of(RELIABILITY, LOW),
Set.of()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ class TestRule {
assertThat(rule.severity()).isEqualTo("MINOR");
assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
assertThat(rule.cleanCodeAttribute()).isNull();
assertThat(rule.defaultImpacts()).isEmpty();
assertThat(rule.defaultImpacts()).isNotEmpty();
rule.defaultImpacts().forEach((softwareQuality, severity) -> {
assertThat(softwareQuality.name()).isEqualTo("MAINTAINABILITY");
assertThat(severity.name()).isEqualTo("LOW");
});
assertThat(rule.status()).isEqualTo(RuleStatus.READY);
assertThat(rule.tags()).containsExactly("convention");
DebtRemediationFunction remediation = rule.debtRemediationFunction();
Expand All @@ -148,7 +152,11 @@ class TestRule {
assertThat(rule.severity()).isEqualTo("MINOR");
assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
assertThat(rule.cleanCodeAttribute()).isNull();
assertThat(rule.defaultImpacts()).isEmpty();
assertThat(rule.defaultImpacts()).isNotEmpty();
rule.defaultImpacts().forEach((softwareQuality, severity) -> {
assertThat(softwareQuality.name()).isEqualTo("MAINTAINABILITY");
assertThat(severity.name()).isEqualTo("LOW");
});
assertThat(rule.status()).isEqualTo(RuleStatus.READY);
assertThat(rule.tags()).containsExactly("convention");
DebtRemediationFunction remediation = rule.debtRemediationFunction();
Expand Down Expand Up @@ -590,4 +598,4 @@ class TestRule {
return rule.securityStandards();
}

}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

<properties>
<!-- versions -->
<version.sonar>10.1.0.794</version.sonar> <!-- Update version after release -->
<version.sonar>10.1.0.809</version.sonar>
<sonarqube.api.impl.version>10.1.0.73491</sonarqube.api.impl.version>
<version.assertj>3.17.1</version.assertj>
<version.jsr305>3.0.2</version.jsr305>
Expand Down

0 comments on commit 5e317f1

Please sign in to comment.