diff options
6 files changed, 51 insertions, 25 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java index 55977a1c102..fe86e2c5414 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java @@ -154,12 +154,16 @@ public class DefaultDecoratorContext implements DecoratorContext { public void deleteEvent(Event event) { index.deleteEvent(event); } - - public DefaultDecoratorContext saveViolation(Violation violation) { + + public DefaultDecoratorContext saveViolation(Violation violation, boolean force) { if (violation.getResource() == null) { violation.setResource(resource); } - index.addViolation(violation); + index.addViolation(violation, force); return this; } + + public DefaultDecoratorContext saveViolation(Violation violation) { + return saveViolation(violation, false); + } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java index f1f2921e570..24c70220e9d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java @@ -19,6 +19,11 @@ */ package org.sonar.batch; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; + import org.sonar.api.batch.Event; import org.sonar.api.batch.SensorContext; import org.sonar.api.design.Dependency; @@ -31,11 +36,6 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Violation; import org.sonar.batch.index.DefaultIndex; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; - public class DefaultSensorContext implements SensorContext { private DefaultIndex index; @@ -72,7 +72,7 @@ public class DefaultSensorContext implements SensorContext { public String saveResource(Resource resource) { Resource persistedResource = index.addResource(resource); - if (persistedResource!=null) { + if (persistedResource != null) { return persistedResource.getEffectiveKey(); } return null; @@ -94,15 +94,19 @@ public class DefaultSensorContext implements SensorContext { return index.addMeasure(resourceOrProject(resource), measure); } - public void saveViolation(Violation violation) { - if (violation.getResource()==null) { + public void saveViolation(Violation violation, boolean force) { + if (violation.getResource() == null) { violation.setResource(resourceOrProject(violation.getResource())); } - index.addViolation(violation); + index.addViolation(violation, force); + } + + public void saveViolation(Violation violation) { + saveViolation(violation, false); } public void saveViolations(Collection<Violation> violations) { - if (violations!=null) { + if (violations != null) { for (Violation violation : violations) { saveViolation(violation); } @@ -150,6 +154,6 @@ public class DefaultSensorContext implements SensorContext { } private Resource resourceOrProject(Resource resource) { - return (resource!=null ? resource : project); + return (resource != null ? resource : project); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index bc333868624..927177d553e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -373,10 +373,6 @@ public final class DefaultIndex extends SonarIndex { return bucket.getViolations(); } - public void addViolation(Violation violation) { - addViolation(violation, false); - } - public void addViolation(Violation violation, boolean force) { Bucket bucket; Resource resource = violation.getResource(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java index 8d3d14f2837..837cb557978 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorContext.java @@ -108,6 +108,13 @@ public interface DecoratorContext { */ List<Violation> getViolations(); + /** + * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. + * + * @since 2.5 + * @param force allows to force creation of violation even if it was supressed by {@link org.sonar.api.rules.ViolationFilter} + */ + DecoratorContext saveViolation(Violation violation, boolean force); /** * Save a coding rule violation. The decorator which calls this method must be depended upon BatchBarriers.END_OF_VIOLATIONS_GENERATION. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index 0c6e13c6d81..e1082ecdf3e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -103,11 +103,19 @@ public interface SensorContext { /** * Save a coding rule violation. + * + * @since 2.5 + * @param force allows to force creation of violation even if it was supressed by {@link org.sonar.api.rules.ViolationFilter} + */ + void saveViolation(Violation violation, boolean force); + + /** + * Save a coding rule violation. */ void saveViolation(Violation violation); /** - * Saves a list of violations + * Saves a list of violations. */ void saveViolations(Collection<Violation> violations); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java index 1fdddb46bc7..de6d6e1f670 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java @@ -19,6 +19,11 @@ */ package org.sonar.api.batch; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; + import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; @@ -29,11 +34,6 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Violation; import org.sonar.graph.DirectedGraphAccessor; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; - public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> { public abstract Project getProject(); @@ -54,7 +54,14 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe public abstract void setSource(Resource resource, String source); - public abstract void addViolation(Violation violation); + /** + * @since 2.5 + */ + public abstract void addViolation(Violation violation, boolean force); + + public final void addViolation(Violation violation) { + addViolation(violation, false); + } public abstract Measure addMeasure(Resource resource, Measure measure); |