aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-05-22 11:29:43 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-05-25 08:42:11 +0200
commit0a4d5f75f078abd6c6d8d4a58d0b4efc8c5cd512 (patch)
tree06124c25d9cfd2e7c0fe7a6ca543d2ed2f401e56 /server
parente009561a5e3210480c7bef0ee20cebbc83d531bc (diff)
downloadsonarqube-0a4d5f75f078abd6c6d8d4a58d0b4efc8c5cd512.tar.gz
sonarqube-0a4d5f75f078abd6c6d8d4a58d0b4efc8c5cd512.zip
Add project name in compute report queue
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java18
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ws/SubmitReportAction.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java47
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ws/SubmitReportActionTest.java9
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml8
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml3
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/ws/QueueActionTest/list_queue_reports.json4
10 files changed, 59 insertions, 56 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
index afd4fe1a92c..5dbdfe8fef5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ReportQueue.java
@@ -21,8 +21,8 @@
package org.sonar.server.computation;
import org.apache.commons.io.FileUtils;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.config.Settings;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.internal.Uuids;
import org.sonar.api.utils.log.Loggers;
import org.sonar.core.computation.db.AnalysisReportDto;
@@ -51,7 +51,7 @@ public class ReportQueue {
this.settings = settings;
}
- public Item add(String projectKey, InputStream reportData) {
+ public Item add(String projectKey, String projectName, InputStream reportData) {
String uuid = Uuids.create();
File file = reportFileForUuid(uuid);
@@ -60,7 +60,7 @@ public class ReportQueue {
checkThatProjectExistsInDatabase(projectKey, session);
saveReportOnDisk(reportData, file);
- AnalysisReportDto dto = saveReportMetadataInDatabase(projectKey, uuid, session);
+ AnalysisReportDto dto = saveReportMetadataInDatabase(projectKey, projectName, uuid, session);
return new Item(dto, file);
} catch (Exception e) {
@@ -71,9 +71,10 @@ public class ReportQueue {
}
}
- private AnalysisReportDto saveReportMetadataInDatabase(String projectKey, String uuid, DbSession session) {
+ private AnalysisReportDto saveReportMetadataInDatabase(String projectKey, String projectName, String uuid, DbSession session) {
AnalysisReportDto dto = new AnalysisReportDto()
.setProjectKey(projectKey)
+ .setProjectName(projectName)
.setStatus(PENDING)
.setUuid(uuid);
dao().insert(session, dto);
@@ -124,15 +125,6 @@ public class ReportQueue {
}
}
- public List<AnalysisReportDto> selectByProjectKey(String projectKey) {
- DbSession session = dbClient.openSession(false);
- try {
- return dao().selectByProjectKey(session, projectKey);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
/**
* Truncates table ANALYSIS_REPORTS and delete all files from directory {data}/analysis
*/
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java
index fd20ecf2977..0fe4c3d210c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueAction.java
@@ -67,7 +67,7 @@ public class QueueAction implements ComputationWsAction {
json.beginObject();
json.prop("key", report.getId());
json.prop("projectKey", report.getProjectKey());
- json.prop("projectName", report.getProjectKey());
+ json.prop("projectName", report.getProjectName());
json.propDateTime("startedAt", longToDate(report.getStartedAt()));
json.propDateTime("finishedAt", longToDate(report.getFinishedAt()));
json.propDateTime("submittedAt", longToDate(report.getCreatedAt()));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/SubmitReportAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/SubmitReportAction.java
index 86f290b1f7d..8bd4ecb212c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/SubmitReportAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/SubmitReportAction.java
@@ -35,6 +35,7 @@ public class SubmitReportAction implements ComputationWsAction {
public static final String ACTION = "submit_report";
public static final String PARAM_PROJECT_KEY = "projectKey";
+ public static final String PARAM_PROJECT_NAME = "projectName";
public static final String PARAM_REPORT_DATA = "report";
private final ReportQueue queue;
@@ -62,6 +63,12 @@ public class SubmitReportAction implements ComputationWsAction {
.setExampleValue("org.codehaus.sonar:sonar");
action
+ .createParam(PARAM_PROJECT_NAME)
+ .setRequired(true)
+ .setDescription("Project name")
+ .setExampleValue("SonarQube");
+
+ action
.createParam(PARAM_REPORT_DATA)
.setRequired(true)
.setDescription("Report file. Format is not an API, it changes among SonarQube versions.");
@@ -71,9 +78,10 @@ public class SubmitReportAction implements ComputationWsAction {
public void handle(Request request, Response response) throws Exception {
userSession.checkGlobalPermission(GlobalPermissions.SCAN_EXECUTION);
String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY);
+ String projectName = request.mandatoryParam(PARAM_PROJECT_NAME);
InputStream reportData = request.paramAsInputStream(PARAM_REPORT_DATA);
try {
- ReportQueue.Item item = queue.add(projectKey, reportData);
+ ReportQueue.Item item = queue.add(projectKey, projectName, reportData);
workerLauncher.startAnalysisTaskNow();
response.newJsonWriter()
.beginObject()
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java
index ba5ec765781..36de2139087 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ReportQueueTest.java
@@ -22,6 +22,7 @@ package org.sonar.server.computation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -57,6 +58,9 @@ public class ReportQueueTest {
@Rule
public DbTester db = new DbTester();
+ DbClient dbClient;
+ DbSession session;
+
@Rule
public TemporaryFolder temp = new TemporaryFolder();
@@ -71,15 +75,19 @@ public class ReportQueueTest {
settings.setProperty(ProcessProperties.PATH_DATA, dataDir.getAbsolutePath());
when(system.now()).thenReturn(NOW);
- DbClient dbClient = new DbClient(db.database(), db.myBatis(), new ComponentDao(), new AnalysisReportDao(system));
+ dbClient = new DbClient(db.database(), db.myBatis(), new ComponentDao(), new AnalysisReportDao(system));
sut = new ReportQueue(dbClient, settings);
- try (DbSession session = dbClient.openSession(false)) {
+ session = dbClient.openSession(false);
dbClient.componentDao().insert(session, ComponentTesting.newProjectDto().setKey("P1"));
dbClient.componentDao().insert(session, ComponentTesting.newProjectDto().setKey("P2"));
dbClient.componentDao().insert(session, ComponentTesting.newProjectDto().setKey("P3"));
session.commit();
- }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ session.close();
}
@Test
@@ -87,20 +95,21 @@ public class ReportQueueTest {
// must:
// 1. insert metadata in db
// 2. copy report content to directory /data/analysis
- ReportQueue.Item item = sut.add("P1", generateData());
+ ReportQueue.Item item = sut.add("P1", "Project 1", generateData());
assertThat(item).isNotNull();
assertThat(item.zipFile).isFile().exists().hasContent("some data").hasParent(new File(dataDir, "analysis"));
assertThat(item.dto.getUuid()).isNotEmpty();
assertThat(item.dto.getId()).isGreaterThan(0L);
- List<AnalysisReportDto> reports = sut.selectByProjectKey("P1");
+ List<AnalysisReportDto> reports = dbClient.analysisReportDao().selectByProjectKey(session, "P1");
assertThat(reports).hasSize(1);
AnalysisReportDto report = reports.get(0);
assertThat(reports).hasSize(1);
assertThat(report.getStatus()).isEqualTo(PENDING);
assertThat(report.getProjectKey()).isEqualTo("P1");
+ assertThat(report.getProjectName()).isEqualTo("Project 1");
assertThat(report.getUuid()).isNotEmpty();
assertThat(report.getId()).isGreaterThan(0L);
assertThat(report.getCreatedAt()).isEqualTo(NOW);
@@ -112,17 +121,10 @@ public class ReportQueueTest {
}
@Test
- public void find_by_project_key() {
- sut.add("P1", generateData());
- assertThat(sut.selectByProjectKey("P1")).hasSize(1).extracting("projectKey").containsExactly("P1");
- assertThat(sut.selectByProjectKey("P2")).isEmpty();
- }
-
- @Test
public void pop_pending_items_in_fifo_order() {
- sut.add("P1", generateData());
- sut.add("P2", generateData());
- sut.add("P3", generateData());
+ sut.add("P1", "Project 1", generateData());
+ sut.add("P2", "Project 2", generateData());
+ sut.add("P3", "Project 3", generateData());
ReportQueue.Item item = sut.pop();
assertThat(item.dto.getProjectKey()).isEqualTo("P1");
@@ -145,7 +147,7 @@ public class ReportQueueTest {
@Test
public void remove() {
- ReportQueue.Item item = sut.add("P1", generateData());
+ ReportQueue.Item item = sut.add("P1", "Project 1", generateData());
assertThat(db.countRowsOfTable("analysis_reports")).isEqualTo(1);
sut.remove(item);
@@ -155,7 +157,7 @@ public class ReportQueueTest {
@Test
public void do_not_pop_corrupted_item() {
- ReportQueue.Item item = sut.add("P1", generateData());
+ ReportQueue.Item item = sut.add("P1", "Project 1", generateData());
// emulate corruption: file is missing on FS
FileUtils.deleteQuietly(item.zipFile);
@@ -168,8 +170,8 @@ public class ReportQueueTest {
@Test
public void clear() {
- sut.add("P1", generateData());
- sut.add("P2", generateData());
+ sut.add("P1", "Project 1", generateData());
+ sut.add("P2", "Project 2", generateData());
assertThat(analysisDir()).exists().isDirectory();
sut.clear();
@@ -186,14 +188,14 @@ public class ReportQueueTest {
@Test(expected = IllegalStateException.class)
public void add_on_non_existent_project() {
- sut.add("UNKNOWN_PROJECT_KEY", generateData());
+ sut.add("UNKNOWN_PROJECT_KEY", "Unknown project", generateData());
}
@Test
public void reset_to_pending_status() {
// 2 pending
- sut.add("P1", generateData());
- sut.add("P2", generateData());
+ sut.add("P1", "Project 1", generateData());
+ sut.add("P2", "Project 2", generateData());
// pop 1 -> 1 pending and 1 working
ReportQueue.Item workingItem = sut.pop();
@@ -202,7 +204,6 @@ public class ReportQueueTest {
sut.resetToPendingStatus();
assertThat(sut.all()).extracting("status").containsOnly(PENDING).hasSize(2);
-
}
private InputStream generateData() {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
index 6e3a09a0df3..0b636a01c33 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
@@ -75,8 +75,8 @@ public class AnalysisReportDaoTest {
public void insert_multiple_reports() {
db.prepareDbUnit(getClass(), "empty.xml");
- AnalysisReportDto report1 = newDefaultAnalysisReport().setUuid("UUID_1");
- AnalysisReportDto report2 = newDefaultAnalysisReport().setUuid("UUID_2");
+ AnalysisReportDto report1 = new AnalysisReportDto().setProjectKey("ProjectKey1").setProjectName("Project 1").setUuid("UUID_1").setStatus(PENDING);
+ AnalysisReportDto report2 = new AnalysisReportDto().setProjectKey("ProjectKey2").setProjectName("Project 2").setUuid("UUID_2").setStatus(PENDING);
sut.insert(session, report1);
sut.insert(session, report2);
@@ -115,6 +115,8 @@ public class AnalysisReportDaoTest {
assertThat(reports).hasSize(1);
assertThat(report.getProjectKey()).isEqualTo(projectKey);
+ assertThat(report.getProjectName()).isEqualTo("Project 1");
+ assertThat(report.getStatus()).isEqualTo(AnalysisReportDto.Status.WORKING);
assertThat(report.getId()).isEqualTo(1);
}
@@ -206,11 +208,4 @@ public class AnalysisReportDaoTest {
assertThat(reports).hasSize(3);
}
-
- private AnalysisReportDto newDefaultAnalysisReport() {
- return AnalysisReportDto.newForTests(1L)
- .setProjectKey(DEFAULT_PROJECT_KEY)
- .setUuid("REPORT_UUID")
- .setStatus(PENDING);
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java
index 86e27721204..9da351bc172 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueActionTest.java
@@ -51,6 +51,7 @@ public class QueueActionTest {
AnalysisReportDto report = AnalysisReportDto
.newForTests(1L)
.setProjectKey("project-key")
+ .setProjectName("Project name")
.setStatus(PENDING)
.setUuid("PROJECT_UUID")
.setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime())
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/SubmitReportActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/SubmitReportActionTest.java
index 72652f59a43..e0dd6760804 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ws/SubmitReportActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ws/SubmitReportActionTest.java
@@ -42,6 +42,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class SubmitReportActionTest {
+
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@@ -65,7 +66,7 @@ public class SubmitReportActionTest {
WebService.Action action = context.controller("api/computation").action("submit_report");
assertThat(action).isNotNull();
- assertThat(action.params()).hasSize(2);
+ assertThat(action.params()).hasSize(3);
}
@Test
@@ -73,15 +74,16 @@ public class SubmitReportActionTest {
userSessionRule.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
AnalysisReportDto dto = mock(AnalysisReportDto.class);
when(dto.getId()).thenReturn(42L);
- when(queue.add(any(String.class), any(InputStream.class))).thenReturn(new ReportQueue.Item(dto, null));
+ when(queue.add(any(String.class), any(String.class), any(InputStream.class))).thenReturn(new ReportQueue.Item(dto, null));
WsTester.TestRequest request = wsTester
.newPostRequest(ComputationWs.ENDPOINT, "submit_report")
.setParam(SubmitReportAction.PARAM_PROJECT_KEY, "P1")
+ .setParam(SubmitReportAction.PARAM_PROJECT_NAME, "Project 1")
.setParam(SubmitReportAction.PARAM_REPORT_DATA, null);
WsTester.Result response = request.execute();
- verify(queue).add(eq("P1"), any(InputStream.class));
+ verify(queue).add(eq("P1"), eq("Project 1"), any(InputStream.class));
verify(workerLauncher).startAnalysisTaskNow();
assertThat(response.outputAsString()).isEqualTo("{\"key\":\"42\"}");
}
@@ -93,6 +95,7 @@ public class SubmitReportActionTest {
WsTester.TestRequest request = wsTester
.newPostRequest(ComputationWs.ENDPOINT, "submit_report")
.setParam(SubmitReportAction.PARAM_PROJECT_KEY, "P1")
+ .setParam(SubmitReportAction.PARAM_PROJECT_NAME, "Project 1")
.setParam(SubmitReportAction.PARAM_REPORT_DATA, null);
request.execute();
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
index 4fd579504fe..d25e3641ce9 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
@@ -1,8 +1,8 @@
<dataset>
<analysis_reports
id="1"
- project_key="123456789-987654321"
- project_name="[null]"
+ project_key="ProjectKey1"
+ project_name="Project 1"
uuid="UUID_1"
report_status="PENDING"
started_at="[null]"
@@ -12,8 +12,8 @@
/>
<analysis_reports
id="2"
- project_key="123456789-987654321"
- project_name="[null]"
+ project_key="ProjectKey2"
+ project_name="Project 2"
uuid="UUID_2"
report_status="PENDING"
started_at="[null]"
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml
index c1e3284f108..de9d5b9f330 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml
@@ -2,6 +2,7 @@
<analysis_reports
id="1"
project_key="123456789-987654321"
+ project_name="Project 1"
uuid="UUID_1"
report_status="WORKING"
created_at="1411509600000"
@@ -10,6 +11,7 @@
<analysis_reports
id="2"
project_key="987654321-123456789"
+ project_name="Project 2"
uuid="UUID_2"
report_status="WORKING"
created_at="1411596000000"
@@ -18,6 +20,7 @@
<analysis_reports
id="3"
project_key="987654321-123456789"
+ project_name="Project 2"
uuid="UUID_3"
report_status="PENDING"
created_at="1411682400000"
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/ws/QueueActionTest/list_queue_reports.json b/server/sonar-server/src/test/resources/org/sonar/server/computation/ws/QueueActionTest/list_queue_reports.json
index 67f2234136f..10247f2e942 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/ws/QueueActionTest/list_queue_reports.json
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/ws/QueueActionTest/list_queue_reports.json
@@ -3,11 +3,11 @@
{
"key": 1,
"status": "PENDING",
- "projectName": "project-key",
+ "projectName": "Project name",
"projectKey": "project-key",
"submittedAt": "2014-10-13T00:00:00+0200",
"startedAt": "2014-10-13T00:00:00+0200",
"finishedAt": "2014-10-13T00:00:00+0200"
}
]
-} \ No newline at end of file
+}