]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 Don't index aggregator modules
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 31 Jan 2014 17:49:33 +0000 (18:49 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 31 Jan 2014 17:55:26 +0000 (18:55 +0100)
sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileIndex.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileIndexTest.java

index 95b5bdd822cde48d14b20c808ba52bb24bf0754b..402621dadef1aa380e4cd0e4274c2df4ff2a895b 100644 (file)
@@ -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<InputFileFilter> 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<String, String> 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;
       }
index 93aab799b864b701bc354f68657c1d77437c02f0..b0c6ed5c7632a4916b50572f1ca52a6470d0a342 100644 (file)
@@ -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));
+  }
 }