Browse Source

move deprecated rule API to sonar-deprecated

tags/2.6
simonbrandhof 13 years ago
parent
commit
ddcc6272a6
32 changed files with 68 additions and 135 deletions
  1. 5
    0
      plugins/sonar-findbugs-plugin/pom.xml
  2. 1
    1
      plugins/sonar-pmd-plugin/pmd-result.xml
  3. 5
    0
      plugins/sonar-pmd-plugin/pom.xml
  4. 2
    0
      sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractViolationsStaxParser.java
  5. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java
  6. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java
  7. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
  8. 1
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
  9. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/RulePriorityMapper.java
  10. 1
    3
      sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java
  11. 1
    3
      sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java
  12. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
  13. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java
  14. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Profile.java
  15. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Property.java
  16. 0
    0
      sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Rule.java
  17. 0
    0
      sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractViolationsStaxParserTest.java
  18. 0
    0
      sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheck.java
  19. 0
    0
      sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java
  20. 3
    2
      sonar-deprecated/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java
  21. 8
    6
      sonar-deprecated/src/test/java/org/sonar/api/rules/RulePriorityTest.java
  22. 9
    6
      sonar-deprecated/src/test/java/org/sonar/api/rules/RuleTest.java
  23. 4
    2
      sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java
  24. 5
    2
      sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java
  25. 4
    3
      sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java
  26. 19
    17
      sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java
  27. 0
    0
      sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml
  28. 0
    0
      sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml
  29. 0
    0
      sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml
  30. 0
    0
      sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml
  31. 0
    0
      sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml
  32. 0
    90
      sonar-plugin-api/src/test/java/org/sonar/api/FakePlugin.java

+ 5
- 0
plugins/sonar-findbugs-plugin/pom.xml View File

<artifactId>sonar-plugin-api</artifactId> <artifactId>sonar-plugin-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-deprecated</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId> <artifactId>maven-project</artifactId>

+ 1
- 1
plugins/sonar-pmd-plugin/pmd-result.xml View File

<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<pmd version="4.2.5" timestamp="2010-09-12T21:47:59.064">
<pmd version="4.2.5" timestamp="2010-09-14T13:20:30.108">
</pmd> </pmd>

+ 5
- 0
plugins/sonar-pmd-plugin/pom.xml View File

</properties> </properties>


<dependencies> <dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-deprecated</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.sonar</groupId> <groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId> <artifactId>sonar-plugin-api</artifactId>

sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractViolationsStaxParser.java → sonar-deprecated/src/main/java/org/sonar/api/batch/AbstractViolationsStaxParser.java View File



