From 281918aba787280839c9b6899e57309f08077b08 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 31 Jan 2014 18:49:33 +0100 Subject: [PATCH] SONAR-926 Don't index aggregator modules --- .../sonar/batch/scan/filesystem/FileIndex.java | 16 ++++++++++------ .../batch/scan/filesystem/FileIndexTest.java | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 6 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 95b5bdd822c..402621dadef 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 @@ -88,7 +88,7 @@ public class FileIndex implements BatchComponent { private final LanguageRecognizer languageRecognizer; private final InputFileCache fileCache; private final FileHashes fileHashes; - private final Project project; + private final Project module; private final ExclusionFilters exclusionFilters; public FileIndex(List filters, ExclusionFilters exclusionFilters, LanguageRecognizer languageRecognizer, @@ -99,11 +99,15 @@ public class FileIndex implements BatchComponent { this.fileCache = cache; this.fileHashes = fileHashes; this.pathResolver = pathResolver; - this.project = project; + this.module = project; } void index(DefaultModuleFileSystem fileSystem) { Logger logger = LoggerFactory.getLogger(FileIndex.class); + if (!module.getModules().isEmpty()) { + // No indexing for an aggregator module + return; + } logger.info("Index files"); exclusionFilters.logConfiguration(fileSystem); // TODO log configuration too (replace FileSystemLogger) @@ -157,7 +161,7 @@ public class FileIndex implements BatchComponent { Map attributes = Maps.newHashMap(); // paths String resourceKey = PathUtils.sanitize(path); - set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, project.getEffectiveKey() + ":" + resourceKey); + set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, module.getEffectiveKey() + ":" + resourceKey); return DefaultInputDir.create(ioFile, path, attributes); } @@ -193,7 +197,7 @@ public class FileIndex implements BatchComponent { set(attributes, InputFile.ATTRIBUTE_TYPE, type); String resourceKey = PathUtils.sanitize(path); - set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, project.getEffectiveKey() + ":" + resourceKey); + set(attributes, DefaultInputFile.ATTRIBUTE_COMPONENT_KEY, module.getEffectiveKey() + ":" + resourceKey); // hash + status initStatus(file, fileSystem.sourceCharset(), path, attributes); @@ -217,10 +221,10 @@ public class FileIndex implements BatchComponent { set(attributes, DefaultInputFile.ATTRIBUTE_SOURCEDIR_PATH, PathUtils.canonicalPath(src)); set(attributes, DefaultInputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, sourceRelativePath); if (Java.KEY.equals(lang)) { - set(inputFile.attributes(), DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, project.getEffectiveKey() + ":" + set(inputFile.attributes(), DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, module.getEffectiveKey() + ":" + JavaFile.fromRelativePath(sourceRelativePath, false).getDeprecatedKey()); } else { - set(inputFile.attributes(), DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, project.getEffectiveKey() + ":" + sourceRelativePath); + set(inputFile.attributes(), DefaultInputFile.ATTRIBUTE_COMPONENT_DEPRECATED_KEY, module.getEffectiveKey() + ":" + sourceRelativePath); } return; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileIndexTest.java index 93aab799b86..b0c6ed5c763 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileIndexTest.java @@ -24,13 +24,18 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.resources.Project; import org.sonar.api.scan.filesystem.InputDir; +import org.sonar.api.scan.filesystem.InputFile; import org.sonar.api.scan.filesystem.PathResolver; import org.sonar.api.scan.filesystem.internal.DefaultInputDir; import java.io.File; import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class FileIndexTest { @@ -51,4 +56,16 @@ public class FileIndexTest { assertThat(inputDir.file()).isEqualTo(ioFile); assertThat(inputDir.attribute(DefaultInputDir.ATTRIBUTE_COMPONENT_KEY)).isEqualTo("myProject:src/main/java/com/foo"); } + + @Test + public void should_not_index_aggregator() throws Exception { + Project project = new Project("myProject"); + new Project("moduleA").setParent(project); + InputFileCache fileCache = mock(InputFileCache.class); + FileIndex index = new FileIndex(null, null, null, fileCache, null, new PathResolver(), project); + + index.index(null); + + verify(fileCache, never()).put(anyString(), any(InputFile.class)); + } } -- 2.39.5