本文整理汇总了Java中org.sonar.api.batch.rule.internal.ActiveRulesBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ActiveRulesBuilder类的具体用法?Java ActiveRulesBuilder怎么用?Java ActiveRulesBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ActiveRulesBuilder类属于org.sonar.api.batch.rule.internal包,在下文中一共展示了ActiveRulesBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_optimize_on_repository
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void should_optimize_on_repository() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor()
.createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
ActiveRules activeRules = new ActiveRulesBuilder()
.create(RuleKey.of("repo1", "foo"))
.activate()
.build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
activeRules = new ActiveRulesBuilder()
.create(RuleKey.of("repo1", "foo"))
.activate()
.create(RuleKey.of("squid", "rule"))
.activate()
.build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
示例2: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.css");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.CSS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createCssSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例3: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.less");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.LESS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createLessSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例4: should_raise_an_issue_because_the_parsing_error_rule_is_activated
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void should_raise_an_issue_because_the_parsing_error_rule_is_activated() {
inputFile("parsingError.scss");
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(CheckList.SCSS_REPOSITORY_KEY, "S2260"))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
context.setActiveRules(activeRules);
createScssSquidSensor().execute(context);
Collection<Issue> issues = context.allIssues();
assertThat(issues).hasSize(1);
Issue issue = issues.iterator().next();
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
}
示例5: testNumberOfClassesAndInterfaces
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testNumberOfClassesAndInterfaces() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.numberofclassesandinterfaces.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.numberofclassesandinterfaces.packageb");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(NumberOfClassesAndInterfacesRule.RULE_KEY)
.setParam(NumberOfClassesAndInterfacesRule.PARAM_MAXIMUM, "2").activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(
issueLocation.relativePath().endsWith("/numberofclassesandinterfaces/packagea/package-info.java"));
}
示例6: testAfferentCouplings
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testAfferentCouplings() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packageb");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagec");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packaged");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagee");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(AfferentCouplingsRule.RULE_KEY).setParam(AfferentCouplingsRule.PARAM_MAXIMUM, "2")
.activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/coupling/packagee/package-info.java"));
}
示例7: testEfferentCouplings
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testEfferentCouplings() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packageb");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagec");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packaged");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagee");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(EfferentCouplingsRule.RULE_KEY).setParam(EfferentCouplingsRule.PARAM_MAXIMUM, "2")
.activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/coupling/packagea/package-info.java"));
}
示例8: testEfferentCouplingsWithExclusions
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testEfferentCouplingsWithExclusions() {
// Setup exclusions
sensorContext.settings().setProperty("sonar.projectBaseDir", sensorContext.settings().getString("sonar.java.binaries") + "/exclusions/");
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packageb");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagec");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packaged");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagee");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(EfferentCouplingsRule.RULE_KEY).setParam(EfferentCouplingsRule.PARAM_MAXIMUM, "2")
.activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(0, sensorContext.allIssues().size());
}
示例9: testAbstractness
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testAbstractness() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.abstractness.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.abstractness.packageb");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(AbstractnessRule.RULE_KEY).setParam(AbstractnessRule.PARAM_MAXIMUM, "50").activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/abstractness/packageb/package-info.java"));
}
示例10: testInstability
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testInstability() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packageb");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagec");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packaged");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagee");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(InstabilityRule.RULE_KEY).setParam(InstabilityRule.PARAM_MAXIMUM, "80").activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/coupling/packagea/package-info.java"));
}
示例11: testDistanceFromMainSequence
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testDistanceFromMainSequence() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagea");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packageb");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagec");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packaged");
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.coupling.packagee");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(DistanceFromMainSequenceRule.RULE_KEY)
.setParam(DistanceFromMainSequenceRule.PARAM_MAXIMUM, "50").activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/coupling/packagee/package-info.java"));
}
示例12: testPackageDependencyCycle
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testPackageDependencyCycle() {
// Add package info
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.packagedependencycycle.packagea");
// not adding packageb because package dependency cycles are reported at
// both sides
addPackageInfo("nl.futureedge.sonar.plugin.jdepend.test.packagedependencycycle.packagec");
// Add rule with config
final ActiveRulesBuilder activeRules = new ActiveRulesBuilder();
activeRules.create(PackageDependencyCyclesRule.RULE_KEY)
.setParam(PackageDependencyCyclesRule.PARAM_MAXIMUM, "0").activate();
sensorContext.setActiveRules(activeRules.build());
// Execute
final JdependSensor subject = new JdependSensor();
subject.execute(sensorContext);
// Check
Assert.assertEquals(1, sensorContext.allIssues().size());
final InputFile issueLocation = (InputFile) sensorContext.allIssues().iterator().next().primaryLocation()
.inputComponent();
Assert.assertTrue(issueLocation.relativePath().endsWith("/packagedependencycycle/packagea/package-info.java"));
}
示例13: escapesAnalysisInput
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void escapesAnalysisInput() throws Exception {
tester.setActiveRules(new ActiveRulesBuilder()
.create(RuleKey.of(REPOSITORY_KEY, "S1186"))
.setParam("param1", "value1")
.activate()
.create(RuleKey.of(REPOSITORY_KEY, "S9999"))
.setParam("param9", "value9")
.activate()
.build());
String sonarlint = AnalysisInputXml.generate(true, false, true, tester, REPOSITORY_KEY, LANGUAGE_KEY, "utf-8");
assertThat(
sonarlint
.replaceAll("\r?\n|\r", "")
.replaceAll("<File>.*?Program.cs</File>", "<File>Program.cs</File>"))
.isEqualTo(readFile("src/test/resources/AnalysisInputXmlTest/SonarLint-expected.xml").replaceAll("\r?\n|\r", ""));
}
示例14: testSingleActiveRule
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void testSingleActiveRule() {
final String reportFile = new File(resourcesDirectory,
"webgoat/webgoat-Findings-List-all.xml").getAbsolutePath();
settings.setProperty(XanitizerSonarQubePlugin.XAN_XML_REPORT_FILE, reportFile);
final ActiveRulesBuilder builder = new ActiveRulesBuilder();
for (GeneratedProblemType problemType : GeneratedProblemType.values()) {
final RuleKey ruleKey = RuleKey.of(XanitizerRulesDefinition.REPOSITORY_KEY,
problemType.name());
final NewActiveRule activeRule = builder.create(ruleKey);
if (problemType.getPresentationName().equals("SQL Injection")) {
activeRule.activate();
}
}
final XanitizerSensor sensor = new XanitizerSensor(mock(JavaResourceLocator.class),
builder.build(), context);
sensor.execute(context);
assertEquals(26, createdIssues);
}
示例15: should_execute_and_save_issues_on_UTF8_with_BOM_file
import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; //导入依赖的package包/类
@Test
public void should_execute_and_save_issues_on_UTF8_with_BOM_file() {
inputFile("my-feature-bom.feature", Charsets.UTF_8);
ActiveRules activeRules = (new ActiveRulesBuilder())
.create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, CommentConventionCheck.class.getAnnotation(Rule.class).key()))
.activate()
.create(RuleKey.of(GherkinRulesDefinition.REPOSITORY_KEY, MissingNewlineAtEndOfFileCheck.class.getAnnotation(Rule.class).key()))
.activate()
.build();
checkFactory = new CheckFactory(activeRules);
createGherkinSquidSensor().execute(context);
assertThat(context.allIssues()).hasSize(3);
}