diff options
Diffstat (limited to 'sonar-server/src/main/java/org/sonar')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java | 15 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/issue/IssueService.java | 29 |
2 files changed, 20 insertions, 24 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index d0362da17d0..bef324ee95f 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -21,6 +21,7 @@ package org.sonar.server.issue; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; +import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.collect.Iterables; @@ -35,9 +36,11 @@ import org.sonar.api.issue.action.Action; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rule.Severity; import org.sonar.api.utils.SonarException; import org.sonar.core.issue.ActionPlanStats; import org.sonar.core.issue.DefaultActionPlan; +import org.sonar.core.issue.DefaultIssueBuilder; import org.sonar.core.issue.DefaultIssueFilter; import org.sonar.core.issue.workflow.Transition; import org.sonar.core.resource.ResourceDao; @@ -233,8 +236,16 @@ public class InternalRubyIssueService implements ServerComponent { } if (result.ok()) { - DefaultIssue issue = issueService.createManualIssue(componentKey, ruleKey, RubyUtils.toInteger(params.get("line")), params.get("message"), params.get("severity"), - RubyUtils.toDouble(params.get("effortToFix")), UserSession.get()); + DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() + .componentKey(componentKey) + .line(RubyUtils.toInteger(params.get("line"))) + .message(params.get("message")) + .severity(Objects.firstNonNull(params.get("severity"), Severity.MAJOR)) + .effortToFix(RubyUtils.toDouble(params.get("effortToFix"))) + .ruleKey(ruleKey) + .reporter(UserSession.get().login()) + .build(); + issue = issueService.createManualIssue(issue, UserSession.get()); result.set(issue); } diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 7db9d49daca..db1664a919c 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue; -import com.google.common.base.Objects; import com.google.common.base.Strings; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; @@ -29,14 +28,11 @@ import org.sonar.api.issue.IssueQuery; import org.sonar.api.issue.IssueQueryResult; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.IssueChangeContext; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; import org.sonar.api.web.UserRole; -import org.sonar.core.issue.DefaultIssueBuilder; import org.sonar.core.issue.IssueNotifications; import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.db.IssueStorage; @@ -206,26 +202,15 @@ public class IssueService implements ServerComponent { return issue; } - public DefaultIssue createManualIssue(String componentKey, RuleKey ruleKey, @Nullable Integer line, @Nullable String message, @Nullable String severity, - @Nullable Double effortToFix, UserSession userSession) { + public DefaultIssue createManualIssue(DefaultIssue issue, UserSession userSession) { verifyLoggedIn(userSession); - ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(componentKey)); - ResourceDto project = resourceDao.getRootProjectByComponentKey(componentKey); - if (resourceDto == null || project == null) { - throw new IllegalArgumentException("Unknown component: " + componentKey); + ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(issue.componentKey())); + if (resourceDto == null) { + throw new IllegalArgumentException("Unknown component: " + issue.componentKey()); } - - DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder() - .componentKey(resourceDto.getKey()) - .projectKey(project.getKey()) - .line(line) - .message(message) - .severity(Objects.firstNonNull(severity, Severity.MAJOR)) - .effortToFix(effortToFix) - .ruleKey(ruleKey) - .reporter(UserSession.get().login()) - .build(); - + // Force use of correct key in case deprecated key is used + issue.setComponentKey(resourceDto.getKey()); + issue.setComponentId(resourceDto.getId()); if (!authorizationDao.isAuthorizedComponentKey(resourceDto.getKey(), userSession.userId(), UserRole.USER)) { // TODO throw unauthorized throw new IllegalStateException("User does not have the required role"); |