@Test public void should_lazy_load_reference_hashes_when_status_changed_on_branch() throws Exception { final String source = "source"; FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(project.getKeyWithBranch()).thenReturn("foo:myBranch"); when(file.getProjectRelativePath()).thenReturn("src/Foo.java"); String key = "foo:myBranch:src/Foo.java"; when(file.status()).thenReturn(InputFile.Status.CHANGED); when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)}); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); verify(lastSnapshots).getLineHashes(key); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); }
@Test public void should_lazy_load_reference_hashes_when_status_changed() throws Exception { final String source = "source"; FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(project.getKeyWithBranch()).thenReturn("foo"); when(file.getProjectRelativePath()).thenReturn("src/Foo.java"); String key = "foo:src/Foo.java"; when(file.status()).thenReturn(InputFile.Status.CHANGED); when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)}); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); verify(lastSnapshots).getLineHashes(key); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); }
private void initHashes() { if (hashedSource == null) { hashedSource = FileHashes.create(inputFile); Status status = inputFile.status(); if (status == Status.ADDED) { hashedReference = null; } else if (status == Status.SAME) { hashedReference = hashedSource; } else { // Need key with branch String serverSideKey = ComponentKeys.createEffectiveKey(project.getKeyWithBranch(), inputFile); String[] lineHashes = lastSnapshots.getLineHashes(serverSideKey); hashedReference = lineHashes != null ? FileHashes.create(lineHashes) : null; } } }
private void writeJsonComponents(JsonWriter json) { json.name("components").beginArray(); // Dump modules writeJsonProject(json); for (DefaultInputFile inputFile : componentStore.allFilesToPublish()) { String projectKey = project.getKeyWithBranch(); String key = ComponentKeys.createEffectiveKey(projectKey, inputFile); json .beginObject() .prop("key", key) .prop("path", inputFile.relativePath()) .prop("status", inputFile.status().name()) .endObject(); } json.endArray(); }
if (issue.resolution() == null) { InputComponent component = componentStore.getByKey(issue.componentKey()); String componentKeyWithBranch = project.getKeyWithBranch(); if (component.isFile()) { componentKeyWithBranch = ComponentKeys.createEffectiveKey(componentKeyWithBranch, (DefaultInputFile) component);
private void initHashes() { if (hashedSource == null) { hashedSource = FileHashes.create(inputFile); Status status = inputFile.status(); if (status == Status.ADDED) { hashedReference = null; } else if (status == Status.SAME) { hashedReference = hashedSource; } else { // Need key with branch String serverSideKey = ComponentKeys.createEffectiveKey(project.getKeyWithBranch(), inputFile); String[] lineHashes = lastSnapshots.getLineHashes(serverSideKey); hashedReference = lineHashes != null ? FileHashes.create(lineHashes) : null; } } }
private void writeJsonComponents(JsonWriter json) { json.name("components").beginArray(); // Dump modules writeJsonProject(json); for (DefaultInputFile inputFile : componentStore.allFilesToPublish()) { String projectKey = project.getKeyWithBranch(); String key = ComponentKeys.createEffectiveKey(projectKey, inputFile); json .beginObject() .prop("key", key) .prop("path", inputFile.relativePath()) .prop("status", inputFile.status().name()) .endObject(); } json.endArray(); }
if (issue.resolution() == null) { InputComponent component = componentStore.getByKey(issue.componentKey()); String componentKeyWithBranch = project.getKeyWithBranch(); if (component.isFile()) { componentKeyWithBranch = ComponentKeys.createEffectiveKey(componentKeyWithBranch, (DefaultInputFile) component);