diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-19 22:34:14 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-19 22:34:14 +0100 |
commit | 51db1a41ea40cf2d07f4cebaf2feef12d80c2a34 (patch) | |
tree | a61fbb8804cf30cb5ced93e5584332fc20717578 /sonar-plugin-api | |
parent | 0f517d524485bcc0acb47a7f00d54b2e1bac4f50 (diff) | |
download | sonarqube-51db1a41ea40cf2d07f4cebaf2feef12d80c2a34.tar.gz sonarqube-51db1a41ea40cf2d07f4cebaf2feef12d80c2a34.zip |
SONAR-5931 Cleanup new issue API
Diffstat (limited to 'sonar-plugin-api')
11 files changed, 105 insertions, 68 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 336a7eef61a..bd15a900398 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -28,6 +28,7 @@ import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.duplication.NewDuplication; import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder; import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder; @@ -71,9 +72,9 @@ public interface SensorContext { // ----------- ISSUES -------------- /** - * Fluent builder to create a new {@link Issue}. Don't forget to call {@link Issue#save()} once all parameters are provided. + * Fluent builder to create a new {@link Issue}. Don't forget to call {@link NewIssue#save()} once all parameters are provided. */ - Issue newIssue(); + NewIssue newIssue(); // ------------ HIGHLIGHTING ------------ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java index 9dcb3d34ece..56161c29646 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java @@ -19,12 +19,13 @@ */ package org.sonar.api.batch.sensor.dependency.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.dependency.Dependency; import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.internal.DefaultStorable; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java index 496f3cd9332..d9836036646 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplication.java @@ -19,6 +19,8 @@ */ package org.sonar.api.batch.sensor.duplication.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -26,7 +28,6 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.duplication.NewDuplication; import org.sonar.api.batch.sensor.internal.DefaultStorable; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java index e3b7f919f2c..31f16142b57 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java @@ -23,7 +23,6 @@ import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.sensor.SensorStorage; import javax.annotation.Nullable; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorStorage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java index 7ee6b308936..69b79f7addf 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorStorage.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java @@ -17,7 +17,7 @@ * 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.api.batch.sensor; +package org.sonar.api.batch.sensor.internal; import org.sonar.api.batch.sensor.dependency.Dependency; import org.sonar.api.batch.sensor.duplication.Duplication; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java index e126ddef95b..d320bd2c11f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java @@ -19,22 +19,17 @@ */ package org.sonar.api.batch.sensor.issue; -import com.google.common.annotations.Beta; -import org.sonar.api.batch.fs.InputDir; -import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.rule.RuleKey; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; /** * Represents an issue detected by a {@link Sensor}. * - * @since 5.0 + * @since 5.1 */ -@Beta public interface Issue { public enum Severity { @@ -46,43 +41,17 @@ public interface Issue { } /** - * The {@link RuleKey} of the issue. - */ - Issue ruleKey(RuleKey ruleKey); - - /** * The {@link RuleKey} of this issue. */ RuleKey ruleKey(); /** - * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}. - */ - Issue onFile(InputFile file); - - /** - * The {@link InputDir} the issue belongs to. For global issues call {@link #onProject()}. - */ - Issue onDir(InputDir inputDir); - - /** - * Tell that the issue is global to the project. - */ - Issue onProject(); - - /** * The {@link InputPath} this issue belongs to. Returns null if issue is global to the project. */ @CheckForNull InputPath inputPath(); /** - * Line of the issue. Only available for {@link #onFile(InputFile)} issues. - * If no line is specified it means that issue is global to the file. - */ - Issue atLine(int line); - - /** * Line of the issue. Null for global issues and issues on directories. Can also be null * for files (issue global to the file). */ @@ -90,11 +59,6 @@ public interface Issue { Integer line(); /** - * Effort to fix the issue. - */ - Issue effortToFix(@Nullable Double effortToFix); - - /** * Effort to fix the issue. Used by technical debt model. */ @CheckForNull @@ -103,30 +67,13 @@ public interface Issue { /** * Message of the issue. */ - Issue message(String message); - - /** - * Message of the issue. - */ @CheckForNull String message(); /** - * Override severity of the issue. - * Setting a null value or not calling this method means to use severity configured in quality profile. - */ - Issue overrideSeverity(@Nullable Severity severity); - - /** * Overriden severity. */ @CheckForNull Severity overridenSeverity(); - /** - * Save the issue. If rule key is unknow or rule not enabled in the current quality profile then a warning is logged but no exception - * is thrown. - */ - void save(); - } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java new file mode 100644 index 00000000000..8819fc23b25 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java @@ -0,0 +1,85 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.api.batch.sensor.issue; + +import org.sonar.api.batch.fs.InputDir; +import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.sensor.Sensor; +import org.sonar.api.batch.sensor.issue.Issue.Severity; +import org.sonar.api.rule.RuleKey; + +import javax.annotation.Nullable; + +/** + * Represents an issue detected by a {@link Sensor}. + * + * @since 5.1 + */ +public interface NewIssue { + + /** + * The {@link RuleKey} of the issue. + */ + NewIssue ruleKey(RuleKey ruleKey); + + /** + * The {@link InputFile} the issue belongs to. For global issues call {@link #onProject()}. + */ + NewIssue onFile(InputFile file); + + /** + * The {@link InputDir} the issue belongs to. For global issues call {@link #onProject()}. + */ + NewIssue onDir(InputDir inputDir); + + /** + * Tell that the issue is global to the project. + */ + NewIssue onProject(); + + /** + * Line of the issue. Only available for {@link #onFile(InputFile)} issues. + * If no line is specified it means that issue is global to the file. + */ + NewIssue atLine(int line); + + /** + * Effort to fix the issue. + */ + NewIssue effortToFix(@Nullable Double effortToFix); + + /** + * Message of the issue. + */ + NewIssue message(String message); + + /** + * Override severity of the issue. + * Setting a null value or not calling this method means to use severity configured in quality profile. + */ + NewIssue overrideSeverity(@Nullable Severity severity); + + /** + * Save the issue. If rule key is unknown or rule not enabled in the current quality profile then a warning is logged but no exception + * is thrown. + */ + void save(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index df4779a4894..c029722eb9d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -19,21 +19,23 @@ */ package org.sonar.api.batch.sensor.issue.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.sonar.api.batch.fs.InputDir; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.InputPath; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.issue.Issue; +import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.internal.Uuids; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -public class DefaultIssue extends DefaultStorable implements Issue { +public class DefaultIssue extends DefaultStorable implements Issue, NewIssue { private static final String INPUT_DIR_SHOULD_BE_NON_NULL = "InputDir should be non null"; private static final String INPUT_FILE_SHOULD_BE_NON_NULL = "InputFile should be non null"; @@ -110,7 +112,7 @@ public class DefaultIssue extends DefaultStorable implements Issue { } @Override - public Issue overrideSeverity(@Nullable Severity severity) { + public DefaultIssue overrideSeverity(@Nullable Severity severity) { this.overridenSeverity = severity; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java index a6e4a0021fa..e798ce64fde 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasure.java @@ -19,12 +19,13 @@ */ package org.sonar.api.batch.sensor.measure.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java index 5580f881f1a..8973939afe3 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java @@ -19,13 +19,13 @@ */ package org.sonar.api.batch.sensor.issue.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.rule.RuleKey; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java index a4e5c4afb8e..6dae7fc2dbf 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java @@ -19,13 +19,13 @@ */ package org.sonar.api.batch.sensor.measure.internal; +import org.sonar.api.batch.sensor.internal.SensorStorage; + import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.measures.CoreMetrics; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; |