]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5931 Cleanup new issue API
authorJulien HENRY <julien.henry@sonarsource.com>
Thu, 19 Feb 2015 22:06:58 +0000 (23:06 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 20 Feb 2015 08:36:21 +0000 (09:36 +0100)
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/checks/TemplateRuleCheck.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/CreateIssueByInternalKeySensor.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssueOnDirPerFileSensor.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/RandomAccessSensor.java
sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.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/issue/Issuable.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java

index 01fd6ad0c1544bff846886dc039eda8b45d4b027..9e58a41052606ff3d6d157294fc669bb2c8c94b9 100644 (file)
@@ -38,7 +38,7 @@ public class TemplateRuleCheck implements Check {
   public void execute(SensorContext sensorContext, InputFile file, RuleKey ruleKey) {
     sensorContext.newIssue()
       .onFile(file)
-      .ruleKey(ruleKey)
+      .forRule(ruleKey)
       .atLine(line)
       .save();
   }
index 01973adef9741f8abede28d563d2d702705330d0..5a1cefcab8e96a2c049d8c2ecc6251134a833b1a 100644 (file)
@@ -55,7 +55,7 @@ public class CreateIssueByInternalKeySensor implements Sensor {
       context.settings().getString(INTERNAL_KEY_PROPERTY));
     if (rule != null) {
       context.newIssue()
-        .ruleKey(rule.ruleKey())
+        .forRule(rule.ruleKey())
         .onFile(file)
         .message("This issue is generated on each file")
         .save();
index 66a31686e03eafff5288cd1b3feff417578a8a89..6dbda2f741a5c40f2a8dc10195c3e80b996ebeda 100644 (file)
@@ -51,7 +51,7 @@ public class OneIssueOnDirPerFileSensor implements Sensor {
     InputDir inputDir = context.fileSystem().inputDir(file.file().getParentFile());
     if (inputDir != null) {
       context.newIssue()
-        .ruleKey(ruleKey)
+        .forRule(ruleKey)
         .onDir(inputDir)
         .message("This issue is generated for file " + file.relativePath())
         .save();
index 7e79e2857f6e3bfc8bad4f4732e18c31d4f1c7a5..4aa4ea7e33f55cd627da7f1bbd4020559dbc9890 100644 (file)
@@ -58,7 +58,7 @@ public class OneIssuePerLineSensor implements Sensor {
     String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY);
     for (int line = 1; line <= file.lines(); line++) {
       context.newIssue()
-        .ruleKey(ruleKey)
+        .forRule(ruleKey)
         .onFile(file)
         .atLine(line)
         .effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY))
index 6d51bd8661a79fd080ba75f56df7d78ad32dc522..0541d91755243c9379ef91379517038b4e41df41 100644 (file)
@@ -64,7 +64,7 @@ public class RandomAccessSensor implements Sensor {
   private void createIssues(InputFile file, SensorContext context) {
     RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
     context.newIssue()
-      .ruleKey(ruleKey)
+      .forRule(ruleKey)
       .onFile(file)
       .atLine(1)
       .message("This issue is generated on each file")
index 02b526f0375d75e667d138e7fa8cdcf8108fdab1..157bd38a20a530d1292b7e0d8c5c0da52b791f00 100644 (file)
@@ -187,7 +187,7 @@ public class DefaultSensorStorageTest {
 
     sensorStorage.store(new DefaultIssue()
       .onFile(file)
-      .ruleKey(RuleKey.of("foo", "bar"))
+      .forRule(RuleKey.of("foo", "bar"))
       .message("Foo")
       .atLine(3)
       .effortToFix(10.0));
@@ -213,7 +213,7 @@ public class DefaultSensorStorageTest {
 
     sensorStorage.store(new DefaultIssue()
       .onDir(dir)
-      .ruleKey(RuleKey.of("foo", "bar"))
+      .forRule(RuleKey.of("foo", "bar"))
       .message("Foo")
       .effortToFix(10.0));
 
@@ -236,7 +236,7 @@ public class DefaultSensorStorageTest {
 
     sensorStorage.store(new DefaultIssue()
       .onProject()
-      .ruleKey(RuleKey.of("foo", "bar"))
+      .forRule(RuleKey.of("foo", "bar"))
       .message("Foo")
       .overrideSeverity(Severity.BLOCKER)
       .effortToFix(10.0));
index 8819fc23b25fc198b979db9cdaa423c3f8a0ac8c..734627d568d547743f59195c254a56f8d32f16ba 100644 (file)
@@ -37,7 +37,7 @@ public interface NewIssue {
   /**
    * The {@link RuleKey} of the issue.
    */
-  NewIssue ruleKey(RuleKey ruleKey);
+  NewIssue forRule(RuleKey ruleKey);
 
   /**
    * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}.
index c029722eb9d4d9c08ff6100dfa9c7b58011c5c3c..585ebcf647a57b7db7b460eeaf41cc202567ed69 100644 (file)
@@ -61,7 +61,7 @@ public class DefaultIssue extends DefaultStorable implements Issue, NewIssue {
   }
 
   @Override
-  public DefaultIssue ruleKey(RuleKey ruleKey) {
+  public DefaultIssue forRule(RuleKey ruleKey) {
     this.ruleKey = ruleKey;
     return this;
   }
index 73160cfc23dd5cba607a8cda49fd7bc7f9623a07..3e7ef41be8549021c436bfd30e1b5499f8a10ea4 100644 (file)
 
 package org.sonar.api.issue;
 
+import org.sonar.api.batch.sensor.SensorContext;
 import org.sonar.api.component.Perspective;
 import org.sonar.api.rule.RuleKey;
 
 import javax.annotation.Nullable;
+
 import java.util.List;
 
 /**
@@ -59,6 +61,10 @@ import java.util.List;
  */
 public interface Issuable extends Perspective {
 
+  /**
+   * @deprecated since 5.1 use {@link SensorContext#newIssue()}
+   */
+  @Deprecated
   interface IssueBuilder {
     /**
      * The rule key is mandatory. Example: {@code RuleKey.of("pmd", "AvoidArrayLoops")}
@@ -97,7 +103,9 @@ public interface Issuable extends Perspective {
 
   /**
    * Builder is used to create the issue to be passed to {@link #addIssue(Issue)}
+   * @deprecated since 5.1 use {@link SensorContext#newIssue()}
    */
+  @Deprecated
   IssueBuilder newIssueBuilder();
 
   /**
@@ -107,7 +115,9 @@ public interface Issuable extends Perspective {
    * method must be annotated with {@code @DependedUpon(DecoratorBarriers.ISSUES_ADDED)}.
    *
    * @return true if the new issue is registered, false if the related rule does not exist or is disabled in the Quality profile.
+   * @deprecated since 5.1 use {@link SensorContext#newIssue()}
    */
+  @Deprecated
   boolean addIssue(Issue issue);
 
   /**
index 8973939afe35f0d97be822becd617babd9a3d028..86be3bd947fdc3f41d953e6bec2fa845f53baf70 100644 (file)
@@ -40,7 +40,7 @@ public class DefaultIssueTest {
     SensorStorage storage = mock(SensorStorage.class);
     DefaultIssue issue = new DefaultIssue(storage)
       .onFile(new DefaultInputFile("foo", "src/Foo.php"))
-      .ruleKey(RuleKey.of("repo", "rule"))
+      .forRule(RuleKey.of("repo", "rule"))
       .atLine(1)
       .effortToFix(10.0)
       .message("Wrong way!");
@@ -61,7 +61,7 @@ public class DefaultIssueTest {
     SensorStorage storage = mock(SensorStorage.class);
     DefaultIssue issue = new DefaultIssue(storage)
       .onProject()
-      .ruleKey(RuleKey.of("repo", "rule"))
+      .forRule(RuleKey.of("repo", "rule"))
       .effortToFix(10.0)
       .message("Wrong way!");
 
@@ -83,7 +83,7 @@ public class DefaultIssueTest {
     new DefaultIssue()
       .onProject()
       .onFile(new DefaultInputFile("foo", "src/Foo.php"))
-      .ruleKey(RuleKey.of("repo", "rule"))
+      .forRule(RuleKey.of("repo", "rule"))
       .atLine(1)
       .effortToFix(10.0)
       .message("Wrong way!");