diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-22 11:17:01 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-22 11:17:01 +0200 |
commit | 70b2098567fea4cd5619aa81b3757c7a8172088c (patch) | |
tree | 9a441bbf90be133c2efeff3aa3d2c3b79f5fcf84 /sonar-ws-client | |
parent | ac076a048acaadc3945b76da6ad282c60fcd7096 (diff) | |
download | sonarqube-70b2098567fea4cd5619aa81b3757c7a8172088c.tar.gz sonarqube-70b2098567fea4cd5619aa81b3757c7a8172088c.zip |
SONAR-4301 Update IssueFinder to first retreive authorized root projects for user and then search for authorized issues based on issue query. Also add project in Issue.
Diffstat (limited to 'sonar-ws-client')
9 files changed, 108 insertions, 2 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java index c00f4d25f0e..ff9bad62e2c 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java @@ -22,6 +22,7 @@ package org.sonar.wsclient.issue; import org.sonar.wsclient.unmarshallers.JsonUtils; import javax.annotation.CheckForNull; + import java.util.*; /** @@ -46,6 +47,10 @@ public class Issue { return JsonUtils.getString(json, "component"); } + public String projectKey() { + return JsonUtils.getString(json, "project"); + } + public String ruleKey() { return JsonUtils.getString(json, "rule"); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueParser.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueParser.java index 1bde473d793..0f225f03f8e 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueParser.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueParser.java @@ -61,7 +61,14 @@ class IssueParser { List<Map> jsonComponents = (List) jsonRoot.get("components"); if (jsonComponents != null) { for (Map jsonComponent : jsonComponents) { - result.add(new Component(jsonComponent)); + result.addComponent(new Component(jsonComponent)); + } + } + + List<Map> jsonProjects = (List) jsonRoot.get("projects"); + if (jsonProjects != null) { + for (Map jsonProject : jsonProjects) { + result.addProject(new Component(jsonProject)); } } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java index f3d57ebf99c..ab0c8f36ca9 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issues.java @@ -24,6 +24,7 @@ import org.sonar.wsclient.rule.Rule; import org.sonar.wsclient.user.User; import javax.annotation.CheckForNull; + import java.util.*; /** @@ -35,6 +36,7 @@ public class Issues { private final Map<String, Rule> rulesByKey = new HashMap<String, Rule>(); private final Map<String, User> usersByKey = new HashMap<String, User>(); private final Map<String, Component> componentsByKey = new HashMap<String, Component>(); + private final Map<String, Component> projectsByKey = new HashMap<String, Component>(); private Paging paging; private Boolean securityExclusions; @@ -72,6 +74,15 @@ public class Issues { return componentsByKey.get(issue.componentKey()); } + public Collection<Component> projects() { + return projectsByKey.values(); + } + + @CheckForNull + public Component project(Issue issue) { + return projectsByKey.get(issue.projectKey()); + } + public Paging paging() { return paging; } @@ -95,11 +106,16 @@ public class Issues { return this; } - Issues add(Component c) { + Issues addComponent(Component c) { componentsByKey.put(c.key(), c); return this; } + Issues addProject(Component c) { + projectsByKey.put(c.key(), c); + return this; + } + Issues setPaging(Paging paging) { this.paging = paging; return this; diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueParserTest.java index 1d84ad11cbc..6bc95d9fdc3 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueParserTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/IssueParserTest.java @@ -39,6 +39,7 @@ public class IssueParserTest { Issue first = list.get(0); assertThat(first.key()).isEqualTo("ABCDE"); assertThat(first.componentKey()).isEqualTo("Action.java"); + assertThat(first.projectKey()).isEqualTo("struts"); assertThat(first.ruleKey()).isEqualTo("squid:CycleBetweenPackages"); assertThat(first.severity()).isEqualTo("CRITICAL"); assertThat(first.line()).isEqualTo(10); @@ -155,4 +156,18 @@ public class IssueParserTest { assertThat(component.name()).isEqualTo("Action"); assertThat(component.longName()).isEqualTo("org.struts.Action"); } + + @Test + public void should_parse_projects() throws Exception { + String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json")); + Issues issues = new IssueParser().parseIssues(json); + + assertThat(issues.projects()).hasSize(1); + + Component component = issues.project(issues.list().get(0)); + assertThat(component.key()).isEqualTo("struts"); + assertThat(component.qualifier()).isEqualTo("TRK"); + assertThat(component.name()).isEqualTo("Struts"); + assertThat(component.longName()).isEqualTo("org.struts"); + } } diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json index 914e7627e7c..e5a213f7ba6 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-comments.json @@ -3,6 +3,7 @@ { "key": "ABCDE", "component": "Action.java", + "project": "struts", "rule": "squid:CycleBetweenPackages", "severity": "CRITICAL", "status": "OPEN", diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json index 0eae0aca856..86655ee1470 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-components.json @@ -3,6 +3,7 @@ { "key": "ABCDE", "component": "struts:Action.java", + "project": "struts", "rule": "squid:CycleBetweenPackages", "severity": "CRITICAL", "status": "OPEN", diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json new file mode 100644 index 00000000000..f0542d4f8bd --- /dev/null +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-projects.json @@ -0,0 +1,58 @@ +{ + "issues": [ + { + "key": "ABCDE", + "component": "struts:Action.java", + "project": "struts", + "rule": "squid:CycleBetweenPackages", + "severity": "CRITICAL", + "status": "OPEN", + "comments": [ + { + "key": "COMMENT-1", + "login": "morgan", + "htmlText": "the first comment", + "createdAt": "2013-05-18T13:45:34+0200" + }, + { + "key": "COMMENT-2", + "login": "arthur", + "htmlText": "the second comment", + "createdAt": "2013-06-19T00:02:03+0100" + } + ] + } + ], + "rules": [ + { + + "key": "squid:CycleBetweenPackages", + "name": "Avoid cycle between java packages", + "desc": "<p>\nWhen several packages are involved in a cycle (package A > package B > package C > package A where \">\" means \"depends upon\"),\nthat means that those packages are highly coupled and that there is no way to reuse/extract one of those packages without importing all the other packages.\nSuch cycle could quickly increase the effort required to maintain an application and to embrace business change.\nSonar not only detect cycles between packages but also determines what is the minimum effort to break those cycles.\nThis rule log a violation on each source file having an outgoing dependency to be but in order to break a cycle.\n</p>\n" + + } + ], + "components": [ + { + "key": "struts:Action.java", + "name": "Action", + "qualifier": "CLA", + "longName": "org.struts.Action" + } + ], + "projects": [ + { + "key": "struts", + "name": "Struts", + "qualifier": "TRK", + "longName": "org.struts" + } + ], + "paging": { + "pageIndex": 1, + "pageSize": 100, + "total": 2, + "pages": 1 + }, + "securityExclusions": true +}
\ No newline at end of file diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json index 7c4735ca98d..f076b290b4d 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/issue-with-users.json @@ -3,6 +3,7 @@ { "key": "ABCDE", "component": "Action.java", + "project": "struts", "rule": "squid:CycleBetweenPackages", "severity": "CRITICAL", "status": "OPEN", diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json index 8385fa8b09b..c88120f2dd9 100644 --- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/IssueParserTest/search.json @@ -3,6 +3,7 @@ { "key": "ABCDE", "component": "Action.java", + "project": "struts", "rule": "squid:CycleBetweenPackages", "severity": "CRITICAL", "line": 10, @@ -23,6 +24,7 @@ { "key": "FGHIJ", "component": "Filter.java", + "project": "struts", "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck", "severity": "BLOCKER", "resolution": "FIXED", |