/** /**
* @since 1.10 * @since 1.10
* @deprecated since 2.3. Too much "black-box".
*/ */
@Deprecated
public abstract class AbstractViolationsStaxParser { public abstract class AbstractViolationsStaxParser {


protected RulesManager rulesManager; protected RulesManager rulesManager;

sonar-plugin-api/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java → sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractImportableRulesRepository.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java → sonar-deprecated/src/main/java/org/sonar/api/rules/AbstractRulesRepository.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java → sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationExportable.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java → sonar-deprecated/src/main/java/org/sonar/api/rules/ConfigurationImportable.java View File

package org.sonar.api.rules; package org.sonar.api.rules;
import java.util.List; import java.util.List;
import org.sonar.api.rules.Rule;
@Deprecated @Deprecated
public interface ConfigurationImportable { public interface ConfigurationImportable {

sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java → sonar-deprecated/src/main/java/org/sonar/api/rules/RulePriorityMapper.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesManager.java → sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java View File

import java.util.Set; import java.util.Set;


/** /**
* Manage and access rules defined in Sonar.
*
* @deprecated UGLY COMPONENT - WILL BE COMPLETELY REFACTORED IN SONAR 2.3
* @deprecated since 2.3
*/ */
@Deprecated @Deprecated
public abstract class RulesManager { public abstract class RulesManager {

sonar-plugin-api/src/main/java/org/sonar/api/rules/RulesRepository.java → sonar-deprecated/src/main/java/org/sonar/api/rules/RulesRepository.java View File

import java.util.List; import java.util.List;
/** /**
* The interface to implement to create a repository of rules
*
* @param <LANG>
* @deprecated since 2.3
*/ */
@Deprecated @Deprecated
public interface RulesRepository<LANG extends Language> extends BatchExtension, ServerExtension { public interface RulesRepository<LANG extends Language> extends BatchExtension, ServerExtension {

sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java → sonar-deprecated/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java → sonar-deprecated/src/main/java/org/sonar/api/rules/StandardRulesXmlParser.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java → sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Profile.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java → sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Property.java View File


sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java → sonar-deprecated/src/main/java/org/sonar/api/rules/xml/Rule.java View File


sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractViolationsStaxParserTest.java → sonar-deprecated/src/test/java/org/sonar/api/batch/AbstractViolationsStaxParserTest.java View File


sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotatedCheck.java → sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheck.java View File


sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java → sonar-deprecated/src/test/java/org/sonar/api/rules/AnnotatedCheckWithParameters.java View File


sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java View File

*/ */
package org.sonar.api.rules; package org.sonar.api.rules;


import org.hamcrest.core.Is;
import org.junit.Test; import org.junit.Test;


import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.nullValue;
assertThat(rule.getConfigKey(), nullValue()); assertThat(rule.getConfigKey(), nullValue());
assertThat(rule.getParams().size(), is(0)); assertThat(rule.getParams().size(), is(0));
assertThat(rule.getDescription(), is("Description")); assertThat(rule.getDescription(), is("Description"));
assertThat(rule.getCardinality(), is(Rule.Cardinality.SINGLE));
assertThat(rule.getRulesCategory().getName(), is(Iso9126RulesCategories.RELIABILITY.getName()));
assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.SINGLE));
assertThat(rule.getRulesCategory().getName(), Is.is(Iso9126RulesCategories.RELIABILITY.getName()));
} }


@Test @Test

sonar-plugin-api/src/test/java/org/sonar/api/rules/RulePriorityTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/RulePriorityTest.java View File

package org.sonar.api.rules; package org.sonar.api.rules;


import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;

import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;


public class RulePriorityTest { public class RulePriorityTest {


@Test @Test
public void testValueOfString() { public void testValueOfString() {
assertEquals(RulePriority.INFO, RulePriority.valueOfString("info"));
assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("MAJOR"));
assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ERROR"));
assertEquals(RulePriority.INFO, RulePriority.valueOfString("WARNING"));
assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ErRor"));
assertEquals(RulePriority.INFO, RulePriority.valueOfString("WaRnInG"));
Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("info"));
Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("MAJOR"));
Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ERROR"));
Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("WARNING"));
Assert.assertEquals(RulePriority.MAJOR, RulePriority.valueOfString("ErRor"));
Assert.assertEquals(RulePriority.INFO, RulePriority.valueOfString("WaRnInG"));
} }


@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)

sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/RuleTest.java View File



import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*; import static org.junit.Assert.*;

import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;


import java.util.Arrays; import java.util.Arrays;
public void descriptionShouldBeCleaned() { public void descriptionShouldBeCleaned() {
Rule rule = new Rule(); Rule rule = new Rule();
rule.setDescription(" my description "); rule.setDescription(" my description ");
assertEquals("my description", rule.getDescription());
Assert.assertEquals("my description", rule.getDescription());


rule.setDescription(null); rule.setDescription(null);
assertNull(rule.getDescription()); assertNull(rule.getDescription());
@Test @Test
public void defaultPriorityIsMajor() { public void defaultPriorityIsMajor() {
Rule rule = new Rule(); Rule rule = new Rule();
assertThat(rule.getPriority(), is(RulePriority.MAJOR));
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));


rule = new Rule("name", "key"); rule = new Rule("name", "key");
assertThat(rule.getPriority(), is(RulePriority.MAJOR));
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));


rule = new Rule("pkey", "key", "name", Iso9126RulesCategories.EFFICIENCY, null, null); rule = new Rule("pkey", "key", "name", Iso9126RulesCategories.EFFICIENCY, null, null);
assertThat(rule.getPriority(), is(RulePriority.MAJOR));
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));


