diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-07 14:56:25 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-07 14:57:04 +0200 |
commit | fa3100e005c2fc3884ae6cce708129b71830fe91 (patch) | |
tree | cc063979da9cf26c6df99e920dcce937e075d117 /sonar-plugin-api | |
parent | 3dbfee3fe1e9d2d5f2f25135e8633377b09dd541 (diff) | |
download | sonarqube-fa3100e005c2fc3884ae6cce708129b71830fe91.tar.gz sonarqube-fa3100e005c2fc3884ae6cce708129b71830fe91.zip |
SONAR-6253 Add lines count in report
Diffstat (limited to 'sonar-plugin-api')
3 files changed, 8 insertions, 28 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java index 83b4473fbea..4f89a1c0dd3 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java @@ -51,7 +51,6 @@ public class DefaultInputFile implements InputFile { private String hash; private int nonBlankLines; private int[] originalLineOffsets; - private boolean empty; public DefaultInputFile(String moduleKey, String relativePath) { this.moduleKey = moduleKey; @@ -195,15 +194,6 @@ public class DefaultInputFile implements InputFile { return this; } - public boolean isEmpty() { - return this.empty; - } - - public DefaultInputFile setEmpty(boolean empty) { - this.empty = empty; - return this; - } - @Override public TextPointer newPointer(int line, int lineOffset) { DefaultTextPointer textPointer = new DefaultTextPointer(line, lineOffset); @@ -261,7 +251,6 @@ public class DefaultInputFile implements InputFile { this.setNonBlankLines(metadata.nonBlankLines); this.setHash(metadata.hash); this.setOriginalLineOffsets(metadata.originalLineOffsets); - this.setEmpty(metadata.empty); return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java index d6ef257afa8..40a0cb87d89 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java @@ -66,8 +66,7 @@ public class FileMetadata implements BatchComponent { } private static class LineCounter extends CharHandler { - private boolean empty = true; - private int lines = 1; + private int lines = 0; private int nonBlankLines = 0; private boolean blankLine = true; boolean alreadyLoggedInvalidCharacter = false; @@ -81,7 +80,9 @@ public class FileMetadata implements BatchComponent { @Override void handleAll(char c) { - this.empty = false; + if (this.lines == 0) { + this.lines = 1; + } if (!alreadyLoggedInvalidCharacter && c == '\ufffd') { LOG.warn("Invalid character encountered in file {} at line {} for encoding {}. Please fix file content or configure the encoding to be used using property '{}'.", file, lines, encoding, CoreProperties.ENCODING_PROPERTY); @@ -120,9 +121,6 @@ public class FileMetadata implements BatchComponent { return nonBlankLines; } - public boolean isEmpty() { - return empty; - } } private static class FileHashComputer extends CharHandler { @@ -229,8 +227,7 @@ public class FileMetadata implements BatchComponent { LineOffsetCounter lineOffsetCounter = new LineOffsetCounter(); readFile(file, encoding, lineCounter, fileHashComputer, lineOffsetCounter); return new Metadata(lineCounter.lines(), lineCounter.nonBlankLines(), fileHashComputer.getHash(), lineOffsetCounter.getOriginalLineOffsets(), - lineOffsetCounter.getLastValidOffset(), - lineCounter.isEmpty()); + lineOffsetCounter.getLastValidOffset()); } /** @@ -246,8 +243,7 @@ public class FileMetadata implements BatchComponent { throw new IllegalStateException("Should never occurs", e); } return new Metadata(lineCounter.lines(), lineCounter.nonBlankLines(), fileHashComputer.getHash(), lineOffsetCounter.getOriginalLineOffsets(), - lineOffsetCounter.getLastValidOffset(), - lineCounter.isEmpty()); + lineOffsetCounter.getLastValidOffset()); } private static void readFile(File file, Charset encoding, CharHandler... handlers) { @@ -304,13 +300,11 @@ public class FileMetadata implements BatchComponent { final String hash; final int[] originalLineOffsets; final int lastValidOffset; - final boolean empty; - private Metadata(int lines, int nonBlankLines, String hash, List<Integer> originalLineOffsets, int lastValidOffset, boolean empty) { + private Metadata(int lines, int nonBlankLines, String hash, List<Integer> originalLineOffsets, int lastValidOffset) { this.lines = lines; this.nonBlankLines = nonBlankLines; this.hash = hash; - this.empty = empty; this.originalLineOffsets = Ints.toArray(originalLineOffsets); this.lastValidOffset = lastValidOffset; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java index 7696c1afcbf..93f3a8e57d7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java @@ -55,12 +55,11 @@ public class FileMetadataTest { FileUtils.touch(tempFile); FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8); - assertThat(metadata.lines).isEqualTo(1); + assertThat(metadata.lines).isEqualTo(0); assertThat(metadata.nonBlankLines).isEqualTo(0); assertThat(metadata.hash).isNotEmpty(); assertThat(metadata.originalLineOffsets).containsOnly(0); assertThat(metadata.lastValidOffset).isEqualTo(0); - assertThat(metadata.empty).isTrue(); } @Test @@ -74,7 +73,6 @@ public class FileMetadataTest { assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz")); assertThat(metadata.originalLineOffsets).containsOnly(0, 5, 10); assertThat(metadata.lastValidOffset).isEqualTo(13); - assertThat(metadata.empty).isFalse(); } @Test @@ -263,7 +261,6 @@ public class FileMetadataTest { assertThat(metadata.lines).isEqualTo(135); assertThat(metadata.nonBlankLines).isEqualTo(134); assertThat(metadata.hash).isNotEmpty(); - assertThat(metadata.empty).isFalse(); assertThat(logTester.logs(LoggerLevel.WARN).get(0)).contains("Invalid character encountered in file"); assertThat(logTester.logs(LoggerLevel.WARN).get(0)).contains( |