long getAnalysisDate();
/**
- * Convenience method equivalent to calling {@link #getBaseProjectSnapshot() == null}
+ * Convenience method equivalent to calling {@link #getBaseAnalysis() == null}
*
* @throws IllegalStateException if baseProjectSnapshot has not been set
*/
boolean isFirstAnalysis();
/**
- * Return the last snapshot of the project.
+ * Return the last analysis of the project.
* If it's the first analysis, it will return null.
*
- * @throws IllegalStateException if baseProjectSnapshot has not been set
+ * @throws IllegalStateException if baseAnalysis has not been set
*/
@CheckForNull
- Analysis getBaseProjectSnapshot();
+ Analysis getBaseAnalysis();
/**
* @throws IllegalStateException if cross project duplication flag has not been set
@Override
public boolean isFirstAnalysis() {
- return getBaseProjectSnapshot() == null;
+ return getBaseAnalysis() == null;
}
@Override
- public MutableAnalysisMetadataHolder setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis) {
+ public MutableAnalysisMetadataHolder setBaseAnalysis(@Nullable Analysis baseAnalysis) {
checkState(!this.baseProjectSnapshot.isInitialized(), "Base project snapshot has already been set");
- this.baseProjectSnapshot.setProperty(baseProjectAnalysis);
+ this.baseProjectSnapshot.setProperty(baseAnalysis);
return this;
}
@Override
@CheckForNull
- public Analysis getBaseProjectSnapshot() {
+ public Analysis getBaseAnalysis() {
checkState(baseProjectSnapshot.isInitialized(), "Base project snapshot has not been set");
return baseProjectSnapshot.getProperty();
}
MutableAnalysisMetadataHolder setAnalysisDate(long date);
/**
- * @throws IllegalStateException if baseProjectAnalysis has already been set
+ * @throws IllegalStateException if baseAnalysis has already been set
*/
- MutableAnalysisMetadataHolder setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis);
+ MutableAnalysisMetadataHolder setBaseAnalysis(@Nullable Analysis baseAnalysis);
/**
* @throws IllegalStateException if cross project duplication flag has already been set
@Override
public void execute() {
// do nothing if no files in db (first analysis)
- Analysis baseProjectAnalysis = analysisMetadataHolder.getBaseProjectSnapshot();
+ Analysis baseProjectAnalysis = analysisMetadataHolder.getBaseAnalysis();
if (baseProjectAnalysis == null) {
LOG.debug("First analysis. Do nothing.");
return;
UuidFactory uuidFactory = new UuidFactory(dbClient, moduleKey(reportProject, branch));
Component project = new ComponentRootBuilder(reportProject, uuidFactory, branch).build();
treeRootHolder.setRoot(project);
- setBaseProjectSnapshot(project.getUuid());
+ setBaseAnalysis(project.getUuid());
}
- private void setBaseProjectSnapshot(String projectUuid) {
+ private void setBaseAnalysis(String projectUuid) {
DbSession dbSession = dbClient.openSession(false);
try {
SnapshotDto snapshotDto = dbClient.snapshotDao().selectAnalysisByQuery(dbSession,
new SnapshotQuery()
.setComponentUuid(projectUuid)
.setIsLast(true));
- analysisMetadataHolder.setBaseProjectSnapshot(toAnalysis(snapshotDto));
+ analysisMetadataHolder.setBaseAnalysis(toAnalysis(snapshotDto));
} finally {
dbClient.closeSession(dbSession);
}
private List<DuplicationUnitDto> selectDuplicates(Component file, Collection<String> hashes) {
DbSession dbSession = dbClient.openSession(false);
try {
- Analysis projectAnalysis = analysisMetadataHolder.getBaseProjectSnapshot();
+ Analysis projectAnalysis = analysisMetadataHolder.getBaseAnalysis();
String analysisUuid = projectAnalysis == null ? null : projectAnalysis.getUuid();
return dbClient.duplicationDao().selectCandidates(dbSession, analysisUuid, file.getFileAttributes().getLanguageKey(), hashes);
} finally {
public void isFirstAnalysis_return_true() throws Exception {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setBaseProjectSnapshot(null);
+ underTest.setBaseAnalysis(null);
assertThat(underTest.isFirstAnalysis()).isTrue();
}
public void isFirstAnalysis_return_false() throws Exception {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setBaseProjectSnapshot(baseProjectAnalysis);
+ underTest.setBaseAnalysis(baseProjectAnalysis);
assertThat(underTest.isFirstAnalysis()).isFalse();
}
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Base project snapshot has not been set");
- new AnalysisMetadataHolderImpl().getBaseProjectSnapshot();
+ new AnalysisMetadataHolderImpl().getBaseAnalysis();
}
@Test
public void setBaseProjectSnapshot_throws_ISE_when_called_twice() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
- underTest.setBaseProjectSnapshot(baseProjectAnalysis);
+ underTest.setBaseAnalysis(baseProjectAnalysis);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Base project snapshot has already been set");
- underTest.setBaseProjectSnapshot(baseProjectAnalysis);
+ underTest.setBaseAnalysis(baseProjectAnalysis);
}
@Test
private final InitializedProperty<Long> analysisDate = new InitializedProperty<>();
- private final InitializedProperty<Analysis> baseProjectSnapshot = new InitializedProperty<>();
+ private final InitializedProperty<Analysis> baseAnalysis = new InitializedProperty<>();
private final InitializedProperty<Boolean> crossProjectDuplicationEnabled = new InitializedProperty<>();
@Override
public boolean isFirstAnalysis() {
- return getBaseProjectSnapshot() == null;
+ return getBaseAnalysis() == null;
}
@Override
- public AnalysisMetadataHolderRule setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis) {
- this.baseProjectSnapshot.setProperty(baseProjectAnalysis);
+ public AnalysisMetadataHolderRule setBaseAnalysis(@Nullable Analysis baseAnalysis) {
+ this.baseAnalysis.setProperty(baseAnalysis);
return this;
}
@Override
@CheckForNull
- public Analysis getBaseProjectSnapshot() {
- checkState(baseProjectSnapshot.isInitialized(), "Base project snapshot has not been set");
- return baseProjectSnapshot.getProperty();
+ public Analysis getBaseAnalysis() {
+ checkState(baseAnalysis.isInitialized(), "Base analysis has not been set");
+ return baseAnalysis.getProperty();
}
@Override
}
@Override
- public MutableAnalysisMetadataHolderRule setBaseProjectSnapshot(@Nullable Analysis baseProjectAnalysis) {
- delegate.setBaseProjectSnapshot(baseProjectAnalysis);
+ public MutableAnalysisMetadataHolderRule setBaseAnalysis(@Nullable Analysis baseAnalysis) {
+ delegate.setBaseAnalysis(baseAnalysis);
return this;
}
@Override
@CheckForNull
- public Analysis getBaseProjectSnapshot() {
- return delegate.getBaseProjectSnapshot();
+ public Analysis getBaseAnalysis() {
+ return delegate.getBaseAnalysis();
}
@Override
@Test
public void execute_detects_no_move_if_baseProjectSnapshot_is_null() {
- analysisMetadataHolder.setBaseProjectSnapshot(null);
+ analysisMetadataHolder.setBaseAnalysis(null);
underTest.execute();
@Test
public void execute_detects_no_move_if_baseSnapshot_has_no_file_and_report_has_no_file() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
underTest.execute();
@Test
public void execute_detects_no_move_if_baseSnapshot_has_no_file() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
setFilesInReport(FILE_1, FILE_2);
underTest.execute();
@Test
public void execute_retrieves_only_file_and_unit_tests_from_last_snapshot() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
ArgumentCaptor<ComponentTreeQuery> captor = ArgumentCaptor.forClass(ComponentTreeQuery.class);
when(componentDao.selectDescendants(eq(dbSession), captor.capture()))
.thenReturn(Collections.emptyList());
@Test
public void execute_detects_no_move_if_there_is_no_file_in_report() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents( /* no components */);
setFilesInReport();
@Test
public void execute_detects_no_move_if_file_key_exists_in_both_DB_and_report() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey(), FILE_2.getKey());
setFilesInReport(FILE_2, FILE_1);
@Test
public void execute_detects_move_if_content_of_file_is_same_in_DB_and_report() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
ComponentDto[] dtos = mockComponents(FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
setFilesInReport(FILE_2);
@Test
public void execute_detects_no_move_if_content_of_file_is_not_similar_enough() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
setFilesInReport(FILE_2);
@Test
public void execute_detects_no_move_if_content_of_file_is_empty_in_DB() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT_EMPTY);
setFilesInReport(FILE_2);
@Test
public void execute_detects_no_move_if_content_of_file_has_no_path_in_DB() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(key -> newComponentDto(key).setPath(null), FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
@Test
public void execute_detects_no_move_if_content_of_file_is_empty_in_report() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
setFilesInReport(FILE_2);
@Test
public void execute_detects_no_move_if_two_added_files_have_same_content_as_the_one_in_db() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
setFilesInReport(FILE_2, FILE_3);
@Test
public void execute_detects_no_move_if_two_deleted_files_have_same_content_as_the_one_added() {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
mockComponents(FILE_1.getKey(), FILE_2.getKey());
mockContentOfFileInDb(FILE_1.getKey(), CONTENT1);
mockContentOfFileInDb(FILE_2.getKey(), CONTENT1);
// - file2 deleted
// - file4 untouched
// - file5 renamed to file6 with a small change
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
Component file4 = fileComponent(5);
Component file5 = fileComponent(6);
Component file6 = fileComponent(7);
*/
@Test
public void real_life_use_case() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS);
+ analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
List<String> componentDtoKey = new ArrayList<>();
for (File f : FileUtils.listFiles(new File("src/test/resources/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest/v1"), null, false)) {
componentDtoKey.add(f.getName());
@Test
public void read_from_report() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addChangesetInReport("john", DATE_1, "rev-1");
ScmInfo scmInfo = underTest.getScmInfo(FILE).get();
@Test
public void getScmInfo_returns_absent_if_CopyFromPrevious_is_false_and_there_is_no_changeset_in_report() {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
// put data in DB, which should not be used
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
addFileSourceInReport(1);
@Test
public void getScmInfo_returns_ScmInfo_from_DB_CopyFromPrevious_is_true_if_hashes_are_the_same() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
addFileSourceInReport(1);
addCopyFromPreviousChangesetInReport();
@Test
public void getScmInfo_returns_absent_when_CopyFromPrevious_is_true_but_hashes_are_not_the_same() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1) + "_different");
addFileSourceInReport(1);
addCopyFromPreviousChangesetInReport();
@Test
public void read_from_report_even_if_data_in_db_exists() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
addChangesetInReport("john", DATE_2, "rev-2");
@Test
public void read_from_db_even_if_data_in_report_exists_when_CopyFromPrevious_is_true() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1));
addFileSourceInReport(1);
addChangesetInReport("john", DATE_2, "rev-2", true);
@Test
public void return_nothing_when_no_data_in_report_nor_db() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
assertThat(underTest.getScmInfo(FILE)).isAbsent();
}
@Test
public void return_nothing_when_nothing_in_report_and_db_has_no_scm() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addFileSourceInDb(null, null, null, "don't care");
addFileSourceInReport(1);
@Test
public void fail_with_NPE_when_component_is_null() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
thrown.expect(NullPointerException.class);
thrown.expectMessage("Component cannot be bull");
@Test
public void load_scm_info_from_cache_when_already_read() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
addChangesetInReport("john", DATE_1, "rev-1");
ScmInfo scmInfo = underTest.getScmInfo(FILE).get();
assertThat(scmInfo.getAllChangesets()).hasSize(1);
@Test
public void not_read_in_db_on_first_analysis_when_CopyFromPrevious_is_true() throws Exception {
- analysisMetadataHolder.setBaseProjectSnapshot(null);
+ analysisMetadataHolder.setBaseAnalysis(null);
addFileSourceInDb("henry", DATE_1, "rev-1", "don't care");
addFileSourceInReport(1);
addCopyFromPreviousChangesetInReport();
@Test
public void call_compute_cpd_on_one_duplication() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
ComponentDto otherProject = createProject("OTHER_PROJECT_KEY");
SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject);
@Test
public void call_compute_cpd_on_many_duplication() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
ComponentDto otherProject = createProject("OTHER_PROJECT_KEY");
SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject);
@Test
public void nothing_to_do_when_cross_project_duplication_is_disabled() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(false);
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
ComponentDto otherProject = createProject("OTHER_PROJECT_KEY");
SnapshotDto otherProjectSnapshot = createProjectSnapshot(otherProject);
@Test
public void nothing_to_do_when_no_cpd_text_blocks_found() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
batchReportReader.putDuplicationBlocks(FILE_REF, Collections.<ScannerReport.CpdTextBlock>emptyList());
@Test
public void nothing_to_do_when_cpd_text_blocks_exists_but_no_duplicated_found() throws Exception {
when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
- analysisMetadataHolder.setBaseProjectSnapshot(baseProjectAnalysis);
+ analysisMetadataHolder.setBaseAnalysis(baseProjectAnalysis);
ScannerReport.CpdTextBlock originBlock = ScannerReport.CpdTextBlock.newBuilder()
.setHash("a8998353e96320ec")