rule.setPriority(RulePriority.BLOCKER); rule.setPriority(RulePriority.BLOCKER);
assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));


rule.setPriority(null); rule.setPriority(null);
assertThat(rule.getPriority(), is(RulePriority.MAJOR));
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR));
} }





sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleUtilsTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/RuleUtilsTest.java View File

import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

import org.mockito.Matchers;
import org.sonar.api.CoreProperties; import org.sonar.api.CoreProperties;


import java.util.Map; import java.util.Map;
@Test @Test
public void getPriorityWeights() { public void getPriorityWeights() {
Configuration conf = mock(Configuration.class); Configuration conf = mock(Configuration.class);
when(conf.getString(eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("info=0;minor=1;major=2;critical=5;blocker=10");
when(conf.getString(Matchers.eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("info=0;minor=1;major=2;critical=5;blocker=10");


final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf); final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf);


@Test @Test
public void loadMissingWeights() { public void loadMissingWeights() {
Configuration conf = mock(Configuration.class); Configuration conf = mock(Configuration.class);
when(conf.getString(eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("foo=0;bar=1;CRITICAL=5");
when(conf.getString(Matchers.eq(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY), anyString())).thenReturn("foo=0;bar=1;CRITICAL=5");


final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf); final Map<RulePriority, Integer> map = RuleUtils.getPriorityWeights(conf);



sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/StandardProfileXmlParserTest.java View File

import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*; import static org.junit.Assert.*;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.sonar.api.profiles.RulesProfile; import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.xml.Profile; import org.sonar.api.rules.xml.Profile;
RulesProfile profile = standardProfileXmlParser.importConfiguration(IOUtils.toString(input)); RulesProfile profile = standardProfileXmlParser.importConfiguration(IOUtils.toString(input));
List<ActiveRule> results = profile.getActiveRules(); List<ActiveRule> results = profile.getActiveRules();


assertThat("Sonar way", is(profile.getName()));
assertThat("Sonar way", CoreMatchers.is(profile.getName()));
assertThat(results.size(), is(activeRulesExpected.size())); assertThat(results.size(), is(activeRulesExpected.size()));
assertActiveRulesAreEquals(results, activeRulesExpected); assertActiveRulesAreEquals(results, activeRulesExpected);
} }
ActiveRule activeRule2 = activeRules2.get(i); ActiveRule activeRule2 = activeRules2.get(i);
assertTrue(activeRule1.getRule().equals(activeRule2.getRule()) && activeRule1.getPriority().equals(activeRule2.getPriority())); assertTrue(activeRule1.getRule().equals(activeRule2.getRule()) && activeRule1.getPriority().equals(activeRule2.getPriority()));


assertEquals(activeRule1.getActiveRuleParams().size(), (activeRule2.getActiveRuleParams().size()));
Assert.assertEquals(activeRule1.getActiveRuleParams().size(), (activeRule2.getActiveRuleParams().size()));
for (int j = 0; j < activeRule1.getActiveRuleParams().size(); j++) { for (int j = 0; j < activeRule1.getActiveRuleParams().size(); j++) {
ActiveRuleParam activeRuleParam1 = activeRule1.getActiveRuleParams().get(j); ActiveRuleParam activeRuleParam1 = activeRule1.getActiveRuleParams().get(j);
ActiveRuleParam activeRuleParam2 = activeRule2.getActiveRuleParams().get(j); ActiveRuleParam activeRuleParam2 = activeRule2.getActiveRuleParams().get(j);

sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRuleXmlFormatTest.java View File

*/ */
package org.sonar.api.rules; package org.sonar.api.rules;


import org.hamcrest.core.Is;
import org.junit.Test; import org.junit.Test;
import org.sonar.api.utils.SonarException; import org.sonar.api.utils.SonarException;


Rule rule = rules.get(0); Rule rule = rules.get(0);
assertThat(rule.getName(), is("Local Variable Name")); assertThat(rule.getName(), is("Local Variable Name"));
assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property.")); assertThat(rule.getDescription(), is("Checks that local, non-final variable names conform to a format specified by the format property."));
assertThat(rule.getPriority(), is(RulePriority.BLOCKER));
assertThat(rule.getCardinality(), is(Rule.Cardinality.MULTIPLE));
assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER));
assertThat(rule.getCardinality(), Is.is(Rule.Cardinality.MULTIPLE));
assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName")); assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));


assertThat(rule.getParams().size(), is(2)); assertThat(rule.getParams().size(), is(2));
List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml")); List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml"));
assertThat(rules.size(), is(1)); assertThat(rules.size(), is(1));
Rule rule = rules.get(0); Rule rule = rules.get(0);
assertThat(rule.getPriority(), is(RulePriority.CRITICAL));
assertThat(rule.getPriority(), Is.is(RulePriority.CRITICAL));
assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck")); assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
assertThat(rule.getParam("minMethodsCount"), not(nullValue())); assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
} }

sonar-plugin-api/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java → sonar-deprecated/src/test/java/org/sonar/api/rules/StandardRulesXmlParserTest.java View File

import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*; import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Test; import org.junit.Test;


import java.util.List; import java.util.List;
assertEquals(1, rules.size()); assertEquals(1, rules.size());


Rule rule = rules.get(0); Rule rule = rules.get(0);
assertEquals("key1", rule.getKey());
assertEquals("my name", rule.getName());
assertEquals("my_config_key", rule.getConfigKey());
assertEquals("my description", rule.getDescription());
assertEquals(2, rule.getParams().size());
assertEquals("param1", rule.getParams().get(0).getKey());
assertEquals("s", rule.getParams().get(0).getType());
assertEquals("param description", rule.getParams().get(0).getDescription());
Assert.assertEquals("key1", rule.getKey());
Assert.assertEquals("my name", rule.getName());
Assert.assertEquals("my_config_key", rule.getConfigKey());
Assert.assertEquals("my description", rule.getDescription());
Assert.assertEquals(2, rule.getParams().size());
Assert.assertEquals("param1", rule.getParams().get(0).getKey());
Assert.assertEquals("s", rule.getParams().get(0).getType());
Assert.assertEquals("param description", rule.getParams().get(0).getDescription());
} }


