]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4069 Cleanup of snapshot creation
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 19 Mar 2013 15:21:14 +0000 (16:21 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 19 Mar 2013 15:41:35 +0000 (16:41 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java
sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java

index 6af64feb22fd66380ba41d7e80a29c603d0b2ec5..a5ab0caf4b4d6d11248e1139e911a882502b5b43 100644 (file)
@@ -26,7 +26,11 @@ import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.database.BaseIdentifiable;
 import org.sonar.api.database.DatabaseSession;
 
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 
 import java.util.Date;
 
@@ -156,24 +160,18 @@ public class Snapshot extends BaseIdentifiable {
       this.createdAt = parent.getCreatedAt();
       this.depth = parent.getDepth() + 1;
       this.path = new StringBuilder()
-        .append(parent.getPath())
-        .append(parent.getId())
-        .append(".")
-        .toString();
+          .append(parent.getPath())
+          .append(parent.getId())
+          .append(".")
+          .toString();
     }
     this.rootProjectId = guessRootProjectId(resource, parent);
   }
 
   private static Integer guessRootProjectId(ResourceModel resource, Snapshot parent) {
     Integer result;
-
-    // design problem : constants are defined in the Resource class, that should not be used by this class...
-    if ("TRK".equals(resource.getQualifier()) || "VW".equals(resource.getQualifier()) || "SVW".equals(resource.getQualifier())) {
-      result = resource.getCopyResourceId() != null ? resource.getCopyResourceId() : resource.getId();
-
-    } else if (parent == null) {
-      result = resource.getCopyResourceId() != null ? resource.getCopyResourceId() : resource.getId();
-
+    if (parent == null) {
+      result = resource.getId();
     } else {
       result = (parent.getRootProjectId() == null ? parent.getResourceId() : parent.getRootProjectId());
     }
@@ -703,17 +701,17 @@ public class Snapshot extends BaseIdentifiable {
     }
     Snapshot other = (Snapshot) obj;
     return new EqualsBuilder()
-      .append(resourceId, other.getResourceId())
-      .append(createdAt, other.getCreatedAt())
-      .isEquals();
+        .append(resourceId, other.getResourceId())
+        .append(createdAt, other.getCreatedAt())
+        .isEquals();
   }
 
   @Override
   public int hashCode() {
     return new HashCodeBuilder(17, 37)
-      .append(resourceId)
-      .append(createdAt)
-      .toHashCode();
+        .append(resourceId)
+        .append(createdAt)
+        .toHashCode();
   }
 
   @Override
index d030fbe00bed2b5980ef8abd30aac8ad86173192..f1bfce8b437f79b4864fb4d0bc2da9e4d379fffd 100644 (file)
@@ -24,11 +24,13 @@ import org.junit.Test;
 import java.util.Date;
 
 import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
 
 public class SnapshotTest {
 
-
   @Test
   public void testGetDate() {
     Snapshot snapshot = new Snapshot();
@@ -86,24 +88,4 @@ public class SnapshotTest {
     assertThat(snapshot.getRootProjectId(), is(3));
   }
 
-  @Test
-  public void testRootProjectIdOfViews() {
-    ResourceModel view = new ResourceModel();
-    view.setId(3);
-    view.setQualifier("VW");
-    Snapshot viewSnapshot = new Snapshot(view, null);
-
-    ResourceModel subview = new ResourceModel();
-    subview.setId(4);
-    subview.setQualifier("SVW");
-    Snapshot subviewSnapshot = new Snapshot(subview, viewSnapshot);
-    assertThat(subviewSnapshot.getRootProjectId(), is(4));
-
-    ResourceModel project = new ResourceModel();
-    project.setId(5);
-    project.setQualifier("TRK");
-    project.setCopyResourceId(66);
-    Snapshot projectSnapshot = new Snapshot(project, subviewSnapshot);
-    assertThat(projectSnapshot.getRootProjectId(), is(66));
-  }
 }