]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8011 support when file in DB has no path during file move step 1170/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 24 Aug 2016 10:45:29 +0000 (12:45 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 25 Aug 2016 13:05:41 +0000 (15:05 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStepTest.java

index a000a76537278afb98616b32e64347b89a579fdc..aabd0cd2706e7b3f8cd676ecfa3f0875fd275de2 100644 (file)
@@ -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;
index 3075c6c366a5ad68904d00729777eda11bf5efd3..3514500f558348593c3c149fb8e8ea50538b2c76 100644 (file)
@@ -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<String, ComponentDto> newComponentDto, String... componentKeys) {
     List<ComponentDto> componentDtos = stream(componentKeys)
-      .map(key -> newComponentDto(key))
+      .map(newComponentDto)
       .collect(toList());
     when(componentDao.selectDescendants(eq(dbSession), any(ComponentTreeQuery.class)))
       .thenReturn(componentDtos);