• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ActiveRule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.sonar.api.batch.rule.ActiveRule的典型用法代码示例。如果您正苦于以下问题:Java ActiveRule类的具体用法?Java ActiveRule怎么用?Java ActiveRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ActiveRule类属于org.sonar.api.batch.rule包,在下文中一共展示了ActiveRule类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 + ")");
		}
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:19,代码来源:AfferentCouplingRule.java


示例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 + ")");
		}
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:19,代码来源:EfferentCouplingRule.java


示例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 + "%)");
		}
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:24,代码来源:InstabilityRule.java


示例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 + "%)");
		}
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:22,代码来源:AbstractnessRule.java


示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:21,代码来源:DefaultSensorStorage.java


示例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>");
  }
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:19,代码来源:AnalysisInputXml.java


示例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);
	}
}
 
开发者ID:RIGS-IT,项目名称:sonar-xanitizer,代码行数:28,代码来源:XanitizerSensor.java


示例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);
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:11,代码来源:AbstractPackageAnalyzerRule.java


示例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;
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:16,代码来源:AbstractPackageAnalyzerRule.java


示例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);
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:40,代码来源:AbstractPackageAnalyzerRule.java


示例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.");
			}
		}
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:13,代码来源:MissingPackageInfoRule.java


示例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");
	}

}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:8,代码来源:AbstractPackageAnalyzerRuleTest.java


示例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());
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:12,代码来源:DefaultClientIssue.java


示例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);
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:10,代码来源:AnalysisInputXml.java


示例16: generate

