.setName(ruleDto.getName())
.setSeverity(ruleDto.getSeverityString())
.setDescription(ruleDto.getDescription())
- .setStatus(RuleStatus.valueOf(ruleDto.getStatus()));
- // TODO should we set metadata ?
+ .setStatus(RuleStatus.valueOf(ruleDto.getStatus()))
+ .setInternalKey(ruleDto.getConfigKey());
if (hasCharacteristic(ruleDto)) {
newRule.setDebtSubCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key());
assertThat(rule.name()).isEqualTo("Avoid Null");
assertThat(rule.description()).isEqualTo("Should avoid NULL");
assertThat(rule.severity()).isEqualTo(Severity.MINOR);
- assertThat(rule.metadata()).isNull();
+ assertThat(rule.internalKey()).isNull();
assertThat(rule.params()).hasSize(1);
RuleParam param = rule.param("myParameter");
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Qualifiers;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Collections;
return this;
}
- public MeasureFilter setFromDate(Date d) {
+ public MeasureFilter setFromDate(@Nullable Date d) {
this.fromDate = d;
return this;
}
- public MeasureFilter setToDate(Date d) {
+ public MeasureFilter setToDate(@Nullable Date d) {
this.toDate = d;
return this;
}
+ @CheckForNull
public Date getFromDate() {
return fromDate;
}
+ @CheckForNull
public Date getToDate() {
return toDate;
}
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
-import java.util.*;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
public class MeasureFilterFactory implements ServerComponent {
if (condition != null) {
filter.addCondition(condition);
}
- String onBaseComponents = "onBaseComponents";
- if (properties.containsKey(onBaseComponents)) {
- filter.setOnBaseResourceChildren(Boolean.valueOf((String) properties.get(onBaseComponents)));
+ String onBaseComponents = (String) properties.get("onBaseComponents");
+ if (onBaseComponents != null) {
+ filter.setOnBaseResourceChildren(Boolean.valueOf(onBaseComponents));
}
filter.setResourceName((String) properties.get("nameSearch"));
filter.setResourceKey((String) properties.get("keySearch"));
- String onFavourites = "onFavourites";
- if (properties.containsKey(onFavourites)) {
- filter.setUserFavourites(Boolean.valueOf((String) properties.get(onFavourites)));
+ String onFavourites = (String) properties.get("onFavourites");
+ if (onFavourites != null) {
+ filter.setUserFavourites(Boolean.valueOf(onFavourites));
}
fillDateConditions(filter, properties);
fillSorting(filter, properties);
}
private void fillDateConditions(MeasureFilter filter, Map<String, Object> properties) {
- String fromDate = "fromDate";
- if (properties.containsKey(fromDate)) {
- filter.setFromDate(toDate((String) properties.get(fromDate)));
+ String fromDate = (String) properties.get("fromDate");
+ if (fromDate != null) {
+ filter.setFromDate(toDate(fromDate));
} else {
- String ageMaxDays = "ageMaxDays";
- if (properties.containsKey(ageMaxDays)) {
- filter.setFromDate(toDays((String) properties.get(ageMaxDays)));
- }
+ filter.setFromDate(toDays((String) properties.get("ageMaxDays")));
}
- String toDate = "toDate";
- if (properties.containsKey(toDate)) {
- filter.setToDate(toDate((String) properties.get(toDate)));
+ String toDate = (String) properties.get("toDate");
+ if (toDate != null) {
+ filter.setToDate(toDate(toDate));
} else {
- String ageMinDays = "ageMinDays";
- if (properties.containsKey(ageMinDays)) {
- filter.setToDate(toDays((String) properties.get(ageMinDays)));
- }
+ filter.setToDate(toDays((String) properties.get("ageMinDays")));
}
}
/**
* @since 4.2
*/
-@Beta
public interface Rule {
RuleKey key();
String description();
@CheckForNull
- String metadata();
+ String internalKey();
String severity();
private final RuleKey key;
private final Integer id;
- private final String name, severity, description, metadata, debtSubCharacteristic;
+ private final String name, severity, description, internalKey, debtSubCharacteristic;
private final RuleStatus status;
private final DebtRemediationFunction debtRemediationFunction;
this.name = newRule.name;
this.severity = newRule.severity;
this.description = newRule.description;
- this.metadata = newRule.metadata;
+ this.internalKey = newRule.internalKey;
this.status = newRule.status;
this.debtSubCharacteristic = newRule.debtSubCharacteristic;
this.debtRemediationFunction = newRule.debtRemediationFunction;
}
@Override
- public String metadata() {
- return metadata;
+ public String internalKey() {
+ return internalKey;
}
@Override
final RuleKey key;
Integer id;
- String name, description, severity = DEFAULT_SEVERITY, metadata, debtSubCharacteristic;
+ String name, description, severity = DEFAULT_SEVERITY, internalKey, debtSubCharacteristic;
DebtRemediationFunction debtRemediationFunction;
RuleStatus status = RuleStatus.defaultStatus();
Map<String, NewRuleParam> params = new HashMap<String, NewRuleParam>();
return this;
}
- public NewRule setMetadata(@Nullable String metadata) {
- this.metadata = metadata;
+ public NewRule setInternalKey(@Nullable String s) {
+ this.internalKey = s;
return this;
}
* <p/>
* <h3>How to use</h3>
* <pre>
- * public class JsSquidRulesDefinition implements RulesDefinition {
+ * public class MyJsRulesDefinition implements RulesDefinition {
*
* {@literal @}Override
* public void define(Context context) {
- * NewRepository repository = context.createRepository("js_squid", "js").setName("Javascript Squid");
+ * NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer");
*
* // define a rule programmatically. Note that rules
* // could be loaded from files (JSON, XML, ...)
* }
* </pre>
* <p/>
- * If rules are declared in a XML file with the standard SonarQube format, then it can be loaded by using :
+ * If rules are declared in a XML file with the standard SonarQube format (see
+ * {@link org.sonar.api.server.rule.RulesDefinitionXmlLoader}), then it can be loaded by using :
* <p/>
* <pre>
- * public class JsSquidRulesDefinition implements RulesDefinition {
+ * public class MyJsRulesDefinition implements RulesDefinition {
*
* private final RulesDefinitionXmlLoader xmlLoader;
*
- * public JsSquidRulesDefinition(RulesDefinitionXmlLoader xmlLoader) {
+ * public MyJsRulesDefinition(RulesDefinitionXmlLoader xmlLoader) {
* this.xmlLoader = xmlLoader;
* }
*
* {@literal @}Override
* public void define(Context context) {
- * NewRepository repository = context.createRepository("js_squid", "js").setName("Javascript Squid");
+ * NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer");
* // see javadoc of RulesDefinitionXmlLoader for the format
* xmlLoader.load(repository, getClass().getResourceAsStream("/path/to/rules.xml"));
* repository.done();
* (deprecated) English bundles can be used :
* <p/>
* <pre>
- * public class JsSquidRulesDefinition implements RulesDefinition {
+ * public class MyJsRulesDefinition implements RulesDefinition {
*
* private final RulesDefinitionXmlLoader xmlLoader;
* private final RulesDefinitionI18nLoader i18nLoader;
*
- * public JsSquidRulesDefinition(RulesDefinitionXmlLoader xmlLoader, RulesDefinitionI18nLoader i18nLoader) {
+ * public MyJsRulesDefinition(RulesDefinitionXmlLoader xmlLoader, RulesDefinitionI18nLoader i18nLoader) {
* this.xmlLoader = xmlLoader;
* this.i18nLoader = i18nLoader;
* }
*
* {@literal @}Override
* public void define(Context context) {
- * NewRepository repository = context.createRepository("js_squid", "js").setName("Javascript Squid");
+ * NewRepository repository = context.createRepository("my_js", "js").setName("My Javascript Analyzer");
* xmlLoader.load(repository, getClass().getResourceAsStream("/path/to/rules.xml"));
* i18nLoader.load(repository);
* repository.done();
private static final Logger LOG = LoggerFactory.getLogger(RulesDefinitionAnnotationLoader.class);
+ private static final Function<Class<?>, RuleParamType> TYPE_FOR_CLASS = Functions.forMap(
+ ImmutableMap.<Class<?>, RuleParamType>builder()
+ .put(Integer.class, RuleParamType.INTEGER)
+ .put(int.class, RuleParamType.INTEGER)
+ .put(Float.class, RuleParamType.FLOAT)
+ .put(float.class, RuleParamType.FLOAT)
+ .put(Boolean.class, RuleParamType.BOOLEAN)
+ .put(boolean.class, RuleParamType.BOOLEAN)
+ .build(),
+ RuleParamType.STRING
+ );
+
public void load(RulesDefinition.NewExtendedRepository repo, Class... annotatedClasses) {
for (Class annotatedClass : annotatedClasses) {
loadRule(repo, annotatedClass);
}
}
- private static final Function<Class<?>, RuleParamType> TYPE_FOR_CLASS = Functions.forMap(
- ImmutableMap.<Class<?>, RuleParamType>builder()
- .put(Integer.class, RuleParamType.INTEGER)
- .put(int.class, RuleParamType.INTEGER)
- .put(Float.class, RuleParamType.FLOAT)
- .put(float.class, RuleParamType.FLOAT)
- .put(Boolean.class, RuleParamType.BOOLEAN)
- .put(boolean.class, RuleParamType.BOOLEAN)
- .build(),
- RuleParamType.STRING
- );
-
@VisibleForTesting
static RuleParamType guessType(Class<?> type) {
return TYPE_FOR_CLASS.apply(type);
NewRule newSquid1 = builder.add(RuleKey.of("squid", "S0001"));
newSquid1.setName("Detect bug");
newSquid1.setDescription("Detect potential bug");
- newSquid1.setMetadata("foo=bar");
+ newSquid1.setInternalKey("foo=bar");
newSquid1.setSeverity(Severity.CRITICAL);
newSquid1.setStatus(RuleStatus.BETA);
newSquid1.setDebtSubCharacteristic("COMPILER");
assertThat(squid1.key().rule()).isEqualTo("S0001");
assertThat(squid1.name()).isEqualTo("Detect bug");
assertThat(squid1.description()).isEqualTo("Detect potential bug");
- assertThat(squid1.metadata()).isEqualTo("foo=bar");
+ assertThat(squid1.internalKey()).isEqualTo("foo=bar");
assertThat(squid1.status()).isEqualTo(RuleStatus.BETA);
assertThat(squid1.severity()).isEqualTo(Severity.CRITICAL);
assertThat(squid1.debtSubCharacteristic()).isEqualTo("COMPILER");
assertThat(squid2.key().repository()).isEqualTo("squid");
assertThat(squid2.key().rule()).isEqualTo("S0002");
assertThat(squid2.description()).isNull();
- assertThat(squid2.metadata()).isNull();
+ assertThat(squid2.internalKey()).isNull();
assertThat(squid2.status()).isEqualTo(RuleStatus.defaultStatus());
assertThat(squid2.severity()).isEqualTo(Severity.defaultSeverity());
assertThat(squid2.debtSubCharacteristic()).isNull();
@Override
public void stop() {
-
+ // do nothing
}
@Override
import org.picocontainer.Startable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.Plugin;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.platform.ServerFileSystem;
for (PluginMetadata pluginMetadata : pluginRepository.getMetadata()) {
String pluginKey = pluginMetadata.getKey();
- try {
- deployRailsApp(appsDir, pluginKey, pluginRepository.getPlugin(pluginKey).getClass().getClassLoader());
- } catch (Exception e) {
- throw new IllegalStateException("Fail to deploy Ruby on Rails application: " + pluginKey, e);
+ Plugin plugin = pluginRepository.getPlugin(pluginKey);
+ if (plugin != null) {
+ try {
+ deployRailsApp(appsDir, pluginKey, plugin.getClass().getClassLoader());
+ } catch (Exception e) {
+ throw new IllegalStateException("Fail to deploy Ruby on Rails application: " + pluginKey, e);
+ }
}
}
}