]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaw
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 27 Jan 2015 13:39:25 +0000 (14:39 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 27 Jan 2015 13:39:25 +0000 (14:39 +0100)
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java

index 4b6cd2f96b21460bf1d7e4eb7b4a9975f9a3f4f8..2aa037092bfc205e075c279977b6309ac7b01c40 100644 (file)
@@ -73,7 +73,7 @@ public class DuplicationsParser implements ServerComponent {
               duplications.add(createDuplication(componentsByKey, from, size, componentKey, session));
             }
           }
-          Collections.sort(duplications, new DuplicationComparator(component));
+          Collections.sort(duplications, new DuplicationComparator(component.uuid(), component.projectUuid()));
           blocks.add(new Block(duplications));
         }
         Collections.sort(blocks, new BlockComparator());
@@ -107,10 +107,12 @@ public class DuplicationsParser implements ServerComponent {
   static class DuplicationComparator implements Comparator<Duplication>, Serializable {
     private static final long serialVersionUID = 1;
 
-    private final ComponentDto component;
+    private final String uuid;
+    private final String projectUuid;
 
-    DuplicationComparator(ComponentDto component) {
-      this.component = component;
+    DuplicationComparator(String uuid, String projectUuid) {
+      this.uuid = uuid;
+      this.projectUuid = projectUuid;
     }
 
     @Override
@@ -129,16 +131,16 @@ public class DuplicationsParser implements ServerComponent {
       if (file1.equals(d2.file())) {
         // if duplication on same file => order by starting line
         return d1.from().compareTo(d2.from());
-      } else if (file1.equals(component)) {
+      } else if (file1.uuid().equals(uuid)) {
         // the current resource must be displayed first
         return -1;
-      } else if (file2.equals(component)) {
+      } else if (file2.uuid().equals(uuid)) {
         // the current resource must be displayed first
         return 1;
-      } else if (StringUtils.equals(file1.projectUuid(), component.projectUuid()) && !StringUtils.equals(file2.projectUuid(), component.projectUuid())) {
+      } else if (StringUtils.equals(file1.projectUuid(), projectUuid) && !StringUtils.equals(file2.projectUuid(), projectUuid)) {
         // if resource is in the same project, this it must be displayed first
         return -1;
-      } else if (StringUtils.equals(file2.projectUuid(), component.projectUuid()) && !StringUtils.equals(file1.projectUuid(), component.projectUuid())) {
+      } else if (StringUtils.equals(file2.projectUuid(), projectUuid) && !StringUtils.equals(file1.projectUuid(), projectUuid)) {
         // if resource is in the same project, this it must be displayed first
         return 1;
       } else {
index d9d09a7c7e2660e63e26045a4486292602f5d40c..a51a04124050dc119484e5304b390e7bb9962f77 100644 (file)
@@ -203,7 +203,7 @@ public class DuplicationsParserTest {
     ComponentDto fileOnSameProject = ComponentTesting.newFileDto(project1).setId(12L);
     ComponentDto fileOnDifferentProject = ComponentTesting.newFileDto(project2).setId(13L);
 
-    DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile);
+    DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile.uuid(), currentFile.projectUuid());
 
     // On same file
     assertThat(comparator.compare(new DuplicationsParser.Duplication(currentFile, 2, 2), new DuplicationsParser.Duplication(currentFile, 5, 2))).isEqualTo(-1);