}
private DefaultIssue newDefaultIssue(String message, Integer line, RuleKey ruleKey, String checksum) {
- return new DefaultIssue().setDescription(message).setLine(line).setRuleKey(ruleKey).setChecksum(checksum).setResolution(Issue.RESOLUTION_OPEN).setStatus(Issue.STATUS_OPEN);
+ return new DefaultIssue().setDescription(message).setLine(line).setRuleKey(ruleKey).setChecksum(checksum).setStatus(Issue.STATUS_OPEN);
}
private IssueDto newReferenceIssue(String message, Integer lineId, int ruleId, String lineChecksum) {
referenceIssue.setDescription(message);
referenceIssue.setRuleId(ruleId);
referenceIssue.setChecksum(lineChecksum);
- referenceIssue.setResolution(Issue.RESOLUTION_OPEN);
+ referenceIssue.setResolution(null);
referenceIssue.setStatus(Issue.STATUS_OPEN);
return referenceIssue;
}
return this;
}
+ @CheckForNull
public String resolution() {
return resolution;
}
- public DefaultIssue setResolution(String s) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(s), "Resolution must be set");
+ public DefaultIssue setResolution(@Nullable String s) {
this.resolution = s;
return this;
}
issue.setAttributes(attributes);
issue.setNew(true);
issue.setAlive(true);
- issue.setResolution(Issue.RESOLUTION_OPEN);
+ issue.setResolution(null);
issue.setStatus(Issue.STATUS_OPEN);
return issue;
}
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.issue.DefaultIssue;
+import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Date;
return this;
}
+ @CheckForNull
public String getSeverity() {
return severity;
}
return this;
}
+ @CheckForNull
public String getDescription() {
return description;
}
return this;
}
+ @CheckForNull
public Integer getLine() {
return line;
}
return this;
}
+ @CheckForNull
public Double getEffortToFix() {
return effortToFix;
}
return this;
}
+ @CheckForNull
public String getResolution() {
return resolution;
}
return this;
}
+ @CheckForNull
public String getChecksum() {
return checksum;
}
- public IssueDto setChecksum(String checksum) {
+ public IssueDto setChecksum(@Nullable String checksum) {
this.checksum = checksum;
return this;
}
+ @CheckForNull
public String getUserLogin() {
return userLogin;
}
import org.sonar.api.issue.Issue;
+import javax.annotation.Nullable;
+
interface Function {
interface Context {
Issue issue();
- Context setResolution(String s);
+ Context setResolution(@Nullable String s);
Context setCloseDate(boolean b);
}
.build())
.transition(Transition.builder(DefaultTransitions.REOPEN)
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
- .functions(new SetResolution(Issue.RESOLUTION_OPEN))
+ .functions(new SetResolution(null))
.build())
.transition(Transition.builder(DefaultTransitions.REOPEN)
.from(Issue.STATUS_CLOSED).to(Issue.STATUS_REOPENED)
- .functions(new SetResolution(Issue.RESOLUTION_OPEN), new SetCloseDate(false))
+ .functions(new SetResolution(null), new SetCloseDate(false))
.build())
.transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE)
.from(Issue.STATUS_OPEN).to(Issue.STATUS_RESOLVED)
.transition(Transition.builder("automaticreopen")
.from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
.conditions(new IsAlive(true), new HasResolution(Issue.RESOLUTION_FIXED))
- .functions(new SetResolution(Issue.RESOLUTION_OPEN))
+ .functions(new SetResolution(null))
.automatic()
.build())
.build();
*/
package org.sonar.core.issue.workflow;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
+import javax.annotation.Nullable;
public class SetResolution implements Function {
private final String resolution;
- public SetResolution(String resolution) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(resolution), "Resolution must be set");
+ public SetResolution(@Nullable String resolution) {
this.resolution = resolution;
}
assertThat(issue.technicalUpdateDate()).isNotNull();
assertThat(issue.assignee()).isNull();
assertThat(issue.isNew()).isTrue();
- assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_OPEN);
+ assertThat(issue.resolution()).isNull();
assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123");
assertThat(issue.attribute("YOUTRACK")).isEqualTo("YT-123");
}
}
- @Test
- public void should_fail_on_empty_resolution() {
- try {
- issue.setResolution("");
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("Resolution must be set");
- }
- }
-
@Test
public void should_fail_on_bad_severity() {
try {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue.workflow;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class SetResolutionTest {
+ @Test
+ public void execute() throws Exception {
+ SetResolution function = new SetResolution("FIXED");
+ Function.Context context = mock(Function.Context.class);
+ function.execute(context);
+ verify(context, times(1)).setResolution("FIXED");
+ }
+}
String STATUS_RESOLVED = "RESOLVED";
String STATUS_CLOSED = "CLOSED";
- String RESOLUTION_OPEN = "OPEN";
String RESOLUTION_FIXED = "FIXED";
String RESOLUTION_FALSE_POSITIVE = "FALSE-POSITIVE";
String status();
+ /**
+ * The type of resolution. Return null if the issue is not resolved.
+ */
+ @CheckForNull
String resolution();
@CheckForNull
:key => issue.key,
:component => issue.componentKey,
:rule => issue.ruleKey.toString(),
- :resolution => issue.resolution,
:status => issue.status
}
+ json[:resolution] = issue.resolution if issue.resolution
json[:severity] = issue.severity if issue.severity
json[:desc] = issue.description if issue.description
json[:line] = issue.line.to_i if issue.line
import org.sonar.wsclient.unmarshallers.JsonUtils;
+import javax.annotation.CheckForNull;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
return JsonUtils.getString(json, "severity");
}
+ @CheckForNull
public String description() {
return JsonUtils.getString(json, "desc");
}
+ @CheckForNull
public Integer line() {
return JsonUtils.getInteger(json, "line");
}
return JsonUtils.getDouble(json, "effortToFix");
}
+ @CheckForNull
public Double effortToFix() {
return JsonUtils.getDouble(json, "effortToFix");
}
return JsonUtils.getString(json, "status");
}
+ /**
+ * The resolution type. Null if the issue is not resolved.
+ */
+ @CheckForNull
public String resolution() {
return JsonUtils.getString(json, "resolution");
}
+ /**
+ * Login of the user who created the manual issue, else null.
+ */
+ @CheckForNull
public String userLogin() {
return JsonUtils.getString(json, "userLogin");
}
+ /**
+ * Login of assignee. Null if issue is not assigned.
+ */
+ @CheckForNull
public String assignee() {
return JsonUtils.getString(json, "assignee");
}
return JsonUtils.getDateTime(json, "updateDate");
}
+ @CheckForNull
public Date closeDate() {
return JsonUtils.getDateTime(json, "closeDate");
}
+ @CheckForNull
public String attribute(String key) {
return attributes().get(key);
}
assertThat(newIssue.urlParams()).hasSize(7).includes(
entry("component", "Action.java"),
- entry("cost", 4.2),
+ entry("effortToFix", 4.2),
entry("desc", "the desc"),
entry("line", 123),
entry("rule", "squid:AvoidCycle"),