Skip to content

Commit

Permalink
Simplification for CoreMetrics save
Browse files Browse the repository at this point in the history
  • Loading branch information
nbihan-mediware committed Feb 6, 2019
1 parent f7c76ed commit 10dd4e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ private void metricsLinesCounter(InputFile inputFile, SensorContext context) thr
int commentLines = 0;
int blankLines = 0;
int lines = 0;
Metric metricLinesOfCode = CoreMetrics.NCLOC;
Metric metricLines = CoreMetrics.LINES;
Metric metricCommentLines = CoreMetrics.COMMENT_LINES;
if(inputFile==null){
return;
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputFile.inputStream()))) {
if (inputFile.inputStream() != null) {
Expand All @@ -166,10 +160,9 @@ private void metricsLinesCounter(InputFile inputFile, SensorContext context) thr
}
}
}

context.newMeasure().forMetric(metricCommentLines).on(inputFile).withValue(commentLines).save();
context.newMeasure().forMetric(metricLinesOfCode).on(inputFile).withValue(lines-blankLines-commentLines).save();
context.newMeasure().forMetric(metricLines).on(inputFile).withValue(lines).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.COMMENT_LINES).on(inputFile).withValue(commentLines).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.NCLOC).on(inputFile).withValue(lines-blankLines-commentLines).save();
context.<Integer>newMeasure().forMetric(CoreMetrics.LINES).on(inputFile).withValue(lines).save();
}

}
Expand Down
16 changes: 6 additions & 10 deletions src/test/java/com/wellsky/ColdfusionSensorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ColdfusionSensorTest {
public TemporaryFolder tmpFolder = new TemporaryFolder();

@Test
public void testBasicCFMAnalysis() throws IOException {
public void testBasicCFMAnalysis() {
DefaultFileSystem fileSystem = new DefaultFileSystem(tmpFolder.getRoot());
fileSystem.setEncoding(Charsets.UTF_8);
fileSystem.setWorkDir(tmpFolder.getRoot().toPath());
Expand All @@ -66,17 +66,13 @@ public void testBasicCFMAnalysis() throws IOException {
sensor.execute(context);

Integer nloc = 0;
Integer comments = 0;
for (InputFile o : context.fileSystem().inputFiles()) {
Measure<Integer> measureNloc = context.measure(o.key(),CoreMetrics.NCLOC.key());
Measure<Integer> measureComment = context.measure(o.key(),CoreMetrics.COMMENT_LINES.key());
nloc+=measureNloc.value();
comments+=measureComment.value();
for (InputFile inputFile : context.fileSystem().inputFiles()) {
Measure<Integer> measureNloc = context.measure(inputFile.key(),CoreMetrics.NCLOC);
if(measureNloc!=null) {
nloc += measureNloc.value();
}
}

assertThat(nloc).isEqualTo(36);
assertThat(comments).isEqualTo(9);

}

private void addFilesToFs() {
Expand Down

0 comments on commit 10dd4e5

Please sign in to comment.