if (reportIssue.hasSeverity()) {
issue.setSeverity(reportIssue.getSeverity().name());
}
- if (reportIssue.hasEffortToFix()) {
- issue.setGap(reportIssue.getEffortToFix());
+ if (reportIssue.hasGap()) {
+ issue.setGap(reportIssue.getGap());
}
DbIssues.Locations.Builder dbLocationsBuilder = DbIssues.Locations.newBuilder();
if (reportIssue.hasTextRange()) {
.setRuleRepository("java")
.setRuleKey("S001")
.setSeverity(Constants.Severity.BLOCKER)
- .setEffortToFix(3.14)
+ .setGap(3.14)
.build();
reportReader.putIssues(FILE.getReportAttributes().getRef(), asList(reportIssue));
Input<DefaultIssue> input = underTest.create(FILE);
assertThat(issue.severity()).isEqualTo(Severity.BLOCKER);
assertThat(issue.line()).isEqualTo(2);
assertThat(issue.effortToFix()).isEqualTo(3.14);
+ assertThat(issue.gap()).isEqualTo(3.14);
assertThat(issue.message()).isEqualTo("the message");
// fields set by compute engine
optional int32 line = 3;
optional string msg = 4;
optional Severity severity = 5;
- optional double effort_to_fix = 6;
+ optional double gap = 6;
// Only when issue component is a file. Can also be empty for a file if this is an issue global to the file.
optional TextRange text_range = 7;
repeated Flow flow = 8;
*/
package org.sonar.batch.issue;
+import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-
import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
-
-import java.util.Date;
-
-import org.sonar.batch.protocol.output.BatchReport.Issue;
import org.sonar.api.scan.issue.filter.FilterableIssue;
+import org.sonar.batch.protocol.output.BatchReport.Issue;
public class DefaultFilterableIssue implements FilterableIssue {
private final Issue rawIssue;
return rawIssue.hasLine() ? rawIssue.getLine() : null;
}
+ @Override
+ public Double gap() {
+ return rawIssue.hasGap() ? rawIssue.getGap() : null;
+ }
+
@Override
public Double effortToFix() {
- return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null;
+ return gap();
}
@Override
@Override
public Double gap() {
- return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null;
+ return rawIssue.hasGap() ? rawIssue.getGap() : null;
}
@Override
*/
package org.sonar.batch.issue;
-import org.sonar.batch.issue.tracking.SourceHashHolder;
-
-import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import javax.annotation.Nullable;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.batch.index.BatchComponent;
+import org.sonar.batch.issue.tracking.SourceHashHolder;
import org.sonar.batch.issue.tracking.TrackedIssue;
+import org.sonar.batch.protocol.input.BatchInput.ServerIssue;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReport.TextRange;
import org.sonar.core.component.ComponentKeys;
import org.sonar.core.util.Uuids;
-import javax.annotation.Nullable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
public class IssueTransformer {
private IssueTransformer() {
// static only
issue.setKey(Uuids.createFast());
issue.setComponentKey(component.key());
issue.setRuleKey(ruleKey);
- issue.setEffortToFix(rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null);
+ issue.setGap(rawIssue.hasGap() ? rawIssue.getGap() : null);
issue.setSeverity(rawIssue.getSeverity().name());
issue.setMessage(rawIssue.hasMsg() ? rawIssue.getMsg() : null);
issue.setResolution(null);
builder.setLine(primaryTextRange.start().line());
builder.setTextRange(toProtobufTextRange(primaryTextRange));
}
- Double effortToFix = issue.effortToFix();
- if (effortToFix != null) {
- builder.setEffortToFix(effortToFix);
+ Double gap = issue.gap();
+ if (gap != null) {
+ builder.setGap(gap);
}
applyFlows(issue);
BatchReport.Issue rawIssue = builder.build();
@Override
public Double gap() {
- return issue.effortToFix();
+ return issue.gap();
}
@Override
private Integer startLineOffset;
private Integer endLine;
private Integer endLineOffset;
- private Double effortToFix;
+ private Double gap;
private boolean isNew;
private Date creationDate;
private String resolution;
return severity;
}
- public Double effortToFix() {
- return effortToFix;
+ public Double gap() {
+ return gap;
}
public Date getCreationDate() {
return this;
}
- public TrackedIssue setEffortToFix(Double effortToFix) {
- this.effortToFix = effortToFix;
+ public TrackedIssue setGap(Double gap) {
+ this.gap = gap;
return this;
}
@Override
public Double effortToFix() {
- return wrapped.effortToFix();
+ return wrapped.gap();
}
@Override
.prop("resolution", issue.resolution())
.prop("isNew", issue.isNew())
.prop("assignee", issue.assignee())
- .prop("effortToFix", issue.effortToFix())
+ .prop("effortToFix", issue.gap())
.propDateTime("creationDate", issue.creationDate());
if (!StringUtils.isEmpty(issue.reporter())) {
logins.add(issue.reporter());
private Issue createIssue() {
Issue.Builder builder = Issue.newBuilder();
- builder.setEffortToFix(3.0);
+ builder.setGap(3.0);
builder.setLine(30);
builder.setSeverity(Severity.MAJOR);
return builder.build();
.setSeverity(Severity.BLOCKER)
.setMsg("msg")
.setLine(1)
- .setEffortToFix(2.0)
+ .setGap(2.0)
.build(),
COMPONENT_KEY);
.setSeverity("MAJOR")
.setMessage("msg")
.setStartLine(1)
- .setEffortToFix(2.0)
+ .setGap(2.0)
.setStatus("RESOLVED")
.setResolution("FIXED")
.setReporter("toto")
*/
package org.sonar.batch.mediumtest.fs;
-import org.sonar.api.utils.MessageException;
-
import com.google.common.collect.ImmutableMap;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.sonar.api.utils.MessageException;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.TaskResult;
import org.sonar.batch.protocol.output.BatchReport.Issue;
import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-
import static org.assertj.core.api.Assertions.assertThat;
public class ProjectBuilderMediumTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
-
+
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testProjectBuilder() throws IOException {
File baseDir = prepareProject();
-
+
TaskResult result = tester.newTask()
.properties(ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
if (issue.getLine() == 1) {
foundIssueAtLine1 = true;
assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
- assertThat(issue.hasEffortToFix()).isFalse();
+ assertThat(issue.hasGap()).isFalse();
}
}
assertThat(foundIssueAtLine1).isTrue();
}
-
+
@Test
// SONAR-6976
public void testProjectBuilderWithNewLine() throws IOException {
File baseDir = prepareProject();
-
+
exception.expect(MessageException.class);
exception.expectMessage("is not a valid branch name");
tester.newTask()
if (issue.getLine() == 1) {
foundIssueAtLine1 = true;
assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
- assertThat(issue.hasEffortToFix()).isFalse();
+ assertThat(issue.hasGap()).isFalse();
}
}
assertThat(foundIssueAtLine1).isTrue();
}
-
+
private File prepareProject() throws IOException {
File baseDir = temp.getRoot();
File module1Dir = new File(baseDir, "module1");
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
-
+
return baseDir;
}
.start();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
- assertThat(issues).hasSize(8 /* lines */+ 1 /* file */);
+ assertThat(issues).hasSize(8 /* lines */ + 1 /* file */);
}
@Test
if (issue.getLine() == 1) {
foundIssueAtLine1 = true;
assertThat(issue.getMsg()).isEqualTo("This issue is generated on each line");
- assertThat(issue.hasEffortToFix()).isFalse();
+ assertThat(issue.hasGap()).isFalse();
}
}
assertThat(foundIssueAtLine1).isTrue();
TrackedIssue defaultIssue = new TrackedIssue();
defaultIssue.setComponentKey("foo:src/Foo.php");
- defaultIssue.setEffortToFix(2.0);
+ defaultIssue.setGap(2.0);
defaultIssue.setNew(true);
defaultIssue.setKey("xyz");
defaultIssue.setStartLine(1);
issue.setEndLine(2);
issue.setStartLineOffset(3);
issue.setEndLineOffset(4);
- issue.setEffortToFix(3.14);
+ issue.setGap(3.14);
issue.setReporter("julien");
issue.setAssignee("simon");
issue.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"));
/**
* Effort to fix the issue. Used by technical debt model.
+ * @deprecated since 5.5 use {@link #gap()}
*/
@CheckForNull
+ @Deprecated
Double effortToFix();
+ /**
+ * Gap used to compute the effort for fixing the issue.
+ * @since 5.5
+ */
+ @CheckForNull
+ Double gap();
+
/**
* Overridden severity.
*/
/**
* Effort to fix the issue.
+ * @deprecated since 5.5 use {@link #gap(Double)}
*/
+ @Deprecated
NewIssue effortToFix(@Nullable Double effortToFix);
+ /**
+ * Gap used for the computation of the effort.
+ * @since 5.5
+ */
+ NewIssue gap(@Nullable Double gap);
+
/**
* Override severity of the issue.
* Setting a null value or not calling this method means to use severity configured in quality profile.
}
private RuleKey ruleKey;
- private Double effortToFix;
+ private Double gap;
private Severity overriddenSeverity;
private IssueLocation primaryLocation;
private List<List<IssueLocation>> flows = new ArrayList<>();
@Override
public DefaultIssue effortToFix(@Nullable Double effortToFix) {
- Preconditions.checkArgument(effortToFix == null || effortToFix >= 0, format("Effort to fix must be greater than or equal 0 (got %s)", effortToFix));
- this.effortToFix = effortToFix;
+ return gap(effortToFix);
+ }
+
+ @Override
+ public DefaultIssue gap(@Nullable Double gap) {
+ Preconditions.checkArgument(gap == null || gap >= 0, format("Gap must be greater than or equal 0 (got %s)", gap));
+ this.gap = gap;
return this;
}
return this.overriddenSeverity;
}
+ @Override
+ public Double gap() {
+ return this.gap;
+ }
+
@Override
public Double effortToFix() {
- return this.effortToFix;
+ return this.gap;
}
@Override
*/
package org.sonar.api.scan.issue.filter;
-import org.sonar.api.rule.RuleKey;
-
import java.util.Date;
+import org.sonar.api.rule.RuleKey;
/**
* @since 5.3
Integer line();
+ /**
+ * @deprecated since 5.5 use {@link #gap()}
+ */
+ @Deprecated
Double effortToFix();
+ /**
+ * @since 5.5
+ */
+ Double gap();
+
Date creationDate();
String projectKey();
.at(inputFile.selectLine(1))
.message("Wrong way!"))
.forRule(RuleKey.of("repo", "rule"))
- .effortToFix(10.0);
+ .gap(10.0);
assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile);
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1);
- assertThat(issue.effortToFix()).isEqualTo(10.0);
+ assertThat(issue.gap()).isEqualTo(10.0);
assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!");
issue.save();