From: Sébastien Lesaint Date: Wed, 24 Aug 2016 10:45:29 +0000 (+0200) Subject: SONAR-8011 support when file in DB has no path during file move step X-Git-Tag: 6.1-RC1~300 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=560d8e87f9624cc2ad1b7a5c17ac647d2dcc0d54;p=sonarqube.git SONAR-8011 support when file in DB has no path during file move step --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java index a000a765372..aabd0cd2706 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java @@ -229,6 +229,9 @@ public class FileMoveDetectionStep implements ComputationStep { @CheckForNull private File getFile(DbSession dbSession, DbComponent dbComponent) { + if (dbComponent.getPath() == null) { + return null; + } FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSourceByFileUuid(dbSession, dbComponent.getUuid()); if (fileSourceDto == null) { return null; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java index 3075c6c366a..3514500f558 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.function.Function; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Rule; @@ -357,6 +358,20 @@ public class FileMoveDetectionStepTest { assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); } + @Test + public void execute_detects_no_move_if_content_of_file_has_no_path_in_DB() { + analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS); + + mockComponents(key -> newComponentDto(key).setPath(null), FILE_1.getKey()); + mockContentOfFileInDb(FILE_1.getKey(), CONTENT1); + setFilesInReport(FILE_2); + setFileContentInReport(FILE_2_REF, CONTENT1); + + underTest.execute(); + + assertThat(movedFilesRepository.getComponentsWithOriginal()).isEmpty(); + } + @Test public void execute_detects_no_move_if_content_of_file_is_empty_in_report() { analysisMetadataHolder.setBaseProjectSnapshot(ANALYSIS); @@ -508,8 +523,12 @@ public class FileMoveDetectionStepTest { } private ComponentDto[] mockComponents(String... componentKeys) { + return mockComponents(key -> newComponentDto(key), componentKeys); + } + + private ComponentDto[] mockComponents(Function newComponentDto, String... componentKeys) { List componentDtos = stream(componentKeys) - .map(key -> newComponentDto(key)) + .map(newComponentDto) .collect(toList()); when(componentDao.selectDescendants(eq(dbSession), any(ComponentTreeQuery.class))) .thenReturn(componentDtos);