@@ -23,6 +23,11 @@ | |||
<artifactId>sonar-plugin-api</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-deprecated</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.maven</groupId> | |||
<artifactId>maven-project</artifactId> |
@@ -1,3 +1,3 @@ | |||
<?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> |
@@ -18,6 +18,11 @@ | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-deprecated</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-plugin-api</artifactId> |
@@ -43,7 +43,9 @@ import org.sonar.api.utils.StaxParser; | |||
/** | |||
* @since 1.10 | |||
* @deprecated since 2.3. Too much "black-box". | |||
*/ | |||
@Deprecated | |||
public abstract class AbstractViolationsStaxParser { | |||
protected RulesManager rulesManager; |
@@ -20,6 +20,7 @@ | |||
package org.sonar.api.rules; | |||
import java.util.List; | |||
import org.sonar.api.rules.Rule; | |||
@Deprecated | |||
public interface ConfigurationImportable { |
@@ -28,9 +28,7 @@ import java.util.Map; | |||
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 | |||
public abstract class RulesManager { |
@@ -27,9 +27,7 @@ import org.sonar.api.resources.Language; | |||
import java.util.List; | |||
/** | |||
* The interface to implement to create a repository of rules | |||
* | |||
* @param <LANG> | |||
* @deprecated since 2.3 | |||
*/ | |||
@Deprecated | |||
public interface RulesRepository<LANG extends Language> extends BatchExtension, ServerExtension { |
@@ -19,6 +19,7 @@ | |||
*/ | |||
package org.sonar.api.rules; | |||
import org.hamcrest.core.Is; | |||
import org.junit.Test; | |||
import static org.hamcrest.CoreMatchers.nullValue; | |||
@@ -38,8 +39,8 @@ public class RuleAnnotationUtilsTest { | |||
assertThat(rule.getConfigKey(), nullValue()); | |||
assertThat(rule.getParams().size(), is(0)); | |||
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 |
@@ -20,18 +20,20 @@ | |||
package org.sonar.api.rules; | |||
import static junit.framework.Assert.assertEquals; | |||
import junit.framework.Assert; | |||
import org.junit.Test; | |||
public class RulePriorityTest { | |||
@Test | |||
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) |
@@ -21,6 +21,9 @@ package org.sonar.api.rules; | |||
import static org.hamcrest.core.Is.is; | |||
import static org.junit.Assert.*; | |||
import org.hamcrest.core.Is; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import java.util.Arrays; | |||
@@ -32,7 +35,7 @@ public class RuleTest { | |||
public void descriptionShouldBeCleaned() { | |||
Rule rule = new Rule(); | |||
rule.setDescription(" my description "); | |||
assertEquals("my description", rule.getDescription()); | |||
Assert.assertEquals("my description", rule.getDescription()); | |||
rule.setDescription(null); | |||
assertNull(rule.getDescription()); | |||
@@ -68,19 +71,19 @@ public class RuleTest { | |||
@Test | |||
public void defaultPriorityIsMajor() { | |||
Rule rule = new Rule(); | |||
assertThat(rule.getPriority(), is(RulePriority.MAJOR)); | |||
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); | |||
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); | |||
assertThat(rule.getPriority(), is(RulePriority.MAJOR)); | |||
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); | |||
rule.setPriority(RulePriority.BLOCKER); | |||
assertThat(rule.getPriority(), is(RulePriority.BLOCKER)); | |||
assertThat(rule.getPriority(), Is.is(RulePriority.BLOCKER)); | |||
rule.setPriority(null); | |||
assertThat(rule.getPriority(), is(RulePriority.MAJOR)); | |||
assertThat(rule.getPriority(), Is.is(RulePriority.MAJOR)); | |||
} | |||
@@ -27,6 +27,8 @@ import static org.mockito.Matchers.anyString; | |||
import static org.mockito.Matchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import org.mockito.Matchers; | |||
import org.sonar.api.CoreProperties; | |||
import java.util.Map; | |||
@@ -36,7 +38,7 @@ public class RuleUtilsTest { | |||
@Test | |||
public void getPriorityWeights() { | |||
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); | |||
@@ -50,7 +52,7 @@ public class RuleUtilsTest { | |||
@Test | |||
public void loadMissingWeights() { | |||
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); | |||
@@ -22,6 +22,9 @@ package org.sonar.api.rules; | |||
import org.apache.commons.io.IOUtils; | |||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.junit.Assert.*; | |||
import org.hamcrest.CoreMatchers; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.rules.xml.Profile; | |||
@@ -107,7 +110,7 @@ public class StandardProfileXmlParserTest { | |||
RulesProfile profile = standardProfileXmlParser.importConfiguration(IOUtils.toString(input)); | |||
List<ActiveRule> results = profile.getActiveRules(); | |||
assertThat("Sonar way", is(profile.getName())); | |||
assertThat("Sonar way", CoreMatchers.is(profile.getName())); | |||
assertThat(results.size(), is(activeRulesExpected.size())); | |||
assertActiveRulesAreEquals(results, activeRulesExpected); | |||
} | |||
@@ -156,7 +159,7 @@ public class StandardProfileXmlParserTest { | |||
ActiveRule activeRule2 = activeRules2.get(i); | |||
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++) { | |||
ActiveRuleParam activeRuleParam1 = activeRule1.getActiveRuleParams().get(j); | |||
ActiveRuleParam activeRuleParam2 = activeRule2.getActiveRuleParams().get(j); |
@@ -19,6 +19,7 @@ | |||
*/ | |||
package org.sonar.api.rules; | |||
import org.hamcrest.core.Is; | |||
import org.junit.Test; | |||
import org.sonar.api.utils.SonarException; | |||
@@ -40,8 +41,8 @@ public class StandardRuleXmlFormatTest { | |||
Rule rule = rules.get(0); | |||
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.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.getParams().size(), is(2)); | |||
@@ -83,7 +84,7 @@ public class StandardRuleXmlFormatTest { | |||
List<Rule> rules = StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/api/rules/StandardRuleXmlFormatTest/deprecated.xml")); | |||
assertThat(rules.size(), is(1)); | |||
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.getParam("minMethodsCount"), not(nullValue())); | |||
} |
@@ -23,6 +23,8 @@ import org.apache.commons.io.IOUtils; | |||
import static org.hamcrest.MatcherAssert.assertThat; | |||
import static org.hamcrest.Matchers.is; | |||
import static org.junit.Assert.*; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import java.util.List; | |||
@@ -36,14 +38,14 @@ public class StandardRulesXmlParserTest { | |||
assertEquals(1, rules.size()); | |||
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 | |||
@@ -52,7 +54,7 @@ public class StandardRulesXmlParserTest { | |||
String xml = "<rules><rule><category name='cat1' /></rule></rules>"; | |||
List<Rule> rules = parser.parse(xml); | |||
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().getDescription()); | |||
} | |||
@@ -63,7 +65,7 @@ public class StandardRulesXmlParserTest { | |||
String xml = "<rules><rule key='1' priority='CRITICAL'><category name='cat1'/></rule></rules>"; | |||
List<Rule> rules = parser.parse(xml); | |||
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().getDescription()); | |||
} | |||
@@ -73,7 +75,7 @@ public class StandardRulesXmlParserTest { | |||
StandardRulesXmlParser parser = new StandardRulesXmlParser(); | |||
String xml = "<rules><rule key='1'><category name='cat1'/></rule></rules>"; | |||
List<Rule> rules = parser.parse(xml); | |||
assertEquals(RulePriority.MAJOR, rules.get(0).getPriority()); | |||
Assert.assertEquals(RulePriority.MAJOR, rules.get(0).getPriority()); | |||
} | |||
@Test | |||
@@ -82,8 +84,8 @@ public class StandardRulesXmlParserTest { | |||
String xml = "<rules><rule key='key1' category='cat1' /><rule key='key2' category='cat1' /></rules>"; | |||
List<Rule> rules = parser.parse(xml); | |||
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 | |||
@@ -102,7 +104,7 @@ public class StandardRulesXmlParserTest { | |||
String xml = "<rules><rule key='key1' category='cat1'><description> <![CDATA[<xml> </nodes> and accents Žˆ˜ ]]> </description></rule></rules>"; | |||
List<Rule> rules = parser.parse(xml); | |||
assertEquals(1, rules.size()); | |||
assertEquals("<xml> </nodes> and accents Žˆ˜", rules.get(0).getDescription()); | |||
Assert.assertEquals("<xml> </nodes> and accents Žˆ˜", rules.get(0).getDescription()); | |||
} | |||
@Test | |||
@@ -113,9 +115,9 @@ public class StandardRulesXmlParserTest { | |||
assertEquals(1, rules.size()); | |||
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 |
@@ -1,90 +0,0 @@ | |||
/* | |||
* 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; | |||
} | |||
} |