import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
public static String generate(boolean includeSettings, boolean ignoreHeaderComments, boolean includeRules,
                              SensorContext context, String repositoryKey, String languageKey, String sourceEncoding) {
  StringBuilder sb = new StringBuilder();

  appendLine(sb, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  appendLine(sb, "<AnalysisInput>");

  if (includeSettings) {
    appendLine(sb, "  <Settings>");
    appendLine(sb, "    <Setting>");
    appendLine(sb, "      <Key>sonar." + languageKey + ".ignoreHeaderComments</Key>");
    appendLine(sb, "      <Value>" + (ignoreHeaderComments ? "true" : "false") + "</Value>");
    appendLine(sb, "    </Setting>");
    appendLine(sb, "    <Setting>");
    appendLine(sb, "      <Key>sonar.sourceEncoding</Key>");
    appendLine(sb, "      <Value>" + sourceEncoding + "</Value>");
    appendLine(sb, "    </Setting>");
    appendLine(sb, "  </Settings>");
  }

  appendLine(sb, "  <Rules>");
  if (includeRules) {
    Collection<ActiveRule> activeRules = context.activeRules().findByRepository(repositoryKey);
    writeActiveRules(sb, activeRules);
  }
  appendLine(sb, "  </Rules>");

  appendLine(sb, "  <Files>");
  for (File file : filesToAnalyze(context.fileSystem(), languageKey)) {
    appendLine(sb, "    <File>" + escapeXml(file.getAbsolutePath()) + "</File>");
  }
  appendLine(sb, "  </Files>");

  appendLine(sb, "</AnalysisInput>");

  return sb.toString();
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:38,代码来源:AnalysisInputXml.java


示例17: scanModel

import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
@Override
public void scanModel(final SensorContext context, final ActiveRule rule, final Model<Location> model) {
	// Analyze
	final Analyzer<Location> analyzer = new Analyzer<>();
	final List<PackageCycle<Location>> packageCycles = analyzer.findPackageCycles(model);
	LOGGER.debug("Package cycles: {}", packageCycles.size());

	int packageCycleIdentifier = 0;
	final Map<Package<Location>, StringBuilder> identifierMeasures = new HashMap<>();

	// Rule
	for (final PackageCycle<Location> packageCycle : packageCycles) {
		packageCycleIdentifier++;

		final List<Package<Location>> packagesInCycle = packageCycle.getPackagesInCycle();
		for (int packageInCycleIndex = 0; packageInCycleIndex < packagesInCycle.size(); packageInCycleIndex++) {
			final Package<Location> packageInCycle = packagesInCycle.get(packageInCycleIndex);
			final int nextPackageInCycleIndex = packageInCycleIndex + 1;
			final Package<Location> nextPackageInCycle = packagesInCycle
					.get(nextPackageInCycleIndex == packagesInCycle.size() ? 0 : nextPackageInCycleIndex);

			if (identifierMeasures.containsKey(packageInCycle)) {
				identifierMeasures.get(packageInCycle).append(",").append(Integer.toString(packageCycleIdentifier));
			} else {
				identifierMeasures.put(packageInCycle, new StringBuilder(Integer.toString(packageCycleIdentifier)));
			}

			final String message = formatMessage(packageCycle, packageInCycle);

			// Only select classes that use the 'next' package
			final Set<Class<Location>> classes = selectClasses(packageInCycle.getClasses(), nextPackageInCycle);

			registerIssue(context, settings, rule, packageInCycle, classes, message);
		}
	}

	// Measures
	for (final Map.Entry<Package<Location>, StringBuilder> measure : identifierMeasures.entrySet()) {
		registerMeasure(context, PackageAnalyzerMetrics.PACKAGE_DEPENDENCY_CYCLES_IDENTIFIER, measure.getKey(),
				measure.getValue().toString());
	}
}
 
开发者ID:willemsrb,项目名称:sonar-packageanalyzer-plugin,代码行数:43,代码来源:PackageDependencyCyclesRule.java


示例18: createSpellCheckIssues

import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
private void createSpellCheckIssues(SensorContext sensorContext, InputFile inputFile, Feature feature) throws IOException {

    // TODO: Don't hardcode the ruleKey
    RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "SpellCheck");

    ActiveRule activeRule = sensorContext.activeRules().find(ruleKey);
    if (activeRule == null) {
      LOG.debug("SpellCheck rule is deactivated. RuleKey: " + ruleKey);
      return;
    }

    List<ScenarioDefinition> scenarioDefinitions = feature.getChildren();

    String featureLanguage = feature.getLanguage();
    if ("en".equals(featureLanguage)) {
      featureLanguage = "en-US";
    }

    Language language = Languages.getLanguageForShortName(featureLanguage);
    JLanguageTool langTool = new JLanguageTool(language);


    String disabledRules = activeRule.param("disabledRules");
    String[] disabledRulesArray = new String[0];

    if (disabledRules != null) {
      disabledRulesArray = disabledRules.split(",");
    }

    for (String disabledRuleKey : disabledRulesArray) {
      langTool.disableRule(disabledRuleKey);
    }

    checkNodeSpelling(sensorContext, inputFile, langTool, feature, feature.getName());
    checkNodeSpelling(sensorContext, inputFile, langTool, feature, feature.getDescription());

    for (ScenarioDefinition scenario: scenarioDefinitions ) {
      checkNodeSpelling(sensorContext, inputFile, langTool, scenario, scenario.getName());

      List<Step> steps = scenario.getSteps();
      for (Step step : steps) {
        checkNodeSpelling(sensorContext, inputFile, langTool, step, step.getText());
      }
    }

  }
 
开发者ID:silverbulleters,项目名称:sonar-gherkin,代码行数:47,代码来源:GherkinSquidSensor.java


示例19: createParserErrorIssue

import org.sonar.api.batch.rule.ActiveRule; //导入依赖的package包/类
private void createParserErrorIssue(SensorContext sensorContext, InputFile inputFile, ParserException pe) {
  RuleKey ruleKey = RuleKey.of(GherkinRulesDefinition.REPOSITORY_NAME, "ParserError");

  ActiveRule activeRule = sensorContext.activeRules().find(ruleKey);
  if (activeRule == null) {
    LOG.debug("Parser Error rule is deactivated. RuleKey: " + ruleKey);
    return;
  }

  TextRange textRange = inputFile.newRange(1,1,1,1);
  //TODO Parser error message contains an address - add it


  NewIssue newIssue = sensorContext.newIssue();

  NewIssueLocation primaryLocation = newIssue.newLocation()
          .message(pe.getMessage())
          .on(inputFile)
          .at(textRange);

  newIssue.forRule(ruleKey).at(primaryLocation);
  newIssue.save();


}
 
开发者ID:silverbulleters,项目名称:sonar-gherkin,代码行数:26,代码来源:GherkinSquidSensor.java



注:本文中的org.sonar.api.batch.rule.ActiveRule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SwipeItemMangerInterface类代码示例发布时间:2022-05-22
下一篇:
Java HtmlTableRow类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap