org.sonar.api.measures.CoreMetrics Java Examples
The following examples show how to use
org.sonar.api.measures.CoreMetrics.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnalysisDetails.java From sonarqube-community-branch-plugin with GNU General Public License v3.0 | 6 votes |
public static String format(QualityGate.Condition condition) { Metric<?> metric = CoreMetrics.getMetric(condition.getMetricKey()); if (metric.getType() == Metric.ValueType.RATING) { return String .format("%s %s (%s %s)", Rating.valueOf(Integer.parseInt(condition.getValue())), metric.getName(), condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is worse than" : "is better than", Rating.valueOf(Integer.parseInt(condition.getErrorThreshold()))); } else if (metric.getType() == Metric.ValueType.PERCENT) { NumberFormat numberFormat = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); return String.format("%s%% %s (%s %s%%)", numberFormat.format(new BigDecimal(condition.getValue())), metric.getName(), condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is greater than" : "is less than", numberFormat.format(new BigDecimal(condition.getErrorThreshold()))); } else { return String.format("%s %s (%s %s)", condition.getValue(), metric.getName(), condition.getOperator() == QualityGate.Operator.GREATER_THAN ? "is greater than" : "is less than", condition.getErrorThreshold()); } }
Example #2
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void analyse2() throws FileNotFoundException { DefaultFileSystem fs = new DefaultFileSystem(TEST_DIR); tester.setFileSystem(fs); DefaultInputFile inputFile = new DefaultInputFile("key", "timeFormatter.lua") .setType(InputFile.Type.MAIN) .setLanguage(Lua.KEY) .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "timeFormatter.lua")))); fs.add(inputFile); sensor.execute(tester); String componentKey = inputFile.key(); assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY_IN_CLASSES).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(59); assertThat(tester.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("0=1;5=0;10=0;20=0;30=0;60=0;90=0"); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("1=0;2=0;4=0;6=0;8=0;10=0;12=0"); assertThat(tester.allIssues()).hasSize(0); }
Example #3
Source File: LOCSensorImpl.java From SonarTsPlugin with MIT License | 6 votes |
@Override public Map<InputFile, Set<Integer>> execute(SensorContext ctx) { HashMap<InputFile, Set<Integer>> toReturn = new HashMap<>(); Iterable<InputFile> affectedFiles = ctx .fileSystem() .inputFiles(ctx.fileSystem().predicates().hasLanguage(TypeScriptLanguage.LANGUAGE_KEY)); for (InputFile inputFile : affectedFiles) { Set<Integer> nonCommentLineNumbers = this.getNonCommentLineNumbers(inputFile); toReturn.put(inputFile, nonCommentLineNumbers); ctx.<Integer>newMeasure().forMetric(CoreMetrics.NCLOC).on(inputFile).withValue(nonCommentLineNumbers.size()).save(); } return toReturn; }
Example #4
Source File: EsqlSensorTest.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
@Test public void should_analyse() { String relativePath = "cpd/Person.esql"; inputFile(relativePath); createSensor().execute(context); String key = "moduleKey:" + relativePath; //assertThat(context.measure(key, CoreMetrics.FILES).value()).isEqualTo(1); //assertThat(context.measure(key, CoreMetrics.LINES).value()).isEqualTo(20); assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(18); assertThat(context.measure(key, CoreMetrics.FUNCTIONS).value()).isEqualTo(1); assertThat(context.measure(key, CoreMetrics.STATEMENTS).value()).isEqualTo(8); assertThat(context.measure(key, CoreMetrics.COMPLEXITY).value()).isEqualTo(7); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(3); }
Example #5
Source File: MetricsVisitor.java From sonar-esql-plugin with Apache License 2.0 | 6 votes |
private void saveLineMetrics(TreeVisitorContext context) { LineVisitor lineVisitor = new LineVisitor(context.getTopTree()); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); saveMetricOnFile(CoreMetrics.NCLOC, lineVisitor.getLinesOfCodeNumber()); CommentLineVisitor commentVisitor = new CommentLineVisitor(context.getTopTree(), ignoreHeaderComments); Set<Integer> commentLines = commentVisitor.getCommentLines(); saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentVisitor.getCommentLineNumber()); FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(this.inputFile); linesOfCode.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, 1)); commentLines.forEach(line -> fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, 1)); Set<Integer> executableLines = new ExecutableLineVisitor(context.getTopTree()).getExecutableLines(); projectExecutableLines.put(inputFile, executableLines); executableLines.stream() .forEach(line -> fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, 1)); fileLinesContext.save(); }
Example #6
Source File: MeasureHolder.java From qualinsight-plugins-sonarqube-badges with GNU Lesser General Public License v3.0 | 6 votes |
/** * Constructs a MeasureHolder from a Measure object. * * @param measure used to retrieve the metric name for which the MeasureHolder is built */ @SuppressWarnings("unchecked") public MeasureHolder(final Measure measure) { final Metric<Serializable> metric = CoreMetrics.getMetric(measure.getMetric()); this.metricName = metric.getName() .replace(" (%)", "") .toLowerCase(); String tempValue = null; if (!measure.hasValue()) { if (measure.hasPeriods()) { final PeriodsValue periods = measure.getPeriods(); final PeriodValue periodValue = periods.getPeriodsValue(0); tempValue = periodValue.getValue(); } } else { tempValue = measure.getValue(); } this.value = tempValue == null ? NA : tempValue + (metric.isPercentageType() ? "%" : ""); }
Example #7
Source File: MetricsVisitor.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void leaveFile(Tree tree) { LinesOfCodeVisitor linesOfCodeVisitor = new LinesOfCodeVisitor(tree); saveMetricOnFile(CoreMetrics.NCLOC, linesOfCodeVisitor.getNumberOfLinesOfCode()); CommentLinesVisitor commentLinesVisitor = new CommentLinesVisitor(tree); saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentLinesVisitor.getNumberOfCommentLines()); StatementsVisitor statementsVisitor = new StatementsVisitor(tree); saveMetricOnFile(CoreMetrics.STATEMENTS, statementsVisitor.getNumberOfStatements()); FunctionsVisitor functionsVisitor = new FunctionsVisitor(tree); saveMetricOnFile(CoreMetrics.FUNCTIONS, functionsVisitor.getNumberOfFunctions()); ClassesVisitor classesVisitor = new ClassesVisitor(tree); saveMetricOnFile(CoreMetrics.CLASSES, classesVisitor.getNumberOfClasses()); }
Example #8
Source File: RubyMetricsSensorTest.java From sonar-ruby-plugin with MIT License | 6 votes |
@Test public void testExecute() { RubyMetricsSensor sensor = new RubyMetricsSensor(); sensor.execute(context); Collection<Measure> measures = context.measures("myProjectKey:test_controller.rb"); assertThat(measures.size()).isEqualTo(3); measures.forEach(measure -> { if (CoreMetrics.NCLOC.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(4); } else if (CoreMetrics.COMMENT_LINES.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(11); } else if (CoreMetrics.CLASSES.equals(measure.metric())) { assertThat(measure.value()).isEqualTo(1); } }); }
Example #9
Source File: AbstractMetricsVisitor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void leaveFile(Tree tree) { LinesOfCodeVisitor linesOfCodeVisitor = new LinesOfCodeVisitor(tree); saveMetricOnFile(CoreMetrics.NCLOC, linesOfCodeVisitor.getNumberOfLinesOfCode()); StatementsVisitor statementsVisitor = new StatementsVisitor(tree); saveMetricOnFile(CoreMetrics.STATEMENTS, statementsVisitor.getNumberOfStatements()); ComplexityInFunctionsVisitor complexityInFunctionsVisitor = new ComplexityInFunctionsVisitor(tree); saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, complexityInFunctionsVisitor.getComplexityInFunctions()); ComplexityVisitor complexityVisitor = new ComplexityVisitor(tree); saveMetricOnFile(CoreMetrics.COMPLEXITY, complexityVisitor.getComplexity()); FunctionsVisitor functionsVisitor = new FunctionsVisitor(tree); saveMetricOnFile(CoreMetrics.FUNCTIONS, functionsVisitor.getNumberOfFunctions()); }
Example #10
Source File: BitbucketServerPullRequestDecorator.java From sonarqube-community-branch-plugin with GNU General Public License v3.0 | 5 votes |
private BigDecimal newDuplication(AnalysisDetails details) { return details.findQualityGateCondition(CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) .filter(condition -> condition.getStatus() != QualityGate.EvaluationStatus.NO_VALUE) .map(QualityGate.Condition::getValue) .map(BigDecimal::new) .orElse(BigDecimal.ZERO); }
Example #11
Source File: MetricsVisitorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void test() { File moduleBaseDir = new File("src/test/resources/metrics/"); SensorContextTester context = SensorContextTester.create(moduleBaseDir); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", "metrics.feature") .setModuleBaseDir(moduleBaseDir.toPath()) .setLanguage("gherkin") .setType(InputFile.Type.MAIN); context.fileSystem().add(inputFile); MetricsVisitor metricsVisitor = new MetricsVisitor(context); TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class); when(treeVisitorContext.getFile()).thenReturn(inputFile.file()); when(treeVisitorContext.getTopTree()).thenReturn((GherkinDocumentTree) GherkinParserBuilder.createTestParser(Charsets.UTF_8).parse(inputFile.file())); metricsVisitor.scanTree(treeVisitorContext); String componentKey = "moduleKey:metrics.feature"; assertThat(context.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(22); assertThat(context.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(10); assertThat(context.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(2); assertThat(context.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(4); assertThat(context.measure(componentKey, CoreMetrics.CLASSES).value()).isEqualTo(1); }
Example #12
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void assertMeasure(String key) { assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(9); assertThat(context.measure(key, CoreMetrics.STATEMENTS).value()).isEqualTo(6); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(2); assertThat(context.measure(key, CoreMetrics.FUNCTIONS).value()).isEqualTo(2); assertThat(context.measure(key, CoreMetrics.CLASSES).value()).isEqualTo(1); }
Example #13
Source File: GherkinSquidSensorTest.java From sonar-gherkin-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void assertMeasureFr(String key) { assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(10); assertThat(context.measure(key, CoreMetrics.STATEMENTS).value()).isEqualTo(6); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(2); assertThat(context.measure(key, CoreMetrics.FUNCTIONS).value()).isEqualTo(2); assertThat(context.measure(key, CoreMetrics.CLASSES).value()).isEqualTo(1); }
Example #14
Source File: ComplexityVisitor.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Override public void fillContext(SensorContext sensorContext, AntlrContext antrlContext) { final InputFile file = antrlContext.getFile(); synchronized (sensorContext) { try { sensorContext.<Integer>newMeasure().on(file).forMetric(CoreMetrics.COGNITIVE_COMPLEXITY) .withValue(complexity).save(); } catch (final Throwable e) { LOGGER.warn(format("Unexpected adding cognitive complexity measures on file %s", file.absolutePath()), e); } } }
Example #15
Source File: CComplexityVisitor.java From sonar-tsql-plugin with GNU General Public License v3.0 | 5 votes |
@Override public void fillContext(SensorContext sensorContext, AntlrContext antrlContext) { final InputFile file = antrlContext.getFile(); synchronized (sensorContext) { try { sensorContext.<Integer>newMeasure().on(file).forMetric(CoreMetrics.COMPLEXITY).withValue(complexity) .save(); } catch (final Throwable e) { LOGGER.warn(format("Unexpected adding complexity measures on file %s", file.absolutePath()), e); } } }
Example #16
Source File: MetricsSaver.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
public static void saveLineLevelMeasures(InputFile inputFile, HtmlSourceCode htmlSourceCode, FileLinesContextFactory fileLinesContextFactory) { FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile); final int lineContainsCode = 1; for (Integer line : htmlSourceCode.getDetailedLinesOfCode()) { fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, lineContainsCode); } fileLinesContext.save(); }
Example #17
Source File: MeasureHolder.java From qualinsight-plugins-sonarqube-badges with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructs a MeasureHolder from a metric key. * * @param metricKey key used to retrieve the metric name for which the MeasureHolder is built */ public MeasureHolder(final String metricKey) { try { this.metricName = CoreMetrics.getMetric(metricKey) .getName() .replace(" (%)", "") .toLowerCase(); } catch (final NoSuchElementException e) { LOGGER.debug("Metric '{}' is not referenced in CoreMetrics.", metricKey, e); this.metricName = metricKey; } this.value = NA; }
Example #18
Source File: MetricsVisitor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void saveCounterMetrics(TreeVisitorContext context) { CounterVisitor counter = new CounterVisitor(context.getTopTree()); saveMetricOnFile(CoreMetrics.FUNCTIONS, counter.getFunctionsNumber()); saveMetricOnFile(CoreMetrics.STATEMENTS, counter.getStatementsNumber()); saveMetricOnFile(EsqlMetrics.MODULES, counter.getModulesNumber()); saveMetricOnFile(EsqlMetrics.PROCEDURES, counter.getProceduresNumber()); }
Example #19
Source File: MetricsVisitor.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
private void saveComplexityMetrics(TreeVisitorContext context) { int fileComplexity = new ComplexityVisitor().getComplexity(context.getTopTree()); saveMetricOnFile(CoreMetrics.COMPLEXITY, fileComplexity); saveMetricOnFile(EsqlMetrics.MODULE_COMPLEXITY, moduleComplexity); saveMetricOnFile(CoreMetrics.COMPLEXITY_IN_FUNCTIONS, functionComplexity); sensorContext.<String>newMeasure().on(inputFile).forMetric(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) .withValue(functionComplexityDistribution.build()).save(); fileComplexityDistribution.add(fileComplexity); sensorContext.<String>newMeasure().on(inputFile).forMetric(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION) .withValue(fileComplexityDistribution.build()).save(); }
Example #20
Source File: CssMetricsVisitor.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void leaveFile(Tree tree) { super.leaveFile(tree); CommentLinesVisitor commentLinesVisitor = new CommentLinesVisitor(tree, new CssCommentAnalyser()); saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentLinesVisitor.getNumberOfCommentLines()); noSonarFilter.noSonarInFile(inputFile, commentLinesVisitor.getNoSonarLines()); }
Example #21
Source File: MetricsVisitorTest.java From sonar-esql-plugin with Apache License 2.0 | 5 votes |
@Test public void test() { MetricsVisitor metricsVisitor = createMetricsVisitor(); metricsVisitor.scanTree(treeVisitorContext); assertThat(context.measure(COMPONENT_KEY, CoreMetrics.FUNCTIONS).value()).isEqualTo(0); assertThat(context.measure(COMPONENT_KEY, CoreMetrics.STATEMENTS).value()).isEqualTo(1); assertThat(context.measure(COMPONENT_KEY, EsqlMetrics.MODULES).value()).isEqualTo(1); assertThat(metricsVisitor.executableLines().get(INPUT_FILE)).containsOnly(5); }
Example #22
Source File: BitbucketServerPullRequestDecorator.java From sonarqube-community-branch-plugin with GNU General Public License v3.0 | 5 votes |
private BigDecimal newCoverage(AnalysisDetails details) { return details.findQualityGateCondition(CoreMetrics.NEW_COVERAGE_KEY) .filter(condition -> condition.getStatus() != QualityGate.EvaluationStatus.NO_VALUE) .map(QualityGate.Condition::getValue) .map(BigDecimal::new) .orElse(BigDecimal.ZERO); }
Example #23
Source File: LOCSensorImplTest.java From SonarTsPlugin with MIT License | 5 votes |
private void assertLineCount(String testName, Integer expected) throws FileNotFoundException { DefaultInputFile resource = resource("src/test/resources/loc/" + testName + ".txt"); this.sensorContext.fileSystem().add(resource); this.sensor.execute(this.sensorContext); assertEquals(expected, this.sensorContext.measure(resource.key(), CoreMetrics.NCLOC).value()); }
Example #24
Source File: FileLinesVisitor.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void leaveFile(AstNode astNode) { FileLinesContext fileLinesContext = fileLinesContextFactory.createFor( fileSystem.inputFile(fileSystem.predicates().hasAbsolutePath(getContext().getFile().getAbsolutePath()))); int fileLength = getContext().peekSourceCode().getInt(LuaMetric.LINES); for (int line = 1; line <= fileLength; line++) { fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, linesOfCode.contains(line) ? 1 : 0); fileLinesContext.setIntValue(CoreMetrics.COMMENT_LINES_DATA_KEY, line, linesOfComments.contains(line) ? 1 : 0); } fileLinesContext.save(); linesOfCode.clear(); linesOfComments.clear(); }
Example #25
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
private static void saveMeasures(SensorContext context, InputFile inputFile, SourceFile squidFile) { context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.NCLOC) .withValue(squidFile.getInt(LuaMetric.LINES_OF_CODE)) .save(); context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.CLASSES) .withValue(squidFile.getInt(LuaMetric.TABLECONSTRUCTORS)) .save(); context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.COMMENT_LINES) .withValue(squidFile.getInt(LuaMetric.COMMENT_LINES)) .save(); context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.FUNCTIONS) .withValue(squidFile.getInt(LuaMetric.FUNCTIONS)) .save(); context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.STATEMENTS) .withValue(squidFile.getInt(LuaMetric.STATEMENTS)) .save(); context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.COMPLEXITY) .withValue(squidFile.getInt(LuaMetric.COMPLEXITY)) .save(); }
Example #26
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
private void saveClassComplexity(SensorContext context, InputFile inputFile, SourceFile squidFile) { Collection<SourceCode> classes = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceClass.class)); int complexityInClasses = 0; for (SourceCode squidClass : classes) { int classComplexity = squidClass.getInt(LuaMetric.COMPLEXITY); complexityInClasses += classComplexity; } context.<Integer>newMeasure() .on(inputFile) .forMetric(CoreMetrics.COMPLEXITY_IN_CLASSES) .withValue(complexityInClasses) .save(); }
Example #27
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
private void saveFunctionsComplexityDistribution(SensorContext context, InputFile inputFile, SourceFile squidFile) { Collection<SourceCode> squidFunctionsInFile = scanner.getIndex().search(new QueryByParent(squidFile), new QueryByType(SourceFunction.class)); RangeDistributionBuilder complexityDistribution = new RangeDistributionBuilder(FUNCTIONS_DISTRIB_BOTTOM_LIMITS); for (SourceCode squidFunction : squidFunctionsInFile) { complexityDistribution.add(squidFunction.getDouble(LuaMetric.COMPLEXITY)); } context.<String>newMeasure() .on(inputFile) .forMetric(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION) .withValue(complexityDistribution.build()) .save(); }
Example #28
Source File: LuaSquidSensor.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
private static void saveFilesComplexityDistribution(SensorContext context, InputFile inputFile, SourceFile squidFile) { String distribution = new RangeDistributionBuilder(FILES_DISTRIB_BOTTOM_LIMITS) .add(squidFile.getDouble(LuaMetric.COMPLEXITY)) .build(); context.<String>newMeasure() .on(inputFile) .forMetric(CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION) .withValue(distribution) .save(); }
Example #29
Source File: LuaSquidSensorTest.java From sonar-lua with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void analyse() throws FileNotFoundException { DefaultFileSystem fs = new DefaultFileSystem(TEST_DIR); tester.setFileSystem(fs); DefaultInputFile inputFile = new DefaultInputFile("key", "smallFile.lua") .setType(InputFile.Type.MAIN) .setLanguage(Lua.KEY) .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "smallFile.lua")))); fs.add(inputFile); inputFile = new DefaultInputFile("key", "bom.lua") .setType(InputFile.Type.MAIN) .setLanguage(Lua.KEY) .initMetadata(new FileMetadata().readMetadata(new FileReader(new File(TEST_DIR, "bom.lua")))); fs.add(inputFile); sensor.execute(tester); String componentKey = "key:smallFile.lua"; assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY_IN_CLASSES).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.NCLOC).value()).isEqualTo(4); assertThat(tester.measure(componentKey, CoreMetrics.COMMENT_LINES).value()).isEqualTo(1); assertThat(tester.measure(componentKey, CoreMetrics.STATEMENTS).value()).isEqualTo(0); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTIONS).value()).isEqualTo(3); assertThat(tester.measure(componentKey, CoreMetrics.COMPLEXITY).value()).isEqualTo(4); assertThat(tester.measure(componentKey, CoreMetrics.FILE_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("0=1;5=0;10=0;20=0;30=0;60=0;90=0"); assertThat(tester.measure(componentKey, CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION).value()).isEqualTo("1=2;2=0;4=1;6=0;8=0;10=0;12=0"); }
Example #30
Source File: LessAnalyzerSensorTest.java From sonar-css-plugin with GNU Lesser General Public License v3.0 | 5 votes |
private void assertMeasures(String key) { assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(17); assertThat(context.measure(key, CoreMetrics.STATEMENTS).value()).isEqualTo(11); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(5); assertThat(context.measure(key, CoreMetrics.STATEMENTS).value()).isEqualTo(11); assertThat(context.measure(key, CoreMetrics.FUNCTIONS).value()).isEqualTo(6); assertThat(context.measure(key, CoreMetrics.COMPLEXITY).value()).isEqualTo(7); assertThat(context.measure(key, CoreMetrics.COMPLEXITY_IN_FUNCTIONS).value()).isEqualTo(7); }