Package org.sonar.api.server.rule
Class RulesDefinition.NewRule
- java.lang.Object
-
- org.sonar.api.server.rule.RulesDefinition.NewRule
-
- Enclosing interface:
- RulesDefinition
public abstract static class RulesDefinition.NewRule extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description NewRule()
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description abstract RulesDefinition.NewRule
addCwe(int... nums)
abstract RulesDefinition.NewRule
addDeprecatedRuleKey(java.lang.String repository, java.lang.String key)
Register a repository and key under which this rule used to be known (seeRulesDefinition.Rule.deprecatedRuleKeys()
for details).abstract RulesDefinition.NewRule
addDescriptionSection(RuleDescriptionSection ruleDescriptionSection)
Add a rule description section.abstract RulesDefinition.NewRule
addEducationPrincipleKeys(java.lang.String... list)
abstract RulesDefinition.NewRule
addOwaspTop10(RulesDefinition.OwaspTop10... standards)
Deprecated.since 9.3 Supports only OWASP Top 10 2017 standard, use addOwaspTop10(OwaspTop10Version, OwaspTop10...) for 2017,2021...abstract RulesDefinition.NewRule
addOwaspTop10(RulesDefinition.OwaspTop10Version version, RulesDefinition.OwaspTop10... standards)
abstract RulesDefinition.NewRule
addPciDss(RulesDefinition.PciDssVersion version, java.lang.String... requirements)
abstract RulesDefinition.NewRule
addTags(java.lang.String... list)
abstract RulesDefinition.NewParam
createParam(java.lang.String paramKey)
Create a parameter with given unique key.abstract RulesDefinition.DebtRemediationFunctions
debtRemediationFunctions()
Factory ofDebtRemediationFunction
abstract java.lang.String
key()
abstract RulesDefinition.NewParam
param(java.lang.String paramKey)
abstract java.util.Collection<RulesDefinition.NewParam>
params()
abstract RuleScope
scope()
abstract RulesDefinition.NewRule
setActivatedByDefault(boolean activatedByDefault)
Should this rule be enabled by default.abstract RulesDefinition.NewRule
setDebtRemediationFunction(DebtRemediationFunction fn)
abstract RulesDefinition.NewRule
setGapDescription(java.lang.String s)
For rules that use LINEAR or LINEAR_OFFSET remediation functions, the meaning of the function parameter (= "gap") must be set.abstract RulesDefinition.NewRule
setHtmlDescription(java.lang.String s)
The optional description, in HTML format, has no max length.abstract RulesDefinition.NewRule
setHtmlDescription(java.net.URL classpathUrl)
Load description from a file available in classpath.abstract RulesDefinition.NewRule
setInternalKey(java.lang.String s)
Optional key that can be used by the rule engine.abstract RulesDefinition.NewRule
setMarkdownDescription(java.lang.String s)
Deprecated, for removal: This API element is subject to removal in a future version.useaddDescriptionSection(RuleDescriptionSection)
insteadabstract RulesDefinition.NewRule
setMarkdownDescription(java.net.URL classpathUrl)
Deprecated, for removal: This API element is subject to removal in a future version.useaddDescriptionSection(RuleDescriptionSection)
insteadabstract RulesDefinition.NewRule
setName(java.lang.String s)
Required rule nameabstract RulesDefinition.NewRule
setScope(RuleScope scope)
abstract RulesDefinition.NewRule
setSeverity(java.lang.String s)
abstract RulesDefinition.NewRule
setStatus(RuleStatus status)
Default value isRuleStatus.READY
.abstract RulesDefinition.NewRule
setTags(java.lang.String... list)
abstract RulesDefinition.NewRule
setTemplate(boolean template)
abstract RulesDefinition.NewRule
setType(RuleType t)
The type as defined by the SonarQube Quality Model.
-
-
-
Method Detail
-
key
public abstract java.lang.String key()
-
scope
@CheckForNull public abstract RuleScope scope()
- Since:
- 7.1
-
setScope
public abstract RulesDefinition.NewRule setScope(RuleScope scope)
- Since:
- 7.1
-
setName
public abstract RulesDefinition.NewRule setName(java.lang.String s)
Required rule name
-
setTemplate
public abstract RulesDefinition.NewRule setTemplate(boolean template)
-
setActivatedByDefault
public abstract RulesDefinition.NewRule setActivatedByDefault(boolean activatedByDefault)
Should this rule be enabled by default. For example in SonarLint standalone.- Since:
- 6.0
-
setSeverity
public abstract RulesDefinition.NewRule setSeverity(java.lang.String s)
-
setType
public abstract RulesDefinition.NewRule setType(RuleType t)
The type as defined by the SonarQube Quality Model.
When a plugin does not define rule type, then it is deduced from tags:- if the rule has the "bug" tag then type is
RuleType.BUG
- if the rule has the "security" tag then type is
RuleType.VULNERABILITY
- if the rule has both tags "bug" and "security", then type is
RuleType.BUG
- default type is
RuleType.CODE_SMELL
- Since:
- 5.5
- if the rule has the "bug" tag then type is
-
addDescriptionSection
public abstract RulesDefinition.NewRule addDescriptionSection(RuleDescriptionSection ruleDescriptionSection)
Add a rule description section. The sections must be added in the right order. For backward compatibility, one of the old methodsetHtmlDescription(String)
orsetHtmlDescription(URL)
still need to be called on top of that one. Each section must have a different section key when they are non-contextual. As soon as one section is contextual for a section key, all sections with that key must be contextual. The pair "section key, context key" pair must still be unique. If several sections provide contexts, the provided context keys must be the same between sections.- Since:
- 9.5
-
setHtmlDescription
public abstract RulesDefinition.NewRule setHtmlDescription(@Nullable java.lang.String s)
The optional description, in HTML format, has no max length. It's exclusive with markdown description (seesetMarkdownDescription(String)
)
-
setHtmlDescription
public abstract RulesDefinition.NewRule setHtmlDescription(@Nullable java.net.URL classpathUrl)
Load description from a file available in classpath. Example :setHtmlDescription(getClass().getResource("/myrepo/Rule1234.html")
-
setMarkdownDescription
@Deprecated(since="9.6", forRemoval=true) public abstract RulesDefinition.NewRule setMarkdownDescription(@Nullable java.lang.String s)
Deprecated, for removal: This API element is subject to removal in a future version.useaddDescriptionSection(RuleDescriptionSection)
insteadThe optional description, in a restricted Markdown format, has no max length. It's exclusive with HTML description (seesetHtmlDescription(String)
)
-
setMarkdownDescription
@Deprecated(since="9.6", forRemoval=true) public abstract RulesDefinition.NewRule setMarkdownDescription(@Nullable java.net.URL classpathUrl)
Deprecated, for removal: This API element is subject to removal in a future version.useaddDescriptionSection(RuleDescriptionSection)
insteadLoad description from a file available in classpath. Example :setMarkdownDescription(getClass().getResource("/myrepo/Rule1234.md")
-
setStatus
public abstract RulesDefinition.NewRule setStatus(RuleStatus status)
Default value isRuleStatus.READY
. The valueRuleStatus.REMOVED
is not accepted and raises anIllegalArgumentException
.
-
debtRemediationFunctions
public abstract RulesDefinition.DebtRemediationFunctions debtRemediationFunctions()
Factory ofDebtRemediationFunction
-
setDebtRemediationFunction
public abstract RulesDefinition.NewRule setDebtRemediationFunction(@Nullable DebtRemediationFunction fn)
- See Also:
debtRemediationFunctions()
-
setGapDescription
public abstract RulesDefinition.NewRule setGapDescription(@Nullable java.lang.String s)
For rules that use LINEAR or LINEAR_OFFSET remediation functions, the meaning of the function parameter (= "gap") must be set. This description explains what 1 point of "gap" represents for the rule.
Example: for the "Insufficient condition coverage", this description for the remediation function gap multiplier/base effort would be something like "Effort to test one uncovered condition".
-
createParam
public abstract RulesDefinition.NewParam createParam(java.lang.String paramKey)
Create a parameter with given unique key. Max length of key is 128 characters.
-
param
@CheckForNull public abstract RulesDefinition.NewParam param(java.lang.String paramKey)
-
params
public abstract java.util.Collection<RulesDefinition.NewParam> params()
-
addTags
public abstract RulesDefinition.NewRule addTags(java.lang.String... list)
- See Also:
RuleTagFormat
-
setTags
public abstract RulesDefinition.NewRule setTags(java.lang.String... list)
- See Also:
RuleTagFormat
-
addOwaspTop10
@Deprecated public abstract RulesDefinition.NewRule addOwaspTop10(RulesDefinition.OwaspTop10... standards)
Deprecated.since 9.3 Supports only OWASP Top 10 2017 standard, use addOwaspTop10(OwaspTop10Version, OwaspTop10...) for 2017,2021...- Since:
- 7.3
-
addOwaspTop10
public abstract RulesDefinition.NewRule addOwaspTop10(RulesDefinition.OwaspTop10Version version, RulesDefinition.OwaspTop10... standards)
- Since:
- 9.3
-
addPciDss
public abstract RulesDefinition.NewRule addPciDss(RulesDefinition.PciDssVersion version, java.lang.String... requirements)
- Since:
- 9.5
-
addCwe
public abstract RulesDefinition.NewRule addCwe(int... nums)
- Since:
- 7.3
-
setInternalKey
public abstract RulesDefinition.NewRule setInternalKey(@Nullable java.lang.String s)
Optional key that can be used by the rule engine. Not displayed in webapp. For example the Java Checkstyle plugin feeds this field with the internal path ("Checker/TreeWalker/AnnotationUseStyle").
-
addDeprecatedRuleKey
public abstract RulesDefinition.NewRule addDeprecatedRuleKey(java.lang.String repository, java.lang.String key)
Register a repository and key under which this rule used to be known (seeRulesDefinition.Rule.deprecatedRuleKeys()
for details).Deprecated keys should be added with this method in order, oldest first, for documentation purpose.
- Throws:
java.lang.IllegalArgumentException
- ifrepository
orkey
isnull
or empty.- Since:
- 7.1
- See Also:
RulesDefinition.Rule.deprecatedRuleKeys()
-
addEducationPrincipleKeys
public abstract RulesDefinition.NewRule addEducationPrincipleKeys(java.lang.String... list)
- Since:
- 9.8
Register a list of education principle keys to attach to the given rule.
Education principles must follow the format defined in
EducationPrincipleKeyFormat
Examples of education principle keys: "defense_in_depth", "least_trust_principle"
-
-