package org.sonar.api.batch.sensor.internal;
import com.google.common.base.Preconditions;
+import javax.annotation.Nullable;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.batch.fs.InputFile;
-
-import javax.annotation.Nullable;
public abstract class DefaultStorable {
- protected transient final SensorStorage storage;
+ protected final transient SensorStorage storage;
private transient boolean saved = false;
public DefaultStorable() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
- protected void validateLineArgument(InputFile inputFile, int line, String label) {
- Preconditions.checkArgument(line > 0 && line <= inputFile.lines(), "Invalid " + label + ": " + line + ". File " + inputFile + " has " + inputFile.lines()
- + " lines.");
- }
-
}
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.coverage.CoverageType;
import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
// Computed by LinesSensor
CoreMetrics.LINES);
- private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.<String>asList(
+ private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.asList(
CoreMetrics.DEPENDENCY_MATRIX_KEY,
CoreMetrics.DIRECTORY_CYCLES_KEY,
CoreMetrics.DIRECTORY_EDGES_WEIGHT_KEY,
private final Settings settings;
public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues,
- Settings settings, FileSystem fs, ActiveRules activeRules,
+ Settings settings,
CoverageExclusions coverageExclusions, BatchComponentCache componentCache, ReportPublisher reportPublisher, MeasureCache measureCache, SonarCpdBlockIndex index) {
this.metricFinder = metricFinder;
this.moduleIssues = moduleIssues;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
import org.sonar.api.config.Settings;
import org.sonar.api.measures.CoreMetrics;
@Rule
public ExpectedException thrown = ExpectedException.none();
- private ActiveRules activeRules;
- private DefaultFileSystem fs;
- private DefaultSensorStorage sensorStorage;
+ private DefaultSensorStorage underTest;
private Settings settings;
private ModuleIssues moduleIssues;
private Project project;
private BatchComponentCache resourceCache;
@Before
- public void prepare() throws Exception {
- activeRules = new ActiveRulesBuilder().build();
- fs = new DefaultFileSystem(temp.newFolder().toPath());
+ public void prepare() {
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
CoverageExclusions coverageExclusions = mock(CoverageExclusions.class);
when(coverageExclusions.accept(any(Resource.class), any(Measure.class))).thenReturn(true);
resourceCache = new BatchComponentCache();
- sensorStorage = new DefaultSensorStorage(metricFinder,
- moduleIssues, settings, fs, activeRules, coverageExclusions, resourceCache, mock(ReportPublisher.class), measureCache, mock(SonarCpdBlockIndex.class));
+ underTest = new DefaultSensorStorage(metricFinder,
+ moduleIssues, settings, coverageExclusions, resourceCache, mock(ReportPublisher.class), measureCache, mock(SonarCpdBlockIndex.class));
}
@Test
- public void shouldFailIfUnknowMetric() {
+ public void shouldFailIfUnknownMetric() {
InputFile file = new DefaultInputFile("foo", "src/Foo.php");
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Unknow metric with key: lines");
- sensorStorage.store(new DefaultMeasure()
+ underTest.store(new DefaultMeasure()
.on(file)
.forMetric(CoreMetrics.LINES)
.withValue(10));
Resource sonarFile = File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
resourceCache.add(sonarFile, null).setInputComponent(file);
when(measureCache.put(eq(sonarFile), argumentCaptor.capture())).thenReturn(null);
- sensorStorage.store(new DefaultMeasure()
+ underTest.store(new DefaultMeasure()
.on(file)
.forMetric(CoreMetrics.NCLOC)
.withValue(10));
ArgumentCaptor<org.sonar.api.measures.Measure> argumentCaptor = ArgumentCaptor.forClass(org.sonar.api.measures.Measure.class);
when(measureCache.put(eq(project), argumentCaptor.capture())).thenReturn(null);
- sensorStorage.store(new DefaultMeasure()
+ underTest.store(new DefaultMeasure()
.on(module)
.forMetric(CoreMetrics.NCLOC)
.withValue(10));