/** * 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()); }
@Override public String relativePath() { return sensorStrategy.isGlobal() ? projectRelativePath : moduleRelativePath; }
@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 test() throws Exception { Metadata metadata = new Metadata(42, 42, "", new int[0], new int[0], 10); DefaultInputFile inputFile = new DefaultInputFile(indexedFile, (f) -> f.setMetadata(metadata)) .setStatus(InputFile.Status.ADDED) .setCharset(StandardCharsets.ISO_8859_1); assertThat(inputFile.absolutePath()).endsWith("Foo.php"); assertThat(inputFile.filename()).isEqualTo("Foo.php"); assertThat(inputFile.uri()).hasPath(baseDir.resolve(PROJECT_RELATIVE_PATH).toUri().getPath()); assertThat(new File(inputFile.absolutePath())).isAbsolute(); assertThat(inputFile.language()).isEqualTo("php"); assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED); assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST); assertThat(inputFile.lines()).isEqualTo(42); assertThat(inputFile.charset()).isEqualTo(StandardCharsets.ISO_8859_1); assertThat(inputFile.getModuleRelativePath()).isEqualTo(MODULE_RELATIVE_PATH); assertThat(inputFile.getProjectRelativePath()).isEqualTo(PROJECT_RELATIVE_PATH); sensorStrategy.setGlobal(false); assertThat(inputFile.relativePath()).isEqualTo(MODULE_RELATIVE_PATH); assertThat(new File(inputFile.relativePath())).isRelative(); sensorStrategy.setGlobal(true); assertThat(inputFile.relativePath()).isEqualTo(PROJECT_RELATIVE_PATH); assertThat(new File(inputFile.relativePath())).isRelative(); }
@Override public Iterable<InputFile> inputFiles() { if (strategy.isGlobal()) { return inputComponentStore.inputFiles(); } else { return inputComponentStore.filesByModule(moduleKey); } }
@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(); } }
@Override public InputFile inputFile(String relativePath) { if (strategy.isGlobal()) { return inputComponentStore.inputFile(relativePath); } else { return inputComponentStore.getFile(moduleKey, relativePath); } }
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; }
@Override public SortedSet<String> languages() { if (strategy.isGlobal()) { return inputComponentStore.languages(); } else { return inputComponentStore.languages(moduleKey); } }
@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); }
@Override public String relativePath() { return sensorStrategy.isGlobal() ? projectRelativePath : moduleRelativePath; }
/** * 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()); }
@Override public InputFile inputFile(String relativePath) { if (strategy.isGlobal()) { return inputComponentStore.inputFile(relativePath); } else { return inputComponentStore.getFile(moduleKey, relativePath); } }
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; }
@Override public SortedSet<String> languages() { if (strategy.isGlobal()) { return inputComponentStore.languages(); } else { return inputComponentStore.languages(moduleKey); } }
@Override public Iterable<InputFile> inputFiles() { if (strategy.isGlobal()) { return inputComponentStore.inputFiles(); } else { return inputComponentStore.filesByModule(moduleKey); } }