@Test @Test
String xml = "<rules><rule><category name='cat1' /></rule></rules>"; String xml = "<rules><rule><category name='cat1' /></rule></rules>";
List<Rule> rules = parser.parse(xml); List<Rule> rules = parser.parse(xml);
assertNotNull(rules.get(0).getRulesCategory()); assertNotNull(rules.get(0).getRulesCategory());
assertEquals("cat1", rules.get(0).getRulesCategory().getName());
Assert.assertEquals("cat1", rules.get(0).getRulesCategory().getName());
assertNull(rules.get(0).getRulesCategory().getId()); assertNull(rules.get(0).getRulesCategory().getId());
assertNull(rules.get(0).getRulesCategory().getDescription()); assertNull(rules.get(0).getRulesCategory().getDescription());
} }
String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>"; String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>";
List<Rule> rules = parser.parse(xml); List<Rule> rules = parser.parse(xml);
assertNotNull(rules.get(0).getRulesCategory()); assertNotNull(rules.get(0).getRulesCategory());
assertEquals(RulePriority.CRITICAL, rules.get(0).getPriority());
Assert.assertEquals(RulePriority.CRITICAL, rules.get(0).getPriority());
assertNull(rules.get(0).getRulesCategory().getId()); assertNull(rules.get(0).getRulesCategory().getId());
assertNull(rules.get(0).getRulesCategory().getDescription()); assertNull(rules.get(0).getRulesCategory().getDescription());
} }
StandardRulesXmlParser parser = new StandardRulesXmlParser(); StandardRulesXmlParser parser = new StandardRulesXmlParser();
String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>"; String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>";
List<Rule> rules = parser.parse(xml); List<Rule> rules = parser.parse(xml);
assertEquals(RulePriority.MAJOR, rules.get(0).getPriority());
Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getPriority());
} }


