diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 14:04:55 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-10-10 14:04:55 +0200 |
commit | 71d0fab1ebb6082bb0178da61c6b73e51e651b1f (patch) | |
tree | 708459aa31941b22b01e02ab36182cf9420e8d11 /sonar-batch | |
parent | e108f5de333cf36aff978aa03940590f9caca9fc (diff) | |
download | sonarqube-71d0fab1ebb6082bb0178da61c6b73e51e651b1f.tar.gz sonarqube-71d0fab1ebb6082bb0178da61c6b73e51e651b1f.zip |
SONAR-3677 fix re-indexation of files
Diffstat (limited to 'sonar-batch')
3 files changed, 22 insertions, 13 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java index f27abed0145..944bf3d973f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java @@ -35,6 +35,7 @@ import org.sonar.api.scan.filesystem.ModuleFileSystem; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.scan.filesystem.internal.DefaultInputFile; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.io.File; import java.nio.charset.Charset; @@ -84,7 +85,7 @@ public class FileIndex implements BatchComponent { logger.info("Index files"); // TODO log configuration too (replace FileSystemLogger) - IndexStatus status = new IndexStatus(cache.filePathsOfModule(fileSystem.moduleKey())); + IndexStatus status = new IndexStatus(cache.fileRelativePaths(fileSystem.moduleKey())); for (File sourceDir : fileSystem.sourceDirs()) { indexDirectory(fileSystem, status, sourceDir, InputFile.TYPE_SOURCE); @@ -111,31 +112,34 @@ public class FileIndex implements BatchComponent { for (File file : files) { String relativePath = pathResolver.relativePath(fileSystem.baseDir(), file); if (!cache.containsFile(fileSystem.moduleKey(), relativePath)) { - InputFile input = newInputFile(fileSystem, sourceDir, type, file); - if (accept(input)) { + InputFile input = newInputFile(fileSystem, sourceDir, type, file, relativePath); + if (input != null && accept(input)) { cache.put(fileSystem.moduleKey(), input); - status.markAsIndexed(relativePath); } } + status.markAsIndexed(relativePath); } } + @CheckForNull + private InputFile newInputFile(ModuleFileSystem fileSystem, File sourceDir, String type, File file, String baseRelativePath) { + // File extension must be kept case-sensitive + String extension = FilenameUtils.getExtension(file.getName()); + String lang = languageRecognizer.ofExtension(extension); + if (lang == null) { + return null; + } - private InputFile newInputFile(ModuleFileSystem fileSystem, File sourceDir, String type, File file) { try { Map<String, String> attributes = Maps.newHashMap(); + set(attributes, InputFile.ATTRIBUTE_EXTENSION, extension); set(attributes, InputFile.ATTRIBUTE_TYPE, type); + set(attributes, InputFile.ATTRIBUTE_LANGUAGE, lang); // paths - String baseRelativePath = pathResolver.relativePath(fileSystem.baseDir(), file); set(attributes, InputFile.ATTRIBUTE_SOURCEDIR_PATH, FilenameUtils.normalize(sourceDir.getCanonicalPath(), true)); set(attributes, InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, pathResolver.relativePath(sourceDir, file)); - // File extension must be kept case-sensitive - String extension = FilenameUtils.getExtension(file.getName()); - set(attributes, InputFile.ATTRIBUTE_EXTENSION, extension); - set(attributes, InputFile.ATTRIBUTE_LANGUAGE, languageRecognizer.ofExtension(extension)); - // hash + status initStatus(file, fileSystem.sourceCharset(), baseRelativePath, attributes); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileCache.java index 75be9ad4643..bdae94fb996 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/InputFileCache.java @@ -57,7 +57,7 @@ public class InputFileCache implements BatchComponent { return cache.allValues(); } - public Set<String> filePathsOfModule(String moduleKey) { + public Set<String> fileRelativePaths(String moduleKey) { return cache.keySet(moduleKey); } @@ -66,7 +66,7 @@ public class InputFileCache implements BatchComponent { } public InputFileCache put(String moduleKey, InputFile file) { - cache.put(moduleKey, file.path(), file); + cache.put(moduleKey, file.relativePath(), file); return this; } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java index 3aca556e9c1..3b576e8a3fc 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileCacheTest.java @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.sonar.api.scan.filesystem.InputFile; import org.sonar.api.scan.filesystem.internal.DefaultInputFile; import org.sonar.batch.index.Caches; @@ -56,6 +57,10 @@ public class InputFileCacheTest { assertThat(cache.byModule("struts")).hasSize(1); assertThat(cache.byModule("struts-core")).hasSize(1); assertThat(cache.all()).hasSize(2); + for (InputFile inputFile : cache.all()) { + assertThat(inputFile.relativePath()).startsWith("src/main/java"); + } + assertThat(cache.fileRelativePaths("struts-core")).containsOnly("src/main/java/Foo.java"); cache.removeModule("struts"); assertThat(cache.byModule("struts")).hasSize(0); |