本文整理汇总了Java中org.sonar.api.batch.rule.ActiveRule类的典型用法代码示例。如果您正苦于以下问题:Java ActiveRule类的具体用法?Java ActiveRule怎么用?Java ActiveRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActiveRule类属于org.sonar.api.batch.rule包,在下文中一共展示了ActiveRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
final Integer maximum = Integer.valueOf(rule.param(PARAM_MAXIMUM));
for (final Package<Location> packageToCheck : model.getPackages()) {
final int afferentCoupling = packageToCheck.getUsedByPackages().size();
LOGGER.debug("Package {}: afferent={}", packageToCheck.getName(), afferentCoupling);
if (afferentCoupling > maximum) {
final Set<Class<Location>> classes = selectClassesWithAfferentUsage(packageToCheck.getClasses());
registerIssue(context, settings, rule, packageToCheck, classes,
"Reduce number of packages that use this package (allowed: " + maximum + ", actual: "
+ afferentCoupling + ")");
}
}
}
示例2: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
final Integer maximum = Integer.valueOf(rule.param(PARAM_MAXIMUM));
for (final Package<Location> packageToCheck : model.getPackages()) {
final int efferentCoupling = packageToCheck.getPackageUsages().size();
LOGGER.debug("Package {}: efferent={}", packageToCheck.getName(), efferentCoupling);
if (efferentCoupling > maximum) {
final Set<Class<Location>> classes = selectClassesWithEfferentUsage(packageToCheck.getClasses());
registerIssue(context, settings, rule, packageToCheck, classes,
"Reduce number of packages used by this package (allowed: " + maximum + ", actual: "
+ efferentCoupling + ")");
}
}
}
示例3: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
final Integer maximum = Integer.valueOf(rule.param(PARAM_MAXIMUM));
for (final Package<Location> packageToCheck : model.getPackages()) {
final int afferentCoupling = packageToCheck.getUsedByPackages().size();
final int efferentCoupling = packageToCheck.getPackageUsages().size();
final int totalCoupling = efferentCoupling + afferentCoupling;
final int instability = totalCoupling == 0 ? 0 : (efferentCoupling * 100) / totalCoupling;
LOGGER.debug("Package {}: efferent={}, total={}, instability={}", packageToCheck.getName(),
efferentCoupling, totalCoupling, instability);
if (instability > maximum) {
final Set<Class<Location>> classes = EfferentCouplingRule
.selectClassesWithEfferentUsage(packageToCheck.getClasses());
registerIssue(context, settings, rule, packageToCheck, classes,
"Reduce number of packages used by this package to lower instability (allowed: " + maximum
+ "%, actual: " + instability + "%)");
}
}
}
示例4: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
final Integer maximum = Integer.valueOf(rule.param(PARAM_MAXIMUM));
for (final Package<Location> packageToCheck : model.getPackages()) {
final Set<Class<Location>> classes = packageToCheck.getClasses().stream().filter(Class::isAbstract)
.collect(Collectors.toSet());
final int abstractClasses = classes.size();
final int totalClasses = packageToCheck.getClasses().size();
final int abstractness = totalClasses == 0 ? 0 : (abstractClasses * 100 / totalClasses);
LOGGER.debug("Package {}: abstract={}, total={}, abstractness={}", packageToCheck.getName(),
abstractClasses, totalClasses, abstractness);
if (abstractness > maximum) {
registerIssue(context, settings, rule, packageToCheck, classes,
"Reduce number of abstract classes in this package (allowed: " + maximum + "%, actual: "
+ abstractness + "%)");
}
}
}
示例5: store
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void store(Issue issue) {
InputComponent inputComponent = issue.primaryLocation().inputComponent();
DefaultRule rule = validateRule(issue);
ActiveRule activeRule = activeRules.find(issue.ruleKey());
if (activeRule == null) {
// rule does not exist or is not enabled -> ignore the issue
return;
}
String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message();
org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
String severity = overriddenSeverity != null ? overriddenSeverity.name() : activeRule.severity();
String type = rule.type();
DefaultClientIssue newIssue = new DefaultClientIssue(severity, type, activeRule, rules.find(activeRule.ruleKey()), primaryMessage, issue.primaryLocation().textRange(),
inputComponent.isFile() ? ((SonarLintInputFile) inputComponent).getClientInputFile() : null, issue.flows());
issueListener.handle(newIssue);
}
示例6: writeActiveRules
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
private static void writeActiveRules(StringBuilder sb, Collection<ActiveRule> activeRules) {
for (ActiveRule activeRule : activeRules) {
appendLine(sb, " <Rule>");
appendLine(sb, " <Key>" + escapeXml(activeRule.ruleKey().rule()) + "</Key>");
Map<String, String> parameters = effectiveParameters(activeRule);
if (!parameters.isEmpty()) {
appendLine(sb, " <Parameters>");
for (Entry<String, String> parameter : parameters.entrySet()) {
appendLine(sb, " <Parameter>");
appendLine(sb, " <Key>" + escapeXml(parameter.getKey()) + "</Key>");
appendLine(sb, " <Value>" + escapeXml(parameter.getValue()) + "</Value>");
appendLine(sb, " </Parameter>");
}
appendLine(sb, " </Parameters>");
}
appendLine(sb, " </Rule>");
}
}
示例7: XanitizerSensor
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
/**
* The Xanitizer sensor
*
* @param javaResourceLocator
* @param settings
* @param activeRules
* @param sensorContext
*/
public XanitizerSensor(final JavaResourceLocator javaResourceLocator,
final ActiveRules activeRules, final SensorContext sensorContext) {
this.javaResourceLocator = javaResourceLocator;
for (final ActiveRule activeRule : activeRules.findAll()) {
if (activeRule.ruleKey().repository().equals(XanitizerRulesDefinition.REPOSITORY_KEY)) {
final String ruleAsString = activeRule.ruleKey().rule();
activeXanRuleNames.add(ruleAsString);
}
}
if (activeXanRuleNames.isEmpty()) {
/*
* If no rule is active, we do not need to read the report file
*/
this.reportFile = null;
} else {
this.reportFile = SensorUtil.geReportFile(sensorContext);
}
}
示例8: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public final void scanModel(final SensorContext context, final String language, final Model<Location> model) {
final ActiveRule rule = context.activeRules().find(RuleKey.of(BaseRules.getRepositoryKey(language), ruleKey));
if (rule == null) {
LOGGER.debug("Rule {}:{} is not active", BaseRules.getRepositoryKey(language), ruleKey);
return;
}
scanModel(context, rule, model);
}
示例9: newIssue
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
private boolean newIssue(final SensorContext context, final ActiveRule rule, final External<Location> model,
final String message) {
final Location location = model.getExternal();
if (location == null) {
LOGGER.debug("Rule {} triggered, but {} did not contain a location to register issue", rule.ruleKey(),
model);
return false;
} else {
LOGGER.debug("Rule {} triggered, registering issue on {}", rule.ruleKey(), model);
final NewIssue issue = context.newIssue().forRule(rule.ruleKey());
issue.at(issue.newLocation().on(location.getOn()).at(location.getAt()).message(message));
issue.save();
return true;
}
}
示例10: registerIssue
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
/**
* Register an issue.
*
* @param context
* sensor context
* @param rule
* rule to register issue for
* @param model
* object to register issue on (external location)
* @param message
* message
*/
protected final void registerIssue(final SensorContext context, final Settings settings, final ActiveRule rule,
final Package<Location> modelPackage, final Set<Class<Location>> modelClasses, final String message) {
LOGGER.debug("registerIssue(context={}, settings={}, rule={}, package={}, classes={}, message={}", context,
settings, rule, modelPackage, modelClasses, message);
boolean registered = false;
if (PackageAnalyzerProperties.shouldRegisterOnPackage(settings)
&& newIssue(context, rule, modelPackage, message)) {
registered = true;
}
if (!registered && PackageAnalyzerProperties.shouldRegisterOnClasses(settings) && !modelClasses.isEmpty()) {
if (PackageAnalyzerProperties.shouldRegisterOnAllClasses(settings)) {
for (final Class<Location> modelClass : modelClasses) {
newIssue(context, rule, modelClass, message);
}
} else {
newIssue(context, rule, modelClasses.iterator().next(), message);
}
registered = true;
}
if (!registered) {
LOGGER.warn("Rule {} triggered, but {} did not contain a location to register issues.", rule.ruleKey(),
modelPackage);
}
}
示例11: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
final Integer maximum = Integer.valueOf(rule.param(PARAM_MAXIMUM));
for (final Package<Location> packageToCheck : model.getPackages()) {
final int classcount = packageToCheck.getClasses().size();
LOGGER.debug("Package {}: total={}", packageToCheck.getName(), classcount);
if (classcount > maximum) {
registerIssue(context, settings, rule, packageToCheck, packageToCheck.getClasses(),
"Reduce number of classes in package (allowed: " + maximum + ", actual: " + classcount + ")");
}
}
}
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:16,代码来源:NumberOfClassesAndInterfacesRule.java
示例12: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
for (final Package<Location> packageToCheck : model.getPackages()) {
LOGGER.debug("Package {}: extenal={}", packageToCheck.getExternal());
if (packageToCheck.getExternal() == null) {
for (final Class<Location> classToReport : packageToCheck.getClasses()) {
registerIssue(context, rule, classToReport, "Add a package-info.java to the package.");
}
}
}
}
示例13: scanModel
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
protected void scanModel(SensorContext context, ActiveRule rule, Model<Location> model) {
for (Package<Location> modelPackage : model.getPackages()) {
registerIssue(context, settings, rule, modelPackage, modelPackage.getClasses(), "Issue");
}
}
示例14: DefaultClientIssue
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
public DefaultClientIssue(String severity, @Nullable String type, ActiveRule activeRule, Rule rule, String primaryMessage, @Nullable TextRange textRange,
@Nullable ClientInputFile clientInputFile, List<org.sonar.api.batch.sensor.issue.Issue.Flow> flows) {
super(textRange);
this.severity = severity;
this.type = type;
this.activeRule = activeRule;
this.rule = rule;
this.primaryMessage = primaryMessage;
this.clientInputFile = clientInputFile;
this.flows = flows.stream().map(f -> new DefaultFlow(f.locations())).collect(Collectors.toList());
}
示例15: effectiveParameters
import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
protected static Map<String, String> effectiveParameters(ActiveRule activeRule) {
Map<String, String> builder = new HashMap<>();
for (Entry<String, String> param : activeRule.params().entrySet()) {
builder.put(param.getKey(), param.getValue());
}
return Collections.unmodifiableMap(builder);
}