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,
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)
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);
}
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);
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;
}
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 {
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));
+ }
}