From 510f15727092dfd75a1476c6054fbb3ff40e831e Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 31 May 2013 13:11:25 +0200 Subject: [PATCH] SONAR-3755 fix JSON report when directly analyzing module (like in Eclipse plugin) --- .../sonar/plugins/core/issue/InitialOpenIssuesSensor.java | 4 ++++ .../plugins/core/issue/InitialOpenIssuesSensorTest.java | 7 +++++++ .../org/sonar/core/persistence/DryRunDatabaseFactory.java | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensor.java index a5677fb1894..a0b9f41e94f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensor.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensor.java @@ -53,4 +53,8 @@ public class InitialOpenIssuesSensor implements Sensor { initialOpenIssuesStack.setIssues(dtos, loadingDate); } + @Override + public String toString() { + return getClass().getSimpleName(); + } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensorTest.java index ba380daaec4..8a91e329f3c 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/InitialOpenIssuesSensorTest.java @@ -27,6 +27,7 @@ import org.sonar.core.issue.db.IssueDto; import java.util.Date; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyListOf; import static org.mockito.Mockito.mock; @@ -49,4 +50,10 @@ public class InitialOpenIssuesSensorTest { verify(issueDao).selectNonClosedIssuesByModule(1); verify(stack).setIssues(anyListOf(IssueDto.class), any(Date.class)); } + + @Test + public void test_toString() throws Exception { + assertThat(sensor.toString()).isEqualTo("InitialOpenIssuesSensor"); + + } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 0ecfc403f79..dcf0231c742 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -77,7 +77,7 @@ public class DryRunDatabaseFactory implements ServerComponent { .copyTable(source, dest, "rules_profiles"); if (projectId != null) { String snapshotCondition = "islast=" + database.getDialect().getTrueSqlValue() + " and (project_id=" + projectId + " or root_project_id=" + projectId + ")"; - template.copyTable(source, dest, "projects", "(id=" + projectId + " or root_id=" + projectId + ")"); + template.copyTable(source, dest, "projects", "id in (select project_id from snapshots where " + snapshotCondition + ") or (id=" + projectId + " or root_id=" + projectId + ")"); template.copyTable(source, dest, "snapshots", snapshotCondition); String forRootModule = "(root_component_id in (select id from projects where id=" + projectId + " and qualifier='TRK'))"; -- 2.39.5