@Test @Test
String xml = "<rules><rule key='key1' category='cat1' /><rule key='key2' category='cat1' /></rules>"; String xml = "<rules><rule key='key1' category='cat1' /><rule key='key2' category='cat1' /></rules>";
List<Rule> rules = parser.parse(xml); List<Rule> rules = parser.parse(xml);
assertEquals(2, rules.size()); assertEquals(2, rules.size());
assertEquals("key1", rules.get(0).getKey());
assertEquals("key2", rules.get(1).getKey());
Assert.assertEquals("key1", rules.get(0).getKey());
Assert.assertEquals("key2", rules.get(1).getKey());
} }


@Test @Test
String xml = "<rules><rule key='key1' category='cat1'><description> <![CDATA[<xml> </nodes> and accents Žˆ˜ ]]> </description></rule></rules>"; String xml = "<rules><rule key='key1' category='cat1'><description> <![CDATA[<xml> </nodes> and accents Žˆ˜ ]]> </description></rule></rules>";
List<Rule> rules = parser.parse(xml); List<Rule> rules = parser.parse(xml);
assertEquals(1, rules.size()); assertEquals(1, rules.size());
assertEquals("<xml> </nodes> and accents Žˆ˜", rules.get(0).getDescription());
Assert.assertEquals("<xml> </nodes> and accents Žˆ˜", rules.get(0).getDescription());
} }


@Test @Test
assertEquals(1, rules.size()); assertEquals(1, rules.size());


Rule rule = rules.get(0); Rule rule = rules.get(0);
assertEquals("key1", rule.getKey());
assertEquals(1, rule.getParams().size());
assertEquals("param1", rule.getParams().get(0).getKey());
Assert.assertEquals("key1", rule.getKey());
Assert.assertEquals(1, rule.getParams().size());
Assert.assertEquals("param1", rule.getParams().get(0).getKey());
} }


@Test @Test

sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml → sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml View File


sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml → sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/rules.xml View File


sonar-plugin-api/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml → sonar-deprecated/src/test/resources/org/sonar/api/rules/StandardRuleXmlFormatTest/utf8.xml View File


sonar-plugin-api/src/test/resources/org/sonar/api/rules/test_profile.xml → sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile.xml View File


sonar-plugin-api/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml → sonar-deprecated/src/test/resources/org/sonar/api/rules/test_profile_name_null.xml View File


+ 0
- 90
sonar-plugin-api/src/test/java/org/sonar/api/FakePlugin.java View File

/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.api;

import java.util.ArrayList;
import java.util.List;

import org.sonar.api.batch.Sensor;
import org.sonar.api.resources.AbstractLanguage;
import org.sonar.api.resources.Language;
import org.sonar.api.rules.RulesRepository;

public class FakePlugin implements Plugin {
private Language lang;
private String key;
private Class<? extends RulesRepository> rulesClass;
private Class<? extends Sensor> sensor = null;

public FakePlugin(String key, Language lang) {
this.lang = lang;
this.key = key;
}

public FakePlugin(String key, Language lang, Class<? extends RulesRepository> rulesClass) {
this.lang = lang;
this.key = key;
this.rulesClass = rulesClass;
}

public FakePlugin(String key, Language lang, Class<? extends RulesRepository> rulesClass, Class<? extends Sensor> sensor) {
this.lang = lang;
this.key = key;
this.rulesClass = rulesClass;
this.sensor = sensor;
}

FakePlugin() {
this("fake", new AbstractLanguage("fake", "Fake") {
public String[] getFileSuffixes() {
return new String[0];
}
});
}

public String getKey() {
return key;
}

public String getName() {
return null;
}

public String getDescription() {
return null;
}

public Language getLanguage() {
return lang;
}

public List<Class<? extends Extension>> getExtensions() {
List<Class<? extends Extension>> list = new ArrayList<Class<? extends Extension>>();
if (sensor != null) {
list.add(sensor);
}
if (rulesClass != null) {
list.add(rulesClass);
}
return list;
}


}

Loading…
Cancel
Save