/** * Testing purposes only! */ public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) { this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(), new SensorStrategy()); }
public DefaultInputFile build() { Path absolutePath = moduleBaseDir.resolve(relativePath); if (projectBaseDir == null) { projectBaseDir = moduleBaseDir; } String projectRelativePath = projectBaseDir.relativize(absolutePath).toString(); DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, projectKey, projectRelativePath, relativePath, type, language, id, new SensorStrategy()); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(new Metadata(lines, nonBlankLines, hash, originalLineStartOffsets, originalLineEndOffsets, lastValidOffset)), contents); inputFile.setStatus(status); inputFile.setCharset(charset); inputFile.setPublished(publish); return inputFile; }
@Before public void prepare() throws IOException { baseDir = temp.newFolder().toPath(); sensorStrategy = new SensorStrategy(); indexedFile = new DefaultIndexedFile(baseDir.resolve(PROJECT_RELATIVE_PATH), "ABCDE", PROJECT_RELATIVE_PATH, MODULE_RELATIVE_PATH, InputFile.Type.TEST, "php", 0, sensorStrategy); }
@Test public void should_find_module_components_with_non_global_strategy() { InputComponentStore inputComponentStore = mock(InputComponentStore.class); SensorStrategy strategy = new SensorStrategy(); InputModule module = mock(InputModule.class); when(module.key()).thenReturn("foo"); ModuleInputComponentStore store = new ModuleInputComponentStore(module, inputComponentStore, strategy); strategy.setGlobal(false); store.inputFiles(); verify(inputComponentStore).filesByModule("foo"); String relativePath = "somepath"; store.inputFile(relativePath); verify(inputComponentStore).getFile(any(String.class), eq(relativePath)); store.languages(); verify(inputComponentStore).languages(any(String.class)); }
@Test public void should_find_all_components_with_global_strategy() { InputComponentStore inputComponentStore = mock(InputComponentStore.class); SensorStrategy strategy = new SensorStrategy(); ModuleInputComponentStore store = new ModuleInputComponentStore(mock(InputModule.class), inputComponentStore, strategy); strategy.setGlobal(true); store.inputFiles(); verify(inputComponentStore).inputFiles(); String relativePath = "somepath"; store.inputFile(relativePath); verify(inputComponentStore).inputFile(relativePath); store.languages(); verify(inputComponentStore).languages(); } }
/** * Testing purposes only! */ public DefaultIndexedFile(String projectKey, Path baseDir, String relativePath, @Nullable String language) { this(baseDir.resolve(relativePath), projectKey, relativePath, relativePath, Type.MAIN, language, TestInputFileBuilder.nextBatchId(), new SensorStrategy()); }
public DefaultInputFile build() { Path absolutePath = moduleBaseDir.resolve(relativePath); if (projectBaseDir == null) { projectBaseDir = moduleBaseDir; } String projectRelativePath = projectBaseDir.relativize(absolutePath).toString(); DefaultIndexedFile indexedFile = new DefaultIndexedFile(absolutePath, projectKey, projectRelativePath, relativePath, type, language, id, new SensorStrategy()); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(new Metadata(lines, nonBlankLines, hash, originalLineStartOffsets, originalLineEndOffsets, lastValidOffset)), contents); inputFile.setStatus(status); inputFile.setCharset(charset); inputFile.setPublished(publish); return inputFile; }