Skip to content

Commit

Permalink
SONAR-6368 Remove deprecated violation API
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jul 24, 2015
1 parent 94c8b93 commit 0d9baa8
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.sensor.DefaultSensorContext;
import org.sonar.batch.sensor.coverage.CoverageExclusions;
Expand Down Expand Up @@ -171,28 +170,6 @@ public Measure saveMeasure(Resource resource, Measure measure) {
}
}

@Override
public void saveViolation(Violation violation, boolean force) {
if (violation.getResource() == null) {
violation.setResource(resourceOrProject(violation.getResource()));
}
index.addViolation(violation, force);
}

@Override
public void saveViolation(Violation violation) {
saveViolation(violation, false);
}

@Override
public void saveViolations(Collection<Violation> violations) {
if (violations != null) {
for (Violation violation : violations) {
saveViolation(violation);
}
}
}

@Override
public Dependency saveDependency(Dependency dependency) {
return null;
Expand Down
56 changes: 0 additions & 56 deletions sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.batch.sensor.issue.NewIssueLocation;
import org.sonar.api.batch.sensor.issue.internal.DefaultIssue;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
Expand All @@ -52,9 +48,6 @@
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.batch.DefaultProjectTree;
import org.sonar.batch.scan.measure.MeasureCache;
Expand Down Expand Up @@ -190,55 +183,6 @@ public Set<Resource> getResources() {
return buckets.keySet();
}

//
//
//
// VIOLATIONS
//
//
//

@Override
public void addViolation(Violation violation, boolean force) {
// Reload
Resource resource = getResource(violation.getResource());
if (resource == null) {
LOG.warn("Resource is not indexed. Ignoring violation {}", violation);
return;
}
BatchComponent component = componentCache.get(resource);

Rule rule = violation.getRule();
if (rule == null) {
LOG.warn("Rule is null. Ignoring violation {}", violation);
return;
}

// keep a limitation (bug?) of deprecated violations api : severity is always
// set by sonar. The severity set by plugins is overridden.
// This is not the case with issue api.

DefaultIssue newIssue = new DefaultIssue(sensorStorage);
NewIssueLocation newLocation = newIssue.newLocation();
if (component.isProjectOrModule()) {
newLocation.onProject();
} else if (component.isDir()) {
newLocation.onDir((InputDir) component.inputPath());
} else if (component.isFile()) {
InputFile inputFile = (InputFile) component.inputPath();
newLocation.onFile(inputFile);
if (violation.hasLineId()) {
newLocation.at(inputFile.selectLine(violation.getLineId()));
}
}
newLocation.message(violation.getMessage());

newIssue.addLocation(newLocation)
.forRule(RuleKey.of(violation.getRule().getRepositoryKey(), violation.getRule().getKey()))
.effortToFix(violation.getCost())
.save();
}

@Override
public String getSource(Resource reference) {
Resource resource = getResource(reference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
*/
package org.sonar.api.batch;

import java.util.Collection;
import java.util.List;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;

import java.util.Collection;
import java.util.List;

/**
* @since 1.10
Expand Down Expand Up @@ -93,22 +91,4 @@ public interface DecoratorContext {
@Deprecated
Dependency saveDependency(Dependency dependency);

// RULES
/**
* 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 suppressed by {@link org.sonar.api.rules.ViolationFilter}
* @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable}
*/
@Deprecated
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.
* @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable}
*/
@Deprecated
DecoratorContext saveViolation(Violation violation);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
*/
package org.sonar.api.batch;

import java.io.Serializable;
import java.util.Collection;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;

import javax.annotation.CheckForNull;

import java.io.Serializable;
import java.util.Collection;

/**
* @since 1.10
Expand Down Expand Up @@ -162,32 +159,6 @@ public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext
*/
Measure saveMeasure(Resource resource, Measure measure);

// ----------- RULE VIOLATIONS --------------

/**
* Save a coding rule violation.
*
* @param force allows to force creation of violation even if it was supressed by {@link org.sonar.api.rules.ViolationFilter}
* @since 2.5
* @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable}
*/
@Deprecated
void saveViolation(Violation violation, boolean force);

/**
* Save a coding rule violation.
* @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable}
*/
@Deprecated
void saveViolation(Violation violation);

/**
* Saves a list of violations.
* @deprecated in 3.6, replaced by {@link org.sonar.api.issue.Issuable}
*/
@Deprecated
void saveViolations(Collection<Violation> violations);

// ----------- DEPENDENCIES BETWEEN RESOURCES --------------

/**
Expand Down
22 changes: 2 additions & 20 deletions sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
*/
package org.sonar.api.batch;

import java.util.Collection;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.design.Dependency;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.Violation;

import javax.annotation.CheckForNull;

import java.util.Collection;

/**
* @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
Expand Down Expand Up @@ -115,21 +112,6 @@ public abstract class SonarIndex {
@CheckForNull
public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);

/**
* @since 2.5
* @deprecated in 3.6
*/
@Deprecated
public abstract void addViolation(Violation violation, boolean force);

/**
* @deprecated in 3.6
*/
@Deprecated
public final void addViolation(Violation violation) {
addViolation(violation, false);
}

/**
* Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
* indexed before. Next versions will deactivate this automatic indexation.
Expand Down
Loading

0 comments on commit 0d9baa8

Please sign in to comment.