aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch-protocol
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-11-03 11:07:31 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-11-03 11:55:30 +0100
commit89eede7717dd056d314a214afb64a17be98fbc0e (patch)
tree3c9ed05a9749ea9a9557a2bb9a88b988f6ab26b1 /sonar-batch-protocol
parent19a6905ce6c877f1497b2ce47b7aeb478591b036 (diff)
downloadsonarqube-89eede7717dd056d314a214afb64a17be98fbc0e.tar.gz
sonarqube-89eede7717dd056d314a214afb64a17be98fbc0e.zip
SONAR-5815 Store last update time on source data
Diffstat (limited to 'sonar-batch-protocol')
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java19
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java13
2 files changed, 26 insertions, 6 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
index d967e933de4..68d06e73b48 100644
--- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
@@ -20,12 +20,15 @@
package org.sonar.batch.protocol.input;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@@ -40,6 +43,7 @@ public class ProjectReferentials {
private Collection<ActiveRule> activeRules = new ArrayList<ActiveRule>();
private Map<String, Map<String, String>> settingsByModule = new HashMap<String, Map<String, String>>();
private Map<String, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<String, Map<String, FileData>>();
+ private Date lastAnalysisDate;
public Map<String, String> settings(String projectKey) {
return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
@@ -100,12 +104,23 @@ public class ProjectReferentials {
this.timestamp = timestamp;
}
+ @CheckForNull
+ public Date lastAnalysisDate() {
+ return lastAnalysisDate;
+ }
+
+ public void setLastAnalysisDate(@Nullable Date lastAnalysisDate) {
+ this.lastAnalysisDate = lastAnalysisDate;
+ }
+
public String toJson() {
- return new Gson().toJson(this);
+ Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
+ return gson.toJson(this);
}
public static ProjectReferentials fromJson(String json) {
- return new Gson().fromJson(json, ProjectReferentials.class);
+ Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
+ return gson.fromJson(json, ProjectReferentials.class);
}
}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
index 5e537a1f523..8d55f4054dc 100644
--- a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
@@ -48,6 +48,7 @@ public class ProjectReferentialsTest {
ActiveRule activeRule = new ActiveRule("repo", "rule", "Rule", "MAJOR", "rule", "java");
activeRule.addParam("param1", "value1");
ref.addActiveRule(activeRule);
+ ref.setLastAnalysisDate(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014"));
ref.setTimestamp(10);
ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
@@ -55,10 +56,11 @@ public class ProjectReferentialsTest {
JSONAssert
.assertEquals(
"{timestamp:10,"
- + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
+ "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}},"
- + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}",
+ + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
+ + "lastAnalysisDate:\"2014-10-31T00:00:00+0100\"}",
ref.toJson(), true);
}
@@ -66,10 +68,11 @@ public class ProjectReferentialsTest {
public void testFromJson() throws JSONException, ParseException {
ProjectReferentials ref = ProjectReferentials
.fromJson("{timestamp:1,"
- + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
+ "settingsByModule:{foo:{prop:value}},"
- + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}");
+ + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
+ + "lastAnalysisDate:\"2014-10-31T00:00:00+0100\"}");
assertThat(ref.timestamp()).isEqualTo(1);
@@ -92,5 +95,7 @@ public class ProjectReferentialsTest {
assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
+
+ assertThat(ref.lastAnalysisDate()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014"));
}
}