<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
- <dependency>
- <groupId>org.sonarsource.sslr-squid-bridge</groupId>
- <artifactId>sslr-squid-bridge</artifactId>
- <version>2.6.1</version>
- <exclusions>
- <exclusion>
- <groupId>org.codehaus.sonar.sslr</groupId>
- <artifactId>sslr-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-plugin-api</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.codehaus.sonar.sslr</groupId>
- <artifactId>sslr-xpath</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
+
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-frontend</artifactId>
import org.sonar.api.server.rule.RulesDefinition;
import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
import org.sonar.api.utils.AnnotationUtils;
-import org.sonar.check.Cardinality;
import org.sonar.plugins.java.Java;
import org.sonar.squidbridge.annotations.RuleTemplate;
-import org.sonar.squidbridge.rules.ExternalDescriptionLoader;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
if (rule == null) {
throw new IllegalStateException("No rule was created for " + ruleClass + " in " + repository.key());
}
+
+ // Check whether it is a Rule Template.
rule.setTemplate(AnnotationUtils.getAnnotation(ruleClass, RuleTemplate.class) != null);
- if (ruleAnnotation.cardinality() == Cardinality.MULTIPLE) {
- throw new IllegalArgumentException("Cardinality is not supported, use the RuleTemplate annotation instead for " + ruleClass);
- }
ruleMetadata(ruleClass, rule);
}
}
private void addMetadata(NewRule rule, String metadataKey) {
- URL resource = ExternalDescriptionLoader.class.getResource(RESOURCE_BASE_PATH + "/" + metadataKey + "_java.json");
+ URL resource = CustomRulesDefinition.class.getResource(RESOURCE_BASE_PATH + "/" + metadataKey + "_java.json");
if (resource != null) {
RuleMetatada metatada = gson.fromJson(readResource(resource), RuleMetatada.class);
rule.setSeverity(metatada.defaultSeverity.toUpperCase());