Browse Source

Rules API: parameters with default value are automatically activated when a rule is activated (profile console + provided profiles loaded at startup)

tags/2.6
simonbrandhof 13 years ago
parent
commit
6494a6d3e9

+ 1
- 1
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java View File

@@ -146,7 +146,7 @@ public class CheckstyleProfileExporter extends ProfileExporter {

private void appendRuleParameters(Writer writer, ActiveRule activeRule) throws IOException {
for (RuleParam ruleParam : activeRule.getRule().getParams()) {
String value = activeRule.getParameter(ruleParam.getKey(), true);
String value = activeRule.getParameter(ruleParam.getKey());
if (StringUtils.isNotBlank(value)) {
appendModuleProperty(writer, ruleParam.getKey(), value);
}

+ 1
- 1
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java View File

@@ -104,7 +104,7 @@ public class CheckstyleProfileExporterTest {
.setConfigKey("Checker/JavadocPackage");
rule.createParameter("format");
rule.createParameter("message"); // not set in the profile and no default value => not exported in checkstyle
rule.createParameter("ignore").setDefaultValue("true");
rule.createParameter("ignore");

profile.activateRule(rule, RulePriority.MAJOR)
.setParameter("format", "abcde");

+ 0
- 1
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml View File

@@ -5,7 +5,6 @@
<module name="JavadocPackage">
<property name="severity" value="warning" />
<property name="format" value="abcde" />
<property name="ignore" value="true" />
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>

+ 1
- 11
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java View File

@@ -143,23 +143,13 @@ public class ActiveRule implements Cloneable {
}

public String getParameter(String key) {
return getParameter(key, false);
}
public String getParameter(String key, boolean useDefaultValueIfNeeded) {
if (activeRuleParams != null) {
for (ActiveRuleParam param : activeRuleParams) {
if (StringUtils.equals(key, param.getKey())) {
return param.getValue(useDefaultValueIfNeeded);
return param.getValue();
}
}
}
if (useDefaultValueIfNeeded && rule.getParams()!=null) {
RuleParam param = rule.getParam(key);
if (param != null) {
return param.getDefaultValue();
}
}
return null;
}


+ 0
- 7
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java View File

@@ -102,13 +102,6 @@ public class ActiveRuleParam implements Cloneable {
return value;
}
public String getValue(boolean useDefaultValueIfNeeded) {
if (value==null && useDefaultValueIfNeeded) {
return ruleParam.getDefaultValue();
}
return value;
}
public void setValue(String value) {
this.value = value;
}

Loading…
Cancel
Save