Skip to content

Commit 9480fb3

Browse files
PLUGINAPI-43 added the concept of characteristic from the Clean Code Taxonomy
1 parent 717a0b0 commit 9480fb3

18 files changed

Lines changed: 270 additions & 10 deletions

File tree

plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/ExternalIssue.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
package org.sonar.api.batch.sensor.issue;
2121

2222
import javax.annotation.CheckForNull;
23+
import org.sonar.api.Beta;
2324
import org.sonar.api.batch.rule.Severity;
2425
import org.sonar.api.batch.sensor.Sensor;
26+
import org.sonar.api.code.CodeCharacteristic;
2527
import org.sonar.api.rules.RuleType;
2628

2729
/**
@@ -53,4 +55,12 @@ public interface ExternalIssue extends IIssue {
5355
*/
5456
RuleType type();
5557

58+
/**
59+
* Characteristic of the issue according to Clean Code Taxonomy.
60+
* @since 9.16
61+
*/
62+
@Beta
63+
@CheckForNull
64+
CodeCharacteristic characteristic();
65+
5666
}

plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewExternalIssue.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
package org.sonar.api.batch.sensor.issue;
2121

2222
import javax.annotation.Nullable;
23+
import org.sonar.api.Beta;
2324
import org.sonar.api.batch.rule.Severity;
2425
import org.sonar.api.batch.sensor.Sensor;
2526
import org.sonar.api.rule.RuleKey;
27+
import org.sonar.api.code.CodeCharacteristic;
2628
import org.sonar.api.rules.RuleType;
2729

2830
/**
@@ -52,10 +54,19 @@ public interface NewExternalIssue {
5254
NewExternalIssue ruleId(String ruleId);
5355

5456
/**
55-
* Type of issue.
57+
* Type of the issue.
5658
*/
5759
NewExternalIssue type(RuleType type);
5860

61+
/**
62+
* Characteristic of the issue according to Clean Code Taxonomy.
63+
* Providing it is optional for now but will become mandatory in the future.
64+
*
65+
* @since 9.16
66+
*/
67+
@Beta
68+
NewExternalIssue characteristic(CodeCharacteristic characteristic);
69+
5970
/**
6071
* Effort to fix the issue, in minutes.
6172
*/

plugin-api/src/main/java/org/sonar/api/batch/sensor/rule/AdHocRule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
package org.sonar.api.batch.sensor.rule;
2121

2222
import javax.annotation.CheckForNull;
23+
import org.sonar.api.Beta;
2324
import org.sonar.api.batch.rule.Severity;
2425
import org.sonar.api.batch.sensor.Sensor;
26+
import org.sonar.api.code.CodeCharacteristic;
2527
import org.sonar.api.rules.RuleType;
2628

2729
/**
@@ -61,4 +63,13 @@ public interface AdHocRule {
6163
*/
6264
RuleType type();
6365

66+
/**
67+
* Characteristic of the rule according to Clean Code Taxonomy.
68+
*
69+
* @since 9.16
70+
*/
71+
@Beta
72+
@CheckForNull
73+
CodeCharacteristic characteristic();
74+
6475
}

plugin-api/src/main/java/org/sonar/api/batch/sensor/rule/NewAdHocRule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
package org.sonar.api.batch.sensor.rule;
2121

2222
import javax.annotation.Nullable;
23+
import org.sonar.api.Beta;
2324
import org.sonar.api.batch.rule.Severity;
2425
import org.sonar.api.batch.sensor.Sensor;
26+
import org.sonar.api.code.CodeCharacteristic;
2527
import org.sonar.api.rules.RuleType;
2628

2729
/**
@@ -58,6 +60,15 @@ public interface NewAdHocRule {
5860
*/
5961
NewAdHocRule type(RuleType type);
6062

63+
/**
64+
* Characteristic of the rule according to Clean Code Taxonomy.
65+
* Providing it is optional for now but will become mandatory in the future.
66+
*
67+
* @since 9.16
68+
*/
69+
@Beta
70+
NewAdHocRule characteristic(CodeCharacteristic characteristic);
71+
6172
/**
6273
* Set the severity of the rule.
6374
*/

plugin-api/src/main/java/org/sonar/api/ce/measure/Issue.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
package org.sonar.api.ce.measure;
2121

2222
import javax.annotation.CheckForNull;
23+
import org.sonar.api.Beta;
2324
import org.sonar.api.rule.RuleKey;
25+
import org.sonar.api.code.CodeCharacteristic;
2426
import org.sonar.api.rules.RuleType;
2527
import org.sonar.api.utils.Duration;
2628

@@ -59,4 +61,12 @@ public interface Issue {
5961

6062
RuleType type();
6163

64+
/**
65+
* Characteristic of the issue according to Clean Code Taxonomy.
66+
* @since 9.16
67+
*/
68+
@Beta
69+
@CheckForNull
70+
CodeCharacteristic characteristic();
71+
6272
}

plugin-api/src/main/java/org/sonar/api/ce/measure/test/TestIssue.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.sonar.api.ce.measure.Issue;
2626
import org.sonar.api.rule.RuleKey;
2727
import org.sonar.api.rule.Severity;
28+
import org.sonar.api.code.CodeCharacteristic;
2829
import org.sonar.api.rules.RuleType;
2930
import org.sonar.api.utils.Duration;
3031

