]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7414 Change Sensor API to update Issue#effortToFix to Issue#gap 844/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 15 Mar 2016 15:41:22 +0000 (16:41 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 16 Mar 2016 13:04:34 +0000 (14:04 +0100)
23 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerRawInputFactory.java
server/sonar-server/src/test/java/org/sonar/server/computation/issue/TrackerRawInputFactoryTest.java
sonar-batch-protocol/src/main/protobuf/batch_report.proto
sonar-batch/src/main/java/org/sonar/batch/issue/DefaultFilterableIssue.java
sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilter.java
sonar-batch/src/main/java/org/sonar/batch/issue/IssueTransformer.java
sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
sonar-batch/src/main/java/org/sonar/batch/issue/TrackedIssueAdapter.java
sonar-batch/src/main/java/org/sonar/batch/issue/tracking/TrackedIssue.java
sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java
sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
sonar-batch/src/test/java/org/sonar/batch/issue/DefaultFilterableIssueTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedIssueAdapterForFilterTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/TrackedIssueAdapterTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/postjob/DefaultPostJobContextTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java
sonar-plugin-api/src/main/java/org/sonar/api/scan/issue/filter/FilterableIssue.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java

index b557b1a01339bf4dd797b27b52465cb558900a79..4af4e673a9cec4d9294d55d7951c2592a53f2a81 100644 (file)
@@ -125,8 +125,8 @@ public class TrackerRawInputFactory {
       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()) {
index 90c6399d0abdb6a5d2ff072e04426c24b08ab2d7..c2d2baab7062b4d42d2bc1c0a8bd1378f624a68b 100644 (file)
@@ -93,7 +93,7 @@ public class TrackerRawInputFactoryTest {
       .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);
@@ -107,6 +107,7 @@ public class TrackerRawInputFactoryTest {
     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
index 2913e856fb20c3e89b31bad1738aae6ad381fc06..2abebf20e00cf51e9f21eef5f6e2427707b97475 100644 (file)
@@ -100,7 +100,7 @@ message Issue {
   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;
index a66d2cefa50bcddcb68c73893833371ac9791b49..a7f28e5bfa4d036e896eb4c773bcbe5559c5dd81 100644 (file)
  */
 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;
@@ -67,9 +64,14 @@ public class DefaultFilterableIssue implements FilterableIssue {
     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
index 567f66a3fcf722f6ae8a7a4c52501428d29b5704..f6df0fdbd39ac2b26abd6bf2a99b8cef4a59eb1e 100644 (file)
@@ -88,7 +88,7 @@ class DeprecatedIssueAdapterForFilter implements Issue {
 
   @Override
   public Double gap() {
-    return rawIssue.hasEffortToFix() ? rawIssue.getEffortToFix() : null;
+    return rawIssue.hasGap() ? rawIssue.getGap() : null;
   }
 
   @Override
index 53905a2e5cf4fe4b26e79e25a8757230d4fb631f..b606854be93de106c8dbd3aa3c3d0063fea8c50c 100644 (file)
  */
 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
@@ -96,7 +93,7 @@ public class IssueTransformer {
     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);
index eff02beb953ff20c1d16d105a146afdc6f4a73ca..fb798fd563bbcc158bf3501f572b27ce43167d15 100644 (file)
@@ -91,9 +91,9 @@ public class ModuleIssues {
       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();
index f8f21ea2e0eb6695286113660a8d964c360f85b1..19027847d9d778c8a8bc581034f46edb2185c2b2 100644 (file)
@@ -79,7 +79,7 @@ public class TrackedIssueAdapter implements Issue {
 
   @Override
   public Double gap() {
-    return issue.effortToFix();
+    return issue.gap();
   }
 
   @Override
index 16f4273b67e07829b2f8639911236913b809acc8..ea303bf6a4f65639af294a49d95535f9c65de4c6 100644 (file)
@@ -39,7 +39,7 @@ public class TrackedIssue implements Trackable, Serializable {
   private Integer startLineOffset;
   private Integer endLine;
   private Integer endLineOffset;
-  private Double effortToFix;
+  private Double gap;
   private boolean isNew;
   private Date creationDate;
   private String resolution;
@@ -186,8 +186,8 @@ public class TrackedIssue implements Trackable, Serializable {
     return severity;
   }
 
-  public Double effortToFix() {
-    return effortToFix;
+  public Double gap() {
+    return gap;
   }
 
   public Date getCreationDate() {
@@ -222,8 +222,8 @@ public class TrackedIssue implements Trackable, Serializable {
     return this;
   }
 
-  public TrackedIssue setEffortToFix(Double effortToFix) {
-    this.effortToFix = effortToFix;
+  public TrackedIssue setGap(Double gap) {
+    this.gap = gap;
     return this;
   }
 
index 75a80981793b41c1a9e8bf2329c4f52cb128fcd6..02b1582b99980fdd2c13efff8cf71a5c2af7f706 100644 (file)
@@ -108,7 +108,7 @@ public class DefaultPostJobContext implements PostJobContext {
 
     @Override
     public Double effortToFix() {
-      return wrapped.effortToFix();
+      return wrapped.gap();
     }
 
     @Override
index 3ad574574d9d7bc57d164863a7a05fcf712f61dc..f0c2e2b6da78f9a6ca308a268b7db0309ed9d110 100644 (file)
@@ -148,7 +148,7 @@ public class JSONReport implements Reporter {
           .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());
index 8c0c70d822e49cfeefb5e41bf7ad5dffad0e3e16..4e1ed3d053a99be3406bcdcb87b5966c67ea139f 100644 (file)
@@ -47,7 +47,7 @@ public class DefaultFilterableIssueTest {
   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();
index 952b0c587fd197b8bec2ae81c6e1fdcef5388419..ba835314e532aa9bba5f8da22690bd770ea78301 100644 (file)
@@ -52,7 +52,7 @@ public class DeprecatedIssueAdapterForFilterTest {
         .setSeverity(Severity.BLOCKER)
         .setMsg("msg")
         .setLine(1)
-        .setEffortToFix(2.0)
+        .setGap(2.0)
         .build(),
       COMPONENT_KEY);
 
index 268ee46371f01b32c018ffaa88833a3f7d759db8..11fc560b3181c1eb9943a1ce68ff405bfdd0fc86 100644 (file)
@@ -39,7 +39,7 @@ public class TrackedIssueAdapterTest {
       .setSeverity("MAJOR")
       .setMessage("msg")
       .setStartLine(1)
-      .setEffortToFix(2.0)
+      .setGap(2.0)
       .setStatus("RESOLVED")
       .setResolution("FIXED")
       .setReporter("toto")
index 70d31c2f8a2b04f24048d66166250ca545a3931d..418b11044042f6e8c14f95d5f6369b16450dcc24 100644 (file)
  */
 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;
@@ -29,24 +31,20 @@ import org.junit.Rule;
 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();
 
@@ -71,7 +69,7 @@ public class ProjectBuilderMediumTest {
   @Test
   public void testProjectBuilder() throws IOException {
     File baseDir = prepareProject();
-    
+
     TaskResult result = tester.newTask()
       .properties(ImmutableMap.<String, String>builder()
         .put("sonar.task", "scan")
@@ -92,18 +90,18 @@ public class ProjectBuilderMediumTest {
       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()
@@ -147,12 +145,12 @@ public class ProjectBuilderMediumTest {
       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");
@@ -163,7 +161,7 @@ public class ProjectBuilderMediumTest {
 
     File xooFile = new File(srcDir, "sample.xoo");
     FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
-    
+
     return baseDir;
   }
 
index a6bb661943e7c1bfda2c82e714997cab63fef1b1..176c51ca5d7e2c3aafb8eb8d9e0adb0f7b74895d 100644 (file)
@@ -106,7 +106,7 @@ public class IssuesMediumTest {
       .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
@@ -170,7 +170,7 @@ public class IssuesMediumTest {
       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();
index 9c1abdc2d8cb9bc23222612c36ba2464e2968dba..12f00a55d9053a725b1beb2d265d3ded0d8afad7 100644 (file)
@@ -61,7 +61,7 @@ public class DefaultPostJobContextTest {
 
     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);
index 653b26e09bbc0c044f04c6f85152517c86f73e45..fdeadc562dd7957426040ab8dc94d12bdb1cdfe9 100644 (file)
@@ -111,7 +111,7 @@ public class JSONReportTest {
     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"));
index 0f3f88cb1a085e215c064fd6a9bf7f7117b8e5df..1f2753907880792b9f703bbb71191d87f0cb5d96 100644 (file)
@@ -48,10 +48,19 @@ public interface Issue {
 
   /**
    * 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.
    */
index a4a22f50b0e8e8588c7b7cff7a95bbbe300a53bd..2dbf02b31d104ef1794f75b002144d21e190bcbf 100644 (file)
@@ -40,9 +40,17 @@ public interface NewIssue {
 
   /**
    * 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.
index c2bf9bf12ef5e8c9a6910297ef54560dd0d98d16..2ee5cc74ab485ed26ac3c0f5d6cb4b5d6f6e56d0 100644 (file)
@@ -53,7 +53,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {
   }
 
   private RuleKey ruleKey;
-  private Double effortToFix;
+  private Double gap;
   private Severity overriddenSeverity;
   private IssueLocation primaryLocation;
   private List<List<IssueLocation>> flows = new ArrayList<>();
@@ -74,8 +74,13 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {
 
   @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;
   }
 
@@ -124,9 +129,14 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {
     return this.overriddenSeverity;
   }
 
+  @Override
+  public Double gap() {
+    return this.gap;
+  }
+
   @Override
   public Double effortToFix() {
-    return this.effortToFix;
+    return this.gap;
   }
 
   @Override
index dc66b00b1bb4019c5a55972efd10b51687c4958a..026ccf439cbb0a82c90e054ce2712cad8f0c8667 100644 (file)
@@ -19,9 +19,8 @@
  */
 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
@@ -38,8 +37,17 @@ public interface FilterableIssue {
 
   Integer line();
 
+  /**
+   * @deprecated since 5.5 use {@link #gap()}
+   */
+  @Deprecated
   Double effortToFix();
 
+  /**
+   * @since 5.5
+   */
+  Double gap();
+
   Date creationDate();
 
   String projectKey();
index ca629c6baf26501806b0cdacc78afe93fb100f1c..6b380a0c6b70186d3de24a0897c7f22b3bb9f913 100644 (file)
@@ -46,12 +46,12 @@ public class DefaultIssueTest {
         .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();