@@ -34,13 +35,14 @@
3435
@Immutable
3536
public class TestIssue implements Issue {
3637

37-
private String key;
38-
private String status;
39-
private String resolution;
40-
private String severity;
41-
private RuleKey ruleKey;
42-
private Duration effort;
43-
private RuleType type;
38+
private final String key;
39+
private final String status;
40+
private final String resolution;
41+
private final String severity;
42+
private final RuleKey ruleKey;
43+
private final Duration effort;
44+
private final RuleType type;
45+
private final CodeCharacteristic characteristic;
4446

4547
private TestIssue(Builder builder) {
4648
this.key = builder.key;
@@ -50,6 +52,7 @@ private TestIssue(Builder builder) {
5052
this.ruleKey = builder.ruleKey;
5153
this.effort = builder.effort;
5254
this.type = builder.type;
55+
this.characteristic = builder.characteristic;
5356
}
5457

5558
@Override
@@ -94,6 +97,14 @@ public RuleType type() {
9497
return type;
9598
}
9699

100+
/**
101+
* @since 9.16
102+
*/
103+
@Override
104+
public CodeCharacteristic characteristic() {
105+
return characteristic;
106+
}
107+
97108
public static class Builder {
98109
private String key;
99110
private String status;
@@ -102,6 +113,7 @@ public static class Builder {
102113
private RuleKey ruleKey;
103114
private Duration effort;
104115
private RuleType type;
116+
private CodeCharacteristic characteristic;
105117

106118
public Builder setKey(String key) {
107119
this.key = validateKey(key);
@@ -144,6 +156,15 @@ public Builder setType(RuleType type) {
144156
return this;
145157
}
146158

159+
/**
160+
* @since 9.16
161+
*/
162+
public Builder setCharacteristic(CodeCharacteristic characteristic) {
163+
requireNonNull(characteristic, "Characteristic cannot be null");
164+
this.characteristic = characteristic;
165+
return this;
166+
}
167+
147168
private static String validateKey(String key) {
148169
requireNonNull(key, "key cannot be null");
149170
return key;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) 2009-2023 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.api.code;
21+
22+
import org.sonar.api.Beta;
23+
24+
@Beta
25+
public enum CharacteristicsCategory {
26+
DEVELOPMENT, PRODUCTION
27+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Sonar Plugin API
3+
* Copyright (C) 2009-2023 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.api.code;
21+
22+
import org.sonar.api.Beta;
23+
import org.sonar.api.rules.RuleType;
24+
25+
import static org.sonar.api.code.CharacteristicsCategory.*;
26+
27+
/**
28+
* Enum that represents Characteristic according to the new Clean Code Taxonomy. Should be used instead of {@link RuleType} as it will
29+
* become mandatory in the future to provide it.
30+
*
31+
* @since 9.16
32+
*/
33+
@Beta
34+
public enum CodeCharacteristic {
35+
36+
CLEAR(DEVELOPMENT), CONSISTENT(DEVELOPMENT), STRUCTURED(DEVELOPMENT), TESTED(DEVELOPMENT),
37+
38+
ROBUST(PRODUCTION), SECURE(PRODUCTION), PORTABLE(PRODUCTION), COMPLIANT(PRODUCTION);
39+
40+
private final CharacteristicsCategory characteristicsCategory;
41+
42+
CodeCharacteristic(CharacteristicsCategory characteristicsCategory) {
43+
this.characteristicsCategory = characteristicsCategory;
44+
}
45+
46+
public CharacteristicsCategory getCharacteristicsCategory() {
47+
return characteristicsCategory;
48+
}
49+
}

plugin-api/src/main/java/org/sonar/api/rules/RuleType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222
import java.util.LinkedHashSet;
2323
import java.util.Set;
2424
import javax.annotation.CheckForNull;
25+
import org.sonar.api.code.CodeCharacteristic;
2526

2627
import static java.lang.String.format;
2728
import static java.util.Arrays.stream;
2829
import static java.util.Collections.unmodifiableSet;
2930
import static java.util.stream.Collectors.toList;
3031

32+
/**
33+
* Type of the rule. It is strongly recommended using {@link CodeCharacteristic} alongside as it will become mandatory in the future.
34+
*/
3135
public enum RuleType {
3236
CODE_SMELL(1), BUG(2), VULNERABILITY(3), SECURITY_HOTSPOT(4);
3337

plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import javax.annotation.CheckForNull;
3030
import javax.annotation.Nullable;
3131
import javax.annotation.concurrent.Immutable;
32+
import org.sonar.api.Beta;
3233
import org.sonar.api.ExtensionPoint;
3334
import org.sonar.api.ce.ComputeEngineSide;
3435
import org.sonar.api.rule.RuleKey;
3536
import org.sonar.api.rule.RuleScope;
3637
import org.sonar.api.rule.RuleStatus;
38+
import org.sonar.api.code.CodeCharacteristic;
3739
import org.sonar.api.rules.RuleType;
3840
import org.sonar.api.server.ServerSide;
3941
import org.sonar.api.server.debt.DebtRemediationFunction;
@@ -421,6 +423,16 @@ abstract class NewRule {
421423
*/
422424
public abstract NewRule setType(RuleType t);
423425

426+
427+
/**
428+
* The characteristic of the rule according to Clean Code Taxonomy.
429+
*
430+
* Providing it is optional for now but will become mandatory in the future.
431+
* @since 9.16
432+
*/
433+
@Beta
434+
public abstract NewRule setCharacteristic(CodeCharacteristic codeCharacteristic);
435+
424436
/**
425437
* Add a rule description section. The sections must be added in the right order.
426438
* For backward compatibility, one of the old method {@link #setHtmlDescription(String)} or {@link #setHtmlDescription(URL)} still
@@ -589,6 +601,14 @@ abstract class Rule {
589601
*/
590602
public abstract RuleType type();
591603

604+
/**
605+
* @see NewRule#setCharacteristic(CodeCharacteristic)
606+
* @since 9.16
607+
*/
608+
@CheckForNull
609+
@Beta
610+
public abstract CodeCharacteristic characteristic();
611+
592612
public abstract String severity();
593613

594614
/**

0 commit comments

Comments
 (0)